Skip to content

Commit 097aed3

Browse files
committed
Feature #13830 and #13831: improving survey result pages.
* defining result views * keeping the chosen result view into session * starting to create some WEB entities which might be used when moving to WEB service architecture * implementing new VueJS components in order to render the result pages * adding print action with helping messages about print and export actions
1 parent df1d672 commit 097aed3

File tree

19 files changed

+1632
-337
lines changed

19 files changed

+1632
-337
lines changed

survey/survey-configuration/src/main/config/properties/org/silverpeas/survey/multilang/surveyBundle.properties

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ PollingStation.revote = Revoter
8282
Survey.revote = Participer de nouveau \u00e0 l'enqu\u00eate
8383
SurveyNbParticipations = Nombre de participations
8484
survey.NoResponse = au moins une r\u00e9ponse doit \u00eatre selectionn\u00e9e.
85-
custom.st.notification.subject=\u00C0 propos du sondage $surveyName$
85+
custom.st.notification.subject=\u00c0 propos du sondage $surveyName$
8686
survey.imageGallery = Image associ\u00e9e
8787

8888
survey.style = Type de r\u00e9ponse
@@ -96,10 +96,17 @@ survey.confirmUpdatePoll = Attention, modifier cette consultation supprimera tou
9696
survey.surveyAnonymous = Enqu\u00eate anonyme
9797
survey.pollAnonymous = Vote anonyme
9898
survey.choice = vue
99-
survey.C = Classique
100-
survey.D = D\u00e9taill\u00e9e
99+
survey.result.seeVoters.help=Voir la liste des votants
100+
survey.result.seeVoters.clickHelp=(Cliquer pour voir la liste des votants)
101+
survey.result.suggestion.help = Voir le d\u00e9tail des r\u00e9ponses
102+
survey.result.view.classic = Classique
103+
survey.result.view.detail = D\u00e9taill\u00e9e
104+
survey.result.view.graphical=Graphique
105+
survey.result.view.horizontal-bar=Barre horizontale
101106
survey.participationOf = Participation de
102107
survey.results = R\u00e9sultats
108+
survey.results.print.help=L'action <span class="survey-help-action">imprimer</span> permet d'ouvrir la bo\u00eete de dialogue d'impression du navigateur et d'imprimer ou enregistrer en PDF les r\u00e9sultats visualis\u00e9s. Pour l'impression de vos graphiques, pensez \u00e0 cocher l'option <span class="survey-help-action">Imprimer les arri\u00e8re-plans</span>
109+
survey.results.export.help=L'action <span class="survey-help-action">exporter</span> permet d'obtenir les r\u00e9sultats visualis\u00e9s sous la forme d'un fichier CSV \u00e0 t\u00e9l\u00e9charger.
103110

104111
survey.update=Modifier
105112
survey.update.succeed=Les modifications r\u00e9alis\u00e9es sur les questions ont bien \u00e9t\u00e9 enregistr\u00e9es.
@@ -114,6 +121,7 @@ survey.header.fieldset.answers = R\u00e9ponses
114121

115122
survey.answer.image.select = Choisir une image
116123
survey.answer.image.delete = Supprimer cette image
124+
survey.answer.image.open.newTab = Ouvrir l'image dans un nouvel onglet
117125

118126
survey.creation.resultMode = Publication des r\u00e9sultats
119127
survey.creation.resultMode.1 = Imm\u00e9diate apr\u00e8s participation

