Skip to content

Commit

Permalink
Delete a member from a group. I moved around some files for display g…
Browse files Browse the repository at this point in the history
…roup. Also added Underscore. So please do a bower install when you pull
  • Loading branch information
jwoo12 committed Mar 22, 2016
1 parent 7db344f commit 0729a5b
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

</head>
<body>
<h1 style="text-align: center;">Groups</h1>
<h1 style="text-align: center;">Group Details</h1>

<div class="editMember" style="margin-left: 20px;">
<button type="button" class="btn btn-danger" style="float:right; margin-right:30px;"> DELETE GROUP </button>

<div class="addMember" style="">
<div class="form-group">
<label for="addMemberInput">Add a member</label>
Expand All @@ -38,7 +40,8 @@ <h1 style="text-align: center;">Groups</h1>
<table class="table" style="margin-left: 20px;">
<thead>
<tr>
<th>{{group.name}} </th>
<th>Members of {{group_name}}</th>
<th>Date added </th>
</tr>
</thread>
<tbody>
Expand Down
82 changes: 82 additions & 0 deletions app/displayGroup/displayGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
angular.module("myApp.displayGroups", ["ngRoute", "LocalStorageModule", "myApp.groups.groupsHandler"])

.config(["$routeProvider", function($routeProvider) {
$routeProvider.when("/displayGroup", {
templateUrl: "displayGroup/displayGroup.html",
controller: "displaygroupsController"
});
}])

.controller("displaygroupsController", function($scope, $location, localStorageService, groupsHandler) {
var usernameFromStorage,
storageKey = "user",
selected_group = groupsHandler.curr_group;

$scope.groups = [];

function getItem(key) {
return localStorageService.get(key);
};

if(!getItem(storageKey)){
//User has not logged in yet so redirect to login
$location.url("/login");
}else{
usernameFromStorage = getItem(storageKey);
}

function getMembers(groupID) {
groupsHandler.getMembers(groupID, function(result){
var index = 0;
if(result.data.success){
for(index; index < result.data.results.length; index++){
$scope.groups.push({"name": result.data.results[index][1], "date": result.data.results[index][0]});
}
console.log($scope.groups);
}else{
alert("Error loading group. Please try again.");
}
})
};

if(!selected_group){
$location.url("/groups");
}else{
console.log(selected_group);
$scope.group_name = selected_group.name;
// $scope.groups = [];
getMembers(selected_group.id);
// console.log($scope.groups);
}

$scope.addMember = function () {
if($scope.addMemberName){
groupsHandler.addMember(selected_group.id, $scope.addMemberName, function(result){
if(result.data.success){
$scope.groups.push({"name": $scope.addMemberName, "date": selected_group.id});
}else{
alert("Error adding member. Please try again with a valid username.");
}
});
}else{
alert("Please type a valid username to be added");
}
};

$scope.removeMember = function () {
if($scope.removeMemberName){
groupsHandler.deleteMember(selected_group.id, $scope.removeMemberName, function(result){
if(result.data.success){
$scope.groups.splice(_.indexOf($scope.groups, _.findWhere($scope.groups, { "name" : $scope.removeMemberName})), 1);
}else{
alert("Error deleting member. Please try again with a valid username.");
}
});
}else{
alert("Please type a valid username to be added");
}
};



});
41 changes: 0 additions & 41 deletions app/groups/displayGroup/displayGroup.js

This file was deleted.

3 changes: 2 additions & 1 deletion app/groups/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ angular.module("myApp.groups", ["ngRoute", "LocalStorageModule", "myApp.groups.g

$scope.getSelected = function(group) {
console.log(group);
$location.url("/displaygroups");
groupsHandler.curr_group = group;
$location.url("/displayGroup");
};

$scope.addGroup = function () {
Expand Down
42 changes: 42 additions & 0 deletions app/groups/groupsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,46 @@ angular.module("myApp.groups.groupsHandler", [])
});
};

this.getMembers = function (groupID, callback) {
$http({
url: SERVICE_BASE_URL + "displayGroup",
method: "GET",
params: {groupID: groupID}
})
.then(function(result) {
return callback(result);
},
function(result) { // optional
return callback(result);
});
};

