Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions db/update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
USE `moPat`;


CREATE TABLE predefined_slider_icon (
id BIGINT auto_increment NOT NULL,
icon_name VARCHAR(255) NOT NULL,
CONSTRAINT predefined_slider_icon_pk PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_general_ci;

INSERT INTO predefined_slider_icon (icon_name) VALUES
('bi-emoji-angry'),
('bi-emoji-angry-fill'),
('bi-emoji-dizzy'),
('bi-emoji-dizzy-fill'),
('bi-emoji-expressionless'),
('bi-emoji-expressionless-fill'),
('bi-emoji-frown'),
('bi-emoji-frown-fill'),
('bi-emoji-heart-eyes'),
('bi-emoji-heart-eyes-fill'),
('bi-emoji-laughing'),
('bi-emoji-laughing-fill'),
('bi-emoji-neutral'),
('bi-emoji-neutral-fill'),
('bi-emoji-smile'),
('bi-emoji-smile-fill'),
('bi-emoji-smile-upside-down'),
('bi-emoji-smile-upside-down-fill'),
('bi-emoji-sunglasses'),
('bi-emoji-sunglasses-fill'),
('bi-emoji-wink'),
('bi-emoji-wink-fill'),
('bi-hand-thumbs-down'),
('bi-hand-thumbs-down-fill'),
('bi-hand-thumbs-up'),
('bi-hand-thumbs-up-fill'),
('bi-brightness-high-fill'),
('bi-brightness-low-fill'),
('bi-dash-square'),
('bi-dash-lg'),
('bi-plus-square'),
('bi-plus-lg'),
('bi-x-square'),
('bi-x-lg'),
('bi-droplet'),
('bi-droplet-half'),
('bi-droplet-fill'),
('bi-ear'),
('bi-ear-fill'),
('bi-eye'),
('bi-eye-fill'),
('bi-eye-slash'),
('bi-eye-slash-fill'),
('bi-graph-down-arrow'),
('bi-graph-up-arrow'),
('bi-heart-pulse'),
('bi-heart-pulse-fill'),
('bi-lightning-charge'),
('bi-lightning-charge-fill'),
('bi-lungs'),
('bi-lungs-fill'),
('bi-0-square'),
('bi-1-square'),
('bi-2-square'),
('bi-3-square'),
('bi-4-square'),
('bi-5-square'),
('bi-6-square'),
('bi-7-square'),
('bi-8-square'),
('bi-9-square');

CREATE TABLE user_slider_icon (
id BIGINT auto_increment NOT NULL,
icon_path VARCHAR(255) NOT NULL,
CONSTRAINT user_slider_icon_pk PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_general_ci;


-- mopat.slider_icon_config definition

CREATE TABLE `slider_icon_config` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`number_of_icons` int(11) DEFAULT NULL,
`config_name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `slider_icon_config_name_unique` (`config_name`)
) ENGINE=InnoDB AUTO_INCREMENT=4110 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;


CREATE TABLE slider_icon_detail (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
icon_position INTEGER,
slider_icon_config_id BIGINT,
predefined_slider_icon_id BIGINT,
user_slider_icon_id BIGINT,
FOREIGN KEY (slider_icon_config_id) REFERENCES slider_icon_config(id),
FOREIGN KEY (predefined_slider_icon_id) REFERENCES predefined_slider_icon(id),
FOREIGN KEY (user_slider_icon_id) REFERENCES user_slider_icon(id)
);

ALTER TABLE slider_icons CHANGE icon icon_id BIGINT DEFAULT NULL NULL;

ALTER TABLE answer
ADD COLUMN slider_icon_config_id BIGINT;

ALTER TABLE answer
ADD CONSTRAINT fk_slider_icon_config
FOREIGN KEY (slider_icon_config_id)
REFERENCES slider_icon_config(id)
ON DELETE SET NULL;
125 changes: 75 additions & 50 deletions src/main/java/de/imi/mopat/controller/QuestionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import de.imi.mopat.helper.controller.LocaleHelper;
import de.imi.mopat.helper.controller.QuestionService;
import de.imi.mopat.helper.controller.ServletContextInfo;
import de.imi.mopat.helper.controller.SliderIconConfigService;
import de.imi.mopat.helper.controller.StringUtilities;
import de.imi.mopat.model.*;
import de.imi.mopat.model.dto.SliderIconConfigDTO;
import de.imi.mopat.model.dto.SliderIconDetailDTO;
import de.imi.mopat.model.dto.export.SliderIconDTO;
import de.imi.mopat.model.enumeration.QuestionType;
import de.imi.mopat.model.conditions.Condition;
Expand All @@ -29,6 +32,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import javax.imageio.ImageIO;
import java.util.regex.Pattern;

Expand All @@ -41,9 +45,12 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
*
Expand Down Expand Up @@ -78,6 +85,16 @@ public class QuestionController {

@Autowired
private QuestionService questionService;

@Autowired
private PredefinedSliderIconDao predefinedSliderIconDao;

@Autowired
private SliderIconConfigDao sliderIconConfigDao;

@Autowired
private SliderIconConfigService sliderIconConfigService;

/**
* @param id (<i>optional</i>) Id of the {@link Question} object
* @return Returns a new {@link Question} object to the attribute
Expand Down Expand Up @@ -185,13 +202,20 @@ public String editQuestion(
}
}
}

List<SliderIconConfig> sliderIconConfigs = sliderIconConfigDao.getAllElements();
List<SliderIconConfigDTO> sliderIconConfigDTOS = new ArrayList<>();
for(SliderIconConfig sliderIconConfig: sliderIconConfigs){
sliderIconConfigDTOS.add(sliderIconConfigService.toSliderIconConfigDTO(sliderIconConfig));
}
model.addAttribute("savedConfigs",sliderIconConfigDTOS);
model.addAttribute("icons", predefinedSliderIconDao.getAllIcons());
model.addAttribute("availableLocales", LocaleHelper.getAvailableLocales());
model.addAttribute("questionDTO", questionDTO);
model.addAttribute("questionnaireId", questionnaireId);
model.addAttribute("imagePathBodyPartMap", BodyPart.getImagePathBodyPartMap());
model.addAttribute("imageTypes", Constants.BODY_PART_IMAGE_TYPES);
model.addAttribute("codedValueTypes", CodedValueType.values());

return "question/edit";
}

Expand Down Expand Up @@ -235,15 +259,9 @@ public String duplicateQuestion(
}

// override old question in model with the new one
model.addAttribute(
"question",
newQuestion);
model.addAttribute(
"questionDTO",
questionService.toQuestionDTO(newQuestion));
model.addAttribute(
"questionnaireId",
questionnaireId);
model.addAttribute("question", newQuestion);
model.addAttribute("questionDTO", questionService.toQuestionDTO(newQuestion));
model.addAttribute("questionnaireId", questionnaireId);
// Let the jsp know, that this is a duplicated question
model.addAttribute("duplicate", true);
model.addAttribute("availableLocales", LocaleHelper.getAvailableLocales());
Expand All @@ -266,7 +284,9 @@ public String duplicateQuestion(
*/
@PostMapping(value = "/question/edit")
@PreAuthorize("hasRole('ROLE_EDITOR')")
public String editQuestion(@RequestParam final String action,
public String editQuestion(
MultipartHttpServletRequest multipartHttpServletRequest,
@RequestParam final String action,
@ModelAttribute("questionDTO") final QuestionDTO questionDTO, final BindingResult result,
final Model model, final HttpServletRequest request) {
if (action.equalsIgnoreCase("cancel")) {
Expand All @@ -282,20 +302,16 @@ public String editQuestion(@RequestParam final String action,
// edit page
if (questionDTO.getId() != null) {
question = questionDao.getElementById(questionDTO.getId());
if (questionDTO.getQuestionType()
.equals(QuestionType.IMAGE) && question.getQuestionType()
.equals(QuestionType.IMAGE)) {
questionDTO.getAnswers()
.get(0L)
.setImagePath(((ImageAnswer) question.getAnswers()
.get(0)).getImagePath());
if (questionDTO.getQuestionType().equals(QuestionType.IMAGE)
&& question.getQuestionType().equals(QuestionType.IMAGE)) {
questionDTO.getAnswers().get(0L)
.setImagePath(((ImageAnswer) question.getAnswers().get(0)).getImagePath());
try {
String realPath = configurationDao.getImageUploadPath() + "/question/"+ ((ImageAnswer) question.getAnswers().get(0)).getImagePath();
String realPath = configurationDao.getImageUploadPath() + "/question/"
+ ((ImageAnswer) question.getAnswers().get(0)).getImagePath();
String fileName = realPath.substring(realPath.lastIndexOf("/"));
questionDTO.getAnswers()
.get(0L)
.setImageBase64(
StringUtilities.convertImageToBase64String(realPath, fileName));
questionDTO.getAnswers().get(0L).setImageBase64(
StringUtilities.convertImageToBase64String(realPath, fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -338,6 +354,13 @@ public String editQuestion(@RequestParam final String action,
} else {
questionDTO.setHasScores(false);
}
List<SliderIconConfig> sliderIconConfigs = sliderIconConfigDao.getAllElements();
List<SliderIconConfigDTO> sliderIconConfigDTOS = new ArrayList<>();
for(SliderIconConfig sliderIconConfig: sliderIconConfigs){
sliderIconConfigDTOS.add(sliderIconConfigService.toSliderIconConfigDTO(sliderIconConfig));
}
model.addAttribute("savedConfigs",sliderIconConfigDTOS);
model.addAttribute("icons", predefinedSliderIconDao.getAllIcons());
model.addAttribute("questionnaireId", questionDTO.getQuestionnaireId());
model.addAttribute("availableLocales", LocaleHelper.getAvailableLocales());
model.addAttribute("imagePathBodyPartMap", BodyPart.getImagePathBodyPartMap());
Expand Down Expand Up @@ -668,26 +691,11 @@ public String editQuestion(@RequestParam final String action,
sliderAnswer.setVertical(vertical);
sliderAnswer.setIsEnabled(isEnabled);
sliderAnswer.setShowIcons(showIcons);
//
Set<SliderIcon> iconSet = new HashSet<>();
for (SliderIconDTO icon : answerDTO.getIcons()) {
SliderIcon newIcon = new SliderIcon(icon.getPosition(), icon.getIcon(),
sliderAnswer);
iconSet.add(newIcon);
}
sliderAnswer.setIcons(iconSet);
} else {
// Create new answer
sliderAnswer = new SliderAnswer(question, isEnabled, minValue, maxValue,
stepsize, vertical);
sliderAnswer.setShowIcons(showIcons);
Set<SliderIcon> iconSet = new HashSet<>();
for (SliderIconDTO icon : answerDTO.getIcons()) {
SliderIcon newIcon = new SliderIcon(icon.getPosition(), icon.getIcon(),
sliderAnswer);
iconSet.add(newIcon);
}
sliderAnswer.setIcons(iconSet);
}
if (answerDTO.getLocalizedMinimumText() != null) {
for (Map.Entry<String, String> entry : answerDTO.getLocalizedMinimumText()
Expand Down Expand Up @@ -720,7 +728,29 @@ public String editQuestion(@RequestParam final String action,
} else {
sliderAnswer.setShowValueOnButton(false);
}
break;

SliderIconConfig sliderIconConfig;
if(Objects.equals(answerDTO.getSliderIconConfigDTO().getConfigType(), "oldConfig")){
if(answerDTO.getSliderIconConfigDTO().getId() != null){
sliderIconConfig = sliderIconConfigDao.getElementById(answerDTO.getSliderIconConfigDTO().getId());
sliderAnswer.setSliderIconConfig(sliderIconConfig);
}
}
else if(Objects.equals(answerDTO.getSliderIconConfigDTO().getConfigType(), "newConfig")){
sliderAnswer.setSliderIconConfig(sliderIconConfigService.newSliderIconConfig(answerDTO.getSliderIconConfigDTO(), questionDTO, question));
}
else if(Objects.equals(answerDTO.getSliderIconConfigDTO().getConfigType(), "noConfig")){
Set<SliderIcon> iconSet = new HashSet<>();
for (SliderIconDTO icon : answerDTO.getIcons()) {
SliderIcon newIcon = new SliderIcon(icon.getIconPosition(),
predefinedSliderIconDao.getIconByName(icon.getPredefinedSliderIcon()), sliderAnswer);
iconSet.add(newIcon);
}
sliderAnswer.setIcons(iconSet);
sliderAnswer.setSliderIconConfig(null);
}

break;
}
case NUMBER_CHECKBOX_TEXT: {
AnswerDTO answerDTO = questionDTO.getAnswers().get(0L);
Expand Down Expand Up @@ -868,12 +898,10 @@ public String editQuestion(@RequestParam final String action,
if (!answerDTO.getImageFile().isEmpty()) {
// Store the extension of the image and the path with the
// questionnaire ID
String imageExtension =
FilenameUtils.getExtension(answerDTO.getImageFile()
.getOriginalFilename());
String imagePath =
(configurationDao.getImageUploadPath()
+ "/question/" + questionnaire.getId());
String imageExtension = FilenameUtils.getExtension(
answerDTO.getImageFile().getOriginalFilename());
String imagePath = (configurationDao.getImageUploadPath() + "/question/"
+ questionnaire.getId());

// Check if the upload dir exists. If not, create it
File uploadDir = new File(imagePath);
Expand Down Expand Up @@ -901,10 +929,8 @@ public String editQuestion(@RequestParam final String action,
}
}
// Store the full storage path with name and extension
storagePath =
questionnaire.getId()
+ "/question" + question.getId()
+ "." + imageExtension;
storagePath = questionnaire.getId() + "/question" + question.getId() + "."
+ imageExtension;
} else {
// If the image has not changed use the old image path
storagePath = answerDTO.getImagePath();
Expand All @@ -927,7 +953,6 @@ public String editQuestion(@RequestParam final String action,

// Validate the question
questionValidator.validate(question, result);

if (result.hasErrors()) {
model.addAttribute("questionnaireId", questionDTO.getQuestionnaireId());
model.addAttribute("availableLocales", LocaleHelper.getAvailableLocales());
Expand Down
Loading