survey/survey-configuration/src/main/config/properties/org/silverpeas/survey/multilang/surveyBundle_de.properties

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,17 @@ survey.confirmUpdatePoll = Achtung! \u00c4ndern diese Umfrage l\u00f6scht alle a
9797
survey.surveyAnonymous = Anonyme Umfrage
9898
survey.pollAnonymous = Anonyme Abstimmung
9999
survey.choice = Ansicht
100-
survey.C = klassich
101-
survey.D = Detailansicht
100+
survey.result.seeVoters.help=Siehe die Liste der W\u00e4hler
101+
survey.result.seeVoters.clickHelp=(Klicken Sie hier, um die Liste der W\u00e4hler zu sehen)
102+
survey.result.suggestion.help=Siehe Details der Antworten
103+
survey.result.view.classic = klassich
104+
survey.result.view.detail = Detailansicht
105+
survey.result.view.graphical=Grafische Darstellung
106+
survey.result.view.horizontal-bar=Horizontaler Balken
102107
survey.participationOf = Teilnahme von
103108
survey.results = Ergebnisse
109+
survey.results.print.help=Mit der Aktion <span class="survey-help-action">Drucken</span> k\u00f6nnen Sie das Druckdialogfeld des Browsers \u00f6ffnen und die angezeigten Ergebnisse ausdrucken oder als PDF speichern. Denken Sie beim Drucken Ihrer Grafiken daran, die Option <span class="survey-help-action">Hintergr\u00fcnde drucken</span> anzukreuzen.
110+
survey.results.export.help=Mit der Aktion <span class="survey-help-action">Exportieren</span> erhalten Sie die visualisierten Ergebnisse in Form einer CSV-Datei zum Herunterladen.
104111

105112
survey.update= \u00c4ndern
106113
survey.update.succeed=\u00c4nderungen wurden erfolgreich gespeichert.
@@ -115,6 +122,7 @@ survey.header.fieldset.answers = Answers
115122

116123
survey.answer.image.select = Select an image
117124
survey.answer.image.delete = Remove this image
125+
survey.answer.image.open.newTab=Das Bild in einem neuen Tab \u00f6ffnen
118126

119127
survey.creation.resultMode = Ver\u00f6ffentlichung der Ergebnisse
120128
survey.creation.resultMode.1 = Unmittelbar nach der Teilnahme

survey/survey-configuration/src/main/config/properties/org/silverpeas/survey/multilang/surveyBundle_en.properties

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,17 @@ survey.confirmUpdatePoll = Warning! Modifying this poll will delete all recorded
9797
survey.surveyAnonymous = Anonymous survey
9898
survey.pollAnonymous = Anonymous vote
9999
survey.choice = look view
100-
survey.C = Classic
101-
survey.D = Detailed
100+
survey.result.seeVoters.help=See the list of voters
101+
survey.result.seeVoters.clickHelp=(Click to see the list of voters)
102+
survey.result.suggestion.help=See details of answers
103+
survey.result.view.classic = Classic
104+
survey.result.view.detail = Detailed
105+
survey.result.view.graphical=Graphical
106+
survey.result.view.horizontal-bar=Horizontal bar
102107
survey.participationOf = Participation of
103108
survey.results = Results
109+
survey.results.print.help=The <span class="survey-help-action">print</span> action is used to open the browser's print dialog box and print or save as a PDF the results viewed. When printing your graphics, remember to check the <span class="survey-help-action">Print backgrounds</span> option.
110+
survey.results.export.help=The <span class="survey-help-action">export</span> action is used to obtain the visualised results in the form of a CSV file for downloading.
104111

105112
survey.update=Update
106113
survey.update.succeed=Changes have been saved successfully.
@@ -115,6 +122,7 @@ survey.header.fieldset.answers = Answers
115122

116123
survey.answer.image.select = Select an image
117124
survey.answer.image.delete = Remove this image
125+
survey.answer.image.open.newTab=Open the image in a new tab
118126

119127
survey.creation.resultMode = Publication of results
120128
survey.creation.resultMode.1 = Immediately after participation

survey/survey-configuration/src/main/config/properties/org/silverpeas/survey/multilang/surveyBundle_fr.properties

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ PollingStation.revote = Revoter
8282
Survey.revote = Participer de nouveau \u00e0 l'enqu\u00eate
8383
SurveyNbParticipations = Nombre de participations
8484
survey.NoResponse = au moins une r\u00e9ponse doit \u00eatre selectionn\u00e9e.
85-
custom.st.notification.subject=\u00C0 propos du sondage $surveyName$
85+
custom.st.notification.subject=\u00c0 propos du sondage $surveyName$
8686
# notification
8787
survey.imageGallery = Image associ\u00e9e
8888

