branch develop updated (aac2c1f -> 05f4622)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from aac2c1f Merge branch 'develop' of https://git.codelutin.com/coselmar into develop new 89abcfe fixes #6016 add entry in application to add question new 05f4622 list questions, can delete them The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 05f46225810fb69fa65dceafe37bc8427d13b0c1 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 5 18:16:27 2014 +0100 list questions, can delete them commit 89abcfe0aefe5f76ce4d62b4f76a4d5de52fa8a1 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 5 11:21:53 2014 +0100 fixes #6016 add entry in application to add question Summary of changes: .../fr/ifremer/coselmar/beans/QuestionBean.java | 50 +++++++++ .../coselmar/converter/BeanEntityConverter.java | 92 +++++++++++++++++ .../coselmar/services/v1/DocumentsWebService.java | 2 +- .../coselmar/services/v1/QuestionsWebService.java | 113 +++++++++++++++++++-- coselmar-rest/src/main/resources/mapping | 8 +- coselmar-ui/pom.xml | 20 ++-- coselmar-ui/src/main/webapp/index.html | 8 +- .../src/main/webapp/js/coselmar-controllers.js | 31 +++++- .../main/webapp/js/coselmar-questions-services.js | 9 ++ coselmar-ui/src/main/webapp/js/coselmar.js | 6 +- .../main/webapp/views/questions/editquestion.html | 2 +- .../main/webapp/views/questions/newquestion.html | 7 +- .../src/main/webapp/views/questions/questions.html | 47 +++++++++ 13 files changed, 367 insertions(+), 28 deletions(-) create mode 100644 coselmar-ui/src/main/webapp/views/questions/questions.html -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 89abcfe0aefe5f76ce4d62b4f76a4d5de52fa8a1 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 5 11:21:53 2014 +0100 fixes #6016 add entry in application to add question --- coselmar-ui/src/main/webapp/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coselmar-ui/src/main/webapp/index.html b/coselmar-ui/src/main/webapp/index.html index 83cff41..d4b3650 100644 --- a/coselmar-ui/src/main/webapp/index.html +++ b/coselmar-ui/src/main/webapp/index.html @@ -79,8 +79,8 @@ <li class="dropdown"> <a role="button" class="dropdown-toggle">Questions<span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> - <!--<li><a href="#/questions">List</a></li>--> - <!--<li><a href="#/questions">List</a></li>--> + <!--<li><a href="#/questions">List</a></li>--> + <li><a href="#/questions/new">Add a question</a></li> </ul> </li> </ul> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 05f46225810fb69fa65dceafe37bc8427d13b0c1 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 5 18:16:27 2014 +0100 list questions, can delete them --- .../fr/ifremer/coselmar/beans/QuestionBean.java | 50 +++++++++ .../coselmar/converter/BeanEntityConverter.java | 92 +++++++++++++++++ .../coselmar/services/v1/DocumentsWebService.java | 2 +- .../coselmar/services/v1/QuestionsWebService.java | 113 +++++++++++++++++++-- coselmar-rest/src/main/resources/mapping | 8 +- coselmar-ui/pom.xml | 20 ++-- coselmar-ui/src/main/webapp/index.html | 4 +- .../src/main/webapp/js/coselmar-controllers.js | 31 +++++- .../main/webapp/js/coselmar-questions-services.js | 9 ++ coselmar-ui/src/main/webapp/js/coselmar.js | 6 +- .../main/webapp/views/questions/editquestion.html | 2 +- .../main/webapp/views/questions/newquestion.html | 7 +- .../src/main/webapp/views/questions/questions.html | 47 +++++++++ 13 files changed, 365 insertions(+), 26 deletions(-) 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 ef12af1..7f306c6 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 @@ -2,6 +2,7 @@ package fr.ifremer.coselmar.beans; import java.io.Serializable; import java.util.Date; +import java.util.HashSet; import java.util.Set; public class QuestionBean implements Serializable { @@ -113,6 +114,13 @@ public class QuestionBean implements Serializable { this.participants = participants; } + public void addParticipant(UserBean participant) { + if (this.participants == null) { + this.participants = new HashSet<>(); + } + this.participants.add(participant); + } + public Set<UserBean> getSupervisors() { return supervisors; } @@ -121,6 +129,13 @@ public class QuestionBean implements Serializable { this.supervisors = supervisors; } + public void addSupervisor(UserBean supervisor) { + if (this.supervisors == null) { + this.supervisors = new HashSet<>(); + } + this.supervisors.add(supervisor); + } + public Set<UserBean> getContributors() { return contributors; } @@ -129,6 +144,13 @@ public class QuestionBean implements Serializable { this.contributors = contributors; } + public void addContributor(UserBean contributor) { + if (this.contributors == null) { + this.contributors = new HashSet<>(); + } + this.contributors.add(contributor); + } + public Set<UserBean> getClients() { return clients; } @@ -137,6 +159,13 @@ public class QuestionBean implements Serializable { this.clients = clients; } + public void addClient(UserBean client) { + if (this.clients == null) { + this.clients = new HashSet<>(); + } + this.clients.add(client); + } + public Set<QuestionBean> getParents() { return parents; } @@ -145,6 +174,13 @@ public class QuestionBean implements Serializable { this.parents = parents; } + public void addParent(QuestionBean parent) { + if(this.parents == null) { + this.parents = new HashSet<>(); + } + this.parents.add(parent); + } + public Set<QuestionBean> getChildren() { return children; } @@ -153,6 +189,13 @@ public class QuestionBean implements Serializable { this.children = children; } + public void addChild(QuestionBean child) { + if(this.children == null) { + this.children = new HashSet<>(); + } + this.children.add(child); + } + public String getPrivacy() { return privacy; } @@ -169,6 +212,13 @@ public class QuestionBean implements Serializable { this.relatedDocuments = relatedDocuments; } + public void addRelatedDocument(DocumentBean relatedDocument) { + if (this.relatedDocuments == null) { + this.relatedDocuments = new HashSet<>(); + } + this.relatedDocuments.add(relatedDocument); + } + public String getStatus() { return status; } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index 0eae916..589260d 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -24,15 +24,22 @@ package fr.ifremer.coselmar.converter; * #L% */ +import java.util.Collection; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import fr.ifremer.coselmar.beans.DocumentBean; +import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.UserBean; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; +import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; import fr.ifremer.coselmar.persistence.entity.CoselmarUserImpl; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; import fr.ifremer.coselmar.persistence.entity.Document; +import fr.ifremer.coselmar.persistence.entity.Question; import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaIdFactory; /** * @author ymartel <martel@codelutin.com> @@ -98,4 +105,89 @@ public class BeanEntityConverter { return user; } + public static QuestionBean toBean(TopiaIdFactory idFactory, Question question) { + QuestionBean result = new QuestionBean(); + result.setId(idFactory.getRandomPart(question.getTopiaId())); + + result.setTitle(question.getTitle()); + result.setSummary(question.getSummary()); + result.setType(question.getType()); + result.setPrivacy(question.getPrivacy().name()); + + Collection<String> theme = question.getTheme(); + if (theme != null && !theme.isEmpty()) { + result.setTheme(new HashSet(theme)); + } + + Date submissionDate = question.getSubmissionDate(); + if (submissionDate != null){ + result.setSubmissionDate(new Date(submissionDate.getTime())); + } + + Date deadline = question.getDeadline(); + if (deadline != null){ + result.setDeadline(new Date(deadline.getTime())); + } + + Date closingDate = question.getClosingDate(); + if (closingDate != null){ + result.setClosingDate(new Date(closingDate.getTime())); + } + + CoselmarUserGroup participants = question.getParticipants(); + if (participants != null && participants.getMembers() != null) { + for (CoselmarUser participant : participants.getMembers()) { + String lightId = idFactory.getRandomPart(participant.getTopiaId()); + UserBean participantBean = toBean(lightId, participant); + result.addParticipant(participantBean); + } + } + + Set<CoselmarUser> supervisors = question.getSupervisors(); + if (supervisors != null && !supervisors.isEmpty()) { + for (CoselmarUser supervisor : supervisors) { + String lightId = idFactory.getRandomPart(supervisor.getTopiaId()); + UserBean supervisorBean = toBean(lightId, supervisor); + result.addSupervisor(supervisorBean); + } + } + + Set<CoselmarUser> clients = question.getClients(); + if (clients != null && !clients.isEmpty()) { + for (CoselmarUser client : clients) { + String lightId = idFactory.getRandomPart(client.getTopiaId()); + UserBean clientBean = toBean(lightId, client); + result.addClient(clientBean); + } + } + + Set<CoselmarUser> contributors = question.getContributors(); + if (contributors != null && !contributors.isEmpty()) { + for (CoselmarUser contributor : contributors) { + String lightId = idFactory.getRandomPart(contributor.getTopiaId()); + UserBean contributorBean = toBean(lightId, contributor); + result.addClient(contributorBean); + } + } + + Collection<Document> relatedDocuments = question.getRelatedDocuments(); + if (relatedDocuments != null && !relatedDocuments.isEmpty()) { + for (Document relatedDocument : relatedDocuments) { + String lightId = idFactory.getRandomPart(relatedDocument.getTopiaId()); + DocumentBean documentBean = toBean(lightId, relatedDocument); + result.addRelatedDocument(documentBean); + } + } + + Collection<Question> parents = question.getParents(); + if (parents != null && !parents.isEmpty()) { + for (Question parent : parents) { + QuestionBean questionBean = toBean(idFactory, parent); + result.addParent(questionBean); + } + } + + return result; + } + } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index f3940ab..528257c 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -116,7 +116,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { List<Document> documentList; // Admin and Supervisor can see all documents (public, private and restricted) - if (Lists.newArrayList(CoselmarUserRole.ADMIN.name(), CoselmarUserRole.ADMIN.name()).contains(currentUserRole)) { + if (Lists.newArrayList(CoselmarUserRole.ADMIN.name(), CoselmarUserRole.SUPERVISOR.name()).contains(currentUserRole)) { documentList = findAllDocuments(searchKeywords); } else { 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 19fa8ef..4284cb9 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 @@ -1,5 +1,6 @@ package fr.ifremer.coselmar.services.v1; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashSet; @@ -12,6 +13,7 @@ import fr.ifremer.coselmar.beans.DocumentBean; import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.UserBean; import fr.ifremer.coselmar.beans.UserWebToken; +import fr.ifremer.coselmar.converter.BeanEntityConverter; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; @@ -19,13 +21,13 @@ import fr.ifremer.coselmar.persistence.entity.Document; import fr.ifremer.coselmar.persistence.entity.Privacy; import fr.ifremer.coselmar.persistence.entity.Question; import fr.ifremer.coselmar.persistence.entity.Status; -import fr.ifremer.coselmar.services.CoselmarTechnicalException; import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; import fr.ifremer.coselmar.services.errors.UnauthorizedException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaIdFactory; import org.nuiton.topia.persistence.TopiaNoResultException; /** @@ -62,11 +64,11 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { supervisor = getCoselmarUserDao().forTopiaIdEquals(fullId).findUnique(); } catch (TopiaNoResultException tnre) { // Should not happened, cause user are not really deleted - String message = String.format("Seems that logged user ('%s') does not exist anymore.", fullId); + String message = String.format("Logged user ('%s') does not exist.", fullId); if (log.isErrorEnabled()) { - log.equals(message); + log.error(message); } - throw new CoselmarTechnicalException(message); + throw new InvalidCredentialException(message); } // let's go @@ -80,6 +82,11 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { questionEntity.setType(question.getType()); + Set<String> themes = question.getTheme(); + if (themes != null) { + questionEntity.setTheme(new HashSet(themes)); + } + // By default, privacy is private String privacy = question.getPrivacy(); Privacy realPrivacy = privacy != null ? Privacy.valueOf(privacy.toUpperCase()) : Privacy.PRIVATE; @@ -92,6 +99,8 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { Date submissionDate = question.getSubmissionDate(); if (submissionDate != null) { questionEntity.setSubmissionDate(new Date(submissionDate.getTime())); + } else { + questionEntity.setSubmissionDate(new Date()); } Date deadline = question.getDeadline(); @@ -160,6 +169,99 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { questionEntity.addAllRelatedDocuments(documents); } + commit(); + } + + public List<QuestionBean> getQuestions() throws InvalidCredentialException, UnauthorizedException { + + // Check authentication + String authorization = getContext().getHeader("Authorization"); + UserWebToken userWebToken = checkAuthentication(authorization); + + // Retrieve current user + String fullCurrentUserId = getFullUserIdFromShort(userWebToken.getUserId()); + CoselmarUser currentUser = getCoselmarUserDao().forTopiaIdEquals(fullCurrentUserId).findAnyOrNull(); + + String currentUserRole = userWebToken.getRole().toUpperCase(); + + List<Question> questionList; + + if (StringUtils.equalsIgnoreCase(CoselmarUserRole.ADMIN.name(), currentUserRole) + || StringUtils.equalsIgnoreCase(CoselmarUserRole.SUPERVISOR.name(), currentUserRole)) { + questionList = getQuestionDao().findAll(); + + } else if (StringUtils.equalsIgnoreCase(CoselmarUserRole.MEMBER.name(), currentUserRole)) { + questionList = getQuestionDao().forPrivacyEquals(Privacy.PUBLIC).findAll(); + + } else if (StringUtils.equalsIgnoreCase(CoselmarUserRole.CLIENT.name(), currentUserRole)) { + questionList = getQuestionDao().forClientsContains(currentUser).findAll(); + } else { + String message = "Not allowed to access this page"; + if (log.isWarnEnabled()) { + log.warn("Unknown user type try to access questions list."); + } + throw new UnauthorizedException(message); + } + + List<QuestionBean> result = new ArrayList<>(questionList.size()); + + for (Question question : questionList) { + TopiaIdFactory topiaIdFactory = getPersistenceContext().getTopiaIdFactory(); + QuestionBean questionBean = BeanEntityConverter.toBean(topiaIdFactory, question); + result.add(questionBean); + } + + return result; + } + + public void deleteQuestion(String questionId) throws InvalidCredentialException, UnauthorizedException { + + // Check authentication + String authorization = getContext().getHeader("Authorization"); + UserWebToken userWebToken = checkAuthentication(authorization); + + // Only Supervisor can add question + String userRole = userWebToken.getRole(); + + if (!StringUtils.equalsIgnoreCase(CoselmarUserRole.SUPERVISOR.name(), userRole) + && StringUtils.equalsIgnoreCase(CoselmarUserRole.ADMIN.name(), userRole)) { + String message = String.format("User %s %s ('%s') is not allowed to delete question", + userWebToken.getFirstName(), userWebToken.getLastName(), userWebToken.getUserId()); + if (log.isWarnEnabled()) { + log.warn(message); + } + throw new UnauthorizedException(message); + + } + + String fullUserId = getFullIdFromShort(CoselmarUser.class, userWebToken.getUserId()); + + try { + getCoselmarUserDao().forTopiaIdEquals(fullUserId).findUnique(); + } catch (TopiaNoResultException tnre) { + // Should not happened, cause user are not really deleted + String message = String.format("Logged user ('%s') does not exist.", fullUserId); + if (log.isErrorEnabled()) { + log.error(message); + } + throw new InvalidCredentialException(message); + } + + // Retrieve Question + String fullQuestionId = getFullIdFromShort(Question.class, questionId); + Question question = getQuestionDao().forTopiaIdEquals(fullQuestionId).findUnique(); + + // Participant group should be deleted, and so, we should remove it from Document using this group + CoselmarUserGroup participantGroup = question.getParticipants(); + List<Document> documents = getDocumentDao().forRestrictedListContains(participantGroup).findAll(); + for (Document document : documents) { + document.removeRestrictedList(participantGroup); + } + + getQuestionDao().delete(question); + getPersistenceContext().getCoselmarUserGroupDao().delete(participantGroup); + + commit(); } @@ -210,7 +312,4 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } - protected String getFullQuestionIdFromShort(String shortQuestionId) { - return Question.class.getCanonicalName() + getPersistenceContext().getTopiaIdFactory().getSeparator() + shortQuestionId; - } } diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index 8e557c1..173dc88 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -23,7 +23,7 @@ default.render=fr.ifremer.coselmar.services.CoselmarRender # DocApi -GET /v1/doc DocApi.showMapping +GET /v1/doc DocApi.showMapping # Documents Api @@ -45,10 +45,10 @@ DELETE /v1/users/{userId} UsersWebService.deleteUser # Questions Api -#GET /v1/questions QuestionsWebService.getQuestions +GET /v1/questions QuestionsWebService.getQuestions #GET /v1/questions/{questionId} QuestionsWebService.getQuestion #POST /v1/questions/{questionId} QuestionsWebService.saveQuestion #POST /v1/questions/{questionId}/documents QuestionsWebService.addDocuments -POST /v1/questions QuestionsWebService.addQuestion -#DELETE /v1/questions/{questionId} QuestionsWebService.closeQuestion +POST /v1/questions QuestionsWebService.addQuestion +DELETE /v1/questions/{questionId} QuestionsWebService.deleteQuestion diff --git a/coselmar-ui/pom.xml b/coselmar-ui/pom.xml index 974f36b..23aae44 100644 --- a/coselmar-ui/pom.xml +++ b/coselmar-ui/pom.xml @@ -59,12 +59,12 @@ <scope>runtime</scope> </dependency> - <dependency> - <groupId>org.nuiton.js</groupId> - <artifactId>nuiton-js-angular-ui-bootstrap</artifactId> - <version>0.11.0-2</version> - <scope>runtime</scope> - </dependency> + <!--<dependency>--> + <!--<groupId>org.nuiton.js</groupId>--> + <!--<artifactId>nuiton-js-angular-ui-bootstrap</artifactId>--> + <!--<version>0.11.0-2</version>--> + <!--<scope>runtime</scope>--> + <!--</dependency>--> <dependency> <groupId>org.nuiton.js</groupId> @@ -85,6 +85,14 @@ <artifactId>angular-ui-select</artifactId> <scope>runtime</scope> </dependency> + + <dependency> + <groupId>org.webjars</groupId> + <artifactId>angular-ui-bootstrap</artifactId> + <version>0.12.0</version> + <scope>runtime</scope> + </dependency> + </dependencies> <build> diff --git a/coselmar-ui/src/main/webapp/index.html b/coselmar-ui/src/main/webapp/index.html index d4b3650..d430a3e 100644 --- a/coselmar-ui/src/main/webapp/index.html +++ b/coselmar-ui/src/main/webapp/index.html @@ -33,12 +33,14 @@ <script src="nuiton-js/angular-resource.js"></script> <script src="nuiton-js/angular.js"></script> <script src="nuiton-js/angular-messages.js"></script> - <script src="nuiton-js/angular-ui-bootstrap.js"></script> + <!--<script src="nuiton-js/angular-ui-bootstrap.js"></script>--> <script src="nuiton-js/bootstrap.js"></script> <!--TODO ymartel 20141203 : extract version, or use wro --> <script src="webjars/angular-ui-select/0.9.0/select.js"></script> <link rel="stylesheet" href="webjars/angular-ui-select/0.9.0/select.css"> + <script src="webjars/angular-ui-bootstrap/0.12.0/ui-bootstrap.js"></script> + <script src="webjars/angular-ui-bootstrap/0.12.0/ui-bootstrap-tpls.js"></script> <script src="js/angular-jwt.js"></script> <script src="js/coselmar.js"></script> diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index e19dc55..8e1abde 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -21,7 +21,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -var coselmarControllers = angular.module('coselmarControllers', ['ui.bootstrap', 'ui.select']); +var coselmarControllers = angular.module('coselmarControllers', ['ui.bootstrap', 'ui.select', 'ui.bootstrap.tooltip']); // Controller when the main page/view loads coselmarControllers.controller("HomeCtrl", ['$scope', '$http', '$location', 'userService', 'jwtHelper', @@ -365,6 +365,35 @@ coselmarControllers.controller("NewQuestionCtrl", ['$scope', '$route', '$locatio }]); +// Controller for All User View +coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routeParams', '$location', 'questionsService', + function($scope, $route, $routeParams, $location, questionsService){ + + questionsService.getQuestions(function(questions) { + // success : just get the questions + $scope.questions = questions; + + }, function(error) { + // Fail function : TODO + console.log(error); + }); + + + $scope.deleteQuestion = function(questionId) { + console.log("prepare to delete " + questionId); + + questionsService.deleteQuestion(questionId, function(questions) { + // success : just get the questions + $route.reload(); + + }, function(error) { + // Fail function : TODO + console.log(error); + }); + } + +}]); + coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $modalInstance, documentService) { $scope.searchKeywords = []; diff --git a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js index 7b91279..2675751 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -38,4 +38,13 @@ function Question(resource, config){ }; + this.getQuestions = function(successFunction, failFunction) { + var questionResource = resource(baseURL); + questionResource.query().$promise.then(successFunction, failFunction); + } + + this.deleteQuestion = function(questionId, successFunction, failFunction) { + var questionResource = resource(baseURL + "/" + questionId); + questionResource.delete().$promise.then(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 cc3cd52..15fe537 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar.js +++ b/coselmar-ui/src/main/webapp/js/coselmar.js @@ -52,9 +52,9 @@ coselmarApp.config(['$routeProvider', function($routeProvider) { templateUrl : 'views/users/user.html' //questions -// }).when('/questions', { -// controller : 'QuestionsCtrl', -// templateUrl : 'views/questions/questions.html' + }).when('/questions', { + controller : 'QuestionsCtrl', + templateUrl : 'views/questions/questions.html' }).when('/questions/new', { controller : 'NewQuestionCtrl', diff --git a/coselmar-ui/src/main/webapp/views/questions/editquestion.html b/coselmar-ui/src/main/webapp/views/questions/editquestion.html index 9dc0507..4680816 100644 --- a/coselmar-ui/src/main/webapp/views/questions/editquestion.html +++ b/coselmar-ui/src/main/webapp/views/questions/editquestion.html @@ -181,7 +181,7 @@ <input type="text" ng-model="question.externalExperts" class="form-control" name="externalExperts" - placeholder="expert1, expert2, ..." list > + placeholder="expert1, expert2, ..." ng-list > </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 8b3b830..b05689b 100644 --- a/coselmar-ui/src/main/webapp/views/questions/newquestion.html +++ b/coselmar-ui/src/main/webapp/views/questions/newquestion.html @@ -3,9 +3,12 @@ <h2>Add a question</h2> </div> - <div style="padding-bottom: 50px" ng-include="src='views/questions/editquestion.html'"> - + <div style="padding-bottom: 50px" ng-include="src='views/questions/editquestion.html'" + ng-if="currentUser.role == 'SUPERVISOR'"> + </div> + <div style="padding-bottom: 50px" ng-if="currentUser.role != 'SUPERVISOR'"> + You are not allowed to create question. </div> </div> \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html new file mode 100644 index 0000000..c51c66c --- /dev/null +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -0,0 +1,47 @@ + +<div style="padding: 0px 0px 0px 30px"> + <div class="page-header"> + <h1> + <!-- Heading goes here --> + Questions + </h1> + </div> + + <div> + <div> + <div class="form-group" ng-if="currentUser.role == 'SUPERVISOR'"> + <a href="#/questions/new" class="form-inline navbar-left btn btn-primary">Add a Question</a> + </div> + </div> + <br/> + <table class="table"> + <tr> + <th>Title</th> + <th>Submission Date</th> + <th>Themes</th> + <th>DeadLine</th> + <th>Clients</th> + <th>Participants</th> + <th>Documents</th> + <th></th> + </tr> + <tr ng-repeat="question in questions" > + <td><a href="#/questions/{{question.id}}" tooltip-placement="bottom" tooltip-html-unsafe="{{question.summary}}">{{question.title}}</a></td> + <td>{{question.submissionDate | date:'mediumDate'}}</td> + <td>{{question.theme}}</td> + <td>{{question.deadline | date:'mediumDate'}}</td> + <td>{{question.clients.length}}</td> + <td>{{question.participants.length}}</td> + <td>{{question.relatedDocuments.length}}</td> + <td> + <!--<a class="btn btn-action btn-disable" ng-click="closeQuestion(question.id)"--> + <!--ng-if="currentUser.role == 'SUPERVISOR'">--> + <!--<span class="fa fa-close" aria-hidden="true"></span>Close</a>--> + <a class="btn btn-action btn-disable" ng-click="deleteQuestion(question.id)" + ng-if="currentUser.role == 'SUPERVISOR' || currentUser.role == 'ADMIN'"> + <span class="fa fa-close" aria-hidden="true"></span>Delete</a> + </td> + </tr> + </table> + </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>.
participants (1)
-
codelutin.com scm