From a822df5d16bbefc9258814ce589cf86f9c2a03ef Mon Sep 17 00:00:00 2001 From: Manatsawin Hanmongkolchai Date: Mon, 7 Dec 2015 22:47:30 +0700 Subject: [PATCH 1/3] groupmanage: add/remove subgroup (close #114) --- ui/static/templates/groupfeed.html | 1 - ui/static/templates/groupmanage.html | 35 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ui/static/templates/groupfeed.html b/ui/static/templates/groupfeed.html index 45c027c..913241b 100644 --- a/ui/static/templates/groupfeed.html +++ b/ui/static/templates/groupfeed.html @@ -1,7 +1,6 @@
diff --git a/ui/static/templates/groupmanage.html b/ui/static/templates/groupmanage.html index 4602d0b..a0338b6 100644 --- a/ui/static/templates/groupmanage.html +++ b/ui/static/templates/groupmanage.html @@ -32,8 +32,33 @@
+ +
+ + + + + + + + + + + + + + + + +
NameAction
Name + +
+ Create subgroup +
+
+
-
+

What's this group about

@@ -54,6 +79,14 @@

Your activities?

+
+

Cover image

+ +
+ 945x200 pixels +
+
+

Directory

From 8e317444c2a310e0b0af6fa22a26848bc276153e Mon Sep 17 00:00:00 2001 From: smart2538 Date: Tue, 8 Dec 2015 03:04:45 +0700 Subject: [PATCH 2/3] delete subgroup --- group/views.py | 18 ++++++++++++++++-- ui/static/app/group.js | 15 +++++++++++++-- ui/static/templates/groupmanage.html | 8 ++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/group/views.py b/group/views.py index bc6aec1..9c5ea5b 100644 --- a/group/views.py +++ b/group/views.py @@ -419,20 +419,34 @@ def get(self, request, group_parent_id, format=None): def post(self, request, group_parent_id, format=None): parent_group = self.get_group(group_parent_id) - print parent_group try: sub_group = Group.objects.create( name=request.data.get('name'), type=1, description="Subgroup of"+parent_group.name, short_description="Subgroup of"+parent_group.name, activities="somthing", parent=parent_group ).save() - print sub_group return Response(sub_group) except Exception as inst: print type(inst) # the exception instance print inst # __str__ allows args to be printed directly raise Http404 + def put(self, request, group_parent_id, format=None): + parent_group = self.get_group(group_parent_id) + print request.data.get('group_id') + try: + sub_group = Group.objects.get(id=request.data.get('group_id')) + print sub_group + print sub_group.parent + print parent_group + if sub_group.parent == parent_group: + sub_group.delete() + return Response(status=status.HTTP_204_NO_CONTENT) + except Exception as inst: + print type(inst) # the exception instance + print inst # __str__ allows args to be printed directly + raise Http404 + class GroupPostPegination(APIView): diff --git a/ui/static/app/group.js b/ui/static/app/group.js index 577b308..669ef2e 100644 --- a/ui/static/app/group.js +++ b/ui/static/app/group.js @@ -78,7 +78,6 @@ app.controller('GroupFeedController', function($scope, $stateParams, $http, $loc } $http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){ - console.log(data); $scope.subgroups = data; }); @@ -150,7 +149,7 @@ app.controller('GroupInfoController', function($scope, $http, $location){ }); -app.controller('GroupManageController', function($scope, $http, $location){ +app.controller('GroupManageController', function($scope, $http, $location, $stateParams){ var groupID = $location.path().split('/')[2]; function fetchMember(){ $http.get('/api/group/'+groupID+'/member/accepted').then(function(data){ @@ -176,11 +175,23 @@ app.controller('GroupManageController', function($scope, $http, $location){ $scope.acceptMember = acceptMember; $scope.denyMember = denyMember; + $scope.deleteSubgroup = function (id){ + data = { + group_id : id + }; + $http.put('/api/group/'+ $stateParams.id + '/subgroup',data).success(function(data){ + }); + + }; $http.get('/api/group/'+groupID).then(function(data){ $scope.group = data.data; }); + $http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){ + $scope.subgroups = data; + }); + $scope.editInfo = function(){ $http.put('/api/group/'+groupID+'/edit/',$scope.group).success(function(data){ }); diff --git a/ui/static/templates/groupmanage.html b/ui/static/templates/groupmanage.html index a0338b6..360f769 100644 --- a/ui/static/templates/groupmanage.html +++ b/ui/static/templates/groupmanage.html @@ -42,10 +42,10 @@ - - Name + + {{subgroup.name}} - + @@ -145,4 +145,4 @@

Directory

- \ No newline at end of file + From 2f3a6100a48248abdf4cbd96d4dbd786477559a2 Mon Sep 17 00:00:00 2001 From: smart2538 Date: Tue, 8 Dec 2015 03:30:46 +0700 Subject: [PATCH 3/3] fetch group after delete --- ui/static/app/group.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/static/app/group.js b/ui/static/app/group.js index 669ef2e..9ae7175 100644 --- a/ui/static/app/group.js +++ b/ui/static/app/group.js @@ -159,8 +159,14 @@ app.controller('GroupManageController', function($scope, $http, $location, $stat $scope.groupMember_pending = data.data; }); } + function fetchSubgroup(){ + $http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){ + $scope.subgroups = data; + }); + } fetchMember(); + fetchSubgroup(); function acceptMember(pk){ $http.put('/api/group/'+groupID+'/member/'+ pk).then(function(data){ @@ -180,6 +186,7 @@ app.controller('GroupManageController', function($scope, $http, $location, $stat group_id : id }; $http.put('/api/group/'+ $stateParams.id + '/subgroup',data).success(function(data){ + fetchSubgroup(); }); }; @@ -188,9 +195,8 @@ app.controller('GroupManageController', function($scope, $http, $location, $stat $scope.group = data.data; }); - $http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){ - $scope.subgroups = data; - }); + + $scope.editInfo = function(){ $http.put('/api/group/'+groupID+'/edit/',$scope.group).success(function(data){