@@ -97,10 +97,17 @@ survey.confirmUpdatePoll = Attention, modifier cette consultation supprimera tou
9797
survey.surveyAnonymous = Enqu\u00eate anonyme
9898
survey.pollAnonymous = Vote anonyme
9999
survey.choice = vue
100-
survey.C = Classique
101-
survey.D = D\u00e9taill\u00e9e
100+
survey.result.seeVoters.help=Voir la liste des votants
101+
survey.result.seeVoters.clickHelp=(Cliquer pour voir la liste des votants)
102+
survey.result.suggestion.help = Voir le d\u00e9tail des r\u00e9ponses
103+
survey.result.view.classic = Classique
104+
survey.result.view.detail = D\u00e9taill\u00e9e
105+
survey.result.view.graphical = Graphique
106+
survey.result.view.horizontal-bar=Barre horizontale
102107
survey.participationOf = Participation(s) de
103108
survey.results = R\u00e9sultats
109+
survey.results.print.help=L'action <span class="survey-help-action">Imprimer</span> permet d'ouvrir la bo\u00eete de dialogue d'impression du navigateur et d'imprimer ou enregistrer en PDF les r\u00e9sultats visualis\u00e9s. Pour l'impression de vos graphiques, pensez \u00e0 cocher l'option <span class="survey-help-action">Imprimer les arri\u00e8re-plans</span>
110+
survey.results.export.help=L'action <span class="survey-help-action">Exporter</span> permet d'obtenir les r\u00e9sultats visualis\u00e9s sous la forme d'un fichier CSV \u00e0 t\u00e9l\u00e9charger.
104111

105112
survey.update=Modifier
106113
survey.update.succeed=Les modifications r\u00e9alis\u00e9es sur les questions ont bien \u00e9t\u00e9 enregistr\u00e9es.
@@ -115,6 +122,7 @@ survey.header.fieldset.answers = R\u00e9ponses
115122

116123
survey.answer.image.select = Choisir une image
117124
survey.answer.image.delete = Supprimer cette image
125+
survey.answer.image.open.newTab = Ouvrir l'image dans un nouvel onglet
118126

119127
survey.creation.resultMode = Publication des r\u00e9sultats
120128
survey.creation.resultMode.1 = Imm\u00e9diate apr\u00e8s participation

survey/survey-war/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<name>Survey Web Application</name>
1414

