From 6f236f07b828b437a79611d082547f59b8a87e3f Mon Sep 17 00:00:00 2001 From: cassshh Date: Mon, 22 Jan 2018 12:42:44 +0100 Subject: [PATCH 01/30] Edit README --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96ee822..1ddcc07 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://travis-ci.com/Want100Cookies/GradeMaster.svg?token=sKpyGyXRMBtmPh6qJBuM&branch=develop)](https://travis-ci.com/Want100Cookies/GradeMaster) # GradeMaster -A small application to ease the grading of groups for teachers. +A small application to ease the grading of project groups for teachers. ### Features: - Teachers can assign and deadline a grade to a group @@ -10,3 +10,15 @@ A small application to ease the grading of groups for teachers. ### Documentation To view the documentation run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) + +### Setup +Docker is being used to run all the needed backend services: +``` +$ docker-compose up -d +``` + +To run the backend the following environment variables should exist: +- EMAIL_HOST +- EMAIL_PORT +- EMAIL_USERNAME +- EMAIL_PASSWORD \ No newline at end of file From 81d7baa710d855b1dac74ea6b32dd58f4cda0abf Mon Sep 17 00:00:00 2001 From: cassshh Date: Mon, 22 Jan 2018 15:41:57 +0100 Subject: [PATCH 02/30] Add software to README --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ddcc07..7895cf6 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,11 @@ To run the backend the following environment variables should exist: - EMAIL_HOST - EMAIL_PORT - EMAIL_USERNAME -- EMAIL_PASSWORD \ No newline at end of file +- EMAIL_PASSWORD + +### Requirements +- Java SDK >= 8.x +- NPM >= 5.x +- Node >= 9.x +- Docker >= 17.x +- Docker-compose >= 1.18.x \ No newline at end of file From a04e1107832ce60cf6bf63fe827f246229725aef Mon Sep 17 00:00:00 2001 From: Pascal Drewes Date: Tue, 23 Jan 2018 11:17:16 +0100 Subject: [PATCH 03/30] Add progress bar to teacherCard --- .../com/datbois/grademaster/model/Group.java | 35 ++++++++++++ .../app/components/teacherCard.component.html | 18 +++--- .../app/components/teacherCard.component.js | 55 +++++++------------ 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/datbois/grademaster/model/Group.java b/src/main/java/com/datbois/grademaster/model/Group.java index 587c151..ad23f3a 100644 --- a/src/main/java/com/datbois/grademaster/model/Group.java +++ b/src/main/java/com/datbois/grademaster/model/Group.java @@ -121,6 +121,41 @@ public void setGrades(List grades) { this.grades = grades; } + public Integer getGradingProgress() { + if (getGroupGrade() == null) { + return 0; + } + + Integer gradesFromTeachers = (int) getGrades() + .stream() + .filter(grade -> grade.getFromUser().hasAnyRole("TEACHER_ROLE")) + .count(); + + if (gradesFromTeachers > 0) { + return 100; + } + + if (getGrades().size() == 0) { + return 10; + } + + Integer gradesFromStudents = getGrades() + .stream() + .filter(grade -> grade.getFromUser().hasAnyRole("STUDENT_ROLE")) + .toArray() + .length; + + Double noStudents = (double) getUsers() + .stream() + .filter(user -> user.hasAnyRole("STUDENT_ROLE")) + .toArray() + .length; + + Double studentsThatGraded = gradesFromStudents / noStudents; + + return (int) (studentsThatGraded / noStudents * 100); + } + @JsonIgnore public Status getGradingStatusForUser(User user) { Status status; diff --git a/src/main/resources/public/app/components/teacherCard.component.html b/src/main/resources/public/app/components/teacherCard.component.html index e729c25..5e81aad 100644 --- a/src/main/resources/public/app/components/teacherCard.component.html +++ b/src/main/resources/public/app/components/teacherCard.component.html @@ -3,14 +3,14 @@
- {{groupName}} - + {{$ctrl.group.groupName}} + - + - +
@@ -20,17 +20,17 @@
- {{groupStatus}} + {{$ctrl.groupStatus}}
- {{groupGrade}} + {{$ctrl.group.groupGrade.grade || 'TBD'}}
-
+
{{member.name}},  
@@ -38,10 +38,10 @@ {{member.name}}
- GRADE + GRADE

