src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java

changeset 109
2e0669e814ff
parent 107
b5f740a87af4
child 110
9d0be0b1580f
     1.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Thu Oct 08 18:28:16 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Thu Oct 08 20:16:47 2020 +0200
     1.3 @@ -42,7 +42,6 @@
     1.4  import java.io.IOException;
     1.5  import java.sql.Date;
     1.6  import java.sql.SQLException;
     1.7 -import java.util.ArrayList;
     1.8  import java.util.NoSuchElementException;
     1.9  import java.util.Optional;
    1.10  import java.util.stream.Collectors;
    1.11 @@ -68,73 +67,6 @@
    1.12          return "localization.projects";
    1.13      }
    1.14  
    1.15 -    private String queryParams(Project p, Version v) {
    1.16 -        return String.format("pid=%d&vid=%d",
    1.17 -                p == null ? -1 : p.getId(),
    1.18 -                v == null ? -1 : v.getId()
    1.19 -        );
    1.20 -    }
    1.21 -
    1.22 -    /**
    1.23 -     * Creates the navigation menu.
    1.24 -     *
    1.25 -     * @param req the servlet request
    1.26 -     * @param viewModel the current view model
    1.27 -     */
    1.28 -    private void setNavigationMenu(HttpServletRequest req, ProjectView viewModel) {
    1.29 -        final Project selectedProject = Optional.ofNullable(viewModel.getProjectInfo()).map(ProjectInfo::getProject).orElse(null);
    1.30 -
    1.31 -        final var navigation = new ArrayList<MenuEntry>();
    1.32 -
    1.33 -        for (ProjectInfo plistInfo : viewModel.getProjectList()) {
    1.34 -            final var proj = plistInfo.getProject();
    1.35 -            final var projEntry = new MenuEntry(
    1.36 -                    proj.getName(),
    1.37 -                    "projects/view?" + queryParams(proj, null)
    1.38 -            );
    1.39 -            navigation.add(projEntry);
    1.40 -            if (proj.equals(selectedProject)) {
    1.41 -                final var projInfo = viewModel.getProjectInfo();
    1.42 -                projEntry.setActive(true);
    1.43 -
    1.44 -                // ****************
    1.45 -                // Versions Section
    1.46 -                // ****************
    1.47 -                {
    1.48 -                    final var entry = new MenuEntry(1,
    1.49 -                            new ResourceKey(getResourceBundleName(), "menu.versions"),
    1.50 -                            "projects/view?" + queryParams(proj, null)
    1.51 -                    );
    1.52 -                    navigation.add(entry);
    1.53 -                }
    1.54 -
    1.55 -                final var level2 = new ArrayList<MenuEntry>();
    1.56 -                {
    1.57 -                    final var entry = new MenuEntry(
    1.58 -                            new ResourceKey(getResourceBundleName(), "filter.none"),
    1.59 -                            "projects/view?" + queryParams(proj, null)
    1.60 -                    );
    1.61 -                    if (viewModel.getVersionFilter() == null) entry.setActive(true);
    1.62 -                    level2.add(entry);
    1.63 -                }
    1.64 -
    1.65 -                for (Version version : projInfo.getVersions()) {
    1.66 -                    final var entry = new MenuEntry(
    1.67 -                            version.getName(),
    1.68 -                            "projects/view?" + queryParams(proj, version)
    1.69 -                    );
    1.70 -                    if (version.equals(viewModel.getVersionFilter())) entry.setActive(true);
    1.71 -                    level2.add(entry);
    1.72 -                }
    1.73 -
    1.74 -                level2.forEach(e -> e.setLevel(2));
    1.75 -                navigation.addAll(level2);
    1.76 -            }
    1.77 -        }
    1.78 -
    1.79 -        setNavigationMenu(req, navigation);
    1.80 -    }
    1.81 -
    1.82      private int syncParamWithSession(HttpServletRequest req, String param, String attr) {
    1.83          final var session = req.getSession();
    1.84          final var idParam = getParameter(req, Integer.class, param);
    1.85 @@ -179,7 +111,7 @@
    1.86          setViewModel(req, viewModel);
    1.87          setContentPage(req, name);
    1.88          setStylesheet(req, "projects");
    1.89 -        setNavigationMenu(req, viewModel);
    1.90 +        setNavigationMenu(req, "project-navmenu");
    1.91          return ResponseType.HTML;
    1.92      }
    1.93  
    1.94 @@ -232,7 +164,7 @@
    1.95  
    1.96              dao.getProjectDao().saveOrUpdate(project);
    1.97  
    1.98 -            setRedirectLocation(req, "./projects/view?pid="+project.getId());
    1.99 +            setRedirectLocation(req, "./projects/versions?pid="+project.getId());
   1.100              setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL);
   1.101              LOG.debug("Successfully updated project {}", project.getName());
   1.102  
   1.103 @@ -270,6 +202,26 @@
   1.104          return forwardView(req, viewModel, "project-details");
   1.105      }
   1.106  
   1.107 +    @RequestMapping(requestPath = "versions", method = HttpMethod.GET)
   1.108 +    public ResponseType versions(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException {
   1.109 +        final var viewModel = new VersionsView();
   1.110 +        populate(viewModel, req, dao);
   1.111 +        viewModel.setVersionFilter(null);
   1.112 +
   1.113 +        final var projectInfo = viewModel.getProjectInfo();
   1.114 +        if (projectInfo == null) {
   1.115 +            resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No project selected.");
   1.116 +            return ResponseType.NONE;
   1.117 +        }
   1.118 +
   1.119 +        final var issueDao = dao.getIssueDao();
   1.120 +        final var issues = issueDao.list(projectInfo.getProject());
   1.121 +        for (var issue : issues) issueDao.joinVersionInformation(issue);
   1.122 +        viewModel.update(projectInfo.getVersions(), issues);
   1.123 +
   1.124 +        return forwardView(req, viewModel, "versions");
   1.125 +    }
   1.126 +
   1.127      @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET)
   1.128      public ResponseType editVersion(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
   1.129          final var viewModel = new VersionEditView();
   1.130 @@ -297,7 +249,7 @@
   1.131              dao.getVersionDao().saveOrUpdate(version);
   1.132  
   1.133              // specifying the pid parameter will purposely reset the session selected version!
   1.134 -            setRedirectLocation(req, "./projects/view?pid=" + version.getProject().getId());
   1.135 +            setRedirectLocation(req, "./projects/versions?pid=" + version.getProject().getId());
   1.136              setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL);
   1.137          } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) {
   1.138              LOG.warn("Form validation failure: {}", ex.getMessage());

mercurial