# HG changeset patch # User Mike Becker # Date 1589634667 -7200 # Node ID 67a02e79b7a1f75299f8f94086b47f93567cf264 # Parent dd0a45ae25d7f78adf66b783e367f00f60092cf5 adds project selection diff -r dd0a45ae25d7 -r 67a02e79b7a1 src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java --- 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; } diff -r dd0a45ae25d7 -r 67a02e79b7a1 src/main/webapp/WEB-INF/dynamic_fragments/projects.jsp --- 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" %> + @@ -44,7 +46,7 @@ - +
@@ -63,9 +65,9 @@ - + data-selected > - +
diff -r dd0a45ae25d7 -r 67a02e79b7a1 src/main/webapp/lightpit.css --- 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; } diff -r dd0a45ae25d7 -r 67a02e79b7a1 src/main/webapp/projects.css --- /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; +}