From d3edeae44043f9b0d4c01c75e424d67fde200ed5 Mon Sep 17 00:00:00 2001 From: jstrating Date: Thu, 25 Jan 2018 14:40:44 +0100 Subject: [PATCH 1/2] Add edit group functionality --- .../app/components/teacherCard.component.js | 70 +++++++++++++++++-- .../components/userChipsInput.component.js | 8 ++- .../app/dialogs/editGroupDialog.tmpl.html | 66 ++++++++++++++++- src/main/resources/public/app/js/groups.js | 3 + .../public/app/services/group.service.js | 13 ++++ 5 files changed, 153 insertions(+), 7 deletions(-) diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index 365ef1a..77ec92d 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -11,15 +11,22 @@ function teacherCardCtrl($scope, GroupService, $state, $mdDialog, API) { }; ctrl.gradeGroup = () => { - $state.transitionTo("app.groupGrade", {groupId: ctrl.group.id}); + $state.transitionTo("app.groupGrade", { + groupId: ctrl.group.id + }); }; ctrl.finalGroupView = () => { - $state.transitionTo("app.finalGroupOverview", {groupId: ctrl.group.id}); + $state.transitionTo("app.finalGroupOverview", { + groupId: ctrl.group.id + }); }; ctrl.editGroup = (ev) => { $mdDialog.show({ + locals: { + group: ctrl.group + }, bindToController: true, controller: EditGroupDialogController, templateUrl: '/app/dialogs/editGroupDialog.tmpl.html', @@ -90,13 +97,66 @@ function teacherCardCtrl($scope, GroupService, $state, $mdDialog, API) { }; } -function EditGroupDialogController($scope, $mdDialog) { +function EditGroupDialogController($scope, $mdDialog, EducationService, group, GroupService, $mdToast) { + $scope.group = group; + $scope.chosenEducation = group.course.education.id; + $scope.courseOptions = []; + $scope.educationOptions = []; + + EducationService.getEducations().then((response) => { + $scope.educationOptions = response.data; + }) + $scope.$watch('chosenEducation', () => { + $scope.courseOptions = null; + if ($scope.chosenEducation !== null) { + EducationService.getCoursesByEducation($scope.chosenEducation).then((response) => { + $scope.courseOptions = response.data; + }) + } + }); + + $scope.vm = { + formData: { + groupName: group.groupName, + startYear: group.startYear, + endYear: group.endYear, + users: group.users, + course: { + id: group.course.id, + education: { + id: group.course.education.id + } + }, + period: group.period, + }, + }; + $scope.usersChange = (val) => { + $scope.vm.formData.users = val; + }; + $scope.hide = () => { $mdDialog.hide(); }; - $scope.close = () => { - $mdDialog.close(); + $scope.cancel = () => { + $mdDialog.cancel(); }; + $scope.showSimpleToast = () => { + $mdToast.show( + $mdToast.simple() + .textContent('Edited Group!') + .hideDelay(3000) + ); + }; + $scope.edit = () => { + if (Object.keys($scope.vm.formData.period).length !== 0 && $scope.vm.formData.users.length !== 0 && + $scope.vm.formData.groupName != null && $scope.vm.formData.startYear != null && $scope.vm.formData.endYear != null && + $scope.vm.formData.course != null) { + GroupService.editGroup($scope.vm.formData, $scope.group.id); + GroupService.editGroupUsers($scope.vm.formData.users, $scope.group.id); + $scope.showSimpleToast(); + $scope.hide(); + } + } } app.component('teacherCard', { diff --git a/src/main/resources/public/app/components/userChipsInput.component.js b/src/main/resources/public/app/components/userChipsInput.component.js index f483be9..1cb0df3 100644 --- a/src/main/resources/public/app/components/userChipsInput.component.js +++ b/src/main/resources/public/app/components/userChipsInput.component.js @@ -1,12 +1,18 @@ app.component('userChipsInput', { templateUrl: '/app/components/userChipsInput.component.html', controller: userChipsInputCtrl, + bindings: { + selectedUsers: '<', + } }); function userChipsInputCtrl(UserService, $scope) { - this.userArray = []; this.users = []; + + $scope.$watchCollection('$ctrl.selectedUsers', (users) => { + this.users = users; + }); $scope.$watchCollection('$ctrl.users', (users) => { $scope.$parent.usersChange(users); diff --git a/src/main/resources/public/app/dialogs/editGroupDialog.tmpl.html b/src/main/resources/public/app/dialogs/editGroupDialog.tmpl.html index 0057bcb..4bba347 100644 --- a/src/main/resources/public/app/dialogs/editGroupDialog.tmpl.html +++ b/src/main/resources/public/app/dialogs/editGroupDialog.tmpl.html @@ -10,6 +10,70 @@

Edit Group

- Work in progress +
+
+ + + +
+
You must supply a group name.
+
+
+
+ + + +
+
You must supply a starting year.
+
+
+ + + +
+
You must supply a ending year.
+
+
+
+
+ + + + {{education.name}} + + + + + + + {{course.name}} + + + +
+

Periods

+
+ + + Q1 + + + Q2 + + + Q3 + + + Q4 + + +
+ + + + Edit group + + +
\ No newline at end of file diff --git a/src/main/resources/public/app/js/groups.js b/src/main/resources/public/app/js/groups.js index 853e9d3..bb5b36f 100644 --- a/src/main/resources/public/app/js/groups.js +++ b/src/main/resources/public/app/js/groups.js @@ -81,6 +81,9 @@ app.controller('TeacherGroupsCtrl', function ($scope, $mdDialog, UserService, Gr $scope.hide = () => { $mdDialog.hide(); } + $scope.cancel = () => { + $mdDialog.cancel(); + } $scope.create = () => { if (Object.keys($scope.vm.formData.period).length !== 0 && $scope.vm.formData.users.length !== 0 && $scope.vm.formData.groupName != null && $scope.vm.formData.startYear != null && $scope.vm.formData.endYear != null && diff --git a/src/main/resources/public/app/services/group.service.js b/src/main/resources/public/app/services/group.service.js index c97fdae..dc78756 100644 --- a/src/main/resources/public/app/services/group.service.js +++ b/src/main/resources/public/app/services/group.service.js @@ -25,6 +25,19 @@ app.factory('GroupService', function (API) { }); }; + this.editGroup = (data, groupId) => { + return API.patch({ + path: `groups/${groupId}`, + data + }) + } + this.editGroupUsers = (users, groupId) => { + return API.patch({ + path: `groups/${groupId}/users`, + data: users + }) + } + this.getGradingStatus = (groupId) => { return API.get({ path: `grades/status/groups/${groupId}` From 93feb451aab97f04518e429287874f5eaa0a6a5f Mon Sep 17 00:00:00 2001 From: jstrating Date: Thu, 25 Jan 2018 19:38:03 +0100 Subject: [PATCH 2/2] remove unused calls --- .../public/app/components/teacherCard.component.js | 1 - src/main/resources/public/app/services/group.service.js | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index 77ec92d..c5f17a6 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -152,7 +152,6 @@ function EditGroupDialogController($scope, $mdDialog, EducationService, group, G $scope.vm.formData.groupName != null && $scope.vm.formData.startYear != null && $scope.vm.formData.endYear != null && $scope.vm.formData.course != null) { GroupService.editGroup($scope.vm.formData, $scope.group.id); - GroupService.editGroupUsers($scope.vm.formData.users, $scope.group.id); $scope.showSimpleToast(); $scope.hide(); } diff --git a/src/main/resources/public/app/services/group.service.js b/src/main/resources/public/app/services/group.service.js index dc78756..72e101c 100644 --- a/src/main/resources/public/app/services/group.service.js +++ b/src/main/resources/public/app/services/group.service.js @@ -31,12 +31,6 @@ app.factory('GroupService', function (API) { data }) } - this.editGroupUsers = (users, groupId) => { - return API.patch({ - path: `groups/${groupId}/users`, - data: users - }) - } this.getGradingStatus = (groupId) => { return API.get({