Move code related with 'GlobalProgressChart' to separate files

FEA: ItEr76S15OrganizingPerProjectDashboard
This commit is contained in:
Diego Pino 2012-05-16 08:25:14 +02:00
parent 40d8e00111
commit 9027217e2d
4 changed files with 240 additions and 190 deletions

View file

@ -22,14 +22,10 @@ package org.libreplan.web.dashboard;
import static org.libreplan.web.I18nHelper._;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.planner.entities.TaskStatusEnum;
import org.libreplan.web.dashboard.DashboardModel.Interval;
@ -265,24 +261,25 @@ public class DashboardController extends GenericForwardComposer {
}
private void renderGlobalProgress() {
GlobalProgress globalProgress = GlobalProgress.create();
GlobalProgressChart globalProgressChart = GlobalProgressChart.create();
// Current values
globalProgress.current(GlobalProgress.CRITICAL_PATH_DURATION,
globalProgressChart.current(GlobalProgressChart.CRITICAL_PATH_DURATION,
dashboardModel.getCriticalPathProgressByDuration());
globalProgress.current(GlobalProgress.CRITICAL_PATH_HOURS,
globalProgressChart.current(GlobalProgressChart.CRITICAL_PATH_HOURS,
dashboardModel.getCriticalPathProgressByNumHours());
globalProgress.current(GlobalProgress.ALL_TASKS_HOURS,
globalProgressChart.current(GlobalProgressChart.ALL_TASKS_HOURS,
dashboardModel.getAdvancePercentageByHours());
// Expected values
globalProgress.expected(GlobalProgress.CRITICAL_PATH_DURATION,
globalProgressChart.expected(
GlobalProgressChart.CRITICAL_PATH_DURATION,
dashboardModel.getExpectedCriticalPathProgressByDuration());
globalProgress.expected(GlobalProgress.CRITICAL_PATH_HOURS,
globalProgressChart.expected(GlobalProgressChart.CRITICAL_PATH_HOURS,
dashboardModel.getExpectedCriticalPathProgressByNumHours());
globalProgress.expected(GlobalProgress.ALL_TASKS_HOURS,
globalProgressChart.expected(GlobalProgressChart.ALL_TASKS_HOURS,
dashboardModel.getExpectedAdvancePercentageByHours());
globalProgress.render();
globalProgressChart.render();
}
private void showCharts() {
@ -295,132 +292,6 @@ public class DashboardController extends GenericForwardComposer {
projectDashboardNoTasksWarningDiv.setVisible(true);
}
/**
*
* @author Diego Pino García <dpino@igalia.com>
*
*/
static class GlobalProgress {
public static final String ALL_TASKS_HOURS = _("By all tasks hours");
public static final String CRITICAL_PATH_HOURS = _("By critical path hours");
public static final String CRITICAL_PATH_DURATION = _("By critical path duration");
private final Map<String, BigDecimal> current = new LinkedHashMap<String, BigDecimal>();
private final Map<String, BigDecimal> expected = new LinkedHashMap<String, BigDecimal>();
private static List<Series> series = new ArrayList<Series>() {
{
add(Series.create(_("Current"), "#004469"));
add(Series.create(_("Expected"), "#3C90BE"));
}
};
private GlobalProgress() {
}
public void current(String key, BigDecimal value) {
current.put(key, value);
}
public void expected(String key, BigDecimal value) {
expected.put(key, value);
}
public static GlobalProgress create() {
return new GlobalProgress();
}
public String getPercentages() {
return String.format("'[%s, %s]'",
jsonifyPercentages(current.values()),
jsonifyPercentages(expected.values()));
}
private String jsonifyPercentages(Collection<BigDecimal> array) {
List<String> result = new ArrayList<String>();
int i = 1;
for (BigDecimal each : array) {
result.add(String.format("[%.2f, %d]", each.doubleValue(), i++));
}
return String.format("[%s]", StringUtils.join(result, ","));
}
private String jsonify(Collection<?> list) {
Collection<String> result = new ArrayList<String>();
for (Object each : list) {
if (each.getClass() == String.class) {
result.add(String.format("\"%s\"", each.toString()));
} else {
result.add(String.format("%s", each.toString()));
}
}
return String.format("'[%s]'", StringUtils.join(result, ','));
}
public String getSeries() {
return jsonify(series);
}
/**
* The order of the ticks is taken from the keys in current
*
* @return
*/
public String getTicks() {
return jsonify(current.keySet());
}
public void render() {
String command = String.format(
"global_progress.render(%s, %s, %s);", getPercentages(),
getTicks(), getSeries());
Clients.evalJavaScript(command);
}
}
/**
*
* @author Diego Pino García <dpino@igalia.com>
*
*/
static class Series {
private String label;
private String color;
private Series() {
}
public static Series create(String label) {
Series series = new Series();
series.label = label;
return series;
}
public static Series create(String label, String color) {
Series series = new Series();
series.label = label;
series.color = color;
return series;
}
@Override
public String toString() {
return String.format("{\"label\": \"%s\", \"color\": \"%s\"}",
label, color);
}
}
/**
*
* @author Diego Pino García<dpino@igalia.com>

View file

@ -0,0 +1,159 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.libreplan.web.dashboard;
import static org.libreplan.web.I18nHelper._;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.zkoss.zk.ui.util.Clients;
/**
*
* @author Diego Pino García <dpino@igalia.com>
*
*/
public class GlobalProgressChart {
public static final String ALL_TASKS_HOURS = _("By all tasks hours");
public static final String CRITICAL_PATH_HOURS = _("By critical path hours");
public static final String CRITICAL_PATH_DURATION = _("By critical path duration");
private final Map<String, BigDecimal> current = new LinkedHashMap<String, BigDecimal>();
private final Map<String, BigDecimal> expected = new LinkedHashMap<String, BigDecimal>();
private static List<Series> series = new ArrayList<Series>() {
{
add(Series.create(_("Current"), "#004469"));
add(Series.create(_("Expected"), "#3C90BE"));
}
};
private GlobalProgressChart() {
}
public void current(String key, BigDecimal value) {
current.put(key, value);
}
public void expected(String key, BigDecimal value) {
expected.put(key, value);
}
public static GlobalProgressChart create() {
return new GlobalProgressChart();
}
public String getPercentages() {
return String.format("'[%s, %s]'",
jsonifyPercentages(current.values()),
jsonifyPercentages(expected.values()));
}
private String jsonifyPercentages(Collection<BigDecimal> array) {
List<String> result = new ArrayList<String>();
int i = 1;
for (BigDecimal each : array) {
result.add(String.format("[%.2f, %d]", each.doubleValue(), i++));
}
return String.format("[%s]", StringUtils.join(result, ","));
}
private String jsonify(Collection<?> list) {
Collection<String> result = new ArrayList<String>();
for (Object each : list) {
if (each.getClass() == String.class) {
result.add(String.format("\"%s\"", each.toString()));
} else {
result.add(String.format("%s", each.toString()));
}
}
return String.format("'[%s]'", StringUtils.join(result, ','));
}
public String getSeries() {
return jsonify(series);
}
/**
* The order of the ticks is taken from the keys in current
*
* @return
*/
public String getTicks() {
return jsonify(current.keySet());
}
public void render() {
String command = String.format(
"global_progress.render(%s, %s, %s);", getPercentages(),
getTicks(), getSeries());
Clients.evalJavaScript(command);
}
/**
*
* @author Diego Pino García <dpino@igalia.com>
*
*/
static class Series {
private String label;
private String color;
private Series() {
}
public static Series create(String label) {
Series series = new Series();
series.label = label;
return series;
}
public static Series create(String label, String color) {
Series series = new Series();
series.label = label;
series.color = color;
return series;
}
@Override
public String toString() {
return String.format("{\"label\": \"%s\", \"color\": \"%s\"}",
label, color);
}
}
}

View file

@ -120,58 +120,7 @@
var global_progress = { };
</script>
<!-- Configure the parameters for the 'global progress' chart. The object contains a method 'render' that
is called from the Java file once all objects in the view have been created -->
<script type="text/javascript" defer="true">
<![CDATA[
global_progress = {
id: 'global-progress',
data: [],
title: 'Project progress percentage',
seriesDefaults: {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
shadowAngle: 135,
rendererOptions: {
barDirection: 'horizontal'
},
},
axes: {
xaxis: {
label: "Progress percentage per progress type"
},
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ['1','2','3'],
tickOptions: {
showGridline: false,
markSize: 0
}
}
},
series:[
{label:'Expected', color: 'blue'},
{label:'Actual', color: 'red'},
],
legend: {
show: true,
location: 'e',
placement: 'outside',
},
render: function(data, ticks, series) {
if (ticks !== undefined) {
this.axes.yaxis.ticks = jQuery.parseJSON(ticks);
}
if (series !== undefined) {
this.series = jQuery.parseJSON(series);
}
this.plot = $.jqplot(this.id, jQuery.parseJSON(data), this);
}
};
]]>
</script>
<include src="/dashboard/_globalProgress.zul" />
<!-- Include jqPlot styles -->
<n:link class="include" rel="stylesheet" type="text/css" href="/libreplan-webapp/jqplot/jquery.jqplot.min.css" />

View file

@ -0,0 +1,71 @@
<!--
This file is part of LibrePlan
Copyright (C) 2010-2012 Igalia, S.L.
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<!-- Configure the parameters for the 'global progress' chart. The object contains a method 'render' that
is called from the Java file once all objects in the view have been created -->
<script type="text/javascript" defer="true">
<![CDATA[
global_progress = {
id: 'global-progress',
data: [],
title: 'Project progress percentage',
seriesDefaults: {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
shadowAngle: 135,
rendererOptions: {
barDirection: 'horizontal'
},
},
axes: {
xaxis: {
label: "Progress percentage per progress type"
},
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ['1','2','3'],
tickOptions: {
showGridline: false,
markSize: 0
}
}
},
series:[
{label:'Expected', color: 'blue'},
{label:'Actual', color: 'red'},
],
legend: {
show: true,
location: 'e',
placement: 'outside',
},
render: function(data, ticks, series) {
if (ticks !== undefined) {
this.axes.yaxis.ticks = jQuery.parseJSON(ticks);
}
if (series !== undefined) {
this.series = jQuery.parseJSON(series);
}
this.plot = $.jqplot(this.id, jQuery.parseJSON(data), this);
}
};
]]>
</script>