#163 removes multi selection for versions

Thu, 19 Aug 2021 14:51:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 19 Aug 2021 14:51:04 +0200
changeset 231
dcb1d5a7ea3a
parent 230
95b419e054fa
child 232
296e12ff8d1c

#163 removes multi selection for versions

setup/postgres/psql_create_tables.sql 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/Issue.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt file | annotate | diff | comparison | revisions
src/main/resources/localization/strings.properties file | annotate | diff | comparison | revisions
src/main/resources/localization/strings_de.properties file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/changelogs/changelog-de.jspf file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/changelogs/changelog.jspf file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/issue-form.jsp file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/issue-view.jsp file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jspf/version-list.jspf file | annotate | diff | comparison | revisions
--- a/setup/postgres/psql_create_tables.sql	Wed Aug 18 16:02:40 2021 +0200
+++ b/setup/postgres/psql_create_tables.sql	Thu Aug 19 14:51:04 2021 +0200
@@ -96,21 +96,9 @@
     assignee    integer references lpit_user (userid),
     created     timestamp with time zone not null default now(),
     updated     timestamp with time zone not null default now(),
-    eta         date
-);
-
-create table lpit_issue_affected_version
-(
-    issueid   integer references lpit_issue (issueid),
-    versionid integer references lpit_version (versionid),
-    primary key (issueid, versionid)
-);
-
-create table lpit_issue_resolved_version
-(
-    issueid   integer references lpit_issue (issueid),
-    versionid integer references lpit_version (versionid),
-    primary key (issueid, versionid)
+    eta         date,
+    affected    integer references lpit_version (versionid),
+    resolved    integer references lpit_version (versionid)
 );
 
 create table lpit_issue_comment
--- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Thu Aug 19 14:51:04 2021 +0200
@@ -153,18 +153,13 @@
 
     override fun listVersionSummaries(project: Project): List<VersionSummary> =
         withStatement(
-            """
-            with version_map(issueid, versionid, isresolved) as (
-                select issueid, versionid, true
-                from lpit_issue_resolved_version
-                union
-                select issueid, versionid, false
-                from lpit_issue_affected_version
-            ),
-            issues as (
-                select versionid, phase, isresolved, count(issueid) as total
-                from lpit_issue
-                join version_map using (issueid)
+            """with
+            version_map as (
+                select issueid, status, resolved as versionid, true as isresolved from lpit_issue
+                union all
+                select issueid, status, affected as versionid, false as isresolved from lpit_issue
+            ), issues as (
+                select versionid, phase, isresolved, count(issueid) as total from version_map
                 join lpit_issue_phases using (status)
                 group by versionid, phase, isresolved
             ),
@@ -461,7 +456,7 @@
             component, c.name as componentname, c.node as componentnode,
             status, category, subject, i.description,
             userid, username, givenname, lastname, mail,
-            created, updated, eta
+            created, updated, eta, affected, resolved
         from lpit_issue i
         join lpit_project p on i.project = projectid
         left join lpit_component c on component = c.id
@@ -490,30 +485,10 @@
             created = getTimestamp("created")
             updated = getTimestamp("updated")
             eta = getDate("eta")
+            affected = getInt("affected").takeIf { it > 0 }?.let { findVersion(it) }
+            resolved = getInt("resolved").takeIf { it > 0 }?.let { findVersion(it) }
         }
 
-        //language=SQL
-        val queryAffected =
-            """
-            $versionQuery join lpit_issue_affected_version using (versionid)
-            where issueid = ? order by ordinal, name
-            """.trimIndent()
-
-        //language=SQL
-        val queryResolved =
-            """
-            $versionQuery join lpit_issue_resolved_version using (versionid)
-            where issueid = ? order by ordinal, name
-            """.trimIndent()
-
-        issue.affectedVersions = withStatement(queryAffected) {
-            setInt(1, issue.id)
-            queryAll { it.extractVersion() }
-        }
-        issue.resolvedVersions = withStatement(queryResolved) {
-            setInt(1, issue.id)
-            queryAll { it.extractVersion() }
-        }
         return issue
     }
 