1515
<dependencies>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.module</groupId>
18+
<artifactId>jackson-module-jaxb-annotations</artifactId>
19+
</dependency>
1620
<dependency>
1721
<groupId>org.silverpeas.components.survey</groupId>
1822
<artifactId>silverpeas-survey</artifactId>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (C) 2000 - 2023 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* As a special exception to the terms and conditions of version 3.0 of
10+
* the GPL, you may redistribute this Program in connection with Free/Libre
11+
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12+
* FLOSS exception. You should have received a copy of the text describing
13+
* the FLOSS exception, and it is also available here:
14+
* "https://www.silverpeas.org/legal/floss_exception.html"
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
*/
24+
25+
package org.silverpeas.components.survey.control;
26+
27+
import org.silverpeas.core.util.StringUtil;
28+
29+
import java.util.List;
30+
import java.util.stream.Stream;
31+
32+
import static java.util.stream.Collectors.toList;
33+
34+
/**
35+
* Definition of the different views of result page a survey can display.
36+
* @author silveryocha
37+
*/
38+
public enum DisplayResultView {
39+
CLASSIC_GRAPHICAL(Constants.CLASSIC_MAIN_VIEW, Constants.GRAPHICAL_SEC_LEVEL_VIEW),
40+
CLASSIC_HORIZONTAL_BAR(Constants.CLASSIC_MAIN_VIEW, Constants.HORIZONTAL_BAR_SEC_LEVEL_VIEW),
41+
DETAIL(Constants.DETAIL_MAIN_VIEW, StringUtil.EMPTY);
42+
43+
private final String mainLevelView;
44+
private final String secondaryLevelView;
45+
46+
DisplayResultView(final String mainView, final String secondaryLevelView) {
47+
this.mainLevelView = mainView;
48+
this.secondaryLevelView = secondaryLevelView;
49+
}
50+
51+
/**
52+
* Gets the {@link DisplayResultView} instance that matches the specified result view name or code.
53+
* @param name the enum name or the full name of a predefined result view in survey component.
54+
* @return the {@link DisplayResultView} instance having as name the specified role name or
55+
* {@link DisplayResultView#DETAIL} if no such role exists.
56+
*/
57+
public static DisplayResultView fromString(String name) {
58+
if (StringUtil.isNotDefined(name)) {
59+
return DETAIL;
60+
}
61+
final String trimmedName = name.trim();
62+
return Stream.of(values())
63+
.filter(r -> r.name().equalsIgnoreCase(trimmedName) || r.getIdentifier().equals(trimmedName))
64+
.findFirst()
65+
.orElse(DETAIL);
66+
}
67+
68+
/**
69+
* Gets a list of {@link DisplayResultView} instance from a main view part of identifier.
70+
* @param mainView a main view part of identifier.
71+
* @return a list of {@link DisplayResultView} instance.
72+
*/
73+
public static List<DisplayResultView> fromMainViewOnly(String mainView) {
74+
final String trimmedMainCode = mainView.trim();
75+
return Stream.of(values())
76+
.filter(r -> r.mainLevelView.equalsIgnoreCase(trimmedMainCode))
77+
.collect(toList());
78+
}
79+
80+
/**
81+
* The code of the view is a combination of the main and sub view separated by an underscore.
82+
* @return a code as string.
83+
*/
84+
public String getIdentifier() {
85+
return mainLevelView + "_" + secondaryLevelView;
86+
}
87+
88+
/**
89+
* Gets the main view.
90+
* @return a string.
91+
*/
92+
public String getMainView() {
93+
return mainLevelView;
94+
}
95+
96+
/**
97+
* Gets the secondary level view.
98+
* @return a string.
99+
*/
100+
public String getSecondaryLevelView() {
101+
return secondaryLevelView;
102+
}
103+
104+
/**
105+
* Gets the bundle key of main view.
106+
* @return a string representing a bundle key.
107+
*/
108+
public String getMainViewBundleKey() {
109+
return String.format("survey.result.view.%s", mainLevelView);
110+
}
111+
112+
/**
113+
* Gets the bundle key of secondary level view.
114+
* @return a string representing a bundle key.
115+
*/
116+
public String getSecondaryViewBundleKey() {
117+
return String.format("survey.result.view.%s", secondaryLevelView);
118+
}
119+
120+
public static class Constants {
121+
public static final String CLASSIC_MAIN_VIEW = "classic";
122+
public static final String DETAIL_MAIN_VIEW = "detail";
123+
public static final String GRAPHICAL_SEC_LEVEL_VIEW = "graphical";
124+
public static final String HORIZONTAL_BAR_SEC_LEVEL_VIEW = "horizontal-bar";
125+
126+
private Constants() {
127+
}
128+
}
129+
}

survey/survey-war/src/main/java/org/silverpeas/components/survey/control/SurveySessionController.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@
8686
import java.util.List;
8787
import java.util.Map;
8888

89+
import static org.silverpeas.components.survey.control.DisplayResultView.*;
8990
import static org.silverpeas.core.pdc.pdc.model.PdcClassification.aPdcClassificationOfContent;
9091

