This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit dfe0dab0b637e914b2e9ebca53557c57f16dd056 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 10 16:11:20 2014 +0100 fix question edit mode --- .../coselmar/services/v1/QuestionsWebService.java | 24 +++- .../src/main/webapp/js/coselmar-controllers.js | 158 +++++++-------------- coselmar-ui/src/main/webapp/js/coselmar.js | 2 +- .../main/webapp/views/questions/editquestion.html | 8 +- .../src/main/webapp/views/questions/question.html | 8 +- 5 files changed, 84 insertions(+), 116 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java index 661775c..d2c900b 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java @@ -434,7 +434,18 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { // On creation, Status is Open if (inEdition) { - questionEntity.setStatus(question.getStatus() != null ? Status.valueOf(question.getStatus().toUpperCase()) : Status.OPEN); + String status = question.getStatus(); + questionEntity.setStatus(status != null ? Status.valueOf(status.toUpperCase()) : Status.OPEN); + + // If it is a close or adjourn update, put a closing date, if it is a reopen, remove closing date + if (Lists.newArrayList(Status.CLOSED.name(), Status.ADJOURNED.name()).contains(status) && questionEntity.getClosingDate() == null) { + questionEntity.setClosingDate(new Date()); + + // it could be a reopen ... + } else if (questionEntity.getClosingDate() != null && !Lists.newArrayList(Status.CLOSED.name(), Status.ADJOURNED.name()).contains(status)) { + questionEntity.setClosingDate(null); + } + } else { questionEntity.setStatus(Status.OPEN); } @@ -462,6 +473,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { // Retrieve the clients Set<UserBean> clients = question.getClients(); + questionEntity.clearClients(); if (clients != null && !clients.isEmpty()) { Set<CoselmarUser> clientEntities = retrieveUsers(clients); questionEntity.addAllClients(clientEntities); @@ -488,6 +500,8 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { participantGroup.clearMembers(); participantGroup.addAllMembers(expertEntities); + } else { + participantGroup.clearMembers(); } } else { @@ -504,6 +518,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { // Retrieve the supervisor Set<UserBean> supervisors = question.getSupervisors(); + questionEntity.clearSupervisors(); if (supervisors != null && !supervisors.isEmpty()) { Set<CoselmarUser> supervisorEntities = retrieveUsers(supervisors); questionEntity.addAllSupervisors(supervisorEntities); @@ -517,7 +532,11 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { Set<QuestionBean> parents = question.getParents(); if (parents != null && !parents.isEmpty()) { Set<Question> questions = retrieveQuestions(parents); + questionEntity.addAllParents(questions); + + } else if(inEdition) { + questionEntity.clearParents(); } @@ -532,7 +551,10 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } } + questionEntity.clearRelatedDocuments(); questionEntity.addAllRelatedDocuments(documents); + } else if (inEdition) { + questionEntity.clearRelatedDocuments(); } commit(); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 993e497..d063fac 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -270,109 +270,6 @@ coselmarControllers.controller("UserViewCtrl", //////////// Questions Part /////////////////// ///////////////////////////////////////////////// -// Controller for new question View -coselmarControllers.controller("NewQuestionCtrl", ['$scope', '$route', '$location', '$modal', - 'questionsService', 'userService', 'documentService', - function($scope, $route, $location, $modal, - questionsService, userService, documentService){ - - $scope.question = {'privacy' : 'PUBLIC', - 'themes' : [], 'participants' : [], 'externalExperts' : [], - 'clients' : [], 'relatedDocuments': [] }; - - $scope.users = { 'participants' : [], 'clients': [], 'supervisors' : []}; - questionsService.findUsers({'role': 'EXPERT', 'active': 'true'}, '', function(users) { - $scope.users.participants = users; - }); - questionsService.findUsers({'role': 'CLIENT', 'active': 'true'}, '', function(users) { - $scope.users.clients = users; - }); - questionsService.findUsers({'role': 'SUPERVISOR', 'active': 'true'}, '', function(users) { - $scope.users.supervisors = users; - }); - - $scope.saveQuestion = function(isValidForm){ - - if (angular.isDate($scope.question.deadline)) { - $scope.question.deadline = $scope.question.deadline.getTime(); - } - - // Call service to create a new user - if(isValidForm) { - questionsService.saveQuestion($scope.question, function() { - $location.path("/questions"); - },function(error) { - //TODO ymartel 20141118 : deal with error.status or statusText - console.log("error occurs"); - console.log(error.s); - }); - } - } - - $scope.addTheme = function(theme) { - if (theme && $scope.question.themes.indexOf(theme) == -1) { - $scope.question.themes.push(theme); - } - } - - $scope.removeTheme = function(theme) { - var position = $scope.question.themes.indexOf(theme); - if (theme && position != -1) { - $scope.question.themes.splice(position, 1); - } - } - - $scope.searchDocuments = function () { - - var modalInstance = $modal.open({ - templateUrl: 'views/documents/modalDocumentSearch.html', - controller: 'ModalSearchDocumentsCtrl', - size: 'lg' - }); - - modalInstance.result.then(function (selectedDocument) { - var already = false; - for (var i = 0; i < $scope.question.relatedDocuments.length; i++) { - if ($scope.question.relatedDocuments[i].id == selectedDocument.id) { - already = true - } - } - if (!already) { - $scope.question.relatedDocuments.push(selectedDocument); - } - }); - }; - - $scope.createDocument = function () { - - var modalInstance = $modal.open({ - templateUrl: 'views/documents/modalDocumentEdit.html', - controller: 'ModalCreateDocumentsCtrl', - size: 'lg' - }); - - modalInstance.result.then(function (selectedDocument) { - var already = false; - for (var i = 0; i < $scope.question.relatedDocuments.length; i++) { - if ($scope.question.relatedDocuments[i].id == selectedDocument.id) { - already = true - } - } - if (!already) { - $scope.question.relatedDocuments.push(selectedDocument); - } - }); - }; - - $scope.removeDocument = function(document) { - var position = $scope.question.relatedDocuments.indexOf(document); - if (document && position != -1) { - $scope.question.relatedDocuments.splice(position, 1); - } - } - -}]); - // Controller for All Question View coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routeParams', '$location', 'questionsService', function($scope, $route, $routeParams, $location, questionsService){ @@ -428,7 +325,10 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam $scope.editMode = $routeParams.edit ? $routeParams.edit : false; $scope.isCurrentParticipant = false; - $scope.question = { 'newRelatedDocuments': []}; + + $scope.question = {'privacy' : 'PUBLIC', + 'themes' : [], 'participants' : [], 'externalExperts' : [], + 'clients' : [], 'relatedDocuments': [], 'newRelatedDocuments' : [] }; //to enter in edit mode from view $scope.edit = function() { @@ -496,9 +396,9 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam }; - - questionsService.getQuestion($routeParams.questionId, - function(question) { + if ($routeParams.questionId) { + questionsService.getQuestion($routeParams.questionId, + function(question) { // success : just get the questions $scope.question = question; @@ -514,6 +414,10 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam } } + if(!question.relatedDocuments) { + $scope.question.relatedDocuments = []; + } + if (question.participants) { $scope.users.participants = question.participants; bindUsers($scope.question.participants, $scope.participantsIndex); @@ -531,7 +435,8 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam // Fail function : TODO console.log("error during request"); console.log(error); - }); + }); + }; //Deletion $scope.deleteQuestion = function(){ @@ -560,10 +465,43 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam }); }; + $scope.saveQuestion = function(isValidForm){ + + if (angular.isDate($scope.question.deadline)) { + $scope.question.deadline = $scope.question.deadline.getTime(); + } + + // Call service to create a new user + if(isValidForm) { + questionsService.saveQuestion($scope.question, function() { + if ($routeParams.questionId) { + $location.search(""); + } else { + $location.path("/questions"); + } + },function(error) { + //TODO ymartel 20141118 : deal with error.status or statusText + console.log("error occurs"); + console.log(error.s); + }); + } + } + $scope.closeQuestion = function(){ $scope.question.status = "CLOSED"; questionsService.saveQuestion($scope.question, function() { - $location.search(""); + $route.reload(); + },function(error) { + //TODO ymartel 20141118 : deal with error.status or statusText + console.log("error occurs"); + console.log(error.s); + }); + }; + + $scope.reopenQuestion = function(){ + $scope.question.status = "IN_PROGRESS"; + questionsService.saveQuestion($scope.question, function() { + $route.reload(); },function(error) { //TODO ymartel 20141118 : deal with error.status or statusText console.log("error occurs"); @@ -574,7 +512,7 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam $scope.adjournQuestion = function(){ $scope.question.status = "ADJOURNED"; questionsService.saveQuestion($scope.question, function() { - $location.search(""); + $route.reload(); },function(error) { //TODO ymartel 20141118 : deal with error.status or statusText console.log("error occurs"); diff --git a/coselmar-ui/src/main/webapp/js/coselmar.js b/coselmar-ui/src/main/webapp/js/coselmar.js index cf7cd2f..208594c 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar.js +++ b/coselmar-ui/src/main/webapp/js/coselmar.js @@ -57,7 +57,7 @@ coselmarApp.config(['$routeProvider', function($routeProvider) { templateUrl : 'views/questions/questions.html' }).when('/questions/new', { - controller : 'NewQuestionCtrl', + controller : 'QuestionCtrl', templateUrl : 'views/questions/newquestion.html' }).when('/questions/:questionId', { diff --git a/coselmar-ui/src/main/webapp/views/questions/editquestion.html b/coselmar-ui/src/main/webapp/views/questions/editquestion.html index f58aedb..4a95d72 100644 --- a/coselmar-ui/src/main/webapp/views/questions/editquestion.html +++ b/coselmar-ui/src/main/webapp/views/questions/editquestion.html @@ -228,8 +228,10 @@ <th>Keywords</th> <th>Deposit Date</th> <th> - <a class="btn fa fa-search" title="Search document" ng-click="searchDocuments()" /> - <a class="btn fa fa-plus" title="Add new Document" ng-click="createDocument()"/> + <a class="btn fa fa-search" title="Search document" + ng-click="modalSearchDocuments(question.relatedDocuments)" /> + <a class="btn fa fa-plus" title="Add new Document" + ng-click="modalCreateDocument(question.relatedDocuments)"/> </th> </tr> <tr ng-repeat="document in question.relatedDocuments"> @@ -238,7 +240,7 @@ <td><span ng-repeat="keyword in document.keywords">{{keyword}}, </span></td> <td>{{document.depositDate | date:'mediumDate'}}</td> <td><a class="btn fa fa-minus" title="Remove document" - ng-click="removeDocument(document)" + ng-click="removeDocument(document, question.relatedDocuments)" ng-if="currentUser.role == 'SUPERVISOR'"/></td> </tr> </table> diff --git a/coselmar-ui/src/main/webapp/views/questions/question.html b/coselmar-ui/src/main/webapp/views/questions/question.html index b0d5ab5..dcf238c 100644 --- a/coselmar-ui/src/main/webapp/views/questions/question.html +++ b/coselmar-ui/src/main/webapp/views/questions/question.html @@ -16,7 +16,7 @@ <div style="padding-bottom: 50px" ng-if="editMode == true"> <form name="questionForm" class="form-horizontal" role="form"> <div ng-include="src='views/questions/editquestion.html'"></div> - <div class="form-group" style="padding-left: 200px"><a class="btn btn-action btn-success" ng-click="saveQuestion()"> + <div class="form-group" style="padding-left: 200px"><a class="btn btn-action btn-success" ng-click="saveQuestion(true)"> <span class="fa fa-check-square-o" aria-hidden="true"></span>Validate changes </a></div> </form> @@ -26,6 +26,12 @@ Closed on {{question.closingDate | date:'medium' }}. </div> + <div class="text-center" ng-if="question.closingDate && currentUser.role == 'SUPERVISOR' && editMode == false"> + <a class="btn btn-action btn-success" ng-click="reopenQuestion()"> + <span class="fa fa-check-square-o" aria-hidden="true"></span>Reopen + </a> + </div> + <div class="text-center" ng-if="!question.closingDate && currentUser.role == 'SUPERVISOR' && editMode == false"> <a class="btn btn-action btn-success" ng-click="closeQuestion()"> <span class="fa fa-check-square-o" aria-hidden="true"></span>Close -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.