adds project selection

Sat, 16 May 2020 15:11:07 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 16 May 2020 15:11:07 +0200
changeset 52
67a02e79b7a1
parent 51
dd0a45ae25d7
child 53
6a8498291606

adds project selection

src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/dynamic_fragments/projects.jsp file | annotate | diff | comparison | revisions
src/main/webapp/lightpit.css file | annotate | diff | comparison | revisions
src/main/webapp/projects.css file | annotate | diff | comparison | revisions
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Sat May 16 13:29:44 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Sat May 16 15:11:07 2020 +0200
@@ -39,6 +39,8 @@
 import java.sql.SQLException;
 import java.util.Optional;
 
+import static de.uapcore.lightpit.Functions.fqn;
+
 @LightPITModule(
         bundleBaseName = "localization.projects",
         modulePath = "projects",
@@ -50,10 +52,31 @@
 )
 public final class ProjectsModule extends AbstractLightPITServlet {
 
+    public static final String SESSION_ATTR_SELECTED_PROJECT = fqn(ProjectsModule.class, "selected-project");
+
     @RequestMapping(method = HttpMethod.GET)
     public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
-        req.setAttribute("projects", dao.getProjectDao().list());
+        final var projectList = dao.getProjectDao().list();
+        req.setAttribute("projects", projectList);
         setDynamicFragment(req, "projects");
+        setStylesheet(req, "projects");
+
+        final var session = req.getSession();
+        final var projectSelection = getParameter(req, Integer.class, "select");
+        if (projectSelection.isPresent()) {
+            final var selectedId = projectSelection.get();
+            for (var proj : projectList) {
+                if (proj.getId() == selectedId) {
+                    session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, proj);
+                    break;
+                }
+            }
+        } else {
+            final var selectedProject = session.getAttribute(SESSION_ATTR_SELECTED_PROJECT);
+            if (selectedProject == null) {
+                projectList.stream().findFirst().ifPresent(proj -> session.setAttribute(SESSION_ATTR_SELECTED_PROJECT, proj));
+            }
+        }
 
         return ResponseType.HTML;
     }
--- a/src/main/webapp/WEB-INF/dynamic_fragments/projects.jsp	Sat May 16 13:29:44 2020 +0200
+++ b/src/main/webapp/WEB-INF/dynamic_fragments/projects.jsp	Sat May 16 15:11:07 2020 +0200
@@ -26,10 +26,12 @@
 --%>
 <%@page pageEncoding="UTF-8" %>
 <%@page import="de.uapcore.lightpit.Constants" %>
+<%@page import="de.uapcore.lightpit.modules.ProjectsModule" %>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 
 <c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/>
+<c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/>
 
 <jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request"/>
 
@@ -44,7 +46,7 @@
 </div>
 
 <c:if test="${not empty projects}">
-<table class="datatable medskip">
+<table id="project-list" class="datatable medskip">
     <colgroup>
         <col>
         <col style="width: 10%">
@@ -63,9 +65,9 @@
     </thead>
     <tbody>
     <c:forEach var="project" items="${projects}">
-        <tr>
+        <tr class="nowrap" <c:if test="${project eq selectedProject}">data-selected</c:if> >
             <td style="width: 2em;"><a href="./${moduleInfo.modulePath}/edit?id=${project.id}">&#x270e;</a></td>
-            <td><c:out value="${project.name}"/></td>
+            <td><a href="./${moduleInfo.modulePath}?select=${project.id}"><c:out value="${project.name}"/></a></td>
             <td><c:out value="${project.description}"/></td>
             <td>
                 <c:if test="${not empty project.repoUrl}">
--- a/src/main/webapp/lightpit.css	Sat May 16 13:29:44 2020 +0200
+++ b/src/main/webapp/lightpit.css	Sat May 16 15:11:07 2020 +0200
@@ -29,6 +29,7 @@
 
 html {
     font-family: sans-serif;
+    font-size: 11pt;
     background: white;
     color: #1c204e;
     margin: 0;
@@ -57,6 +58,7 @@
 }
 
 #mainMenu {
+    font-size: large;
     background: #e0e0e5;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/projects.css	Sat May 16 15:11:07 2020 +0200
@@ -0,0 +1,32 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2018 Mike Becker. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#project-list tr[data-selected] {
+    background: lightgoldenrodyellow;
+}

mercurial