9192
/**
9293
* This class contains business layer of survey component
9394
*/
9495
public class SurveySessionController extends AbstractComponentSessionController {
96+
private static final long serialVersionUID = -8522567628476990017L;
9597

9698
private static final String IMAGES_SUB_DIRECTORY_KEY = "imagesSubDirectory";
9799
private static final String ACTION_PARAM = "Action";
@@ -118,6 +120,7 @@ public class SurveySessionController extends AbstractComponentSessionController
118120
private boolean hasAlreadyParticipated = false;
119121
public static final String COOKIE_NAME = "surpoll";
120122
private List<PdcPosition> newSurveyPositions = null;
123+
private DisplayResultView displayResultView = DisplayResultView.fromString(null);
121124

122125
/**
123126
* Creates new sessionClientController
@@ -1206,6 +1209,40 @@ public boolean isDisplayCommentsEnabled(String userProfile, String userId) {
12061209
|| DISPLAY_COMMENTS_FOR_ALL.equals(value));
12071210
}
12081211

1212+
/**
1213+
* Gets the display result view.
1214+
* @return the {@link DisplayResultView} instance representing the result vew.
1215+
*/
1216+
public DisplayResultView getDisplayResultView() {
1217+
return displayResultView;
1218+
}
1219+
1220+
/**
1221+
* Sets the display result view according to given identifier or main view.
1222+
* <p>
1223+
* The result view is set into session.
1224+
* </p>
1225+
* @param survey the representation of the survey.
1226+
* @param identifierOrMainView the name (or full name) or the main part of name of a view.
1227+
* @return the {@link DisplayResultView} instance.
1228+
*/
1229+
public DisplayResultView setSurveyResultViewFromIdentifierOrMainView(
1230+
final QuestionContainerDetail survey, final String identifierOrMainView) {
1231+
final List<DisplayResultView> potentialViews = fromMainViewOnly(identifierOrMainView);
1232+
if (!potentialViews.isEmpty()) {
1233+
displayResultView = potentialViews.stream()
1234+
.filter(displayResultView::equals)
1235+
.findFirst()
1236+
.orElseGet(() -> potentialViews.get(0));
1237+
} else {
1238+
displayResultView = fromString(identifierOrMainView);
1239+
}
1240+
if (DETAIL.equals(displayResultView) && survey.getHeader().getNbVoters() > 50) {
1241+
displayResultView = CLASSIC_GRAPHICAL;
1242+
}
1243+
return displayResultView;
1244+
}
1245+
12091246
private static class Parameters {
12101247

12111248
private String action;

survey/survey-war/src/main/java/org/silverpeas/components/survey/servlets/SurveyRequestRouter.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ public String getDestination(String function, SurveySessionController surveySC,
166166
String surveyId = request.getParameter(SURVEY_ID);
167167
destination = rootDest + "surveyUpdate.jsp?Action=UpdateSurveyHeader&SurveyId=" + surveyId;
168168
} else if ("ViewListResult".equals(function)) {
169+
final QuestionContainerDetail sessionSurvey = surveySC.getSessionSurvey();
170+
if (sessionSurvey.getHeader().isAnonymous()) {
171+
throwHttpForbiddenError();
172+
}
169173
String answerId = request.getParameter("AnswerId");
170174
request.setAttribute("Users", surveySC.getUsersByAnswer(answerId));
171-
request.setAttribute(SURVEY, surveySC.getSessionSurvey());
175+
request.setAttribute(SURVEY, sessionSurvey);
172176
request.setAttribute(PROFILE, flag);
173177
destination = rootDest + "answerResult.jsp";
174178
} else if ("ViewAllUsers".equals(function)) {
@@ -328,16 +332,6 @@ private void setCommonDataToDisplayResult(String surveyId, HttpServletRequest re
328332
SurveySessionController surveySC) throws SurveyException{
329333
if (StringUtil.isDefined(surveyId)) {
330334
request.setAttribute(LIST_DOCUMENT, surveySC.getAllSynthesisFile(surveyId));
331-
332-
String resultDisplayMode = request.getParameter("Choice");
333-
if (StringUtil.isDefined(resultDisplayMode)) {
334-
request.setAttribute("ResultDisplayMode", resultDisplayMode);
335-
} else {
336-
request.setAttribute("ResultDisplayMode", "D");
337-
if (surveySC.getSurvey(surveyId).getHeader().getNbVoters() > 50) {
338-
request.setAttribute("ResultDisplayMode", "C");
339-
}
340-
}
341335
}
342336
}
343337
}

0 commit comments

Comments
 (0)