diff --git a/package-lock.json b/package-lock.json index 7c0d3ff..ccdc095 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "react-dom": "18.2.0", "react-hook-form": "7.43.9", "react-icons": "^4.8.0", + "react-input-slider": "^6.0.1", "react-jhipster": "jhipster/react-jhipster", "react-loadable": "5.5.0", "react-redux": "8.0.5", @@ -1994,6 +1995,127 @@ "stylis": "4.1.3" } }, + "node_modules/@emotion/core": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/@emotion/core/-/core-10.3.1.tgz", + "integrity": "sha512-447aUEjPIm0MnE6QYIaFz9VQOHSXf4Iu6EWOIqq11EAPqinkSZmfymPTmlOE3QjLv846lH4JVZBUOtwGbuQoww==", + "dependencies": { + "@babel/runtime": "^7.5.5", + "@emotion/cache": "^10.0.27", + "@emotion/css": "^10.0.27", + "@emotion/serialize": "^0.11.15", + "@emotion/sheet": "0.9.4", + "@emotion/utils": "0.11.3" + }, + "peerDependencies": { + "react": ">=16.3.0" + } + }, + "node_modules/@emotion/core/node_modules/@emotion/cache": { + "version": "10.0.29", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-10.0.29.tgz", + "integrity": "sha512-fU2VtSVlHiF27empSbxi1O2JFdNWZO+2NFHfwO0pxgTep6Xa3uGb+3pVKfLww2l/IBGLNEZl5Xf/++A4wAYDYQ==", + "dependencies": { + "@emotion/sheet": "0.9.4", + "@emotion/stylis": "0.8.5", + "@emotion/utils": "0.11.3", + "@emotion/weak-memoize": "0.2.5" + } + }, + "node_modules/@emotion/core/node_modules/@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "node_modules/@emotion/core/node_modules/@emotion/memoize": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz", + "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==" + }, + "node_modules/@emotion/core/node_modules/@emotion/serialize": { + "version": "0.11.16", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-0.11.16.tgz", + "integrity": "sha512-G3J4o8by0VRrO+PFeSc3js2myYNOXVJ3Ya+RGVxnshRYgsvErfAOglKAiy1Eo1vhzxqtUvjCyS5gtewzkmvSSg==", + "dependencies": { + "@emotion/hash": "0.8.0", + "@emotion/memoize": "0.7.4", + "@emotion/unitless": "0.7.5", + "@emotion/utils": "0.11.3", + "csstype": "^2.5.7" + } + }, + "node_modules/@emotion/core/node_modules/@emotion/sheet": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-0.9.4.tgz", + "integrity": "sha512-zM9PFmgVSqBw4zL101Q0HrBVTGmpAxFZH/pYx/cjJT5advXguvcgjHFTCaIO3enL/xr89vK2bh0Mfyj9aa0ANA==" + }, + "node_modules/@emotion/core/node_modules/@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "node_modules/@emotion/core/node_modules/@emotion/utils": { + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-0.11.3.tgz", + "integrity": "sha512-0o4l6pZC+hI88+bzuaX/6BgOvQVhbt2PfmxauVaYOGgbsAw14wdKyvMCZXnsnsHys94iadcF+RG/wZyx6+ZZBw==" + }, + "node_modules/@emotion/core/node_modules/@emotion/weak-memoize": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz", + "integrity": "sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==" + }, + "node_modules/@emotion/core/node_modules/csstype": { + "version": "2.6.21", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.21.tgz", + "integrity": "sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w==" + }, + "node_modules/@emotion/css": { + "version": "10.0.27", + "resolved": "https://registry.npmjs.org/@emotion/css/-/css-10.0.27.tgz", + "integrity": "sha512-6wZjsvYeBhyZQYNrGoR5yPMYbMBNEnanDrqmsqS1mzDm1cOTu12shvl2j4QHNS36UaTE0USIJawCH9C8oW34Zw==", + "dependencies": { + "@emotion/serialize": "^0.11.15", + "@emotion/utils": "0.11.3", + "babel-plugin-emotion": "^10.0.27" + } + }, + "node_modules/@emotion/css/node_modules/@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "node_modules/@emotion/css/node_modules/@emotion/memoize": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz", + "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==" + }, + "node_modules/@emotion/css/node_modules/@emotion/serialize": { + "version": "0.11.16", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-0.11.16.tgz", + "integrity": "sha512-G3J4o8by0VRrO+PFeSc3js2myYNOXVJ3Ya+RGVxnshRYgsvErfAOglKAiy1Eo1vhzxqtUvjCyS5gtewzkmvSSg==", + "dependencies": { + "@emotion/hash": "0.8.0", + "@emotion/memoize": "0.7.4", + "@emotion/unitless": "0.7.5", + "@emotion/utils": "0.11.3", + "csstype": "^2.5.7" + } + }, + "node_modules/@emotion/css/node_modules/@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "node_modules/@emotion/css/node_modules/@emotion/utils": { + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-0.11.3.tgz", + "integrity": "sha512-0o4l6pZC+hI88+bzuaX/6BgOvQVhbt2PfmxauVaYOGgbsAw14wdKyvMCZXnsnsHys94iadcF+RG/wZyx6+ZZBw==" + }, + "node_modules/@emotion/css/node_modules/csstype": { + "version": "2.6.21", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.21.tgz", + "integrity": "sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w==" + }, "node_modules/@emotion/hash": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.9.0.tgz", @@ -2074,6 +2196,11 @@ } } }, + "node_modules/@emotion/stylis": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/@emotion/stylis/-/stylis-0.8.5.tgz", + "integrity": "sha512-h6KtPihKFn3T9fuIrwvXXUOwlx3rfUvfZIcP5a6rh8Y7zjE3O06hT5Ss4S/YI1AYhuZ1kjaE/5EaOOI2NqSylQ==" + }, "node_modules/@emotion/unitless": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.8.0.tgz", @@ -5424,6 +5551,101 @@ "@babel/core": "^7.8.0" } }, + "node_modules/babel-plugin-emotion": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/babel-plugin-emotion/-/babel-plugin-emotion-10.2.2.tgz", + "integrity": "sha512-SMSkGoqTbTyUTDeuVuPIWifPdUGkTk1Kf9BWRiXIOIcuyMfsdp2EjeiiFvOzX8NOBvEh/ypKYvUh2rkgAJMCLA==", + "dependencies": { + "@babel/helper-module-imports": "^7.0.0", + "@emotion/hash": "0.8.0", + "@emotion/memoize": "0.7.4", + "@emotion/serialize": "^0.11.16", + "babel-plugin-macros": "^2.0.0", + "babel-plugin-syntax-jsx": "^6.18.0", + "convert-source-map": "^1.5.0", + "escape-string-regexp": "^1.0.5", + "find-root": "^1.1.0", + "source-map": "^0.5.7" + } + }, + "node_modules/babel-plugin-emotion/node_modules/@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "node_modules/babel-plugin-emotion/node_modules/@emotion/memoize": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz", + "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==" + }, + "node_modules/babel-plugin-emotion/node_modules/@emotion/serialize": { + "version": "0.11.16", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-0.11.16.tgz", + "integrity": "sha512-G3J4o8by0VRrO+PFeSc3js2myYNOXVJ3Ya+RGVxnshRYgsvErfAOglKAiy1Eo1vhzxqtUvjCyS5gtewzkmvSSg==", + "dependencies": { + "@emotion/hash": "0.8.0", + "@emotion/memoize": "0.7.4", + "@emotion/unitless": "0.7.5", + "@emotion/utils": "0.11.3", + "csstype": "^2.5.7" + } + }, + "node_modules/babel-plugin-emotion/node_modules/@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "node_modules/babel-plugin-emotion/node_modules/@emotion/utils": { + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-0.11.3.tgz", + "integrity": "sha512-0o4l6pZC+hI88+bzuaX/6BgOvQVhbt2PfmxauVaYOGgbsAw14wdKyvMCZXnsnsHys94iadcF+RG/wZyx6+ZZBw==" + }, + "node_modules/babel-plugin-emotion/node_modules/babel-plugin-macros": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-2.8.0.tgz", + "integrity": "sha512-SEP5kJpfGYqYKpBrj5XU3ahw5p5GOHJ0U5ssOSQ/WBVdwkD2Dzlce95exQTs3jOVWPPKLBN2rlEWkCK7dSmLvg==", + "dependencies": { + "@babel/runtime": "^7.7.2", + "cosmiconfig": "^6.0.0", + "resolve": "^1.12.0" + } + }, + "node_modules/babel-plugin-emotion/node_modules/cosmiconfig": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", + "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", + "dependencies": { + "@types/parse-json": "^4.0.0", + "import-fresh": "^3.1.0", + "parse-json": "^5.0.0", + "path-type": "^4.0.0", + "yaml": "^1.7.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-emotion/node_modules/csstype": { + "version": "2.6.21", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.21.tgz", + "integrity": "sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w==" + }, + "node_modules/babel-plugin-emotion/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/babel-plugin-emotion/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/babel-plugin-istanbul": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", @@ -5517,6 +5739,11 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/babel-plugin-syntax-jsx": { + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", + "integrity": "sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==" + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", @@ -17500,6 +17727,19 @@ "react": ">=16.0.0" } }, + "node_modules/react-input-slider": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/react-input-slider/-/react-input-slider-6.0.1.tgz", + "integrity": "sha512-WASm/k0rVw3cXzvfkoUa4wMnF74SbifeuwSmjPC+zanhV4W9KAmPM+H6yXhIZAjJL4TU+sUw/pgyUyAt/txvIw==", + "dependencies": { + "@babel/runtime": "^7.9.2", + "@emotion/core": "^10.0.14" + }, + "peerDependencies": { + "react": ">=16", + "react-dom": ">=16" + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/package.json b/package.json index 5f1c253..99b75b8 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "react-dom": "18.2.0", "react-hook-form": "7.43.9", "react-icons": "^4.8.0", + "react-input-slider": "^6.0.1", "react-jhipster": "jhipster/react-jhipster", "react-loadable": "5.5.0", "react-redux": "8.0.5", diff --git a/src/main/java/com/pwr/students/domain/AnswerType.java b/src/main/java/com/pwr/students/domain/AnswerType.java new file mode 100644 index 0000000..598e6b1 --- /dev/null +++ b/src/main/java/com/pwr/students/domain/AnswerType.java @@ -0,0 +1,6 @@ +package com.pwr.students.domain; + +public enum AnswerType { + SLIDER, + TEXT, +} diff --git a/src/main/java/com/pwr/students/domain/Question.java b/src/main/java/com/pwr/students/domain/Question.java index ffd4f57..ccb993f 100644 --- a/src/main/java/com/pwr/students/domain/Question.java +++ b/src/main/java/com/pwr/students/domain/Question.java @@ -29,7 +29,8 @@ public class Question implements Serializable { @NotNull @Column(name = "answer_type", nullable = false) - private String answerType; + @Enumerated(EnumType.STRING) + private AnswerType answerType; @NotNull @Size(min = 16, max = 255) @@ -75,16 +76,16 @@ public void setCategory(String category) { this.category = category; } - public String getAnswerType() { + public AnswerType getAnswerType() { return this.answerType; } - public Question answerType(String answerType) { + public Question answerType(AnswerType answerType) { this.setAnswerType(answerType); return this; } - public void setAnswerType(String answerType) { + public void setAnswerType(AnswerType answerType) { this.answerType = answerType; } diff --git a/src/main/java/com/pwr/students/domain/Survey.java b/src/main/java/com/pwr/students/domain/Survey.java index 84eff4d..19ab439 100644 --- a/src/main/java/com/pwr/students/domain/Survey.java +++ b/src/main/java/com/pwr/students/domain/Survey.java @@ -41,7 +41,8 @@ public class Survey implements Serializable { private LocalDate deadline; @Column(name = "status") - private String status; + @Enumerated(EnumType.STRING) + private SurveyStatus status; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "survey") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @@ -115,16 +116,16 @@ public void setDeadline(LocalDate deadline) { this.deadline = deadline; } - public String getStatus() { + public SurveyStatus getStatus() { return this.status; } - public Survey status(String status) { + public Survey status(SurveyStatus status) { this.setStatus(status); return this; } - public void setStatus(String status) { + public void setStatus(SurveyStatus status) { this.status = status; } diff --git a/src/main/java/com/pwr/students/domain/SurveyStatus.java b/src/main/java/com/pwr/students/domain/SurveyStatus.java new file mode 100644 index 0000000..6a5f511 --- /dev/null +++ b/src/main/java/com/pwr/students/domain/SurveyStatus.java @@ -0,0 +1,7 @@ +package com.pwr.students.domain; + +public enum SurveyStatus { + DRAFT, + ACTIVE, + EXPIRED, +} diff --git a/src/main/java/com/pwr/students/repository/SurveyAssigmentRepository.java b/src/main/java/com/pwr/students/repository/SurveyAssigmentRepository.java index 4d7dd46..9195037 100644 --- a/src/main/java/com/pwr/students/repository/SurveyAssigmentRepository.java +++ b/src/main/java/com/pwr/students/repository/SurveyAssigmentRepository.java @@ -40,4 +40,7 @@ default Page findAllWithEagerRelationships(Pageable pageable) { @Query("select surveyAssigment from SurveyAssigment surveyAssigment left join fetch surveyAssigment.user where surveyAssigment.id =:id") Optional findOneWithToOneRelationships(@Param("id") Long id); + + @Query("SELECT sa FROM SurveyAssigment sa WHERE sa.survey.id = :surveyId") + List findAllBySurveyId(@Param("surveyId") Long surveyId); } diff --git a/src/main/java/com/pwr/students/web/rest/SurveyAssigmentResource.java b/src/main/java/com/pwr/students/web/rest/SurveyAssigmentResource.java index 3a2f5ef..f561905 100644 --- a/src/main/java/com/pwr/students/web/rest/SurveyAssigmentResource.java +++ b/src/main/java/com/pwr/students/web/rest/SurveyAssigmentResource.java @@ -39,13 +39,13 @@ public SurveyAssigmentResource(SurveyAssigmentRepository surveyAssigmentReposito } /** - * {@code POST /survey-assigments} : Create a new surveyAssigment. + * {@code POST /survey-assignments} : Create a new surveyAssigment. * * @param surveyAssigment the surveyAssigment to create. * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new surveyAssigment, or with status {@code 400 (Bad Request)} if the surveyAssigment has already an ID. * @throws URISyntaxException if the Location URI syntax is incorrect. */ - @PostMapping("/survey-assigments") + @PostMapping("/survey-assignments") public ResponseEntity createSurveyAssigment(@RequestBody SurveyAssigment surveyAssigment) throws URISyntaxException { log.debug("REST request to save SurveyAssigment : {}", surveyAssigment); if (surveyAssigment.getId() != null) { @@ -53,13 +53,13 @@ public ResponseEntity createSurveyAssigment(@RequestBody Survey } SurveyAssigment result = surveyAssigmentRepository.save(surveyAssigment); return ResponseEntity - .created(new URI("/api/survey-assigments/" + result.getId())) + .created(new URI("/api/survey-assignments/" + result.getId())) .headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, result.getId().toString())) .body(result); } /** - * {@code PUT /survey-assigments/:id} : Updates an existing surveyAssigment. + * {@code PUT /survey-assignments/:id} : Updates an existing surveyAssigment. * * @param id the id of the surveyAssigment to save. * @param surveyAssigment the surveyAssigment to update. @@ -68,7 +68,7 @@ public ResponseEntity createSurveyAssigment(@RequestBody Survey * or with status {@code 500 (Internal Server Error)} if the surveyAssigment couldn't be updated. * @throws URISyntaxException if the Location URI syntax is incorrect. */ - @PutMapping("/survey-assigments/{id}") + @PutMapping("/survey-assignments/{id}") public ResponseEntity updateSurveyAssigment( @PathVariable(value = "id", required = false) final Long id, @RequestBody SurveyAssigment surveyAssigment @@ -93,7 +93,7 @@ public ResponseEntity updateSurveyAssigment( } /** - * {@code PATCH /survey-assigments/:id} : Partial updates given fields of an existing surveyAssigment, field will ignore if it is null + * {@code PATCH /survey-assignments/:id} : Partial updates given fields of an existing surveyAssigment, field will ignore if it is null * * @param id the id of the surveyAssigment to save. * @param surveyAssigment the surveyAssigment to update. @@ -103,7 +103,7 @@ public ResponseEntity updateSurveyAssigment( * or with status {@code 500 (Internal Server Error)} if the surveyAssigment couldn't be updated. * @throws URISyntaxException if the Location URI syntax is incorrect. */ - @PatchMapping(value = "/survey-assigments/{id}", consumes = { "application/json", "application/merge-patch+json" }) + @PatchMapping(value = "/survey-assignments/{id}", consumes = { "application/json", "application/merge-patch+json" }) public ResponseEntity partialUpdateSurveyAssigment( @PathVariable(value = "id", required = false) final Long id, @RequestBody SurveyAssigment surveyAssigment @@ -138,28 +138,35 @@ public ResponseEntity partialUpdateSurveyAssigment( } /** - * {@code GET /survey-assigments} : get all the surveyAssigments. + * {@code GET /survey-assignments} : get all the surveyAssigments. * * @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many). * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of surveyAssigments in body. */ - @GetMapping("/survey-assigments") - public List getAllSurveyAssigments(@RequestParam(required = false, defaultValue = "false") boolean eagerload) { - log.debug("REST request to get all SurveyAssigments"); - if (eagerload) { - return surveyAssigmentRepository.findAllWithEagerRelationships(); + @GetMapping("/survey-assignments") + public List getSurveyAssignments( + @RequestParam(required = false, defaultValue = "false") boolean eagerload, + @RequestParam(required = false) Long surveyId + ) { + log.debug("REST request to get SurveyAssignments"); + if (surveyId != null) { + return surveyAssigmentRepository.findAllBySurveyId(surveyId); } else { - return surveyAssigmentRepository.findAll(); + if (eagerload) { + return surveyAssigmentRepository.findAllWithEagerRelationships(); + } else { + return surveyAssigmentRepository.findAll(); + } } } /** - * {@code GET /survey-assigments/:id} : get the "id" surveyAssigment. + * {@code GET /survey-assignments/:id} : get the "id" surveyAssigment. * * @param id the id of the surveyAssigment to retrieve. * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the surveyAssigment, or with status {@code 404 (Not Found)}. */ - @GetMapping("/survey-assigments/{id}") + @GetMapping("/survey-assignments/{id}") public ResponseEntity getSurveyAssigment(@PathVariable Long id) { log.debug("REST request to get SurveyAssigment : {}", id); Optional surveyAssigment = surveyAssigmentRepository.findOneWithEagerRelationships(id); @@ -167,12 +174,12 @@ public ResponseEntity getSurveyAssigment(@PathVariable Long id) } /** - * {@code DELETE /survey-assigments/:id} : delete the "id" surveyAssigment. + * {@code DELETE /survey-assignments/:id} : delete the "id" surveyAssigment. * * @param id the id of the surveyAssigment to delete. * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. */ - @DeleteMapping("/survey-assigments/{id}") + @DeleteMapping("/survey-assignments/{id}") public ResponseEntity deleteSurveyAssigment(@PathVariable Long id) { log.debug("REST request to delete SurveyAssigment : {}", id); surveyAssigmentRepository.deleteById(id); diff --git a/src/main/resources/config/liquibase/fake-data/question.csv b/src/main/resources/config/liquibase/fake-data/question.csv index 318a16c..a60fe78 100644 --- a/src/main/resources/config/liquibase/fake-data/question.csv +++ b/src/main/resources/config/liquibase/fake-data/question.csv @@ -1,11 +1,11 @@ -id;category;answer_type;question_content;is_required;jhi_order -1;attitude;calculate Infrastructure;including Networked;true;44743 -2;Integration Berkshire up;Rubber;revolutionary above Jazz;true;48233 -3;Jazz;XML;Classical Chevrolet who;true;75409 -4;sensor Phased;Engineer firewall Northwest;orchestration Palladium;true;33686 -5;Account provided;Jersey capacitor Thiel;VanXXXXXXXXXXXXX;true;91402 -6;strategic lame;since Screen Country;lens Principal CSS;true;73489 -7;cyan Denver ferociously;Southwest;to SouthXXXXXXXX;true;11450 -8;Thorium Bowie;bluetooth brr;Soap RubberXXXXX;true;17469 -9;Forward;grey California;Southeast Bacon Copernicium;false;26648 -10;Czech New;benchmark invoice Rialto;but Brakus South;true;60643 +id;category;answer_type;question_content;is_required;jhi_order;survey_id +1;attitude;TEXT;including Networked;true;44743;1 +2;Integration Berkshire up;TEXT;whatever question content;true;48233;2 +3;Jazz;SLIDER;whatever question content;true;75409;3 +4;sensor Phased;TEXT;orchestration Palladium;true;33686;4 +5;Account provided;TEXT;VanXXXXXXXXXXXXX;true;91402;5 +6;strategic lame;TEXT;lens Principal CSS;true;73489;6 +7;cyan Denver ferociously;SLIDER;to SouthXXXXXXXX;true;11450;7 +8;Thorium Bowie;SLIDER;Soap RubberXXXXX;true;17469;8 +9;Forward;SLIDER;Southeast Bacon Copernicium;false;26648;9 +10;Czech New;SLIDER;but Brakus South;true;60643;10 diff --git a/src/main/resources/config/liquibase/fake-data/survey.csv b/src/main/resources/config/liquibase/fake-data/survey.csv index e9ec29b..084c2cc 100644 --- a/src/main/resources/config/liquibase/fake-data/survey.csv +++ b/src/main/resources/config/liquibase/fake-data/survey.csv @@ -1,11 +1,11 @@ -id;name;description;deadline;status -1;Division;BMW Pound Zealand;2023-05-09;weber Cheese -2;Auburn platforms;networks Architect;2023-05-10;Lauderhill Bedfordshire Chips -3;orchid;Drive ZirconiumX;2023-05-10;Principal -4;infomediaries Route;that EngineerXXX;2023-05-09;neutral incentivize -5;navigation synthesize next;Analyst matrix Interactions;2023-05-09;frozen Steel -6;backing holistic;Rupiah North Luxurious;2023-05-10;silky -7;neutral;panel consequently Operations;2023-05-10;withdrawal Account -8;Ohio avaricious Cisgender;CambridgeshireXX;2023-05-10;stable Wooden -9;Convertible oh;Hybrid KiaXXXXXX;2023-05-10;Account -10;IP Orland;kilogramXXXXXXXX;2023-05-10;Bicycle Markets +id;name;description;deadline;status;user_id +1;Division;BMW Pound Zealand;2023-05-09;ACTIVE;1 +2;Auburn platforms;networks Architect;2023-05-10;ACTIVE;1 +3;orchid;Drive ZirconiumX;2023-05-10;ACTIVE;1 +4;infomediaries Route;that EngineerXXX;2023-05-09;ACTIVE;1 +5;navigation synthesize next;Analyst matrix Interactions;2023-05-09;ACTIVE;1 +6;backing holistic;Rupiah North Luxurious;2023-05-10;EXPIRED;2 +7;neutral;panel consequently Operations;2023-05-10;EXPIRED;2 +8;Ohio avaricious Cisgender;CambridgeshireXX;2023-05-10;EXPIRED;2 +9;Convertible oh;Hybrid KiaXXXXXX;2023-05-10;EXPIRED;2 +10;IP Orland;kilogramXXXXXXXX;2023-05-10;DRAFT;2 diff --git a/src/main/resources/config/liquibase/fake-data/survey_assigment.csv b/src/main/resources/config/liquibase/fake-data/survey_assigment.csv index b37377c..3ebf758 100644 --- a/src/main/resources/config/liquibase/fake-data/survey_assigment.csv +++ b/src/main/resources/config/liquibase/fake-data/survey_assigment.csv @@ -1,11 +1,11 @@ -id;is_finished -1;true -2;true -3;false -4;true -5;true -6;true -7;false -8;true -9;false -10;true +id;is_finished;survey_id;user_id +1;true;1;1 +2;true;2;1 +3;false;3;1 +4;true;4;1 +5;true;5;1 +6;true;6;2 +7;false;7;2 +8;true;8;2 +9;false;9;2 +10;true;10;2 diff --git a/src/main/webapp/app/entities/survey-assigment/survey-assigment.reducer.ts b/src/main/webapp/app/entities/survey-assigment/survey-assigment.reducer.ts index 1430224..f76944e 100644 --- a/src/main/webapp/app/entities/survey-assigment/survey-assigment.reducer.ts +++ b/src/main/webapp/app/entities/survey-assigment/survey-assigment.reducer.ts @@ -14,7 +14,7 @@ const initialState: EntityState = { updateSuccess: false, }; -const apiUrl = 'api/survey-assigments'; +const apiUrl = 'api/survey-assignments'; // Actions diff --git a/src/main/webapp/app/modules/managerSurveysDashboard/managerSurveysDashboard.tsx b/src/main/webapp/app/modules/managerSurveysDashboard/managerSurveysDashboard.tsx index 545b9d5..937d03a 100644 --- a/src/main/webapp/app/modules/managerSurveysDashboard/managerSurveysDashboard.tsx +++ b/src/main/webapp/app/modules/managerSurveysDashboard/managerSurveysDashboard.tsx @@ -5,7 +5,7 @@ import './managerSurveysDashboard.css'; import { BsThreeDots, BsGear } from 'react-icons/bs'; import { FiSend, FiTrash2 } from 'react-icons/fi'; import { GrStatusInfo } from 'react-icons/gr'; -import { Link, useNavigate } from 'react-router-dom'; +import { Link } from 'react-router-dom'; import { deleteEntity } from 'app/entities/survey/survey.reducer'; import { useAppDispatch } from 'app/config/store'; @@ -32,8 +32,7 @@ const ManagerSurveysDashboard = () => { }, [refreshSurveys]); function ActiveSurveysSection() { - // const activeSurveys = surveys.filter((survey) => survey.status === 'active'); // TODO uncomment it after column status is added to survey table - const activeSurveys = surveys.filter(survey => survey.id !== 0); // TODO remove it after column status is added to survey table + const activeSurveys = surveys.filter(survey => survey.status === 'ACTIVE'); return (
@@ -49,28 +48,32 @@ const ManagerSurveysDashboard = () => { // Component for the expired surveys section function NotPublishedSurveysSection() { - const notPublishedSurveys = surveys.filter(survey => survey.status === 'inactive'); + const notPublishedSurveys = surveys.filter(survey => survey.status === 'DRAFT'); return (

Not published

- {notPublishedSurveys.map(survey => ( - - ))} +
+ {notPublishedSurveys.map(survey => ( + + ))} +
); } // Component for the expired surveys section function ExpiredSurveysSection() { - const expiredSurveys = surveys.filter(survey => survey.status === 'expired'); + const expiredSurveys = surveys.filter(survey => survey.status === 'EXPIRED'); return (