@@ -527,26 +502,18 @@
             setStringOrNull(i++, description)
             setIntOrNull(i++, assignee?.id)
             setDateOrNull(i++, eta)
+            setIntOrNull(i++, affected?.id)
+            setIntOrNull(i++, resolved?.id)
         }
         return i
     }
 
     override fun listIssues(filter: IssueFilter): List<Issue> =
         withStatement(
-            """
-            with issue_version as (
-                select issueid, versionid from lpit_issue_affected_version
-                union select issueid, versionid from lpit_issue_resolved_version
-            ),
-            filtered_issues as (
-                select distinct issueid from lpit_issue
-                left join issue_version using (issueid)
-                where
-                (not ? or project = ?) and 
-                (not ? or versionid = ?) and (not ? or versionid is null) and
+            """$issueQuery where
+                (not ? or i.project = ?) and 
+                (not ? or ? in (resolved, affected)) and (not ? or (resolved is null and affected is null)) and
                 (not ? or component = ?) and (not ? or component is null)
-            )
-            $issueQuery join filtered_issues using (issueid)
             """.trimIndent()
         ) {
             fun <T : Entity> applyFilter(filter: Filter<T>, fflag: Int, nflag: Int, idcol: Int) {
@@ -594,27 +561,10 @@
             querySingle { it.extractIssue() }
         }
 
-    private fun insertVersionInfo(id: Int, issue: Issue) {
-        withStatement("insert into lpit_issue_affected_version (issueid, versionid) values (?,?)") {
-            setInt(1, id)
-            issue.affectedVersions.forEach {
-                setInt(2, it.id)
-                executeUpdate()
-            }
-        }
-        withStatement("insert into lpit_issue_resolved_version (issueid, versionid) values (?,?)") {
-            setInt(1, id)
-            issue.resolvedVersions.forEach {
-                setInt(2, it.id)
-                executeUpdate()
-            }
-        }
-    }
-
     override fun insertIssue(issue: Issue): Int {
         val id = withStatement(
             """
-            insert into lpit_issue (component, status, category, subject, description, assignee, eta, project)
+            insert into lpit_issue (component, status, category, subject, description, assignee, eta, affected, resolved, project)
             values (?, ?::issue_status, ?::issue_category, ?, ?, ?, ?, ?)
             returning issueid
             """.trimIndent()
@@ -623,7 +573,6 @@
             setInt(col, issue.project.id)
             querySingle { it.getInt(1) }!!
         }
-        insertVersionInfo(id, issue)
         return id
     }
 
@@ -632,7 +581,7 @@
             """
             update lpit_issue set updated = now(),
                 component = ?, status = ?::issue_status, category = ?::issue_category, subject = ?,
