This is an automated email from the git hooks/post-receive script. New commit to branch feature/6016-add-question in repository coselmar. See http://git.codelutin.com/coselmar.git commit 30703a4e386ae534260ebf3c60d429848abbee50 Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 2 18:03:53 2014 +0100 prepare page form for questions --- .../src/main/xmi/coselmar-model.zargo | Bin 9640 -> 9632 bytes .../fr/ifremer/coselmar/beans/QuestionBean.java | 10 +- .../coselmar/services/v1/QuestionsWebService.java | 2 +- coselmar-ui/src/main/webapp/css/coselmar.css | 5 + coselmar-ui/src/main/webapp/index.html | 1 + .../src/main/webapp/js/coselmar-controllers.js | 41 ++++++- .../main/webapp/js/coselmar-questions-services.js | 33 ++++++ coselmar-ui/src/main/webapp/js/coselmar.js | 10 ++ .../main/webapp/views/questions/editquestion.html | 123 +++++++++++++++++++++ .../main/webapp/views/questions/newquestion.html | 11 ++ 10 files changed, 229 insertions(+), 7 deletions(-) diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index f4d34ec..bfdc485 100644 Binary files a/coselmar-persistence/src/main/xmi/coselmar-model.zargo and b/coselmar-persistence/src/main/xmi/coselmar-model.zargo differ diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java index 22efff4..ef12af1 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java @@ -20,7 +20,7 @@ public class QuestionBean implements Serializable { protected Date closingDate; - protected String questionType; + protected String type; protected Set<UserBean> participants; @@ -97,12 +97,12 @@ public class QuestionBean implements Serializable { this.closingDate = closingDate; } - public String getQuestionType() { - return questionType; + public String getType() { + return type; } - public void setQuestionType(String questionType) { - this.questionType = questionType; + public void setType(String type) { + this.type = type; } public Set<UserBean> getParticipants() { 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 b88b12e..2d1791c 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 @@ -73,7 +73,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { question.setSummary(questionBean.getSummary()); - question.setQuestionType(questionBean.getQuestionType()); + question.setType(questionBean.getType()); // By default, privacy is private String privacy = questionBean.getPrivacy(); diff --git a/coselmar-ui/src/main/webapp/css/coselmar.css b/coselmar-ui/src/main/webapp/css/coselmar.css index 3c3b180..fa181c4 100644 --- a/coselmar-ui/src/main/webapp/css/coselmar.css +++ b/coselmar-ui/src/main/webapp/css/coselmar.css @@ -67,4 +67,9 @@ body > .container { text-decoration:none; } } +} + +/* remove the stupid float on right with bootstrap close class */ +.close { + float: none; } \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/index.html b/coselmar-ui/src/main/webapp/index.html index b3f9405..9a7953a 100644 --- a/coselmar-ui/src/main/webapp/index.html +++ b/coselmar-ui/src/main/webapp/index.html @@ -41,6 +41,7 @@ <script src="js/coselmar-controllers.js"></script> <script src="js/coselmar-services.js"></script> <script src="js/coselmar-user-services.js"></script> + <script src="js/coselmar-questions-services.js"></script> </head> <body> diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index c8eb358..39243b3 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -259,4 +259,43 @@ coselmarControllers.controller("UserViewCtrl", } }; -} ]); \ No newline at end of file +} ]); + + +///////////////////////////////////////////////// +//////////// Questions Part /////////////////// +///////////////////////////////////////////////// + +// Controller for new question View +coselmarControllers.controller("NewQuestionCtrl", ['$scope', '$route', '$location', 'questionsService', function($scope, $route, $location, questionsService){ + + $scope.question = {'privacy' : 'PUBLIC', 'themes' : []}; + + $scope.saveQuestion = function(isValidForm){ + + // 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); + } + } + +}]); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js new file mode 100644 index 0000000..de81f2b --- /dev/null +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -0,0 +1,33 @@ + +coselmarServices.factory('questionsService', ['$resource', 'coselmar-config', function($resource, coselmarConfig){ + return new Question($resource, coselmarConfig); +}]); + +function Question(resource, config){ + + + this.resource = resource; + var baseURL = config.BASE_URL + "/questions"; + + this.saveQuestion = function(question, successFunction, failFunction){ + + var formData = new FormData(); + formData.append("question", JSON.stringify(question)); + + // Save the User + var serviceURl = baseURL; + if (question.id) { + serviceURl = baseURL + "/" + question.id + } + var questionResource = resource(serviceURl, null, { + 'save': { + method:'POST', + transformRequest: angular.identity, + headers:{ + 'Content-Type': undefined + } + } + }); + questionResource.save(null, formData, successFunction, failFunction); + } +}; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar.js b/coselmar-ui/src/main/webapp/js/coselmar.js index 6a14cca..cc3cd52 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar.js +++ b/coselmar-ui/src/main/webapp/js/coselmar.js @@ -51,6 +51,16 @@ coselmarApp.config(['$routeProvider', function($routeProvider) { controller : 'UserViewCtrl', templateUrl : 'views/users/user.html' + //questions +// }).when('/questions', { +// controller : 'QuestionsCtrl', +// templateUrl : 'views/questions/questions.html' + + }).when('/questions/new', { + controller : 'NewQuestionCtrl', + templateUrl : 'views/questions/newquestion.html' + + }).otherwise({ redirectTo: '/', templateUrl : 'views/home.html' diff --git a/coselmar-ui/src/main/webapp/views/questions/editquestion.html b/coselmar-ui/src/main/webapp/views/questions/editquestion.html new file mode 100644 index 0000000..d284563 --- /dev/null +++ b/coselmar-ui/src/main/webapp/views/questions/editquestion.html @@ -0,0 +1,123 @@ + +<div class=""> + + <form name="questionForm" class="form-horizontal" role="form"> + + <!-- Line with Title --> + <div class="form-group row" ng-class="{'has-error' : questionForm.title.$invalid && !questionForm.title.$pristine }"> + <label class="col-md-2 control-label">Title *</label> + + <div class="col-md-10"> + <input type="text" class="form-control" name="title" ng-minlength="10" + ng-model="question.title" required/> + <p ng-show="questionForm.title.$invalid && !questionForm.title.$pristine" class="help-block">Title is required, minimum 10 characters.</p> + </div> + + </div> + + <!-- End Line with Title --> + + <!-- Line with Type, Privacy and deadline date --> + + <div class="form-group row"> + + <div class="" ng-class="{'has-error' : questionForm.type.$invalid && !questionForm.type.$pristine}"> + <label class="col-md-2 control-label">Type *</label> + + <div class="col-md-2 "> + <input type="text" class="form-control" name="type" + ng-model="question.type" required/> + <p ng-show="questionForm.type.$invalid && !questionForm.type.$pristine" class="help-block">Type is required.</p> + </div> + + </div> + + <div class=""> + <label class="col-md-2 control-label">Visibility</label> + + <div class="col-md-2"> + <select class="form-control" name="privacy" ng-model="question.privacy"> + <option value="PRIVATE">private</option> + <option value="PUBLIC">public</option> + </select> + + </div> + </div> + + <div class="" > + <label class="col-md-2 control-label">Deadline</label> + + <div class="col-md-2"> + <input type="text" class="form-control" name="deadline" + ng-model="question.deadline" + datepicker-popup="dd/MM/yyyy" is-open="deadlineDateOpened" + ng-click="deadlineDateOpened = true" /> + </div> + </div> + + </div> + + <!-- End Line with Type, Privacy and deadline date --> + + <!-- Line with Summary --> + + <div class="form-group" + ng-class="{'has-error' : questionForm.summary.$invalid && !questionForm.summary.$pristine}"> + <label class="col-md-2 control-label">Summary *</label> + + <div class="col-md-10"> + <textarea type="text" class="form-control" name="summary" rows="8" + ng-model="question.summary" required/> + + <p ng-show="questionForm.summary.$invalid && !questionForm.summary.$pristine" + class="help-block">A summary is required.</p> + </div> + </div> + + <!-- End Line with Summary --> + + + <!-- Line with Themes --> + + <div class="form-group" + ng-class="{'has-error' : question.themes.$invalid && question.themes.length < 1 && !questionForm.themes.$pristine}"> + + <form name="questionThemesForm" > + + <label class="col-md-2 control-label">Themes *</label> + + <div class="col-md-2"> + <input type="text" class="form-control" name="themes" + ng-model="toAddTheme"/> + + <p ng-show="question.themes.length < 1 && !questionForm.themes.$pristine" + class="help-block">At least one theme is required.</p> + </div> + + <div class="col-md-1"> + <button class="btn btn-primary" value="add" ng-click="addTheme(toAddTheme); toAddTheme=''">add</button> + </div> + + </form> + + <div class="col-md-7"> + <span ng-repeat="theme in question.themes" class="" aria-hidden="true"> + {{theme}} + <button type="button" class="close" title="remove" ng-click="removeTheme(theme);"> + × + </button> + </span> + </div> + + </div> + + <!-- End Line with Themes --> + + + <div class="form-group" ng-if="questionForm.$valid && question.themes.length > 0"> + <div style="padding-left: 200px"> + <input type="submit" value="Validate" class="btn btn-primary" ng-click="saveQuestion(questionForm.$valid)"/> + </div> + </div> + </form> +</div> \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/questions/newquestion.html b/coselmar-ui/src/main/webapp/views/questions/newquestion.html new file mode 100644 index 0000000..8b3b830 --- /dev/null +++ b/coselmar-ui/src/main/webapp/views/questions/newquestion.html @@ -0,0 +1,11 @@ +<div style="padding: 0px 0px 0px 30px"> + <div class="page-header" style="margin: 0"> + <h2>Add a question</h2> + </div> + + <div style="padding-bottom: 50px" ng-include="src='views/questions/editquestion.html'"> + + + </div> + +</div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.