adds project ordering - fixes #34

Mon, 04 Jan 2021 15:25:59 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 04 Jan 2021 15:25:59 +0100
changeset 175
1e6f2aace666
parent 174
690a9aad3f16
child 176
4da5b783aa2d

adds project ordering - fixes #34

setup/postgres/psql_create_tables.sql file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/entities/Project.kt file | annotate | diff | comparison | revisions
src/main/resources/localization/projects.properties file | annotate | diff | comparison | revisions
src/main/resources/localization/projects_de.properties file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/project-form.jsp file | annotate | diff | comparison | revisions
--- a/setup/postgres/psql_create_tables.sql	Mon Jan 04 15:14:26 2021 +0100
+++ b/setup/postgres/psql_create_tables.sql	Mon Jan 04 15:25:59 2021 +0100
@@ -13,6 +13,7 @@
     projectid       serial          primary key,
     name            varchar(20)     not null unique,
     node            varchar(20)     not null unique,
+    ordinal         integer         not null default 0,
     description     varchar(200),
     repoUrl         varchar(50),
     owner           integer         references lpit_user(userid)
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Mon Jan 04 15:25:59 2021 +0100
@@ -187,6 +187,7 @@
 
             final var node = getParameter(req, String.class, "node").orElse(null);
             project.setNode(sanitizeNode(node, project.getName()));
+            getParameter(req, Integer.class, "ordinal").ifPresent(project::setOrdinal);
 
             getParameter(req, String.class, "description").ifPresent(project::setDescription);
             getParameter(req, String.class, "repoUrl").ifPresent(project::setRepoUrl);
--- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Mon Jan 04 15:25:59 2021 +0100
@@ -338,6 +338,7 @@
                 yield(Project(rs.getInt("projectid")).apply {
                     name = rs.getString("name")
                     node = rs.getString("node")
+                    ordinal = rs.getInt("ordinal")
                     description = rs.getString("description")
                     repoUrl = rs.getString("repourl")
                     owner = selectUserInfo(rs)
@@ -350,17 +351,18 @@
         with(obj) {
             stmt.setStringSafe(1, name)
             stmt.setStringSafe(2, node)
-            stmt.setStringOrNull(3, description)
-            stmt.setStringOrNull(4, repoUrl)
-            stmt.setIntOrNull(5, owner?.id)
+            stmt.setInt(3, ordinal)
+            stmt.setStringOrNull(4, description)
+            stmt.setStringOrNull(5, repoUrl)
+            stmt.setIntOrNull(6, owner?.id)
         }
-        return 6
+        return 7
     }
 
     //language=SQL
     private val projectQuery =
         """
-        select projectid, name, node, description, repourl,
+        select projectid, name, node, ordinal, description, repourl,
             userid, username, lastname, givenname, mail
         from lpit_project
         left join lpit_user owner on lpit_project.owner = owner.userid
@@ -369,7 +371,7 @@
     private val stmtProjects by lazy {
         connection.prepareStatement(
             """${projectQuery}
-            order by lower(name)
+            order by ordinal, lower(name)
             """
         )
     }
@@ -389,12 +391,12 @@
     }
     private val stmtInsertProject by lazy {
         connection.prepareStatement(
-            "insert into lpit_project (name, node, description, repourl, owner) values (?, ?, ?, ?, ?)"
+            "insert into lpit_project (name, node, ordinal, description, repourl, owner) values (?, ?, ?, ?, ?, ?)"
         )
     }
     private val stmtUpdateProject by lazy {
         connection.prepareStatement(
-            "update lpit_project set name = ?, node = ?, description = ?, repourl = ?, owner = ? where projectid = ?"
+            "update lpit_project set name = ?, node = ?, ordinal = ?, description = ?, repourl = ?, owner = ? where projectid = ?"
         )
     }
     private val stmtIssueSummary by lazy {
--- a/src/main/kotlin/de/uapcore/lightpit/entities/Project.kt	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/entities/Project.kt	Mon Jan 04 15:25:59 2021 +0100
@@ -28,6 +28,7 @@
 data class Project(override val id: Int) : Entity {
     var name: String = ""
     var node: String = name
+    var ordinal = 0
     var description: String? = null
     var repoUrl: String? = null
     var owner: User? = null
--- a/src/main/resources/localization/projects.properties	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/resources/localization/projects.properties	Mon Jan 04 15:25:59 2021 +0100
@@ -43,6 +43,7 @@
 
 name=Name
 node=Node
+ordinal=Ordering
 node.tooltip=Name of the path node that will be used in URL construction.
 description=Description
 repoUrl=Repository
--- a/src/main/resources/localization/projects_de.properties	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/resources/localization/projects_de.properties	Mon Jan 04 15:25:59 2021 +0100
@@ -43,6 +43,7 @@
 
 name=Name
 node=Pfadname
+ordinal=Sequenznummer
 node.tooltip=Name, der zur Konstruktion der URL genutzt werden soll.
 description=Beschreibung
 repoUrl=Repository
--- a/src/main/webapp/WEB-INF/jsp/project-form.jsp	Mon Jan 04 15:14:26 2021 +0100
+++ b/src/main/webapp/WEB-INF/jsp/project-form.jsp	Mon Jan 04 15:25:59 2021 +0100
@@ -67,6 +67,12 @@
                 </select>
             </td>
         </tr>
+        <tr title="<fmt:message key="tooltip.ordinal" />">
+            <th><fmt:message key="ordinal"/></th>
+            <td>
+                <input name="ordinal" type="number" min="0" value="${project.ordinal}"/>
+            </td>
+        </tr>
         </tbody>
         <tfoot>
         <tr>

mercurial