-
+ \ No newline at end of file diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index 33dfec4..effbb20 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -1,40 +1,24 @@ -teacherCardCtrl = ($scope, GroupService, $state, $mdDialog) => { +function teacherCardCtrl($scope, GroupService, $state, $mdDialog) { var ctrl = this; - $scope.init = () => { - $scope.groupGrade = "TBD"; - $scope.groupStatus = "TBD"; - $scope.groupName; - $scope.groupMembers = []; - $scope.groupId = $scope.$ctrl.group.id; + ctrl.$onInit = () => { + ctrl.groupGrade = "TBD"; + ctrl.groupStatus = "TBD"; - GroupService.getGradingStatus($scope.$ctrl.group.id).then((response) => { - $scope.groupStatus = response.data.status; + GroupService.getGradingStatus(ctrl.group.id).then((response) => { + ctrl.groupStatus = response.data.status; }); + }; - // Check the group grade - if ($scope.$ctrl.group.groupGrade !== null) { - $scope.groupGrade = $scope.$ctrl.group.groupGrade.grade; - } - // Check the group name - if ($scope.$ctrl.group !== null) { - $scope.groupName = $scope.$ctrl.group.groupName; - } else { - $scope.groupName = "Couldn't resolve group name"; - } - // Check the group members - if ($scope.$ctrl.group.users !== null) { - $scope.groupMembers = $scope.$ctrl.group.users; - } - } - - $scope.gradeGroup = () => { + ctrl.gradeGroup = () => { $state.transitionTo("app.groupGrade", {groupId: $scope.groupId}); - } - $scope.finalGroupView = () => { + }; + + ctrl.finalGroupView = () => { $state.transitionTo("app.finalGroupOverview", {groupId: $scope.groupId}); - } - $scope.editGroup = (ev) => { + }; + + ctrl.editGroup = (ev) => { $mdDialog.show({ bindToController: true, controller: EditGroupDialogController, @@ -48,9 +32,9 @@ teacherCardCtrl = ($scope, GroupService, $state, $mdDialog) => { }, function () { console.log("close dialog"); }); - } + }; - $scope.deleteGroup = () => { + ctrl.deleteGroup = () => { let confirm = $mdDialog.confirm() .title("Are you sure?") .textContent("Are your sure you want to delete this group? You cannot recover this group after deleting it!") @@ -72,14 +56,15 @@ teacherCardCtrl = ($scope, GroupService, $state, $mdDialog) => { } } -function EditGroupDialogController($scope, $mdDialog, GroupService) { +function EditGroupDialogController($scope, $mdDialog) { $scope.hide = () => { $mdDialog.hide(); - } + }; $scope.close = () => { $mdDialog.close(); - } + }; } + app.component('teacherCard', { templateUrl: '/app/components/teacherCard.component.html', controller: teacherCardCtrl, From c36cdfecd6a48628edec4ee48a7b5514ac225784 Mon Sep 17 00:00:00 2001 From: Pascal Drewes Date: Tue, 23 Jan 2018 11:20:59 +0100 Subject: [PATCH 04/30] add Progress to groupCard --- .../app/components/groupCard.component.html | 18 +++++++++--------- .../app/components/teacherCard.component.html | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/resources/public/app/components/groupCard.component.html b/src/main/resources/public/app/components/groupCard.component.html index 7df02bd..2c123e1 100644 --- a/src/main/resources/public/app/components/groupCard.component.html +++ b/src/main/resources/public/app/components/groupCard.component.html @@ -3,7 +3,7 @@ {{$ctrl.name}} -
+
Status Group grade Your grade @@ -14,11 +14,11 @@
{{$ctrl.group.groupGrade.grade}} -
+
{{$ctrl.finalGrade}} -
- + +
@@ -29,11 +29,11 @@
{{member.name}} -
- + + GRADE -
- +
- + + \ No newline at end of file diff --git a/src/main/resources/public/app/components/teacherCard.component.html b/src/main/resources/public/app/components/teacherCard.component.html index 5e81aad..1ff7258 100644 --- a/src/main/resources/public/app/components/teacherCard.component.html +++ b/src/main/resources/public/app/components/teacherCard.component.html @@ -40,7 +40,6 @@ GRADE -
From f4a79a72db99f18cca3476684dbebad9c9c81751 Mon Sep 17 00:00:00 2001 From: Pascal Drewes Date: Tue, 23 Jan 2018 11:38:30 +0100 Subject: [PATCH 05/30] Add course and education name --- .../public/app/components/groupCard.component.html | 10 ++++++++-- .../public/app/components/groupCard.component.js | 13 +++---------- .../app/components/teacherCard.component.html | 8 +++++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/resources/public/app/components/groupCard.component.html b/src/main/resources/public/app/components/groupCard.component.html index 2c123e1..22dba42 100644 --- a/src/main/resources/public/app/components/groupCard.component.html +++ b/src/main/resources/public/app/components/groupCard.component.html @@ -2,8 +2,14 @@ - {{$ctrl.name}} -
+ + + {{$ctrl.group.course.education.name}} > + {{$ctrl.group.course.name}} > + + {{$ctrl.group.groupName}} + +
Status Group grade Your grade diff --git a/src/main/resources/public/app/components/groupCard.component.js b/src/main/resources/public/app/components/groupCard.component.js index deefa4e..e9271df 100644 --- a/src/main/resources/public/app/components/groupCard.component.js +++ b/src/main/resources/public/app/components/groupCard.component.js @@ -5,9 +5,6 @@ function GroupCardCtrl($state, StudentGroupsService, CourseService) { ctrl.groupMembers = []; ctrl.$onInit = () => { - - ctrl.name = ctrl.group.groupName; - StudentGroupsService.getFinalGroupGrade(ctrl.group.id, ctrl.user.id).then((response) => { if (response.data.grade) { ctrl.finalGrade = response.data.grade; @@ -38,23 +35,19 @@ function GroupCardCtrl($state, StudentGroupsService, CourseService) { } }); - CourseService.getCourse(ctrl.group.course.id).then(function(response){ - ctrl.course = response.data; - }) - ctrl.calculateGradeChange = function(groupGrade, finalGrade){ if (typeof finalGrade === "string") { ctrl.percentage = ""; return "TBD"; } - var diff = finalGrade - groupGrade; - var diffInPercentage = Math.round(diff / finalGrade * 100) + "%"; + const diff = finalGrade - groupGrade; + const diffInPercentage = Math.round(diff / finalGrade * 100) + "%"; if(diffInPercentage > 0){ ctrl.percentage = "negative"; return "+" + diffInPercentage; } - else if(diffInPercentage == 0){ + else if(diffInPercentage === 0){ ctrl.percentage = "equal"; return diffInPercentage; } diff --git a/src/main/resources/public/app/components/teacherCard.component.html b/src/main/resources/public/app/components/teacherCard.component.html index 1ff7258..320957e 100644 --- a/src/main/resources/public/app/components/teacherCard.component.html +++ b/src/main/resources/public/app/components/teacherCard.component.html @@ -3,7 +3,13 @@
- {{$ctrl.group.groupName}} + + + {{$ctrl.group.course.education.name}} > + {{$ctrl.group.course.name}} > + + {{$ctrl.group.groupName}} + From f1152ccd5ddc5c3dcb855749c2ee7584b55fdbde Mon Sep 17 00:00:00 2001 From: Danny Hooyer Date: Tue, 23 Jan 2018 13:07:08 +0100 Subject: [PATCH 06/30] Removed divider from Student Groups Overview --- .../resources/public/app/components/groupCard.component.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/public/app/components/groupCard.component.html b/src/main/resources/public/app/components/groupCard.component.html index 7df02bd..f5cfaee 100644 --- a/src/main/resources/public/app/components/groupCard.component.html +++ b/src/main/resources/public/app/components/groupCard.component.html @@ -32,8 +32,7 @@
GRADE -

- +
\ No newline at end of file From 21a6b817233c8307ce809f08c27020821823811c Mon Sep 17 00:00:00 2001 From: basvtholt Date: Tue, 23 Jan 2018 14:55:56 +0100 Subject: [PATCH 07/30] Commit to merge develop --- src/main/resources/data.sql | 6 ++- .../app/components/dashboard.component.js | 29 +++++++++----- .../dashboardGroupOverview.component.html | 4 ++ .../app/components/empty.component.html | 3 ++ .../public/app/components/empty.component.js | 3 ++ src/main/resources/public/app/js/app.js | 3 ++ .../public/app/pages/dashboard-teacher.html | 39 ++++++++++++++++++- .../resources/public/app/pages/dashboard.html | 4 +- .../resources/public/app/styles/dashboard.css | 12 ++++++ src/main/resources/public/index.html | 2 +- 10 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/public/app/components/dashboardGroupOverview.component.html create mode 100644 src/main/resources/public/app/components/empty.component.html create mode 100644 src/main/resources/public/app/components/empty.component.js diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 7ad942b..a8550ae 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,7 +1,8 @@ INSERT INTO `user` (`id`, `email`, `name`, `password`, `verified`, `reference_id`) VALUES (1, "john.doe@student.stenden.com", "John Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '123456'), (2, "jane.doe@stenden.com", "Jane Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '654321'), - (3, "admin@stenden.com", "Administrator", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '987555'); + (3, "admin@stenden.com", "Administrator", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '987555'), + (4, "test.doe@student.stenden.com", "John Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '123456'); INSERT INTO `role` (`id`, `code`, `label`) VALUES (1, "STUDENT_ROLE", "Student"), @@ -11,7 +12,8 @@ INSERT INTO `role` (`id`, `code`, `label`) VALUES INSERT INTO `user_roles` (`user_id`, `role_id`) VALUES (1, 1), (2, 2), - (3, 3); + (3, 3), + (4, 1); INSERT INTO `education` (`id`, `name`) VALUES (1, "INF"), diff --git a/src/main/resources/public/app/components/dashboard.component.js b/src/main/resources/public/app/components/dashboard.component.js index 7d5fec1..f82784f 100644 --- a/src/main/resources/public/app/components/dashboard.component.js +++ b/src/main/resources/public/app/components/dashboard.component.js @@ -1,5 +1,5 @@ -function DashboardCtrl($scope, StudentGroupsService, UserService){ - var ctrl = this; +function DashboardCtrl($scope, $state, StudentGroupsService, UserService, GroupService){ + let ctrl = this; $scope.init = function(){ ctrl.closed = 0; @@ -9,9 +9,13 @@ function DashboardCtrl($scope, StudentGroupsService, UserService){ UserService.getSelf().then(user => { ctrl.self = user; - StudentGroupsService.getStudentGroups(ctrl.self.data.id).then(function(response){ + GroupService.getGroupsByUserId(ctrl.self.data.id).then(function(response){ ctrl.groupsDetails = response.data; + if(ctrl.groupsDetails.length == 0){ + $state.transitionTo('app.empty'); + } + angular.forEach(ctrl.groupsDetails, function(value, key) { StudentGroupsService.getGradingStatus(value.id).then(function(response){ if(response.data.status == "CLOSED"){ @@ -19,7 +23,7 @@ function DashboardCtrl($scope, StudentGroupsService, UserService){ }else if(response.data.status == "OPEN"){ ctrl.open += 1; }else if(response.data.status == "PENDING"){ - $ctrl.pending += 1; + ctrl.pending += 1; } }) }); @@ -28,7 +32,11 @@ function DashboardCtrl($scope, StudentGroupsService, UserService){ } } -app.component('dashboardCourseOverview', { +app.component('dashboardProjectsOverview', { + templateUrl: '/app/components/dashboardProjectsOverview.component.html', + controller: DashboardCtrl +}) +.component('dashboardCourseOverview', { templateUrl: '/app/components/dashboardCourseOverview.component.html', controller: GroupCardCtrl, bindings: { @@ -36,10 +44,6 @@ app.component('dashboardCourseOverview', { group: '<', } }) -.component('dashboardProjectsOverview', { - templateUrl: '/app/components/dashboardProjectsOverview.component.html', - controller: DashboardCtrl -}) .component('dashboardGradeOverview', { templateUrl: '/app/components/dashboardGradeOverview.component.html', controller: GroupCardCtrl, @@ -47,4 +51,11 @@ app.component('dashboardCourseOverview', { user: '<', group: '<', } +}) +.component('dashboardGroupOverview', { + templateUrl: '/app/components/dashboardGroupOverview.component.html', + controller: DashboardCtrl, + bindings: { + group: '<' + } }); \ No newline at end of file diff --git a/src/main/resources/public/app/components/dashboardGroupOverview.component.html b/src/main/resources/public/app/components/dashboardGroupOverview.component.html new file mode 100644 index 0000000..ad25edf --- /dev/null +++ b/src/main/resources/public/app/components/dashboardGroupOverview.component.html @@ -0,0 +1,4 @@ +
+

Group

+ {{$ctrl.group}} +
diff --git a/src/main/resources/public/app/components/empty.component.html b/src/main/resources/public/app/components/empty.component.html new file mode 100644 index 0000000..4ef4de7 --- /dev/null +++ b/src/main/resources/public/app/components/empty.component.html @@ -0,0 +1,3 @@ +
+ Nothing to see here...yet +
\ No newline at end of file diff --git a/src/main/resources/public/app/components/empty.component.js b/src/main/resources/public/app/components/empty.component.js new file mode 100644 index 0000000..af36b67 --- /dev/null +++ b/src/main/resources/public/app/components/empty.component.js @@ -0,0 +1,3 @@ +app.component('empty', { + templateUrl: '/app/components/empty.component.html' +}) diff --git a/src/main/resources/public/app/js/app.js b/src/main/resources/public/app/js/app.js index 6a68f67..4e3268d 100644 --- a/src/main/resources/public/app/js/app.js +++ b/src/main/resources/public/app/js/app.js @@ -207,5 +207,8 @@ app.config(function ($stateProvider) { return AuthService.authenticate(); }, }, + }) + .state('app.empty', { + component: 'empty' }); }); \ No newline at end of file diff --git a/src/main/resources/public/app/pages/dashboard-teacher.html b/src/main/resources/public/app/pages/dashboard-teacher.html index 64834a2..24e58e5 100644 --- a/src/main/resources/public/app/pages/dashboard-teacher.html +++ b/src/main/resources/public/app/pages/dashboard-teacher.html @@ -1 +1,38 @@ -

Teacher Dashboard

\ No newline at end of file +
+
+
+ + + Projects Overview + + + +
+
+
+
+ + + Groups with finalized grade +
+ +
+
+
+
+
+ + + Groups without grade + + +
+
+ + + Groups that are grading + + +
+
+
\ No newline at end of file diff --git a/src/main/resources/public/app/pages/dashboard.html b/src/main/resources/public/app/pages/dashboard.html index e5790f2..a4b4060 100644 --- a/src/main/resources/public/app/pages/dashboard.html +++ b/src/main/resources/public/app/pages/dashboard.html @@ -1,4 +1,4 @@ -
+
@@ -15,7 +15,7 @@ Projects Overview - +
diff --git a/src/main/resources/public/app/styles/dashboard.css b/src/main/resources/public/app/styles/dashboard.css index 6f1a9f7..8bc5ba9 100644 --- a/src/main/resources/public/app/styles/dashboard.css +++ b/src/main/resources/public/app/styles/dashboard.css @@ -34,4 +34,16 @@ md-grid-list md-card table button{ } .grade{ font-size: 26px; +} +.empty-page-wrap{ + display: table; + width: 100%; + height: 90%; + text-align: center; +} +.empty-page-txt{ + color: rgba(0, 0, 0, 0.3); + display: table-cell; + vertical-align: middle; + font-size: 2.5em; } \ No newline at end of file diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index dcd6484..7991608 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -58,7 +58,7 @@ - + From e5d62e4a33910c28db3b0c464959305b2f309596 Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:07:56 +0100 Subject: [PATCH 08/30] Add lines to README. Refactor some code --- README.md | 8 ++++++ .../grademaster/GradeMasterApplication.java | 5 ++-- .../controller/NotificationController.java | 2 +- .../com/datbois/grademaster/model/Email.java | 3 +- .../datbois/grademaster/model/GroupGrade.java | 2 +- .../com/datbois/grademaster/model/Period.java | 5 +++- .../com/datbois/grademaster/model/Role.java | 5 +++- .../repository/GradeRepository.java | 1 - .../repository/GroupRepository.java | 2 +- .../repository/NotificationRepository.java | 3 +- .../repository/UserRepository.java | 1 - .../grademaster/service/EmailService.java | 1 - .../grademaster/service/GradeService.java | 4 +-- .../service/NotificationService.java | 1 - .../service/impl/NotificationServiceImpl.java | 1 - .../datbois/grademaster/util/CssInliner.java | 28 +++++++------------ .../grademaster/util/CsvGeneratorUtil.java | 1 - .../grademaster/AuthControllerTests.java | 1 - .../NotificationControllerTests.java | 14 ++++------ 19 files changed, 42 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 7895cf6..7078ddc 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ A small application to ease the grading of project groups for teachers. To view the documentation run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) ### Setup +##### Backend Docker is being used to run all the needed backend services: ``` $ docker-compose up -d @@ -22,6 +23,13 @@ To run the backend the following environment variables should exist: - EMAIL_PORT - EMAIL_USERNAME - EMAIL_PASSWORD +**For intellij; Edit configurations... > *Select configuration* > Environment variables** + +##### Frontend +``` +$ cd ./src/main/resources/public +$ npm install +``` ### Requirements - Java SDK >= 8.x diff --git a/src/main/java/com/datbois/grademaster/GradeMasterApplication.java b/src/main/java/com/datbois/grademaster/GradeMasterApplication.java index 13dc738..b199fc2 100644 --- a/src/main/java/com/datbois/grademaster/GradeMasterApplication.java +++ b/src/main/java/com/datbois/grademaster/GradeMasterApplication.java @@ -5,6 +5,7 @@ @SpringBootApplication public class GradeMasterApplication { - - public static void main(String[] args) { SpringApplication.run(GradeMasterApplication.class, args); } + public static void main(String[] args) { + SpringApplication.run(GradeMasterApplication.class, args); + } } diff --git a/src/main/java/com/datbois/grademaster/controller/NotificationController.java b/src/main/java/com/datbois/grademaster/controller/NotificationController.java index 485428b..cb9dbec 100644 --- a/src/main/java/com/datbois/grademaster/controller/NotificationController.java +++ b/src/main/java/com/datbois/grademaster/controller/NotificationController.java @@ -53,7 +53,7 @@ public Notification markNotificationSeen(Authentication authentication, @PathVar User user = ((UserDetails) authentication.getPrincipal()).getUser(); Notification notification = notificationService.findById(notificationId); - if(notification.getUser().getId().equals(user.getId())) { + if (notification.getUser().getId().equals(user.getId())) { notification.setSeen(true); } diff --git a/src/main/java/com/datbois/grademaster/model/Email.java b/src/main/java/com/datbois/grademaster/model/Email.java index b96a178..9b6027c 100644 --- a/src/main/java/com/datbois/grademaster/model/Email.java +++ b/src/main/java/com/datbois/grademaster/model/Email.java @@ -11,7 +11,8 @@ public class Email { private String link; private String linkText; - public Email(){} + public Email() { + } public Email(String to, String subject, String body) { this.to = to; diff --git a/src/main/java/com/datbois/grademaster/model/GroupGrade.java b/src/main/java/com/datbois/grademaster/model/GroupGrade.java index a8efeb2..1316e72 100644 --- a/src/main/java/com/datbois/grademaster/model/GroupGrade.java +++ b/src/main/java/com/datbois/grademaster/model/GroupGrade.java @@ -24,7 +24,7 @@ public class GroupGrade extends BaseModel { @ManyToOne(fetch = FetchType.LAZY) private User teacher; - @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") + @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") private DateTime deadline; // Needs this format: 1970-01-01T00:00:00.000+0000 public GroupGrade() { diff --git a/src/main/java/com/datbois/grademaster/model/Period.java b/src/main/java/com/datbois/grademaster/model/Period.java index 4e8dec5..390e0f8 100644 --- a/src/main/java/com/datbois/grademaster/model/Period.java +++ b/src/main/java/com/datbois/grademaster/model/Period.java @@ -1,5 +1,8 @@ package com.datbois.grademaster.model; public enum Period { - Q1, Q2, Q3, Q4; + Q1, + Q2, + Q3, + Q4 } \ No newline at end of file diff --git a/src/main/java/com/datbois/grademaster/model/Role.java b/src/main/java/com/datbois/grademaster/model/Role.java index 0defcc3..b962e5b 100644 --- a/src/main/java/com/datbois/grademaster/model/Role.java +++ b/src/main/java/com/datbois/grademaster/model/Role.java @@ -1,6 +1,9 @@ package com.datbois.grademaster.model; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.validation.constraints.NotNull; @Entity diff --git a/src/main/java/com/datbois/grademaster/repository/GradeRepository.java b/src/main/java/com/datbois/grademaster/repository/GradeRepository.java index 04fa291..0dd1431 100644 --- a/src/main/java/com/datbois/grademaster/repository/GradeRepository.java +++ b/src/main/java/com/datbois/grademaster/repository/GradeRepository.java @@ -1,6 +1,5 @@ package com.datbois.grademaster.repository; - import com.datbois.grademaster.model.Grade; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/datbois/grademaster/repository/GroupRepository.java b/src/main/java/com/datbois/grademaster/repository/GroupRepository.java index d5e0402..677d23f 100644 --- a/src/main/java/com/datbois/grademaster/repository/GroupRepository.java +++ b/src/main/java/com/datbois/grademaster/repository/GroupRepository.java @@ -6,5 +6,5 @@ @Repository public interface GroupRepository extends JpaRepository { - Group findByGroupNameContainingIgnoreCase(String groupName); + Group findById(Long id); } \ No newline at end of file diff --git a/src/main/java/com/datbois/grademaster/repository/NotificationRepository.java b/src/main/java/com/datbois/grademaster/repository/NotificationRepository.java index 6bc80f2..e68c825 100644 --- a/src/main/java/com/datbois/grademaster/repository/NotificationRepository.java +++ b/src/main/java/com/datbois/grademaster/repository/NotificationRepository.java @@ -1,11 +1,10 @@ package com.datbois.grademaster.repository; +import com.datbois.grademaster.model.Notification; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import com.datbois.grademaster.model.Notification; @Repository public interface NotificationRepository extends JpaRepository { - Notification findById(Long id); } diff --git a/src/main/java/com/datbois/grademaster/repository/UserRepository.java b/src/main/java/com/datbois/grademaster/repository/UserRepository.java index bf90ed6..6926074 100644 --- a/src/main/java/com/datbois/grademaster/repository/UserRepository.java +++ b/src/main/java/com/datbois/grademaster/repository/UserRepository.java @@ -6,7 +6,6 @@ import org.springframework.stereotype.Repository; import java.util.List; -import java.util.Set; @Repository public interface UserRepository extends JpaRepository { diff --git a/src/main/java/com/datbois/grademaster/service/EmailService.java b/src/main/java/com/datbois/grademaster/service/EmailService.java index 7eb2bed..ccba58c 100644 --- a/src/main/java/com/datbois/grademaster/service/EmailService.java +++ b/src/main/java/com/datbois/grademaster/service/EmailService.java @@ -5,7 +5,6 @@ import java.io.IOException; public interface EmailService { - void sendToEmailQueue(Email email); void sendEmail(Email email) throws IOException; diff --git a/src/main/java/com/datbois/grademaster/service/GradeService.java b/src/main/java/com/datbois/grademaster/service/GradeService.java index 7b7a0e7..eafec04 100644 --- a/src/main/java/com/datbois/grademaster/service/GradeService.java +++ b/src/main/java/com/datbois/grademaster/service/GradeService.java @@ -2,8 +2,8 @@ import com.datbois.grademaster.model.Grade; -public interface GradeService{ - Grade save (Grade grade); +public interface GradeService { + Grade save(Grade grade); Grade findById(Long id); diff --git a/src/main/java/com/datbois/grademaster/service/NotificationService.java b/src/main/java/com/datbois/grademaster/service/NotificationService.java index a25719e..7bd5521 100644 --- a/src/main/java/com/datbois/grademaster/service/NotificationService.java +++ b/src/main/java/com/datbois/grademaster/service/NotificationService.java @@ -5,7 +5,6 @@ import java.util.List; public interface NotificationService { - List findAll(); Notification save(Notification notification); diff --git a/src/main/java/com/datbois/grademaster/service/impl/NotificationServiceImpl.java b/src/main/java/com/datbois/grademaster/service/impl/NotificationServiceImpl.java index ce9bc4f..b793fad 100644 --- a/src/main/java/com/datbois/grademaster/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/datbois/grademaster/service/impl/NotificationServiceImpl.java @@ -7,7 +7,6 @@ import com.datbois.grademaster.service.EmailService; import com.datbois.grademaster.service.NotificationService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jms.core.JmsTemplate; import org.springframework.stereotype.Service; import java.util.List; diff --git a/src/main/java/com/datbois/grademaster/util/CssInliner.java b/src/main/java/com/datbois/grademaster/util/CssInliner.java index d05d9da..abd7830 100644 --- a/src/main/java/com/datbois/grademaster/util/CssInliner.java +++ b/src/main/java/com/datbois/grademaster/util/CssInliner.java @@ -1,26 +1,19 @@ package com.datbois.grademaster.util; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - +import com.steadystate.css.parser.CSSOMParser; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; -import org.springframework.stereotype.Service; import org.w3c.css.sac.InputSource; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; +import org.w3c.dom.css.*; -import com.steadystate.css.parser.CSSOMParser; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; public class CssInliner { @@ -28,7 +21,7 @@ private CssInliner() { } - public static String inlineCss(File css, String html) throws FileNotFoundException, IOException { + public static String inlineCss(File css, String html) throws IOException { CSSOMParser parser = new CSSOMParser(); CSSStyleSheet styleSheet = parser.parseStyleSheet(new InputSource(new FileReader(css))); final Document document = Jsoup.parse(html); @@ -58,7 +51,7 @@ private static String inlineCss(CSSStyleSheet styleSheet, Document document) { final Elements selectedElements = document.select(selector); for (final Element selected : selectedElements) { if (!elementStyles.containsKey(selected)) { - elementStyles.put(selected, new LinkedHashMap()); + elementStyles.put(selected, new LinkedHashMap<>()); } final CSSStyleDeclaration styleDeclaration = styleRule.getStyle(); @@ -91,5 +84,4 @@ private static String inlineCss(CSSStyleSheet styleSheet, Document document) { } return document.html(); } - } \ No newline at end of file diff --git a/src/main/java/com/datbois/grademaster/util/CsvGeneratorUtil.java b/src/main/java/com/datbois/grademaster/util/CsvGeneratorUtil.java index 566d737..7d0f101 100644 --- a/src/main/java/com/datbois/grademaster/util/CsvGeneratorUtil.java +++ b/src/main/java/com/datbois/grademaster/util/CsvGeneratorUtil.java @@ -56,7 +56,6 @@ public void writeLine(Writer w, List values, char separators, char custo sb.append("\n"); w.append(sb.toString()); - } } \ No newline at end of file diff --git a/src/test/java/com/datbois/grademaster/AuthControllerTests.java b/src/test/java/com/datbois/grademaster/AuthControllerTests.java index 3501ded..6895eef 100644 --- a/src/test/java/com/datbois/grademaster/AuthControllerTests.java +++ b/src/test/java/com/datbois/grademaster/AuthControllerTests.java @@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; -import org.springframework.jms.core.JmsTemplate; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import java.util.HashMap; diff --git a/src/test/java/com/datbois/grademaster/NotificationControllerTests.java b/src/test/java/com/datbois/grademaster/NotificationControllerTests.java index 52410bb..78db5df 100644 --- a/src/test/java/com/datbois/grademaster/NotificationControllerTests.java +++ b/src/test/java/com/datbois/grademaster/NotificationControllerTests.java @@ -6,21 +6,17 @@ import com.datbois.grademaster.service.UserService; import io.restassured.http.ContentType; import org.hamcrest.Matchers; -import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.security.core.Authentication; -import javax.naming.AuthenticationNotSupportedException; import java.util.HashMap; import java.util.List; import java.util.Map; -import static io.restassured.RestAssured.authentication; import static io.restassured.RestAssured.given; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.IsEqual.equalTo; public class NotificationControllerTests extends OAuthTests { @@ -32,7 +28,7 @@ public class NotificationControllerTests extends OAuthTests { private UserService userService; @Test - public void retrieveAllNotifications(){ + public void retrieveAllNotifications() { String token = this.obtainAccessToken("john.doe@student.stenden.com", "password"); given() @@ -45,7 +41,7 @@ public void retrieveAllNotifications(){ } @Test - public void updateAllNotifications(){ + public void updateAllNotifications() { String token = this.obtainAccessToken("john.doe@student.stenden.com", "password"); User user = userService.findByEmail("john.doe@student.stenden.com"); @@ -60,13 +56,13 @@ public void updateAllNotifications(){ .then() .statusCode(HttpStatus.ACCEPTED.value()); - for(Notification n : notifications){ + for (Notification n : notifications) { assertThat(n.isSeen(), equalTo(true)); } } @Test - public void updateNotification(){ + public void updateNotification() { String token = this.obtainAccessToken("john.doe@student.stenden.com", "password"); Notification notification = notificationService.findById(1L); From 282fee82fed888057dd1a0fe09cae5a02f1fab9e Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:09:04 +0100 Subject: [PATCH 09/30] Improve README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7078ddc..beb5bfd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ To run the backend the following environment variables should exist: - EMAIL_PORT - EMAIL_USERNAME - EMAIL_PASSWORD -**For intellij; Edit configurations... > *Select configuration* > Environment variables** + +*For intellij; Edit configurations... > **Select configuration** > Environment variables* ##### Frontend ``` From 870dfdfe16f078d0d87b2a3a86232f8e4c09a285 Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:11:10 +0100 Subject: [PATCH 10/30] README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index beb5bfd..761c6c7 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A small application to ease the grading of project groups for teachers. - Teachers can finalize the given grades and export it to CSV/PDF ### Documentation +Swagger is used to document the API. To view the documentation run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) ### Setup From 12ee5d792b68c0d64298abc275326593c3b320ee Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:12:52 +0100 Subject: [PATCH 11/30] README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 761c6c7..e223f8c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A small application to ease the grading of project groups for teachers. ### Documentation Swagger is used to document the API. -To view the documentation run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) +To view the documentation, run the Spring boot app and visit [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) ### Setup ##### Backend @@ -33,6 +33,8 @@ $ cd ./src/main/resources/public $ npm install ``` +##### Now you're ready to run the Spring boot app :) + ### Requirements - Java SDK >= 8.x - NPM >= 5.x From b5427acac4d43a2d45453daa6c54dd408fc1ef67 Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:33:42 +0100 Subject: [PATCH 12/30] Refactor register and verify to make use of custom API --- src/main/resources/public/app/js/register.js | 22 +++++--------- src/main/resources/public/app/js/verify.js | 29 +++++++------------ .../public/app/services/register.service.js | 11 +++++++ .../public/app/services/verify.service.js | 11 +++++++ src/main/resources/public/index.html | 2 ++ 5 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 src/main/resources/public/app/services/register.service.js create mode 100644 src/main/resources/public/app/services/verify.service.js diff --git a/src/main/resources/public/app/js/register.js b/src/main/resources/public/app/js/register.js index 571f7fa..f718c3b 100644 --- a/src/main/resources/public/app/js/register.js +++ b/src/main/resources/public/app/js/register.js @@ -1,27 +1,19 @@ -app.controller('RegisterCtrl', function ($scope, $http, $state) { +app.controller('RegisterCtrl', function (RegisterService, $scope, $state) { $scope.form = {}; - $scope.register = function () { + $scope.register = () => { const data = { email: $scope.form.email, referenceId: $scope.form.referenceId, password: $scope.form.password, }; - const req = { - method: 'POST', - url: 'http://localhost:8080/api/v1/users', - headers: { - "Content-type": "application/json" - }, - data - }; - $http(req).then(function (data) { - $state.transitionTo('registered') - }).catch(function (data){ + RegisterService.register(data).then((resp) => { + $state.transitionTo('registered'); + }).catch((error) => { $scope.error = "Register failed." }); - } + }; $scope.toLogin = () => { $state.transitionTo('login'); - } + }; }); \ No newline at end of file diff --git a/src/main/resources/public/app/js/verify.js b/src/main/resources/public/app/js/verify.js index 6ae5709..daaaa8c 100644 --- a/src/main/resources/public/app/js/verify.js +++ b/src/main/resources/public/app/js/verify.js @@ -1,33 +1,26 @@ -app.controller('VerifyCtrl', function ($scope, $state, $stateParams, $resource, $http, $timeout) { +app.controller('VerifyCtrl', function (VerifyService, $scope, $state, $stateParams, $timeout) { $scope.email = $stateParams.email; $scope.token = $stateParams.token; $scope.isLoading = true; $scope.isFinished = false; $scope.isError = false; - $scope.verify = function (email, token) { - var data = { - email: email, - token: token - } - var req = { - method: 'PATCH', - url: 'http://localhost:8080/api/v1/auth/verify', - headers: { - "Content-type": "application/json" - }, - data - } - $http(req).then(function (data) { + $scope.verify = (email, token) => { + const data = { + email, + token + }; + + VerifyService.verify(data).then((resp) => { $scope.isLoading = false; $scope.isFinished = true; - $timeout(function() { + $timeout(() => { $state.transitionTo('login') }, 3000); - }).catch(function (data) { + }).catch((error) => { $scope.error = "verification failed." $scope.isLoading = false; $scope.isError = true; - }) + }); } $scope.verify($scope.email, $scope.token); }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/register.service.js b/src/main/resources/public/app/services/register.service.js new file mode 100644 index 0000000..5520f54 --- /dev/null +++ b/src/main/resources/public/app/services/register.service.js @@ -0,0 +1,11 @@ +app.factory('RegisterService', function (API) { + + this.register = (data) => { + return API.post({ + path: `users`, + data + }); + }; + + return this; +}); \ No newline at end of file diff --git a/src/main/resources/public/app/services/verify.service.js b/src/main/resources/public/app/services/verify.service.js new file mode 100644 index 0000000..90cd7cc --- /dev/null +++ b/src/main/resources/public/app/services/verify.service.js @@ -0,0 +1,11 @@ +app.factory('VerifyService', function (API) { + + this.verify = (data) => { + return API.patch({ + path: `auth/verify`, + data + }); + }; + + return this; +}); \ No newline at end of file diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index dcd6484..bb02054 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -38,6 +38,8 @@ + + From 274d2f50ed66c6d02be599a1460cd0681346dc2c Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 20:48:04 +0100 Subject: [PATCH 13/30] Refactor js files --- src/main/resources/public/app/js/login.js | 4 +- .../public/app/services/api.service.js | 8 ++-- .../public/app/services/course.service.js | 37 ++++++++------- .../public/app/services/education.service.js | 3 +- .../public/app/services/grade.service.js | 3 +- .../public/app/services/group.service.js | 9 ++-- .../app/services/notification.service.js | 26 +++++----- .../app/services/student.groups.service.js | 47 ++++++++++--------- .../public/app/services/user.service.js | 26 +++++----- 9 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/main/resources/public/app/js/login.js b/src/main/resources/public/app/js/login.js index 9837309..7a3b222 100644 --- a/src/main/resources/public/app/js/login.js +++ b/src/main/resources/public/app/js/login.js @@ -9,10 +9,10 @@ app.controller('LoginCtrl', function (API, $scope, $state) { $scope.login($scope.vm.formData.email, $scope.vm.formData.password); } } - $scope.changeLogin = function() { + $scope.changeLogin = () => { $state.transitionTo('register') } - $scope.login = function (username, password) { + $scope.login = (username, password) => { API.auth({user: {username, password}}).then((resp) => { $state.transitionTo('app.dashboard'); }).catch((resp) => { diff --git a/src/main/resources/public/app/services/api.service.js b/src/main/resources/public/app/services/api.service.js index d072073..4c7592c 100644 --- a/src/main/resources/public/app/services/api.service.js +++ b/src/main/resources/public/app/services/api.service.js @@ -44,15 +44,15 @@ app.factory('API', function ($cookies, $http, $httpParamSerializer) { user } = {}) => { user = { ...user, - grant_type: 'password', - scope: 'read write' + grant_type: `password`, + scope: `read write` } let req = Object.assign({}, this.getAuthRequest()); return this.post({ data: $httpParamSerializer(user), req }).then((resp) => { - $cookies.put("access_token", resp.data.access_token); + $cookies.put(`access_token`, resp.data.access_token); return resp; }); }; @@ -143,7 +143,7 @@ app.factory('API', function ($cookies, $http, $httpParamSerializer) { return resp; }).catch((error) => { console.error(`error`, error); - return(error); + reject(error); }); } return $http(req); diff --git a/src/main/resources/public/app/services/course.service.js b/src/main/resources/public/app/services/course.service.js index faf6aec..c3489fc 100644 --- a/src/main/resources/public/app/services/course.service.js +++ b/src/main/resources/public/app/services/course.service.js @@ -1,19 +1,22 @@ app.factory('CourseService', function (API) { - return { - getCourse: (courseId) => { - return API.get({ - path: `courses/${courseId}` - }); - }, - getGroupsByCourse: (courseId) => { - return API.get({ - path: `courses/${courseId}/groups` - }) - }, - deleteCourse: course => { - return API.delete({ - path: `courses/${course.id}` - }); - }, - } + + this.getCourse = (courseId) => { + return API.get({ + path: `courses/${courseId}` + }); + }; + + this.getGroupsByCourse = (courseId) => { + return API.get({ + path: `courses/${courseId}/groups` + }) + }; + + this.deleteCourse = course => { + return API.delete({ + path: `courses/${course.id}` + }); + }; + + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/education.service.js b/src/main/resources/public/app/services/education.service.js index ab0a123..9df1d0f 100644 --- a/src/main/resources/public/app/services/education.service.js +++ b/src/main/resources/public/app/services/education.service.js @@ -1,7 +1,6 @@ app.factory('EducationService', function (API) { - this.getCoursesByEducation = (education) => { - const educationId = education; // TODO use education's id. + this.getCoursesByEducation = (educationId) => { return API.get({ path: `educations/${educationId}/courses` }); diff --git a/src/main/resources/public/app/services/grade.service.js b/src/main/resources/public/app/services/grade.service.js index e23dcef..8760410 100644 --- a/src/main/resources/public/app/services/grade.service.js +++ b/src/main/resources/public/app/services/grade.service.js @@ -52,8 +52,9 @@ app.factory('GradeService', function (API) { this.getGradesByGroup = (groupId) => { return API.get({ - path: `/grades/groups/`+groupId + path: `/grades/groups/${groupId}` }); }; + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/group.service.js b/src/main/resources/public/app/services/group.service.js index a314c59..c97fdae 100644 --- a/src/main/resources/public/app/services/group.service.js +++ b/src/main/resources/public/app/services/group.service.js @@ -14,7 +14,7 @@ app.factory('GroupService', function (API) { this.getGroupsByUserId = (userId) => { return API.get({ - path: 'users/' + userId + '/groups' + path: `users/${userId}/groups` }); }; @@ -27,20 +27,21 @@ app.factory('GroupService', function (API) { this.getGradingStatus = (groupId) => { return API.get({ - path: 'grades/status/groups/' + groupId + path: `grades/status/groups/${groupId}` }); }; this.getGroupMembers = (groupId) => { return API.get({ - path: 'groups/' + groupId + '/users' + path: `groups/${groupId}/users` }); }; this.deleteGroup = (groupId) => { return API.delete({ - path: 'groups/' + groupId + path: `groups/${groupId}` }); }; + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/notification.service.js b/src/main/resources/public/app/services/notification.service.js index c87c1ba..ab7fbf2 100644 --- a/src/main/resources/public/app/services/notification.service.js +++ b/src/main/resources/public/app/services/notification.service.js @@ -1,14 +1,16 @@ app.factory('NotificationService', function (API) { - return { - getNotifications: () => { - return API.get({ - path: `notifications` - }); - }, - readNotification: (notificationId) => { - return API.patch({ - path: notificationId ? `notifications/${notificationId}` : `notifications` - }); - }, - } + + this.getNotifications = () => { + return API.get({ + path: `notifications` + }); + }; + + this.readNotification = (notificationId) => { + return API.patch({ + path: notificationId ? `notifications/${notificationId}` : `notifications` + }); + }; + + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/student.groups.service.js b/src/main/resources/public/app/services/student.groups.service.js index a4ba1f4..a7bf878 100644 --- a/src/main/resources/public/app/services/student.groups.service.js +++ b/src/main/resources/public/app/services/student.groups.service.js @@ -1,27 +1,28 @@ -app.factory('StudentGroupsService', function($http, $cookies, API){ - return { - getStudentGroups : function(userId){ - return API.get({ - path: 'users/'+ userId +'/groups' - }); - }, +app.factory('StudentGroupsService', function(API){ - getGroupMembers : function(groupId){ - return API.get({ - path: 'groups/'+ groupId +'/users' - }); - }, + this.getStudentGroups = (userId) => { + return API.get({ + path: `users/${userId}/groups` + }); + }; - getFinalGroupGrade : function(groupId, userId){ - return API.get({ - path: 'grades/groups/'+ groupId +'/users/'+ userId - }); - }, + this.getGroupMembers = (groupId) => { + return API.get({ + path: `groups/${groupId}/users` + }); + }; - getGradingStatus : function(groupId){ - return API.get({ - path: 'grades/status/groups/' + groupId - }); - } - } + this.getFinalGroupGrade = (groupId, userId) => { + return API.get({ + path: `grades/groups/${groupId}/users/${userId}` + }); + }; + + this.getGradingStatus = (groupId) => { + return API.get({ + path: `grades/status/groups/${groupId}` + }); + }; + + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/app/services/user.service.js b/src/main/resources/public/app/services/user.service.js index f8ae401..f35ca0a 100644 --- a/src/main/resources/public/app/services/user.service.js +++ b/src/main/resources/public/app/services/user.service.js @@ -1,14 +1,16 @@ app.factory('UserService', function (API) { - return { - getSelf: () => { - return API.get({ - path: `users/self` - }); - }, - getAllUsers: () => { - return API.get({ - path: `users` - }); - }, - } + + this.getSelf = () => { + return API.get({ + path: `users/self` + }); + }; + + this.getAllUsers = () => { + return API.get({ + path: `users` + }); + }; + + return this; }); \ No newline at end of file From ebb78d5b7c00ae954f60566f2aa88d9d7c3b0eb0 Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 21:36:22 +0100 Subject: [PATCH 14/30] Add account and logout menu --- .../app/components/dashboard.component.js | 2 +- src/main/resources/public/app/icons/exit.svg | 4 ++ src/main/resources/public/app/js/app.js | 12 +++++- src/main/resources/public/app/pages/app.html | 22 ++++++++-- src/main/resources/public/app/styles/app.css | 40 +++++++++++++++++++ 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/public/app/icons/exit.svg diff --git a/src/main/resources/public/app/components/dashboard.component.js b/src/main/resources/public/app/components/dashboard.component.js index 7d5fec1..9b8bcfd 100644 --- a/src/main/resources/public/app/components/dashboard.component.js +++ b/src/main/resources/public/app/components/dashboard.component.js @@ -19,7 +19,7 @@ function DashboardCtrl($scope, StudentGroupsService, UserService){ }else if(response.data.status == "OPEN"){ ctrl.open += 1; }else if(response.data.status == "PENDING"){ - $ctrl.pending += 1; + ctrl.pending += 1; } }) }); diff --git a/src/main/resources/public/app/icons/exit.svg b/src/main/resources/public/app/icons/exit.svg new file mode 100644 index 0000000..b508cfe --- /dev/null +++ b/src/main/resources/public/app/icons/exit.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/public/app/js/app.js b/src/main/resources/public/app/js/app.js index 72f9a82..f520e9e 100644 --- a/src/main/resources/public/app/js/app.js +++ b/src/main/resources/public/app/js/app.js @@ -8,11 +8,12 @@ var app = angular.module('gmApp', [ 'ui.router' ]); -app.controller('LayoutController', function ($scope, $mdSidenav, $window, $cookies, $mdDialog, AuthService, NotificationService) { +app.controller('LayoutController', function ($scope, $mdSidenav, $window, $cookies, $mdDialog, AuthService, NotificationService, UserService) { this.newNotifications = []; this.oldNotifications = []; this.patchNotifications = []; + this.roles = []; (this.getNotifications = () => { return NotificationService.getNotifications().then((resp) => { @@ -51,6 +52,15 @@ app.controller('LayoutController', function ($scope, $mdSidenav, $window, $cooki $mdOpenMenu(ev); }); } + this.showAccount = ($mdOpenMenu, ev) => { + $mdOpenMenu(ev); + } + (this.getRoles = () => { + return UserService.getSelf().then((resp) => { + this.roles = resp.data.roles; + return resp.data.roles; + }); + })(); this.readNotification = (notification) => { if (!notification.seen) { notification.seen = true; diff --git a/src/main/resources/public/app/pages/app.html b/src/main/resources/public/app/pages/app.html index 5197fd9..b681b91 100644 --- a/src/main/resources/public/app/pages/app.html +++ b/src/main/resources/public/app/pages/app.html @@ -68,9 +68,25 @@

Grade Master

- - - + + + + + + + + +
diff --git a/src/main/resources/public/app/styles/app.css b/src/main/resources/public/app/styles/app.css index 90aec05..70d2628 100644 --- a/src/main/resources/public/app/styles/app.css +++ b/src/main/resources/public/app/styles/app.css @@ -71,6 +71,44 @@ md-menu-content { padding: 0; } +.account-header { + text-align: center; + font-weight: lighter; + padding: 8px; + margin-top: 16px; +} + +.account-header>.username { + font-weight: lighter; + font-size: 16pt; + margin-bottom: 4px; +} + +.account-header>.role { + font-weight: lighter; + font-style: italic; + font-size: 9pt; + padding-top: 4px; +} + +.account-content { + text-align: center; + font-weight: lighter; + padding: 16px; + margin-top: 16px; + border-top: 1px dotted #AFAFAF; + cursor: pointer; +} + +.account-content:hover { + background-color: #F3F3F3; +} + +.account-content>.logout { + margin-left: 8px; + vertical-align: middle; +} + .notification-header { text-align: center; font-weight: lighter; @@ -96,6 +134,8 @@ md-menu-content { font-size: 10pt; padding: 12px; border-top: 1px dotted #AFAFAF; + max-width: 400px; + align-self: center; } .unseen { From dc88a3d540da210783812875ada05ce3b58808cc Mon Sep 17 00:00:00 2001 From: cassshh Date: Wed, 24 Jan 2018 21:40:24 +0100 Subject: [PATCH 15/30] Forgot logout call --- src/main/resources/public/app/pages/app.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/public/app/pages/app.html b/src/main/resources/public/app/pages/app.html index b681b91..9490cb4 100644 --- a/src/main/resources/public/app/pages/app.html +++ b/src/main/resources/public/app/pages/app.html @@ -81,7 +81,7 @@

Grade Master

||
- - GRADE +
+ GRADE + FINALIZE + + + PDF + + + + CSV + +
diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index effbb20..365ef1a 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -1,4 +1,4 @@ -function teacherCardCtrl($scope, GroupService, $state, $mdDialog) { +function teacherCardCtrl($scope, GroupService, $state, $mdDialog, API) { var ctrl = this; ctrl.$onInit = () => { @@ -11,11 +11,11 @@ function teacherCardCtrl($scope, GroupService, $state, $mdDialog) { }; ctrl.gradeGroup = () => { - $state.transitionTo("app.groupGrade", {groupId: $scope.groupId}); + $state.transitionTo("app.groupGrade", {groupId: ctrl.group.id}); }; ctrl.finalGroupView = () => { - $state.transitionTo("app.finalGroupOverview", {groupId: $scope.groupId}); + $state.transitionTo("app.finalGroupOverview", {groupId: ctrl.group.id}); }; ctrl.editGroup = (ev) => { @@ -43,7 +43,7 @@ function teacherCardCtrl($scope, GroupService, $state, $mdDialog) { $mdDialog.show(confirm) .then(() => { - GroupService.deleteGroup($scope.groupId).then(() => { + GroupService.deleteGroup(ctrl.group.id).then(() => { //Refresh groups $scope.$parent.$parent.getGroups(); }, () => { @@ -53,7 +53,41 @@ function teacherCardCtrl($scope, GroupService, $state, $mdDialog) { .ok("Okay")); }); }); - } + }; + + ctrl.export = (format, contentType) => { + API.get({ + path: `grades/groups/${ctrl.group.id}/export.${format}`, + req: Object.assign({ + headers: { + 'Content-type': contentType, + }, + responseType: 'arraybuffer' + }, API.getRequest()) + }).then((response) => { + const file = new Blob([response.data], { + type: contentType + }); + + const fileURL = URL.createObjectURL(file); + const a = document.createElement('a'); + a.href = fileURL; + a.target = '_blank'; + a.download = `${ctrl.group.groupName}.${format}`; + document.body.appendChild(a); + a.click(); + }).catch((error) => { + console.error("Error downloading export"); + }); + }; + + ctrl.downloadPDF = () => { + ctrl.export("pdf", "application/pdf"); + }; + + ctrl.downloadCSV = () => { + ctrl.export("csv", "text/csv"); + }; } function EditGroupDialogController($scope, $mdDialog) { diff --git a/src/main/resources/public/app/icons/download.svg b/src/main/resources/public/app/icons/download.svg new file mode 100644 index 0000000..b8df1af --- /dev/null +++ b/src/main/resources/public/app/icons/download.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From c4a5fa52bf5a507bf469d5624a7723c6f59625d2 Mon Sep 17 00:00:00 2001 From: basvtholt Date: Thu, 25 Jan 2018 12:58:18 +0100 Subject: [PATCH 18/30] added empty state + teacher dashboard --- .../app/components/dashboard.component.js | 22 +++--- .../dashboardCourseOverview.component.html | 33 ++++----- .../dashboardGradeOverview.component.html | 11 +-- .../dashboardGroupOverview.component.html | 30 +++++++- .../dashboardProjectsOverview.component.html | 2 +- .../app/components/groupCard.component.js | 3 + src/main/resources/public/app/js/groups.js | 23 ++++++- .../public/app/pages/dashboard-teacher.html | 68 ++++++++++++++++--- .../resources/public/app/pages/dashboard.html | 8 ++- .../resources/public/app/styles/dashboard.css | 13 ++++ 10 files changed, 164 insertions(+), 49 deletions(-) diff --git a/src/main/resources/public/app/components/dashboard.component.js b/src/main/resources/public/app/components/dashboard.component.js index f82784f..2a9e6bb 100644 --- a/src/main/resources/public/app/components/dashboard.component.js +++ b/src/main/resources/public/app/components/dashboard.component.js @@ -1,7 +1,7 @@ -function DashboardCtrl($scope, $state, StudentGroupsService, UserService, GroupService){ +function DashboardCtrl($scope, $state, StudentGroupsService, UserService, GroupService, CourseService){ let ctrl = this; - $scope.init = function(){ + ctrl.init = function(){ ctrl.closed = 0; ctrl.open = 0; ctrl.pending = 0; @@ -17,13 +17,17 @@ function DashboardCtrl($scope, $state, StudentGroupsService, UserService, GroupS } angular.forEach(ctrl.groupsDetails, function(value, key) { - StudentGroupsService.getGradingStatus(value.id).then(function(response){ - if(response.data.status == "CLOSED"){ - ctrl.closed += 1; - }else if(response.data.status == "OPEN"){ - ctrl.open += 1; - }else if(response.data.status == "PENDING"){ - ctrl.pending += 1; + GroupService.getGradingStatus(value.id).then(function(response){ + switch(response.data.status){ + case 'CLOSED': + ctrl.closed += 1; + break; + case 'OPEN': + ctrl.open += 1; + break; + case 'PENDING': + ctrl.pending += 1; + break; } }) }); diff --git a/src/main/resources/public/app/components/dashboardCourseOverview.component.html b/src/main/resources/public/app/components/dashboardCourseOverview.component.html index a6177a2..9edc9e5 100644 --- a/src/main/resources/public/app/components/dashboardCourseOverview.component.html +++ b/src/main/resources/public/app/components/dashboardCourseOverview.component.html @@ -1,31 +1,26 @@ -
+
- - - + + + - - + + - - -
{{$ctrl.name}}
StatusGroup gradeYour gradeStatusGroup gradeYour grade
{{$ctrl.groupStatus}}{{$ctrl.group.groupGrade.grade}}{{$ctrl.groupStatus}}{{$ctrl.groupGrade}} {{$ctrl.finalGrade}}
-
-
- {{member.name}},   -
-
- {{member.name}} -
-
-
-
+
+
+ {{member.name}},   +
+
+ {{member.name}} +
+
diff --git a/src/main/resources/public/app/components/dashboardGradeOverview.component.html b/src/main/resources/public/app/components/dashboardGradeOverview.component.html index daaba22..e3f4d48 100644 --- a/src/main/resources/public/app/components/dashboardGradeOverview.component.html +++ b/src/main/resources/public/app/components/dashboardGradeOverview.component.html @@ -1,7 +1,7 @@ -
+
- + @@ -9,10 +9,11 @@ - +
{{$ctrl.course.name}}{{$ctrl.group.course.name}}
Group gradeChange in grade
{{$ctrl.group.groupGrade.grade}} + {{$ctrl.groupGrade}} + {{$ctrl.finalGrade}} {{$ctrl.calculateGradeChange($ctrl.group.groupGrade.grade, $ctrl.finalGrade)}}
-
-
\ No newline at end of file +
diff --git a/src/main/resources/public/app/components/dashboardGroupOverview.component.html b/src/main/resources/public/app/components/dashboardGroupOverview.component.html index ad25edf..470701e 100644 --- a/src/main/resources/public/app/components/dashboardGroupOverview.component.html +++ b/src/main/resources/public/app/components/dashboardGroupOverview.component.html @@ -1,4 +1,28 @@ -
-

Group

- {{$ctrl.group}} +
+ + + + + + + + + + + + + + + + + +
Course{{$ctrl.group.course.name}}
Education{{$ctrl.group.course.education.name}}
Group name{{$ctrl.group.groupName}}
Group grade{{$ctrl.group.groupGrade.grade}}
+
+
+ {{member.name}},   +
+
+ {{member.name}} +
+
diff --git a/src/main/resources/public/app/components/dashboardProjectsOverview.component.html b/src/main/resources/public/app/components/dashboardProjectsOverview.component.html index c8c2def..a3a5a73 100644 --- a/src/main/resources/public/app/components/dashboardProjectsOverview.component.html +++ b/src/main/resources/public/app/components/dashboardProjectsOverview.component.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/main/resources/public/app/components/groupCard.component.js b/src/main/resources/public/app/components/groupCard.component.js index deefa4e..831b390 100644 --- a/src/main/resources/public/app/components/groupCard.component.js +++ b/src/main/resources/public/app/components/groupCard.component.js @@ -3,11 +3,14 @@ function GroupCardCtrl($state, StudentGroupsService, CourseService) { let ctrl = this; ctrl.groupMembers = []; + ctrl.groupGrade = ''; ctrl.$onInit = () => { ctrl.name = ctrl.group.groupName; + ctrl.groupGrade = (ctrl.group.groupGrade == null) ? 'TBD' : ctrl.group.groupGrade.grade; + StudentGroupsService.getFinalGroupGrade(ctrl.group.id, ctrl.user.id).then((response) => { if (response.data.grade) { ctrl.finalGrade = response.data.grade; diff --git a/src/main/resources/public/app/js/groups.js b/src/main/resources/public/app/js/groups.js index 853e9d3..09ef18b 100644 --- a/src/main/resources/public/app/js/groups.js +++ b/src/main/resources/public/app/js/groups.js @@ -13,7 +13,8 @@ app.controller('StudentGroupsCtrl', function ($scope, UserService, StudentGroups }); app.controller('TeacherGroupsCtrl', function ($scope, $mdDialog, UserService, GroupService) { - $scope.status = ' '; + $scope.limit = 10; + $scope.limitOptions = [5, 10, 15, 20, 50, 100]; $scope.teacherGroupList = []; $scope.onInit = () => { $scope.getGroups(); @@ -22,6 +23,26 @@ app.controller('TeacherGroupsCtrl', function ($scope, $mdDialog, UserService, Gr UserService.getSelf().then((response) => { return GroupService.getGroupsByUserId(response.data.id).then((response) => { $scope.teacherGroupList = response.data; + + $scope.closed = []; + $scope.pending = []; + $scope.open = []; + + angular.forEach($scope.teacherGroupList, function(value, key) { + GroupService.getGradingStatus(value.id).then(function(response){ + switch(response.data.status){ + case "CLOSED": + $scope.closed.push(value); + break; + case "PENDING": + $scope.pending.push(value); + break; + case "OPEN": + $scope.open.push(value); + break; + } + }) + }); }); }); diff --git a/src/main/resources/public/app/pages/dashboard-teacher.html b/src/main/resources/public/app/pages/dashboard-teacher.html index 24e58e5..e37c147 100644 --- a/src/main/resources/public/app/pages/dashboard-teacher.html +++ b/src/main/resources/public/app/pages/dashboard-teacher.html @@ -13,26 +13,78 @@
- Groups with finalized grade -
+ + + + {{option}} + + + + +
+
+
+
+ + + Recent closed + -
+ +
- + - Groups without grade + Recent open + + + +
- + - Groups that are grading + Recent pending + + + +
- \ No newline at end of file + + + + + \ No newline at end of file diff --git a/src/main/resources/public/app/pages/dashboard.html b/src/main/resources/public/app/pages/dashboard.html index a4b4060..a3264d0 100644 --- a/src/main/resources/public/app/pages/dashboard.html +++ b/src/main/resources/public/app/pages/dashboard.html @@ -1,15 +1,16 @@
-
-
+
+
+
-
+
@@ -25,6 +26,7 @@ Grade Overview
+
diff --git a/src/main/resources/public/app/styles/dashboard.css b/src/main/resources/public/app/styles/dashboard.css index 8bc5ba9..aca4882 100644 --- a/src/main/resources/public/app/styles/dashboard.css +++ b/src/main/resources/public/app/styles/dashboard.css @@ -46,4 +46,17 @@ md-grid-list md-card table button{ display: table-cell; vertical-align: middle; font-size: 2.5em; +} +.caption-compact{ + margin: 5px 0 !important; +} +.dashboard-select{ + max-width: 15%; +} +.teacher-dashboard-groups{ + max-height: 1000px; + overflow-x: auto; +} +.align-status{ + width: 33%; } \ No newline at end of file From 4d05ca431d58a48b63e71422edd68694641d96a9 Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 13:01:45 +0100 Subject: [PATCH 19/30] Implement retard call --- src/main/resources/public/app/js/app.js | 5 +++ src/main/resources/public/app/js/login.js | 7 +++- src/main/resources/public/app/js/retard.js | 38 +++++++++++++++++++ .../resources/public/app/pages/login.html | 4 +- .../resources/public/app/pages/register.html | 2 +- .../public/app/pages/registered.html | 1 + .../resources/public/app/pages/retard.html | 31 +++++++++++++++ .../resources/public/app/pages/verify.html | 28 +++++++------- .../public/app/services/api.service.js | 8 ++++ .../public/app/services/register.service.js | 3 +- .../public/app/services/retard.service.js | 20 ++++++++++ .../public/app/services/verify.service.js | 3 +- src/main/resources/public/app/styles/app.css | 6 +++ src/main/resources/public/index.html | 12 +++--- 14 files changed, 141 insertions(+), 27 deletions(-) create mode 100644 src/main/resources/public/app/js/retard.js create mode 100644 src/main/resources/public/app/pages/retard.html create mode 100644 src/main/resources/public/app/services/retard.service.js diff --git a/src/main/resources/public/app/js/app.js b/src/main/resources/public/app/js/app.js index d72d3bb..7dde2df 100644 --- a/src/main/resources/public/app/js/app.js +++ b/src/main/resources/public/app/js/app.js @@ -102,6 +102,11 @@ app.config(function ($stateProvider) { url: '/registered', templateUrl: '/app/pages/registered.html', }) + .state('retard', { + url: '/retard', + templateUrl: '/app/pages/retard.html', + controller: 'RetardCtrl' + }) .state('verify', { url: '/verify?email&token', templateUrl: '/app/pages/verify.html', diff --git a/src/main/resources/public/app/js/login.js b/src/main/resources/public/app/js/login.js index 7a3b222..44b74ef 100644 --- a/src/main/resources/public/app/js/login.js +++ b/src/main/resources/public/app/js/login.js @@ -10,7 +10,10 @@ app.controller('LoginCtrl', function (API, $scope, $state) { } } $scope.changeLogin = () => { - $state.transitionTo('register') + $state.transitionTo('register'); + } + $scope.changeForgotPassword = () => { + $state.transitionTo('retard'); } $scope.login = (username, password) => { API.auth({user: {username, password}}).then((resp) => { @@ -19,4 +22,4 @@ app.controller('LoginCtrl', function (API, $scope, $state) { $scope.valid = "Invalid credentials."; }); } -}); +}); \ No newline at end of file diff --git a/src/main/resources/public/app/js/retard.js b/src/main/resources/public/app/js/retard.js new file mode 100644 index 0000000..80b8b0a --- /dev/null +++ b/src/main/resources/public/app/js/retard.js @@ -0,0 +1,38 @@ +app.controller('RetardCtrl', function (RetardService, $state) { + + this.changeLogin = () => { + $state.transitionTo('login'); + } + + this.submit = () => { + this.loading = true; + this.error = false; + this.success = false; + RetardService.requestForgot({ + email: this.email + }).then((resp) => { + this.loading = false; + this.success = true; + }).catch((error) => { + this.loading = false; + this.error = true; + }); + } + + this.showLoading = () => { + return this.loading; + } + + this.showForm = () => { + return !this.loading && !this.success; + } + + this.showSuccess = () => { + return this.success; + } + + this.showError = () => { + return this.error; + } + +}); \ No newline at end of file diff --git a/src/main/resources/public/app/pages/login.html b/src/main/resources/public/app/pages/login.html index bed5eee..77ed10f 100644 --- a/src/main/resources/public/app/pages/login.html +++ b/src/main/resources/public/app/pages/login.html @@ -15,7 +15,7 @@

-
You must supply a email.
+
You must supply an email.
@@ -25,6 +25,7 @@

You must supply a password.
{{valid}}

+ Forgot password?
- \ No newline at end of file diff --git a/src/main/resources/public/app/pages/register.html b/src/main/resources/public/app/pages/register.html index c54494a..7596f06 100644 --- a/src/main/resources/public/app/pages/register.html +++ b/src/main/resources/public/app/pages/register.html @@ -15,7 +15,7 @@

-
You must supply a email.
+
You must supply an email.
diff --git a/src/main/resources/public/app/pages/registered.html b/src/main/resources/public/app/pages/registered.html index 2796cf7..7dcf17c 100644 --- a/src/main/resources/public/app/pages/registered.html +++ b/src/main/resources/public/app/pages/registered.html @@ -1,4 +1,5 @@
+

Grade Master

diff --git a/src/main/resources/public/app/pages/retard.html b/src/main/resources/public/app/pages/retard.html new file mode 100644 index 0000000..0a0d166 --- /dev/null +++ b/src/main/resources/public/app/pages/retard.html @@ -0,0 +1,31 @@ +
+

Grade Master

+ + +
+

+ Forgot password +

+
+
+ +

One moment please...

+

Request sent. Please check your mailbox.

+

Seems like something went wrong. Check your details or try again later.

+
+ + + +
+
You must supply an email.
+
+
+
+   Send request   +   Oh wait I member   +
+ +
+
+
\ No newline at end of file diff --git a/src/main/resources/public/app/pages/verify.html b/src/main/resources/public/app/pages/verify.html index 0d47078..0b151b8 100644 --- a/src/main/resources/public/app/pages/verify.html +++ b/src/main/resources/public/app/pages/verify.html @@ -2,6 +2,7 @@
+

Grade Master

@@ -16,17 +17,16 @@

- -
-

- An error has occured! -

-
-
- -
Somehow we weren't able to verify your email. Please try again later.
-
-
-
-

- \ No newline at end of file + +
+

+ An error has occured! +

+
+
+ +
Somehow we weren't able to verify your email. Please try again later.
+
+
+
+
\ No newline at end of file diff --git a/src/main/resources/public/app/services/api.service.js b/src/main/resources/public/app/services/api.service.js index 4c7592c..68848d4 100644 --- a/src/main/resources/public/app/services/api.service.js +++ b/src/main/resources/public/app/services/api.service.js @@ -17,6 +17,13 @@ app.factory('API', function ($cookies, $http, $httpParamSerializer) { /** * DEFAULT REQUESTS */ + // Request for unauthorized requests + this.getUnAuthRequest = () => { + return { + url: `${BASE_URL}/${API}/` + } + }; + // Request with autorization this.getRequest = () => { return { url: `${BASE_URL}/${API}/`, @@ -25,6 +32,7 @@ app.factory('API', function ($cookies, $http, $httpParamSerializer) { } } }; + // OAuth request this.getAuthRequest = () => { return { url: `${BASE_URL}/oauth/token`, diff --git a/src/main/resources/public/app/services/register.service.js b/src/main/resources/public/app/services/register.service.js index 5520f54..666ea53 100644 --- a/src/main/resources/public/app/services/register.service.js +++ b/src/main/resources/public/app/services/register.service.js @@ -3,7 +3,8 @@ app.factory('RegisterService', function (API) { this.register = (data) => { return API.post({ path: `users`, - data + data, + req: Object.assign({}, API.getUnAuthRequest()) }); }; diff --git a/src/main/resources/public/app/services/retard.service.js b/src/main/resources/public/app/services/retard.service.js new file mode 100644 index 0000000..da929a1 --- /dev/null +++ b/src/main/resources/public/app/services/retard.service.js @@ -0,0 +1,20 @@ +app.factory('RetardService', function (API) { + + this.requestForgot = (data) => { + return API.post({ + path: `auth/retard`, + data, + req: Object.assign({}, API.getUnAuthRequest()) + }); + }; + + this.setNewPassword = (data) => { + return API.patch({ + path: `auth/retard`, + data, + req: Object.assign({}, API.getUnAuthRequest()) + }); + }; + + return this; +}); \ No newline at end of file diff --git a/src/main/resources/public/app/services/verify.service.js b/src/main/resources/public/app/services/verify.service.js index 90cd7cc..4c40500 100644 --- a/src/main/resources/public/app/services/verify.service.js +++ b/src/main/resources/public/app/services/verify.service.js @@ -3,7 +3,8 @@ app.factory('VerifyService', function (API) { this.verify = (data) => { return API.patch({ path: `auth/verify`, - data + data, + req: Object.assign({}, API.getUnAuthRequest()) }); }; diff --git a/src/main/resources/public/app/styles/app.css b/src/main/resources/public/app/styles/app.css index 70d2628..1a549e7 100644 --- a/src/main/resources/public/app/styles/app.css +++ b/src/main/resources/public/app/styles/app.css @@ -45,6 +45,12 @@ a { margin-top: 15px; } +.forgot-password { + cursor: pointer; + color: #3F3F3F; + font-size: 10pt; +} + .spinnerContainer { width: 100%; height: 100%; diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index bb02054..b9602ff 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -27,18 +27,22 @@ - + + + + + - + @@ -60,10 +64,6 @@ - - - - \ No newline at end of file From fd585e2df16b36cebffa9fabec11e019f9ed136a Mon Sep 17 00:00:00 2001 From: basvtholt Date: Thu, 25 Jan 2018 13:20:16 +0100 Subject: [PATCH 20/30] resolved merge conflicts - data.sql --- src/main/resources/data.sql | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 1cc4cf3..2cd6e5c 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,16 +1,9 @@ INSERT INTO `user` (`id`, `email`, `name`, `password`, `verified`, `reference_id`) VALUES -<<<<<<< HEAD - (1, "john.doe@student.stenden.com", "John Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '123456'), - (2, "jane.doe@stenden.com", "Jane Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '654321'), - (3, "admin@stenden.com", "Administrator", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '987555'), - (4, "test.doe@student.stenden.com", "John Doe", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '123456'); -======= (1, "pascal.drewes@student.stenden.com", "Pascal Drewes", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, "123456"), (2, "admin@stenden.com", "Administrator", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, '987555'), (3, "cas.van.dinter@student.stenden.com", "Cas van Dinter", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, "123456"), (4, "danny.hooijer@student.stenden.com", "Danny Hooijer", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, "123456"), (5, "bas.van.t.holt@stenden.com", "Bas van't Holt", "$2a$04$FYZXxiv7A74rX33gfs2m/.AGqhQ/unlJCB2nHLRiuHCVlECcyLyb6", 1, "123456"); ->>>>>>> 105352b401274b6ff2367ac5b4f1c8c52968ed58 INSERT INTO `role` (`id`, `code`, `label`) VALUES (1, "STUDENT_ROLE", "Student"), @@ -19,16 +12,10 @@ INSERT INTO `role` (`id`, `code`, `label`) VALUES INSERT INTO `user_roles` (`user_id`, `role_id`) VALUES (1, 1), -<<<<<<< HEAD - (2, 2), - (3, 3), - (4, 1); -======= (2, 3), (3, 1), (4, 1), (5, 2); ->>>>>>> 105352b401274b6ff2367ac5b4f1c8c52968ed58 INSERT INTO `education` (`id`, `name`) VALUES (1, "INF"), From 9c07bd01d0be97da125d8a46cf4cc08faba7ee38 Mon Sep 17 00:00:00 2001 From: basvtholt Date: Thu, 25 Jan 2018 13:21:26 +0100 Subject: [PATCH 21/30] Removed outcommented code --- .../public/app/pages/dashboard-teacher.html | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/main/resources/public/app/pages/dashboard-teacher.html b/src/main/resources/public/app/pages/dashboard-teacher.html index e37c147..e71765b 100644 --- a/src/main/resources/public/app/pages/dashboard-teacher.html +++ b/src/main/resources/public/app/pages/dashboard-teacher.html @@ -58,33 +58,4 @@

-
- - - - \ No newline at end of file +
\ No newline at end of file From a342a61e9f9901daeab38eb837508ffeb4da213c Mon Sep 17 00:00:00 2001 From: basvtholt Date: Thu, 25 Jan 2018 13:28:45 +0100 Subject: [PATCH 22/30] Removed redundant init calls --- .../dashboardCourseOverview.component.html | 44 ++++++++-------- .../dashboardGradeOverview.component.html | 36 +++++++------ .../dashboardGroupOverview.component.html | 50 +++++++++---------- 3 files changed, 62 insertions(+), 68 deletions(-) diff --git a/src/main/resources/public/app/components/dashboardCourseOverview.component.html b/src/main/resources/public/app/components/dashboardCourseOverview.component.html index 9edc9e5..5320e44 100644 --- a/src/main/resources/public/app/components/dashboardCourseOverview.component.html +++ b/src/main/resources/public/app/components/dashboardCourseOverview.component.html @@ -1,26 +1,24 @@ -
-
Projects closed
- - - - - - - - - - - - - -
{{$ctrl.name}}
StatusGroup gradeYour grade
{{$ctrl.groupStatus}}{{$ctrl.groupGrade}}{{$ctrl.finalGrade}}
-
-
- {{member.name}},   -
-
- {{member.name}} -
+ + + + + + + + + + + + + + +
{{$ctrl.name}}
StatusGroup gradeYour grade
{{$ctrl.groupStatus}}{{$ctrl.groupGrade}}{{$ctrl.finalGrade}}
+
+
+ {{member.name}},  
+
+ {{member.name}} +
diff --git a/src/main/resources/public/app/components/dashboardGradeOverview.component.html b/src/main/resources/public/app/components/dashboardGradeOverview.component.html index e3f4d48..78c3241 100644 --- a/src/main/resources/public/app/components/dashboardGradeOverview.component.html +++ b/src/main/resources/public/app/components/dashboardGradeOverview.component.html @@ -1,19 +1,17 @@ -
- - - - - - - - - - - - - - -
{{$ctrl.group.course.name}}
Group gradeYour gradeChange in grade
- {{$ctrl.groupGrade}} - {{$ctrl.finalGrade}}{{$ctrl.calculateGradeChange($ctrl.group.groupGrade.grade, $ctrl.finalGrade)}}
-
+ + + + + + + + + + + + + + +
{{$ctrl.group.course.name}}
Group gradeYour gradeChange in grade
+ {{$ctrl.groupGrade}} + {{$ctrl.finalGrade}}{{$ctrl.calculateGradeChange($ctrl.group.groupGrade.grade, $ctrl.finalGrade)}}
diff --git a/src/main/resources/public/app/components/dashboardGroupOverview.component.html b/src/main/resources/public/app/components/dashboardGroupOverview.component.html index 470701e..ff02376 100644 --- a/src/main/resources/public/app/components/dashboardGroupOverview.component.html +++ b/src/main/resources/public/app/components/dashboardGroupOverview.component.html @@ -1,28 +1,26 @@ -
- - - - - - - - - - - - - - - - - -
Course{{$ctrl.group.course.name}}
Education{{$ctrl.group.course.education.name}}
Group name{{$ctrl.group.groupName}}
Group grade{{$ctrl.group.groupGrade.grade}}
-
-
- {{member.name}},   -
-
- {{member.name}} -
+ + + + + + + + + + + + + + + + + +
Course{{$ctrl.group.course.name}}
Education{{$ctrl.group.course.education.name}}
Group name{{$ctrl.group.groupName}}
Group grade{{$ctrl.group.groupGrade.grade}}
+
+
+ {{member.name}},  
+
+ {{member.name}} +
From c9b108a245b95e5bbba86740b3a3f880cd605159 Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 13:53:09 +0100 Subject: [PATCH 23/30] Add reset password flow --- src/main/resources/public/app/js/app.js | 5 ++ src/main/resources/public/app/js/reset.js | 39 +++++++++++++++ src/main/resources/public/app/js/verify.js | 4 +- .../resources/public/app/pages/reset.html | 47 +++++++++++++++++++ .../public/app/services/retard.service.js | 2 +- src/main/resources/public/index.html | 1 + 6 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/public/app/js/reset.js create mode 100644 src/main/resources/public/app/pages/reset.html diff --git a/src/main/resources/public/app/js/app.js b/src/main/resources/public/app/js/app.js index 7dde2df..b7d6851 100644 --- a/src/main/resources/public/app/js/app.js +++ b/src/main/resources/public/app/js/app.js @@ -107,6 +107,11 @@ app.config(function ($stateProvider) { templateUrl: '/app/pages/retard.html', controller: 'RetardCtrl' }) + .state('reset', { + url: '/reset?token', + templateUrl: '/app/pages/reset.html', + controller: 'ResetCtrl' + }) .state('verify', { url: '/verify?email&token', templateUrl: '/app/pages/verify.html', diff --git a/src/main/resources/public/app/js/reset.js b/src/main/resources/public/app/js/reset.js new file mode 100644 index 0000000..5dd05ad --- /dev/null +++ b/src/main/resources/public/app/js/reset.js @@ -0,0 +1,39 @@ +app.controller('ResetCtrl', function (RetardService, $state, $stateParams, $timeout) { + + this.submit = () => { + this.loading = true; + this.error = false; + this.success = false; + RetardService.setNewPassword({ + email: this.email, + password: this.password, + token: $stateParams.token + }).then((resp) => { + this.loading = false; + this.success = true; + $timeout(() => { + $state.transitionTo('login'); + }, 3000); + }).catch((error) => { + this.loading = false; + this.error = true; + }); + } + + this.showLoading = () => { + return this.loading; + } + + this.showForm = () => { + return !this.loading && !this.success; + } + + this.showSuccess = () => { + return this.success; + } + + this.showError = () => { + return this.error; + } + +}); \ No newline at end of file diff --git a/src/main/resources/public/app/js/verify.js b/src/main/resources/public/app/js/verify.js index daaaa8c..bf9de2e 100644 --- a/src/main/resources/public/app/js/verify.js +++ b/src/main/resources/public/app/js/verify.js @@ -14,8 +14,8 @@ app.controller('VerifyCtrl', function (VerifyService, $scope, $state, $statePara $scope.isLoading = false; $scope.isFinished = true; $timeout(() => { - $state.transitionTo('login') - }, 3000); + $state.transitionTo('login'); + }, 3000); }).catch((error) => { $scope.error = "verification failed." $scope.isLoading = false; diff --git a/src/main/resources/public/app/pages/reset.html b/src/main/resources/public/app/pages/reset.html new file mode 100644 index 0000000..1263f35 --- /dev/null +++ b/src/main/resources/public/app/pages/reset.html @@ -0,0 +1,47 @@ +
+

Grade Master

+ + +
+

+ Reset password +

+
+
+ +

One moment please...

+

Your password has been changed. You will be redirected shortly...

+

Seems like something went wrong. Check your details or try again later.

+
+ + + +
+
You must supply an email.
+
+
+ + + +
+
You must supply a password.
+
No match
+
+
+ + + +
+
You must supply a password.
+
No match
+
{{error}}
+
+
+
+   Reset password   +
+
+
+
+
\ No newline at end of file diff --git a/src/main/resources/public/app/services/retard.service.js b/src/main/resources/public/app/services/retard.service.js index da929a1..b1dbeb7 100644 --- a/src/main/resources/public/app/services/retard.service.js +++ b/src/main/resources/public/app/services/retard.service.js @@ -15,6 +15,6 @@ app.factory('RetardService', function (API) { req: Object.assign({}, API.getUnAuthRequest()) }); }; - + return this; }); \ No newline at end of file diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html index b9602ff..15b1d6c 100644 --- a/src/main/resources/public/index.html +++ b/src/main/resources/public/index.html @@ -33,6 +33,7 @@ + From d3edeae44043f9b0d4c01c75e424d67fde200ed5 Mon Sep 17 00:00:00 2001 From: jstrating Date: Thu, 25 Jan 2018 14:40:44 +0100 Subject: [PATCH 24/30] 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 aaa93a7566da3afa327ad6dc809dc73e97e5c09c Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 16:00:45 +0100 Subject: [PATCH 25/30] Hacky McDacky --- .../grademaster/controller/GroupController.java | 7 ++++--- .../datbois/grademaster/service/GroupService.java | 2 ++ .../service/impl/GroupServiceImpl.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/datbois/grademaster/controller/GroupController.java b/src/main/java/com/datbois/grademaster/controller/GroupController.java index ec06882..0727722 100644 --- a/src/main/java/com/datbois/grademaster/controller/GroupController.java +++ b/src/main/java/com/datbois/grademaster/controller/GroupController.java @@ -69,8 +69,10 @@ public Group getGroup(@PathVariable Long groupId) { public Group changeGroup(@PathVariable Long groupId, @RequestBody Group group) throws Exception { Group existing = groupService.findById(groupId); if (existing == null) throw new InvalidParameterException("Group id not found"); + Set users = group.getUsers(); + group.setUsers(null); // hacks group.copyNonNullProperties(existing); - return groupService.save(existing); + return groupService.save(existing, users); } @RequestMapping(value = "/groups/{groupId}", method = RequestMethod.DELETE) @@ -105,8 +107,7 @@ public Set getGroupUsers(@PathVariable Long groupId) { public Group setGroupUsers(@PathVariable Long groupId, @RequestBody Set users) { Group group = groupService.findById(groupId); if (group == null) throw new InvalidParameterException("Group id not found"); - group.setUsers(users); - return groupService.save(group); + return groupService.save(group, users); } } \ No newline at end of file diff --git a/src/main/java/com/datbois/grademaster/service/GroupService.java b/src/main/java/com/datbois/grademaster/service/GroupService.java index a4d4b21..72d0be2 100644 --- a/src/main/java/com/datbois/grademaster/service/GroupService.java +++ b/src/main/java/com/datbois/grademaster/service/GroupService.java @@ -10,6 +10,8 @@ public interface GroupService { Group save(Group group); + Group save(Group group, Set users); + List findAll(); Group findById(Long id); diff --git a/src/main/java/com/datbois/grademaster/service/impl/GroupServiceImpl.java b/src/main/java/com/datbois/grademaster/service/impl/GroupServiceImpl.java index c74a214..f788ab2 100644 --- a/src/main/java/com/datbois/grademaster/service/impl/GroupServiceImpl.java +++ b/src/main/java/com/datbois/grademaster/service/impl/GroupServiceImpl.java @@ -32,6 +32,11 @@ public Group save(Group group) { return groupRepository.save(setUsers(groupRepository.save(group), group.getUsers())); } + @Override + public Group save(Group group, Set users) { + return groupRepository.save(setUsers(groupRepository.save(group), users)); + } + @Override public List findAll() { return groupRepository.findAll(); @@ -67,6 +72,16 @@ public void delete(Long id) { @Override public Group setUsers(Group group, Set users) { if (users == null) return group; + Group existingGroup = groupRepository.findById(group.getId()); + + for (User u : existingGroup.getUsers()) { // Delete group from the users + User user = userService.findById(u.getId()); + Set groups = user.getGroups(); + groups.remove(group); + user.setGroups(groups); + userService.save(user); + } + group.setUsers(users); for (User u : users) { User user = userService.findById(u.getId()); From 93feb451aab97f04518e429287874f5eaa0a6a5f Mon Sep 17 00:00:00 2001 From: jstrating Date: Thu, 25 Jan 2018 19:38:03 +0100 Subject: [PATCH 26/30] 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({ From e3a344b6263ddb7e040beeceff305c19afe7e372 Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 20:11:07 +0100 Subject: [PATCH 27/30] Fix periods --- .../public/app/components/teacherCard.component.js | 1 + src/main/resources/public/app/js/groups.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index c5f17a6..0232c04 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -151,6 +151,7 @@ function EditGroupDialogController($scope, $mdDialog, EducationService, group, G 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) { + $scope.vm.formData.period = Object.keys($scope.vm.formData.period); GroupService.editGroup($scope.vm.formData, $scope.group.id); $scope.showSimpleToast(); $scope.hide(); diff --git a/src/main/resources/public/app/js/groups.js b/src/main/resources/public/app/js/groups.js index a8ea415..b12f4ea 100644 --- a/src/main/resources/public/app/js/groups.js +++ b/src/main/resources/public/app/js/groups.js @@ -27,10 +27,10 @@ app.controller('TeacherGroupsCtrl', function ($scope, $mdDialog, UserService, Gr $scope.closed = []; $scope.pending = []; $scope.open = []; - - angular.forEach($scope.teacherGroupList, function(value, key) { - GroupService.getGradingStatus(value.id).then(function(response){ - switch(response.data.status){ + + angular.forEach($scope.teacherGroupList, function (value, key) { + GroupService.getGradingStatus(value.id).then(function (response) { + switch (response.data.status) { case "CLOSED": $scope.closed.push(value); break; @@ -109,6 +109,7 @@ app.controller('TeacherGroupsCtrl', function ($scope, $mdDialog, UserService, Gr 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) { + $scope.vm.formData.period = Object.keys($scope.vm.formData.period); GroupService.createGroup($scope.vm.formData); $scope.showSimpleToast(); $scope.hide(); From fc8862337d658e4cb9bd1a1a3a985fa207f5064b Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 20:25:23 +0100 Subject: [PATCH 28/30] Fix group creation --- .../resources/public/app/components/userChipsInput.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/public/app/components/userChipsInput.component.js b/src/main/resources/public/app/components/userChipsInput.component.js index 1cb0df3..6ca9ed2 100644 --- a/src/main/resources/public/app/components/userChipsInput.component.js +++ b/src/main/resources/public/app/components/userChipsInput.component.js @@ -11,7 +11,7 @@ function userChipsInputCtrl(UserService, $scope) { this.users = []; $scope.$watchCollection('$ctrl.selectedUsers', (users) => { - this.users = users; + if(users) this.users = users; }); $scope.$watchCollection('$ctrl.users', (users) => { From 621fb2dabc5c67086fedaa98bfbbbd1ae4e79fe6 Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 20:44:52 +0100 Subject: [PATCH 29/30] Fix periods and auto-selected in edit dialog --- .../app/components/teacherCard.component.js | 15 +++++++++++++-- .../app/components/userChipsInput.component.js | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/resources/public/app/components/teacherCard.component.js b/src/main/resources/public/app/components/teacherCard.component.js index 0232c04..36386e0 100644 --- a/src/main/resources/public/app/components/teacherCard.component.js +++ b/src/main/resources/public/app/components/teacherCard.component.js @@ -115,6 +115,11 @@ function EditGroupDialogController($scope, $mdDialog, EducationService, group, G } }); + const groupPeriods = []; + for(const p of group.period){ + groupPeriods[p] = true; + } + $scope.vm = { formData: { groupName: group.groupName, @@ -127,9 +132,10 @@ function EditGroupDialogController($scope, $mdDialog, EducationService, group, G id: group.course.education.id } }, - period: group.period, + period: groupPeriods, }, }; + $scope.usersChange = (val) => { $scope.vm.formData.users = val; }; @@ -151,7 +157,12 @@ function EditGroupDialogController($scope, $mdDialog, EducationService, group, G 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) { - $scope.vm.formData.period = Object.keys($scope.vm.formData.period); + + const periods = []; + for(const p in $scope.vm.formData.period) { + if($scope.vm.formData.period[p] === true) periods.push(p); + } + $scope.vm.formData.period = periods; GroupService.editGroup($scope.vm.formData, $scope.group.id); $scope.showSimpleToast(); $scope.hide(); diff --git a/src/main/resources/public/app/components/userChipsInput.component.js b/src/main/resources/public/app/components/userChipsInput.component.js index 1cb0df3..b4fcb7e 100644 --- a/src/main/resources/public/app/components/userChipsInput.component.js +++ b/src/main/resources/public/app/components/userChipsInput.component.js @@ -11,7 +11,7 @@ function userChipsInputCtrl(UserService, $scope) { this.users = []; $scope.$watchCollection('$ctrl.selectedUsers', (users) => { - this.users = users; + if(users)this.users = users; }); $scope.$watchCollection('$ctrl.users', (users) => { From 0627e7862bf88d36f23607c46efb4593c65faf6e Mon Sep 17 00:00:00 2001 From: cassshh Date: Thu, 25 Jan 2018 20:46:09 +0100 Subject: [PATCH 30/30] Remove fix from other branch to prevent merge conflict --- .../resources/public/app/components/userChipsInput.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/public/app/components/userChipsInput.component.js b/src/main/resources/public/app/components/userChipsInput.component.js index b4fcb7e..1cb0df3 100644 --- a/src/main/resources/public/app/components/userChipsInput.component.js +++ b/src/main/resources/public/app/components/userChipsInput.component.js @@ -11,7 +11,7 @@ function userChipsInputCtrl(UserService, $scope) { this.users = []; $scope.$watchCollection('$ctrl.selectedUsers', (users) => { - if(users)this.users = users; + this.users = users; }); $scope.$watchCollection('$ctrl.users', (users) => {