branch feature/6016-add-question created (now 2c4c138)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6016-add-question in repository coselmar. See http://git.codelutin.com/coselmar.git at 2c4c138 Fix initialisation : account lambda expert has no password This branch includes the following new commits: new 0f5aa27 add question in entities model new 7998ad3 prepare web service to add question new 30703a4 prepare page form for questions new 2c4c138 Fix initialisation : account lambda expert has no password The 4 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 2c4c138450a699f748dc35c2aa852d9dd44e41a3 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 3 10:24:39 2014 +0100 Fix initialisation : account lambda expert has no password commit 30703a4e386ae534260ebf3c60d429848abbee50 Author: Yannick Martel <martel@©odelutin.com> Date: Tue Dec 2 18:03:53 2014 +0100 prepare page form for questions commit 7998ad35c062f3f5d163265499a87650ef8263fa Author: Yannick Martel <martel@©odelutin.com> Date: Mon Dec 1 17:51:36 2014 +0100 prepare web service to add question commit 0f5aa2792adf5f66515d7077a05ddf742ac27f95 Author: Yannick Martel <martel@©odelutin.com> Date: Mon Dec 1 15:41:48 2014 +0100 add question in entities model -- 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 feature/6016-add-question in repository coselmar. See http://git.codelutin.com/coselmar.git commit 0f5aa2792adf5f66515d7077a05ddf742ac27f95 Author: Yannick Martel <martel@©odelutin.com> Date: Mon Dec 1 15:41:48 2014 +0100 add question in entities model --- .../coselmar/persistence/entity/DocumentTopiaDao.java | 4 ++-- .../src/main/xmi/coselmar-model.zargo | Bin 6557 -> 9618 bytes .../coselmar/services/v1/DocumentsWebService.java | 8 ++++---- pom.xml | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index 77321b7..cfc4a60 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java @@ -50,11 +50,11 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { Map<String, Object> args = new HashMap<>(); // can list all public document - String privacyPublicCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, DocumentPrivacy.PUBLIC, ""); + String privacyPublicCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); hqlBuilder.append(" WHERE ( " + privacyPublicCondition); // Can list his own private document - String privacyPrivateCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, DocumentPrivacy.PRIVATE, ""); + String privacyPrivateCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, Privacy.PRIVATE, ""); String ownerCondition = DaoUtils.andAttributeEquals("D", Document.PROPERTY_OWNER, args, currentUser); hqlBuilder.append(" OR ( " + privacyPrivateCondition + " " + ownerCondition + " ) )"); diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index 04c2341..009697d 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/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 99717c1..dbb5182 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 @@ -41,7 +41,7 @@ import fr.ifremer.coselmar.converter.BeanEntityConverter; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; import fr.ifremer.coselmar.persistence.entity.Document; -import fr.ifremer.coselmar.persistence.entity.DocumentPrivacy; +import fr.ifremer.coselmar.persistence.entity.Privacy; import fr.ifremer.coselmar.services.CoselmarTechnicalException; import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; @@ -186,7 +186,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { documentEntity.setOwner(owner); documentEntity.setName(documentName); - documentEntity.setPrivacy(DocumentPrivacy.valueOf(document.getPrivacy().toUpperCase())); + documentEntity.setPrivacy(Privacy.valueOf(document.getPrivacy().toUpperCase())); documentEntity.addAllKeywords(document.getKeywords()); Date depositDate = document.getDepositDate(); @@ -370,11 +370,11 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String viewerRole = userWebToken.getRole().toUpperCase(); // For public : only admin/supervisor/expert can access - if (document.getPrivacy() == DocumentPrivacy.PUBLIC) { + if (document.getPrivacy() == Privacy.PUBLIC) { isAuthorized = DOCUMENT_VIEW_ALLOWED_USER_ROLES.contains(viewerRole); // For Private : only admin/supervisor/owner can access - } else if (document.getPrivacy() == DocumentPrivacy.PRIVATE) { + } else if (document.getPrivacy() == Privacy.PRIVATE) { CoselmarUser documentOwner = document.getOwner(); boolean isOwner = StringUtils.equals(documentOwner.getTopiaId(), getFullUserIdFromShort(userWebToken.getUserId())); isAuthorized = isOwner || Lists.newArrayList(CoselmarUserRole.ADMIN.name(), CoselmarUserRole.SUPERVISOR.name()).contains(viewerRole); diff --git a/pom.xml b/pom.xml index 7c7bdca..9b21f6c 100644 --- a/pom.xml +++ b/pom.xml @@ -229,7 +229,6 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernateVersion}</version> - <scope>runtime</scope> <exclusions> <exclusion> <groupId>org.hibernate.javax.persistence</groupId> -- 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 feature/6016-add-question in repository coselmar. See http://git.codelutin.com/coselmar.git commit 7998ad35c062f3f5d163265499a87650ef8263fa Author: Yannick Martel <martel@©odelutin.com> Date: Mon Dec 1 17:51:36 2014 +0100 prepare web service to add question --- .../src/main/xmi/coselmar-model.zargo | Bin 9618 -> 9640 bytes .../fr/ifremer/coselmar/beans/QuestionBean.java | 188 +++++++++++++++++++++ .../services/CoselmarWebServiceSupport.java | 10 ++ .../coselmar/services/v1/QuestionsWebService.java | 178 +++++++++++++++++++ 4 files changed, 376 insertions(+) diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index 009697d..f4d34ec 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 new file mode 100644 index 0000000..22efff4 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java @@ -0,0 +1,188 @@ +package fr.ifremer.coselmar.beans; + +import java.io.Serializable; +import java.util.Date; +import java.util.Set; + +public class QuestionBean implements Serializable { + + protected String id; + + protected String title; + + protected Date submissionDate; + + protected Date deadline; + + protected Set<String> theme; + + protected String summary; + + protected Date closingDate; + + protected String questionType; + + protected Set<UserBean> participants; + + protected Set<UserBean> supervisors; + + protected Set<UserBean> contributors; + + protected Set<UserBean> clients; + + protected Set<QuestionBean> parents; + protected Set<QuestionBean> children; + + protected String privacy; + + protected Set<DocumentBean> relatedDocuments; + + protected String status; + + protected Set<String> externalExperts; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Date getSubmissionDate() { + return submissionDate; + } + + public void setSubmissionDate(Date submissionDate) { + this.submissionDate = submissionDate; + } + + public Date getDeadline() { + return deadline; + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public Set<String> getTheme() { + return theme; + } + + public void setTheme(Set<String> theme) { + this.theme = theme; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public Date getClosingDate() { + return closingDate; + } + + public void setClosingDate(Date closingDate) { + this.closingDate = closingDate; + } + + public String getQuestionType() { + return questionType; + } + + public void setQuestionType(String questionType) { + this.questionType = questionType; + } + + public Set<UserBean> getParticipants() { + return participants; + } + + public void setParticipants(Set<UserBean> participants) { + this.participants = participants; + } + + public Set<UserBean> getSupervisors() { + return supervisors; + } + + public void setSupervisors(Set<UserBean> supervisors) { + this.supervisors = supervisors; + } + + public Set<UserBean> getContributors() { + return contributors; + } + + public void setContributors(Set<UserBean> contributors) { + this.contributors = contributors; + } + + public Set<UserBean> getClients() { + return clients; + } + + public void setClients(Set<UserBean> clients) { + this.clients = clients; + } + + public Set<QuestionBean> getParents() { + return parents; + } + + public void setParents(Set<QuestionBean> parents) { + this.parents = parents; + } + + public Set<QuestionBean> getChildren() { + return children; + } + + public void setChildren(Set<QuestionBean> children) { + this.children = children; + } + + public String getPrivacy() { + return privacy; + } + + public void setPrivacy(String privacy) { + this.privacy = privacy; + } + + public Set<DocumentBean> getRelatedDocuments() { + return relatedDocuments; + } + + public void setRelatedDocuments(Set<DocumentBean> relatedDocuments) { + this.relatedDocuments = relatedDocuments; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Set<String> getExternalExperts() { + return externalExperts; + } + + public void setExternalExperts(Set<String> externalExperts) { + this.externalExperts = externalExperts; + } + +} //Question diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java index 0817cde..17e5af2 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java @@ -36,8 +36,10 @@ import com.auth0.jwt.JWTVerifier; import fr.ifremer.coselmar.beans.UserWebToken; import fr.ifremer.coselmar.persistence.CoselmarPersistenceContext; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; +import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroupTopiaDao; import fr.ifremer.coselmar.persistence.entity.CoselmarUserTopiaDao; import fr.ifremer.coselmar.persistence.entity.DocumentTopiaDao; +import fr.ifremer.coselmar.persistence.entity.QuestionTopiaDao; import fr.ifremer.coselmar.services.config.CoselmarServicesConfig; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; import fr.ifremer.coselmar.services.v1.DocumentsWebService; @@ -113,6 +115,14 @@ public abstract class CoselmarWebServiceSupport extends WebMotionController impl return getPersistenceContext().getCoselmarUserDao(); } + protected CoselmarUserGroupTopiaDao getCoselmarUserGroupDao() { + return getPersistenceContext().getCoselmarUserGroupDao(); + } + + protected QuestionTopiaDao getQuestionDao() { + return getPersistenceContext().getQuestionDao(); + } + public void commit() { getPersistenceContext().commit(); } 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 new file mode 100644 index 0000000..b88b12e --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java @@ -0,0 +1,178 @@ +package fr.ifremer.coselmar.services.v1; + +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import fr.ifremer.coselmar.beans.QuestionBean; +import fr.ifremer.coselmar.beans.UserBean; +import fr.ifremer.coselmar.beans.UserWebToken; +import fr.ifremer.coselmar.persistence.entity.CoselmarUser; +import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; +import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; +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.TopiaNoResultException; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class QuestionsWebService extends CoselmarWebServiceSupport { + + private static final Log log = LogFactory.getLog(QuestionsWebService.class); + + public void addQuestion(QuestionBean questionBean) throws InvalidCredentialException, UnauthorizedException { + + // Check authentication + String authorization = getContext().getHeader("Authorization"); + UserWebToken userWebToken = checkAuthentication(authorization); + + // Only Expert or Supervisor can add document + String userRole = userWebToken.getRole(); + + if (!StringUtils.equalsIgnoreCase(CoselmarUserRole.ADMIN.name(), userRole)) { + String message = String.format("User %s %s ('%s') is not allowed to add question", + userWebToken.getFirstName(), userWebToken.getLastName(), userWebToken.getUserId()); + if (log.isWarnEnabled()) { + log.warn(message); + } + throw new UnauthorizedException(message); + + } + + // retrieve user who will be assigned as question supervisor + String fullId = getFullUserIdFromShort(userWebToken.getUserId()); + + CoselmarUser supervisor; + try { + 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); + if (log.isErrorEnabled()) { + log.equals(message); + } + throw new CoselmarTechnicalException(message); + } + + // let's go + Question question = getQuestionDao().create(); + + question.setTitle(questionBean.getTitle()); + + question.setSummary(questionBean.getSummary()); + + question.setQuestionType(questionBean.getQuestionType()); + + // By default, privacy is private + String privacy = questionBean.getPrivacy(); + Privacy realPrivacy = privacy != null ? Privacy.valueOf(privacy.toUpperCase()) : Privacy.PRIVATE; + question.setPrivacy(realPrivacy); + + // On creation, Status is Open + question.setStatus(Status.OPEN); + + // Manage Dates : submission & deadline + Date submissionDate = questionBean.getSubmissionDate(); + if (submissionDate != null) { + question.setSubmissionDate(new Date(submissionDate.getTime())); + } + + Date deadline = questionBean.getDeadline(); + if (deadline != null) { + question.setDeadline(new Date(deadline.getTime())); + } + + + // Users around the question + + // First Supervisor is the one creating this question + question.addSupervisors(supervisor); + + question.addAllExternalExperts(questionBean.getExternalExperts()); + // Retrieve the clients + Set<UserBean> clients = questionBean.getClients(); + if (clients != null && !clients.isEmpty()) { + List<CoselmarUser> clientEntities = retrieveUsers(clients); + question.addAllClients(clientEntities); + } + + // For participants, should create a dedicated group, + // that could be used to restrict documents access + Set<UserBean> participants = questionBean.getParticipants(); + if (participants != null && !participants.isEmpty()) { + CoselmarUserGroup userGroup = getCoselmarUserGroupDao().create(); + userGroup.setName(questionBean.getTitle()); + + List<CoselmarUser> expertEntities = retrieveUsers(participants); + userGroup.addAllMembers(expertEntities); + + question.setParticipants(userGroup); + } + + // Note : no contributors now, contributors are old participants, + // excluded from process + + + // Hierarchy of questions + Set<QuestionBean> parents = questionBean.getParents(); + if (parents != null && !parents.isEmpty()) { + List<Question> questions = retrieveQuestions(parents); + question.addAllParents(questions); + } + + +// // Documents on init +// question.addAllRelatedDocuments(); + + } + + + //////////////////////////////////////////////////////////////////////////// + /////////////////////// Internal Parts ///////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + + protected List<CoselmarUser> retrieveUsers(Collection<UserBean> userBeans) { + Function<UserBean, String> getIds = new Function<UserBean, String>() { + @Override + public String apply(UserBean userBean) { + return getFullUserIdFromShort(userBean.getId()); + } + }; + + Collection<String> userIds = Collections2.transform(userBeans, getIds); + List<CoselmarUser> coselmarUsers = getCoselmarUserDao().forTopiaIdIn(userIds).findAll(); + return coselmarUsers; + + } + + protected List<Question> retrieveQuestions(Collection<QuestionBean> questionBeans) { + Function<QuestionBean, String> getIds = new Function<QuestionBean, String>() { + @Override + public String apply(QuestionBean questionBean) { + return getFullUserIdFromShort(questionBean.getId()); + } + }; + + Collection<String> questionIds = Collections2.transform(questionBeans, getIds); + List<Question> questions = getQuestionDao().forTopiaIdIn(questionIds).findAll(); + return questions; + + } + + protected String getFullQuestionIdFromShort(String shortQuestionId) { + return Question.class.getCanonicalName() + getPersistenceContext().getTopiaIdFactory().getSeparator() + shortQuestionId; + } +} -- 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 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>.
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 2c4c138450a699f748dc35c2aa852d9dd44e41a3 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 3 10:24:39 2014 +0100 Fix initialisation : account lambda expert has no password --- .../coselmar/services/v1/InitialisationService.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/InitialisationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/InitialisationService.java index ec95685..1cd58d1 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/InitialisationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/InitialisationService.java @@ -58,17 +58,17 @@ public class InitialisationService extends CoselmarSimpleServiceSupport { commit(); // Set a lambda expert - CoselmarUser user = getCoselmarUserDao().create(); - user.setFirstname("Lambda"); - user.setName("Expert"); - user.setMail("lambda.expert@temporary.coselmar"); - user.setRole(CoselmarUserRole.EXPERT); - user.setActive(true); + CoselmarUser lambdaUser = getCoselmarUserDao().create(); + lambdaUser.setFirstname("Lambda"); + lambdaUser.setName("Expert"); + lambdaUser.setMail("lambda.expert@temporary.coselmar"); + lambdaUser.setRole(CoselmarUserRole.EXPERT); + lambdaUser.setActive(true); String lambdaSalt = servicesContext.generateSalt(); String lambdaPassword = servicesContext.encodePassword(lambdaSalt, "manager1234"); - admin.setPassword(lambdaPassword); - admin.setSalt(lambdaSalt); + lambdaUser.setPassword(lambdaPassword); + lambdaUser.setSalt(lambdaSalt); commit(); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm