Skip to content

Commit 9947d5f

Browse files
SilverDavmmoqui
authored andcommitted
Bug #13551: The order in which the form is displayed in the list changes after modification
1 parent f845fc2 commit 9947d5f

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

formsOnline/formsOnline-configuration/src/main/config/xmlcomponents/formsOnline.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,49 @@
120120
</message>
121121
</help>
122122
</parameter>
123+
<parameter>
124+
<name>displaySort</name>
125+
<label>
126+
<message lang="fr">Ordre d'affichage des formulaires</message>
127+
<message lang="en">Order of display of forms</message>
128+
<message lang="de">Reihenfolge der Anzeige von Formularen</message>
129+
</label>
130+
<order>2</order>
131+
<mandatory>true</mandatory>
132+
<value>name</value>
133+
<options>
134+
<option>
135+
<name>
136+
<message lang="fr">Par ordre alphabétique</message>
137+
<message lang="en">Name ascending</message>
138+
<message lang="de">In alphabetischer Reihenfolge</message>
139+
</name>
140+
<value>name asc</value>
141+
</option>
142+
<option>
143+
<name>
144+
<message lang="fr">Date de création croissante</message>
145+
<message lang="en">Creation date ascending</message>
146+
<message lang="de">Erstellungsdatum aufsteigend</message>
147+
</name>
148+
<value>creationDate asc</value>
149+
</option>
150+
<option>
151+
<name>
152+
<message lang="fr">Date de création décroissante</message>
153+
<message lang="en">Creation date descending</message>
154+
<message lang="de">Erstellungsdatum absteigend</message>
155+
</name>
156+
<value>creationDate desc</value>
157+
</option>
158+
</options>
159+
<type>select</type>
160+
<updatable>always</updatable>
161+
<help>
162+
<message lang="fr">Permet de définir l'ordre d'affichage des formulaires</message>
163+
<message lang="en">Allows you to define the order in which the forms are displayed</message>
164+
<message lang="de">Ermöglicht es Ihnen, die Reihenfolge festzulegen, in der die Formulare angezeigt werden.</message>
165+
</help>
166+
</parameter>
123167
</parameters>
124168
</WAComponent>

formsOnline/formsOnline-library/src/main/java/org/silverpeas/components/formsonline/model/FormsOnlineDAO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public interface FormsOnlineDAO {
3737
/**
3838
* Get all forms that has been created in given instance
3939
* @param instanceId the instance id
40+
* @param orderBy sort order method
4041
* @return a List of FormDetail object
4142
*/
42-
List<FormDetail> findAllForms(String instanceId) throws FormsOnlineException;
43+
List<FormDetail> findAllForms(String instanceId, String orderBy) throws FormsOnlineException;
4344

4445
/**
4546
* Load forms from database with given instance Id and form id

formsOnline/formsOnline-library/src/main/java/org/silverpeas/components/formsonline/model/FormsOnlineDAOJdbc.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public class FormsOnlineDAOJdbc implements FormsOnlineDAO {
8383
private static final String SELECT_FROM = "SELECT * FROM ";
8484
private static final String INSERT_INTO = "INSERT INTO ";
8585
private static final String DELETE_FROM = "DELETE FROM ";
86+
8687
// Queries about Forms
87-
private static final String QUERY_FIND_FORMS =
88-
SELECT_FROM + FORMS_TABLENAME + " where instanceId = ?";
8988
private static final String QUERY_LOAD_FORM =
9089
SELECT_FROM + FORMS_TABLENAME + " where instanceId = ? and id = ?";
9190
private static final String QUERY_INSERT_FORM = INSERT_INTO + FORMS_TABLENAME +
@@ -199,21 +198,24 @@ public FormDetail getForm(FormPK pk) throws FormsOnlineException {
199198
}
200199

201200
@Override
202-
public List<FormDetail> findAllForms(String instanceId) throws FormsOnlineException {
203-
List<FormDetail> forms = new ArrayList<>();
204-
try (final Connection con = getConnection();
205-
final PreparedStatement stmt = con.prepareStatement(QUERY_FIND_FORMS)) {
206-
stmt.setString(1, instanceId);
207-
try (ResultSet rs = stmt.executeQuery()) {
208-
while (rs.next()) {
209-
FormDetail form = fetchFormDetail(rs);
210-
forms.add(form);
211-
}
212-
}
201+
public List<FormDetail> findAllForms(String instanceId, String orderBy) throws FormsOnlineException {
202+
try {
203+
final List<FormDetail> forms = new ArrayList<>();
204+
final JdbcSqlQuery query = JdbcSqlQuery.createSelect("*")
205+
.from(FORMS_TABLENAME)
206+
// 1st criteria : correct instanceId
207+
.where(INSTANCE_ID).in(instanceId)
208+
.orderBy(orderBy);
209+
query.execute(r -> {
210+
forms.add(fetchFormDetail(r));
211+
return null;
212+
});
213+
return forms;
213214
} catch (SQLException se) {
214-
throw new FormsOnlineException(failureOnGetting("all forms of instance", instanceId), se);
215+
throw new FormsOnlineException(
216+
failureOnGetting("Available forms of instance",
217+
String.join(",", instanceId)), se);
215218
}
216-
return forms;
217219
}
218220

219221
@Override

0 commit comments

Comments
 (0)