this.addMember = function (groupid, username, callback) {
$http({
url: SERVICE_BASE_URL + "displayGroup",
method: "POST",
data: {group_id: groupid, user_name: username, date_added: null, notice: null}
})
.then(function(result) {
return callback(result);
},
function(result) { // optional
return callback(result);
});
};

this.deleteMember = function (groupid, username, callback) {
$http({
url: SERVICE_BASE_URL + "deleteMember",
method: "POST",
data: {group_id: groupid, user_name: username}
})
.then(function(result) {
return callback(result);
},
function(result) { // optional
return callback(result);
});
};

});
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
Expand Down Expand Up @@ -30,7 +31,7 @@
<script src="search/searchHandler.js"></script>
<script src="groups/groups.js"></script>
<script src="groups/groupsHandler.js"></script>
<script src="groups/displayGroup/displayGroup.js"></script>
<script src="displayGroup/displayGroup.js"></script>
<script src="analysis/analysis.js"></script>
<script src="analysis/analysisHandler.js"></script>
</body>
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"angular": "^1.5.0",
"angular-route": "~1.5.0",
"angular-local-storage": "^0.2.5"
"angular-local-storage": "^0.2.5",
"underscore": "^1.8.3"
}
}
106 changes: 106 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ process.on('SIGINT', function() {
process.exit();
});



app.post("/login", function (req, res) {
console.log(util.inspect(req.body, {showHidden: false, depth: null}));

Expand Down Expand Up @@ -105,6 +107,34 @@ app.post("/login", function (req, res) {
);
});

// app.get("/displayGroup", function(req, res){
// var DBQueryString =
// "SELECT * " +
// "FROM GROUP_LISTS " +
// "WHERE GROUP_ID = :groupID" ,
// DBQueryParam = {groupID: req.query.groupID};
//
// oracledb.getConnection(dbConfig, function (err, connection) {
// if (err) {
// connectionError(err, res);
// return;
// }
// connection.execute(DBQueryString, DBQueryParam,
// {autoCommit: true},
// function (err, result) {
// if (err) {
// executeError(err, res);
// } else {
// // console.log(util.inspect(result, {showHidden: false, depth: null}));
// res.send({success: true, results: result.rows});
// }
// doRelease(connection);
// }
// );
// });
// });


app.post("/groupid", function(req, res){
oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
Expand Down Expand Up @@ -140,8 +170,84 @@ app.post("/groupid", function(req, res){
);
}
);
});

app.route("/displayGroup")
.get(function(req, res){
var DBQueryString =
"SELECT * " +
"FROM GROUP_LISTS " +
"WHERE GROUP_ID = :groupID" ,
DBQueryParam = {groupID: req.query.groupID};

oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
{autoCommit: true},
function (err, result) {
if (err) {
executeError(err, res);
} else {
res.send({success: true, results: result.rows});
}
doRelease(connection);
}
);
});
})
.post(function(req, res){
// console.log(util.inspect(req.body, {showHidden: false, depth: null}));
var DBQueryString =
"INSERT INTO GROUP_LISTS (GROUP_ID, FRIEND_ID, DATE_ADDED, NOTICE)" +
"VALUES (:group_id, :user_name, :date_added, :notice)" ,
DBQueryParam = {group_id: req.body.group_id, user_name: req.body.user_name, date_added: null, notice: null};

oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
{autoCommit: true},
function (err, result) {
if (err) {
executeError(err, res);
} else {
res.send({success: true, results: result.rows});
}
doRelease(connection);
}
);
});
});


app.post("/deleteMember" , function(req, res){
var DBQueryString =
"DELETE from GROUP_LISTS WHERE group_id = :group_id AND FRIEND_ID = :user_name" ,
DBQueryParam = {group_id: req.body.group_id, user_name: req.body.user_name};

oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
{autoCommit: true},
function (err, result) {
// console.log(util.inspect(result, {showHidden: false, depth: null}));
if (err) {
executeError(err, res);
} else {
res.send({success: true});
}
doRelease(connection);
}
);
});
});

app.route("/groups")
Expand Down

0 comments on commit 0729a5b

Please sign in to comment.