-                description = ?, assignee = ?, eta = ?
+                description = ?, assignee = ?, eta = ?, affected = ?, resolved = ?
             where issueid = ?
             """.trimIndent()
         ) {
@@ -640,17 +589,6 @@
             setInt(col, issue.id)
             executeUpdate()
         }
-
-        // TODO: improve by only inserting / deleting changed version information
-        withStatement("delete from lpit_issue_affected_version where issueid = ?") {
-            setInt(1, issue.id)
-            executeUpdate()
-        }
-        withStatement("delete from lpit_issue_resolved_version where issueid = ?") {
-            setInt(1, issue.id)
-            executeUpdate()
-        }
-        insertVersionInfo(issue.id, issue)
     }
 
     //</editor-fold>
--- a/src/main/kotlin/de/uapcore/lightpit/entities/Issue.kt	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/entities/Issue.kt	Thu Aug 19 14:51:04 2021 +0200
@@ -45,8 +45,8 @@
     var updated: Timestamp = Timestamp.from(Instant.now())
     var eta: Date? = null
 
-    var affectedVersions = emptyList<Version>()
-    var resolvedVersions = emptyList<Version>()
+    var affected: Version? = null
+    var resolved: Version? = null
 
     /**
      * An issue is overdue, if it is not done and the ETA is before the current time.
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Thu Aug 19 14:51:04 2021 +0200
@@ -482,9 +482,9 @@
                 // pre-select version, if available in the path info
                 if (version != null) {
                     if (version.status.isReleased) {
-                        issue.affectedVersions = listOf(version)
+                        issue.affected = version
                     } else {
-                        issue.resolvedVersions = listOf(version)
+                        issue.resolved = version
                     }
                 }
             }
@@ -565,10 +565,8 @@
                 // TODO: process error messages
                 eta = http.param("eta", ::dateOptValidator, null, mutableListOf())
 
-                affectedVersions = http.paramArray("affected")
-                    .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, project.id) } }
-                resolvedVersions = http.paramArray("resolved")
-                    .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, project.id) } }
+                affected = http.param("affected")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) }
+                resolved = http.param("resolved")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) }
             }
 
             val openId = if (issue.id < 0) {
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt	Thu Aug 19 14:51:04 2021 +0200
@@ -76,7 +76,7 @@
         val renderer = HtmlRenderer.builder(options).build()
         val process = fun(it: String) = renderer.render(parser.parse(it))
 
-        issue.description = process(issue.description?:"")
+        issue.description = process(issue.description ?: "")
         for (comment in comments) {
             comment.commentFormatted = process(comment.comment)
         }
@@ -101,9 +101,10 @@
 
     init {
         val recent = mutableListOf<Version>()
+        issue.affected?.let { recent.add(it) }
         val upcoming = mutableListOf<Version>()
-        recent.addAll(issue.affectedVersions)
-        upcoming.addAll(issue.resolvedVersions)
+        issue.resolved?.let { upcoming.add(it) }
+
         for (v in versions) {
             if (v.status.isReleased) {
                 if (v.status != VersionStatus.Deprecated) recent.add(v)
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt	Thu Aug 19 14:51:04 2021 +0200
@@ -42,11 +42,11 @@
         val reported = mutableListOf<Issue>()
         val resolved = mutableListOf<Issue>()
         for (issue in issues) {
-            if (issue.affectedVersions.contains(version)) {
+            if (issue.affected == version) {
                 reportedTotal.add(issue)
                 reported.add(issue)
             }
-            if (issue.resolvedVersions.contains(version)) {
+            if (issue.resolved == version) {
                 resolvedTotal.add(issue)
                 resolved.add(issue)
             }
--- a/src/main/resources/localization/strings.properties	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/resources/localization/strings.properties	Thu Aug 19 14:51:04 2021 +0200
@@ -121,6 +121,7 @@
 placeholder.null-component=Unassigned
 placeholder.null-lead=Unassigned
 placeholder.null-owner=Unassigned
+placeholder.null-version=None
 progress=Overall Progress
 project.name=Name
 project.owner=Project Lead
--- a/src/main/resources/localization/strings_de.properties	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/resources/localization/strings_de.properties	Thu Aug 19 14:51:04 2021 +0200
@@ -120,6 +120,7 @@
 placeholder.null-component=Keine
 placeholder.null-lead=Niemand
 placeholder.null-owner=Nicht Zugewiesen
+placeholder.null-version=Keine
 progress=Gesamtfortschritt
 project.name=Name
 project.owner=Projektleitung
--- a/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf	Thu Aug 19 14:51:04 2021 +0200
@@ -27,6 +27,7 @@
 <h3>Version 1.0 (Vorschau)</h3>
 
 <ul>
+    <li>Mehrfachauswahl für Versionen im Vorgang entfernt.</li>
     <li>Möglichkeit zum Deaktivieren einer Komponente hinzugefügt.</li>
     <li>Datum der Veröffentlichung und des Supportendes zu Versionen hinzugefügt.</li>
     <li>Gesamtanzahl der Kommentare wird nun angezeigt.</li>
--- a/src/main/webapp/WEB-INF/changelogs/changelog.jspf	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/webapp/WEB-INF/changelogs/changelog.jspf	Thu Aug 19 14:51:04 2021 +0200
@@ -27,6 +27,7 @@
 <h3>Version 1.0 (snapshot)</h3>
 
 <ul>
+    <li>Removes multi selection of versions within an issue.</li>
     <li>Adds possibility to deactivate a component.</li>
     <li>Adds release and end of life dates to versions.</li>
     <li>Adds the total number of comments to the caption.</li>
--- a/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/webapp/WEB-INF/jsp/issue-form.jsp	Thu Aug 19 14:51:04 2021 +0200
@@ -125,19 +125,27 @@
         <tr>
             <th class="vtop"><label for="issue-affected"><fmt:message key="issue.affected-versions"/></label></th>
             <td>
-                <c:set var="fieldname" value="affected"/>
-                <c:set var="selectionList" value="${viewmodel.versionsRecent}"/>
-                <c:set var="data" value="${issue.affectedVersions}" />
-                <%@include file="../jspf/version-list.jspf"%>
+                <select id="issue-affected" name="affected">
+                    <option value="-1"><fmt:message key="placeholder.null-version"/></option>
+                    <c:forEach var="vselitem" items="${viewmodel.versionsRecent}">
+                        <option value="${vselitem.id}" <c:if test="${issue.affected eq vselitem}">selected</c:if> >
+                            <c:out value="${vselitem.name}" />
+                        </option>
+                    </c:forEach>
+                </select>
             </td>
         </tr>
         <tr>
             <th class="vtop"><label for="issue-resolved"><fmt:message key="issue.resolved-versions"/></label></th>
             <td>
-                <c:set var="fieldname" value="resolved"/>
-                <c:set var="selectionList" value="${viewmodel.versionsUpcoming}"/>
-                <c:set var="data" value="${issue.resolvedVersions}" />
-                <%@include file="../jspf/version-list.jspf"%>
+                <select id="issue-resolved" name="resolved">
+                    <option value="-1"><fmt:message key="placeholder.null-version"/></option>
+                    <c:forEach var="vselitem" items="${viewmodel.versionsUpcoming}">
+                        <option value="${vselitem.id}" <c:if test="${issue.resolved eq vselitem}">selected</c:if> >
+                            <c:out value="${vselitem.name}" />
+                        </option>
+                    </c:forEach>
+                </select>
             </td>
         </tr>
         </c:if>
--- a/src/main/webapp/WEB-INF/jsp/issue-view.jsp	Wed Aug 18 16:02:40 2021 +0200
+++ b/src/main/webapp/WEB-INF/jsp/issue-view.jsp	Thu Aug 19 14:51:04 2021 +0200
@@ -95,15 +95,11 @@
     <tr>
         <th><fmt:message key="issue.resolved-versions"/></th>
         <td>
-            <c:forEach var="version" items="${issue.resolvedVersions}">
-                <c:out value="${version.name}"/>
-            </c:forEach>
+            <c:out value="${issue.resolved.name}"/>
         </td>
         <th><fmt:message key="issue.affected-versions"/></th>
         <td>
-            <c:forEach var="version" items="${issue.affectedVersions}">
-                <c:out value="${version.name}"/>
-            </c:forEach>
+            <c:out value="${issue.affected.name}"/>
         </td>
     </tr>
     </tbody>
--- a/src/main/webapp/WEB-INF/jspf/version-list.jspf	Wed Aug 18 16:02:40 2021 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
-
-<select id="issue-${fieldname}" name="${fieldname}" multiple>
-    <c:forEach var="vselitem" items="${selectionList}">
-        <option value="${vselitem.id}"
-                <c:forEach var="v" items="${data}">
-                    <c:if test="${v eq vselitem}">selected</c:if>
-                </c:forEach>
-                <c:if test="${vid eq vselitem.id}">selected</c:if>
-        >
-            <c:out value="${vselitem.name}" />
-        </option>
-    </c:forEach>
-</select>

mercurial