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 e0ddaeec70c316fc305c402146bd843e3758efd1 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Jan 30 12:04:26 2015 +0100 fixes #6593 review management of question.themes in UI and in services --- .../indexation/DocumentsIndexationService.java | 12 +++-- .../indexation/QuestionsIndexationService.java | 12 +++-- .../coselmar/services/v1/QuestionsWebService.java | 14 +++++ .../src/main/webapp/js/coselmar-controllers.js | 60 ++++++++++------------ .../main/webapp/views/questions/editquestion.html | 9 ++-- .../main/webapp/views/questions/newquestion.html | 2 +- .../src/main/webapp/views/questions/question.html | 3 -- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java index a6323df..c8fc36d 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java @@ -79,8 +79,10 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); Set<String> keywords = document.getKeywords(); - for (String keyword : keywords) { - doc.add(new Field(DOCUMENT_KEYWORD_INDEX_PROPERTY, keyword, TextField.TYPE_STORED)); + if (keywords != null) { + for (String keyword : keywords) { + doc.add(new Field(DOCUMENT_KEYWORD_INDEX_PROPERTY, keyword, TextField.TYPE_STORED)); + } } getLuceneUtils().getIndexWriter().addDocument(doc); @@ -205,8 +207,10 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new TextField(DOCUMENT_SUMMARY_INDEX_PROPERTY, document.getSummary(), Field.Store.YES)); Set<String> keywords = document.getKeywords(); - for (String keyword : keywords) { - doc.add(new Field(DOCUMENT_KEYWORD_INDEX_PROPERTY, keyword, TextField.TYPE_STORED)); + if (keywords != null) { + for (String keyword : keywords) { + doc.add(new Field(DOCUMENT_KEYWORD_INDEX_PROPERTY, keyword, TextField.TYPE_STORED)); + } } doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java index 0a8b864..f6e9f65 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java @@ -92,8 +92,10 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new TextField(QUESTION_SUMMARY_INDEX_PROPERTY, question.getSummary(), Field.Store.YES)); Set<String> themes = question.getThemes(); - for (String theme : themes) { - doc.add(new Field(QUESTION_THEME_INDEX_PROPERTY, theme, TextField.TYPE_STORED)); + if (themes != null) { + for (String theme : themes) { + doc.add(new Field(QUESTION_THEME_INDEX_PROPERTY, theme, TextField.TYPE_STORED)); + } } doc.add(new TextField(QUESTION_STATUS_INDEX_PROPERTY, question.getStatus(), Field.Store.YES)); @@ -117,8 +119,10 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new TextField(QUESTION_PRIVACY_INDEX_PROPERTY, question.getPrivacy(), Field.Store.YES)); Set<String> themes = question.getThemes(); - for (String theme : themes) { - doc.add(new Field(QUESTION_THEME_INDEX_PROPERTY, theme, TextField.TYPE_STORED)); + if (themes != null) { + for (String theme : themes) { + doc.add(new Field(QUESTION_THEME_INDEX_PROPERTY, theme, TextField.TYPE_STORED)); + } } doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); 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 15ef989..3d5887b 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 @@ -33,6 +33,7 @@ import java.util.List; import java.util.Set; import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; @@ -102,6 +103,12 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { throw new InvalidCredentialException(message); } + Preconditions.checkNotNull(question); + Preconditions.checkNotNull(question.getTitle()); + Preconditions.checkNotNull(question.getSummary()); + Preconditions.checkNotNull(question.getType()); + Preconditions.checkNotNull(question.getThemes()); + // let's go Question questionEntity = getQuestionDao().create(); @@ -513,6 +520,13 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { throw new InvalidCredentialException(message); } + Preconditions.checkNotNull(question); + Preconditions.checkNotNull(question.getTitle()); + Preconditions.checkNotNull(question.getSummary()); + Preconditions.checkNotNull(question.getType()); + Preconditions.checkNotNull(question.getThemes()); + + // let's go Question questionEntity; // An update diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index aa12114..35509b5 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -759,42 +759,30 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam }); }; - $scope.saveQuestion = function(){ - if (angular.isDate($scope.question.deadline)) { - $scope.question.deadline = $scope.question.deadline.getTime(); - } - - // Call service to create a new user - questionsService.saveQuestion($scope.question, function() { - $location.search(""); - },function(error) { - //TODO ymartel 20141118 : deal with error.status or statusText - console.log("error occurs"); - console.log(error.s); - }); - }; - - $scope.saveQuestion = function(isValidForm){ + $scope.saveQuestion = function() { 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); - }); - } - } + if (!$scope.question.themes || $scope.question.themes.length == 0) { + console.log($scope.question) + $scope.themesError = true; + } else { + // Call service to create a new question + 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"; @@ -854,9 +842,14 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam }; $scope.addTheme = function(theme) { - if (theme && $scope.question.themes.indexOf(theme) == -1) { + if (!$scope.question.themes) { + $scope.question.themes = []; + $scope.question.themes.push(theme); + + } else if (theme && $scope.question.themes.indexOf(theme) == -1) { $scope.question.themes.push(theme); } + $scope.themesError = false; } $scope.removeTheme = function(theme) { @@ -864,6 +857,9 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam if (theme && position != -1) { $scope.question.themes.splice(position, 1); } + if ($scope.question.themes.length == 0) { + $scope.themesError = true; + } } // Modals part for documents diff --git a/coselmar-ui/src/main/webapp/views/questions/editquestion.html b/coselmar-ui/src/main/webapp/views/questions/editquestion.html index 43a7b2e..06725af 100644 --- a/coselmar-ui/src/main/webapp/views/questions/editquestion.html +++ b/coselmar-ui/src/main/webapp/views/questions/editquestion.html @@ -112,17 +112,17 @@ <!-- Line with Themes --> <div class="form-group" - ng-class="{'has-error' : question.themes.$invalid && question.themes.length < 1 && !questionForm.themes.$pristine}"> + ng-class="{'has-error' : (question.themes.$invalid && question.themes.length < 1 && !questionForm.themes.$pristine) || themesError == true}"> <label class="col-md-2 control-label">{{ 'question.metadata.themes' | translate }} *</label> - <div class="col-md-2"> + <div class="col-md-2" > <input type="text" class="form-control" name="themes" placeholder="Validate with add" data-ng-model="toAddTheme" list="existingThemes" /> - <p ng-show="question.themes.length < 1 && !questionForm.themes.$pristine" + <p ng-show="(question.themes.length < 1 && !questionForm.themes.$pristine) || themesError == true" class="help-block">{{ 'question.message.requiredThemes' | translate }}</p> </div> <datalist id="existingThemes"> @@ -334,6 +334,9 @@ </div> + <div class="form-group actions"><a class="btn btn-action btn-success" ng-click="saveQuestion()" ng-disabled="questionForm.$invalid || question.themes.length == 0"> + <span class="fa fa-check-square-o" aria-hidden="true"></span>{{ 'question.button.validateChanges' | translate }} + </a></div> </div> diff --git a/coselmar-ui/src/main/webapp/views/questions/newquestion.html b/coselmar-ui/src/main/webapp/views/questions/newquestion.html index fb9969e..822dc4d 100644 --- a/coselmar-ui/src/main/webapp/views/questions/newquestion.html +++ b/coselmar-ui/src/main/webapp/views/questions/newquestion.html @@ -34,7 +34,7 @@ <div ng-include="src='views/questions/editquestion.html'"></div> <div class="form-group actions"> - <input type="submit" value="Validate" class="btn btn-action" ng-click="saveQuestion(questionForm.$valid)" ng-disabled="questionForm.$invalid"/> + <input type="submit" value="Validate" class="btn btn-action" ng-click="saveQuestion()" ng-disabled="questionForm.$invalid || question.themes.length == 0"/> </div> </form> </div> diff --git a/coselmar-ui/src/main/webapp/views/questions/question.html b/coselmar-ui/src/main/webapp/views/questions/question.html index e8bd1c3..4df990d 100644 --- a/coselmar-ui/src/main/webapp/views/questions/question.html +++ b/coselmar-ui/src/main/webapp/views/questions/question.html @@ -41,9 +41,6 @@ <div style="padding-bottom: 50px" ng-if="editSession == true"> <form name="questionForm" class="form-horizontal" role="form"> <div ng-include="src='views/questions/editquestion.html'"></div> - <div class="form-group actions"><a class="btn btn-action btn-success" ng-click="saveQuestion(true)"> - <span class="fa fa-check-square-o" aria-hidden="true"></span>{{ 'question.button.validateChanges' | translate }} - </a></div> </form> </div> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.