Expired

- {expiredSurveys.map(survey => ( - - ))} +
+ {expiredSurveys.map(survey => ( + + ))} +
); } diff --git a/src/main/webapp/app/modules/surveyCompletion/survey-page.scss b/src/main/webapp/app/modules/surveyCompletion/survey-page.scss new file mode 100644 index 0000000..600675d --- /dev/null +++ b/src/main/webapp/app/modules/surveyCompletion/survey-page.scss @@ -0,0 +1,103 @@ +.container { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.box { + width: 500px; + max-height: 80vh; + overflow-y: auto; + background-color: #d9d9d9; + border-radius: 15px; + border-width: 1px; + border-color: #000000; + border-style: solid; + padding: 20px; + display: flex; + flex-direction: column; + justify-content: space-between; +} + +.question-header { + display: flex; + align-items: center; + justify-content: space-between; +} + +.question-number { + font-size: 20px; + font-weight: bold; + margin-bottom: 40px; +} + +.question-content { + font-size: 18px; + margin-bottom: 40px; +} + +.answer-input { + width: 100%; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; +} + +.comment-input { + width: 100%; + padding: 8px; + border: 1px solid #ccc; + border-radius: 5px; + resize: vertical; + font-size: 14px; + margin-top: 10px; +} + +.comment-submit { + padding: 8px 16px; + background-color: #bdbcbc; + border: none; + border-radius: 15px; + font-size: 14px; + cursor: pointer; +} + +.buttons { + display: flex; + justify-content: center; + margin-top: 20px; +} + +.buttons button { + padding: 10px 20px; + border: none; + border-radius: 15px; + width: 20px; + cursor: pointer; + flex-grow: 1; /* Add flex-grow property */ + margin: 0 20px; /* Set initial margin between buttons */ + background-color: #bdbcbc; +} + +.slider-step-labels { + display: flex; + justify-content: space-between; + margin-top: 10px; + width: 102%; +} + +.slider-step-label { + font-size: 12px; + color: #555; +} + +//.buttons button:first-child { +// background-color: firebrick; +// color: #fff; +//} +// +//.buttons button:last-child { +// background-color: #007bff; +// color: #fff; +//} diff --git a/src/main/webapp/app/modules/surveyCompletion/survey-page.tsx b/src/main/webapp/app/modules/surveyCompletion/survey-page.tsx new file mode 100644 index 0000000..979a539 --- /dev/null +++ b/src/main/webapp/app/modules/surveyCompletion/survey-page.tsx @@ -0,0 +1,248 @@ +import React, { useEffect, useState } from 'react'; +import { useNavigate, useParams } from 'react-router-dom'; +import axios from 'axios'; +import './survey-page.scss'; +import { BiCommentDetail } from 'react-icons/bi'; +import Slider from 'react-input-slider'; +import { useAppDispatch, useAppSelector } from 'app/config/store'; +import { createEntity, getEntities } from 'app/entities/answer/answer.reducer'; +import { IAnswer } from 'app/shared/model/answer.model'; +import { partialUpdateEntity } from 'app/entities/survey-assigment/survey-assigment.reducer'; +import { ISurveyAssigment } from 'app/shared/model/survey-assigment.model'; +import { getSession } from 'app/shared/reducers/authentication'; +import { reset } from 'app/modules/account/settings/settings.reducer'; + +const SurveyPage = () => { + const navigate = useNavigate(); + const { surveyId } = useParams(); + const [survey, setSurvey] = useState(null); + const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0); + const [answers, setAnswers] = useState([]); + const [comments, setComments] = useState([]); + const [isCommentBoxVisible, setIsCommentBoxVisible] = useState(false); + const [surveyAssignmentId, setSurveyAssignmentId] = useState(null); + + const dispatch = useAppDispatch(); + const user = useAppSelector(state => state.authentication.account); + + // Fetch the user information during component initialization + useEffect(() => { + dispatch(getSession()); + return () => { + dispatch(reset()); + }; + }, []); + + useEffect(() => { + axios + .get(`/api/surveys/${surveyId}`) + .then(response => { + setSurvey(response.data); + }) + .catch(error => { + console.error('Error fetching survey data:', error); + }); + axios + .get(`/api/survey-assignments?surveyId=${surveyId}`) + .then(response => { + const surveyAssignment = response.data[0]; // Assuming there is only one survey assignment per survey + setSurveyAssignmentId(surveyAssignment.id); + }) + .catch(error => { + console.error('Error fetching survey assignment data:', error); + }); + }, [surveyId]); + + const renderAnswerInput = () => { + const currentQuestion = survey.questions[currentQuestionIndex]; + + if (currentQuestion.answerType === 'SLIDER') { + const minValue = 1; + const maxValue = 10; + const stepValue = 1; + const sliderValue = parseInt(answers[currentQuestionIndex], 10) || minValue; + + const steps = []; + for (let i = minValue; i <= maxValue; i += stepValue) { + steps.push(i); + } + + return ( +
+
+ {steps.map(step => ( +
+ {step} +
+ ))} +
+ handleAnswerChange({ target: { value: x.toString() } })} + /> +
+ ); + } + + if (currentQuestion.answerType === 'TEXT') { + return ( +
+ +
+ ); + } + + return null; // Handle unsupported answer types or default case + }; + + const handleNext = () => { + if (currentQuestionIndex < survey.questions.length - 1) { + setCurrentQuestionIndex(currentQuestionIndex + 1); + setIsCommentBoxVisible(false); + } else { + // Prepare the data to be submitted + const submittedAnswers: IAnswer[] = answers.map((answer, index) => ({ + answer, + comment: comments[index] || '', + question: survey.questions[index], + user, + })); + + try { + // Dispatch the createEntity action for each answer + for (const answer of submittedAnswers) { + dispatch(createEntity(answer)); + } + if (surveyAssignmentId) { + updateSurveyAssignment(); + } + navigate(`/survey-history/${surveyId}`); + } catch (error) { + // Handle the error response + console.error('Error submitting answers:', error); + // TODO: Handle the error and show appropriate feedback to the user + } finally { + // Dispatch the getEntities action to update the entities + dispatch(getEntities({})); + } + } + }; + + const updateSurveyAssignment = () => { + const changes: ISurveyAssigment = { is_finished: true, id: surveyAssignmentId }; + dispatch(partialUpdateEntity(changes)); + }; + + const handlePrevious = () => { + if (currentQuestionIndex > 0) { + setCurrentQuestionIndex(currentQuestionIndex - 1); + setIsCommentBoxVisible(false); + } + }; + + const handleCancel = () => { + // Redirect to dashboard or previous page + navigate(-1); + }; + + const handleAnswerChange = event => { + const { value } = event.target; + const updatedAnswers = [...answers]; + updatedAnswers[currentQuestionIndex] = value; + setAnswers(updatedAnswers); + }; + + const handleCommentChange = event => { + const { value } = event.target; + const updatedComments = [...comments]; + updatedComments[currentQuestionIndex] = value; + setComments(updatedComments); + }; + + const handleCommentIconClick = () => { + setIsCommentBoxVisible(prevState => !prevState); + }; + + // const handleCommentSubmit = () => { + // setIsCommentBoxVisible(prevState => !prevState); + // // TODO i guess we need to save the comment somewhere to save while submitting the answers + // }; + + if (!survey) { + return
Loading survey...
; + } + + const currentQuestion = survey.questions[currentQuestionIndex]; + + if (!currentQuestion) { + return
No questions found.
; + } + + const questionNumber = currentQuestionIndex + 1; + const totalQuestions = survey.questions.length; + const isLastQuestion = currentQuestionIndex === survey.questions.length - 1; + const nextButtonText = isLastQuestion ? 'Finish' : 'Next'; + + return ( +
+
+
+

+ Question {questionNumber} / {totalQuestions} +

+
+ +
+
+
{currentQuestion.questionContent}
+ {/* Render answer input based on the question type */} + {/* ... */} +
{renderAnswerInput()}
+ {isCommentBoxVisible && ( +
+