/* * Copyright (C) 2020 Christian Pierre MOMON * * This file is part of AgirStatool, simple key value database. * * AgirStatool is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * AgirStatool is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with AgirStatool. If not, see . */ package org.april.agirstatool.core.pages; import org.apache.commons.lang3.StringEscapeUtils; import org.april.agirstatool.core.AgirStatoolException; import org.april.agirstatool.core.AgirStatoolUtils; import org.april.agirstatool.core.Project; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; import fr.devinsy.xidyn.utils.XidynUtils; /** * The class AgirStatool. * * @author Christian Pierre MOMON */ public class ProjectsGroupedView { private static Logger logger = LoggerFactory.getLogger(ProjectsGroupedView.class); /** * Builds the. * * @param project * the project * @return the string * @throws AgirStatoolException * the agir statool exception */ public static String build(final Project project) throws AgirStatoolException { String result; try { logger.debug("Building ProjectsGrouped view…"); TagDataManager data = new TagDataManager(); fillLine(data, 0, project); int index = 1; for (Project subProject : project.subProjects()) { fillLine(data, index, subProject); index += 1; for (Project subSubProject : subProject.subProjects()) { fillLine(data, index, subSubProject); index += 1; } } CharSequence page = PresenterUtils.dynamize("/org/april/agirstatool/core/pages/projectsGroupedView.xhtml", data); result = XidynUtils.extractBodyContent(page); } catch (XidynException exception) { throw new AgirStatoolException("Error building ProjectsGrouped view: " + exception.getMessage(), exception); } // return result; } /** * Fill line. * * @param data * the data * @param index * the index * @param project * the project */ public static void fillLine(final TagDataManager data, final int index, final Project project) { data.setContent("projectGroupedLine", index, "pgl_projectId", project.getId()); if (project.getParentId() != null) { data.setAttribute("projectGroupedLine", index, "pgl_projectName", "style", "padding-left: 25px;"); } data.setAttribute("projectGroupedLine", index, "pgl_projectNameLink", "href", project.getPath()); data.setContent("projectGroupedLine", index, "pgl_projectNameLink", StringEscapeUtils.escapeXml(project.getName())); data.setContent("projectGroupedLine", index, "pgl_childCount", project.getChildCount()); data.setContent("projectGroupedLine", index, "pgl_issueCount", project.issueStats().getCount()); data.setContent("projectGroupedLine", index, "pgl_activeIssueCount", project.issueStats().getActiveCount()); data.setAttribute("projectGroupedLine", index, "pgl_activeIssueCount", "class", AgirStatoolUtils.selectStatIndicator(project.issueStats().getActiveCount())); data.setContent("projectGroupedLine", index, "pgl_maybeIssueCount", project.issueStats().getMaybeCount()); data.setContent("projectGroupedLine", index, "pgl_resolvedIssueCount", project.issueStats().getResolvedCount()); data.setAttribute("projectGroupedLine", index, "pgl_resolvedIssueCount", "class", AgirStatoolUtils.selectStatIndicator(project.issueStats().getResolvedCount())); data.setContent("projectGroupedLine", index, "pgl_concludedIssueCount", project.issueStats().getConcludedCount()); data.setContent("projectGroupedLine", index, "pgl_unassignedIssueCount", project.issueStats().getUnassignedCount()); data.setContent("projectGroupedLine", index, "pgl_unassignedNewIssueCount", project.issueStats().getUnassignedNewCount()); data.setContent("projectGroupedLine", index, "pgl_unassignedStartedIssueCount", project.issueStats().getUnassignedStartedCount()); data.setAttribute("projectGroupedLine", index, "pgl_unassignedStartedIssueCount", "class", AgirStatoolUtils.selectStatIndicator(project.issueStats().getUnassignedStartedCount())); data.setContent("projectGroupedLine", index, "pgl_unassignedResolvedIssueCount", project.issueStats().getUnassignedResolvedCount()); data.setAttribute("projectGroupedLine", index, "pgl_unassignedResolvedIssueCount", "class", AgirStatoolUtils.selectStatIndicator(project.issueStats().getUnassignedResolvedCount())); data.setContent("projectGroupedLine", index, "pgl_unassignedConcludedIssueCount", project.issueStats().getUnassignedConcludedCount()); data.setAttribute("projectGroupedLine", index, "pgl_unassignedConcludedIssueCount", "class", AgirStatoolUtils.selectStatIndicator(project.issueStats().getUnassignedConcludedCount())); data.setContent("projectGroupedLine", index, "pgl_lastUpdate", AgirStatoolUtils.toHumanShort(project.issueStats().getLastUpdate(), "n/a")); data.setAttribute("projectGroupedLine", index, "pgl_lastUpdate", "title", AgirStatoolUtils.toHumanLong(project.issueStats().getLastUpdate(), "n/a")); } }