2020-01-19 23:33:40 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.april.agirstatool.core.pages;
|
|
|
|
|
2020-01-30 22:34:33 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
import org.april.agirstatool.core.AgirStatool;
|
2020-01-19 23:33:40 +01:00
|
|
|
import org.april.agirstatool.core.AgirStatoolException;
|
2020-01-30 22:34:33 +01:00
|
|
|
import org.april.agirstatool.core.AgirStatoolUtils;
|
2020-01-20 08:00:41 +01:00
|
|
|
import org.april.agirstatool.core.Project;
|
2020-01-19 23:33:40 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import fr.devinsy.strings.StringList;
|
2020-01-30 22:34:33 +01:00
|
|
|
import fr.devinsy.xidyn.utils.XidynUtils;
|
2020-01-19 23:33:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class projectsRawPageBuilder.
|
|
|
|
*/
|
2020-01-30 22:34:33 +01:00
|
|
|
public class IssueStatusChartView
|
2020-01-19 23:33:40 +01:00
|
|
|
{
|
2020-01-30 22:34:33 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(IssueStatusChartView.class);
|
|
|
|
|
2020-01-19 23:33:40 +01:00
|
|
|
/**
|
|
|
|
* Builds the.
|
|
|
|
*
|
2020-01-22 19:37:28 +01:00
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
* @param project
|
|
|
|
* the project
|
2020-01-19 23:33:40 +01:00
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
2020-01-20 08:00:41 +01:00
|
|
|
public static String build(final String title, final Project project) throws AgirStatoolException
|
2020-01-19 23:33:40 +01:00
|
|
|
{
|
|
|
|
String result;
|
2020-03-05 03:50:04 +01:00
|
|
|
|
2020-01-19 23:33:40 +01:00
|
|
|
StringList labels = new StringList("Maybe", "New", "Confirmed", "Ongoing", "Waiting", "Resolved");
|
|
|
|
StringList values = new StringList();
|
2020-01-20 08:00:41 +01:00
|
|
|
values.append(project.issueStats().getMaybeCount());
|
|
|
|
values.append(project.issueStats().getNewCount());
|
|
|
|
values.append(project.issueStats().getConfirmedCount());
|
|
|
|
values.append(project.issueStats().getOngoingCount());
|
|
|
|
values.append(project.issueStats().getWaitingCount());
|
|
|
|
values.append(project.issueStats().getResolvedCount());
|
2020-03-05 03:50:04 +01:00
|
|
|
|
2020-03-05 03:51:20 +01:00
|
|
|
result = build(title, title, labels, values);
|
2020-03-05 03:50:04 +01:00
|
|
|
|
2020-01-19 23:33:40 +01:00
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-30 22:34:33 +01:00
|
|
|
* Builds the.
|
2020-01-19 23:33:40 +01:00
|
|
|
*
|
2020-01-22 19:37:28 +01:00
|
|
|
* @param title
|
|
|
|
* the title
|
2020-01-30 22:34:33 +01:00
|
|
|
* @param labelTitle
|
|
|
|
* the label title
|
|
|
|
* @param labels
|
|
|
|
* the labels
|
|
|
|
* @param values
|
|
|
|
* the values
|
2020-01-19 23:33:40 +01:00
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
2020-01-30 22:34:33 +01:00
|
|
|
public static String build(final String title, final String labelTitle, final StringList labels, final StringList values) throws AgirStatoolException
|
2020-01-19 23:33:40 +01:00
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2020-01-30 22:34:33 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/issueStatusChartView.xhtml"));
|
|
|
|
String code = XidynUtils.extractBodyContent(source);
|
2020-01-19 23:33:40 +01:00
|
|
|
|
2020-01-30 22:34:33 +01:00
|
|
|
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "chartBar"));
|
|
|
|
code = code.replace("# of Votes", labelTitle);
|
|
|
|
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
|
|
|
|
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
|
|
|
|
|
|
|
result = code.toString();
|
|
|
|
}
|
|
|
|
catch (IOException exception)
|
|
|
|
{
|
|
|
|
throw new AgirStatoolException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
|
|
|
|
}
|
2020-01-19 23:33:40 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
2020-03-05 03:50:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the grouped.
|
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
* @param project
|
|
|
|
* the project
|
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
|
|
|
public static String buildGrouped(final String title, final Project project) throws AgirStatoolException
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
|
|
|
StringList labels = new StringList("Maybe", "Active", "Resolved");
|
|
|
|
StringList values = new StringList();
|
|
|
|
values.append(project.issueStats().getMaybeCount());
|
|
|
|
values.append(project.issueStats().getActiveCount());
|
|
|
|
values.append(project.issueStats().getResolvedCount());
|
|
|
|
|
2020-03-05 03:51:20 +01:00
|
|
|
result = build(title, title, labels, values);
|
2020-03-05 03:50:04 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
2020-01-19 23:33:40 +01:00
|
|
|
}
|