From 9027217e2d0619b3ae13c056adc6cc61b81b7a5a Mon Sep 17 00:00:00 2001 From: Diego Pino Date: Wed, 16 May 2012 08:25:14 +0200 Subject: [PATCH] Move code related with 'GlobalProgressChart' to separate files FEA: ItEr76S15OrganizingPerProjectDashboard --- .../web/dashboard/DashboardController.java | 147 +--------------- .../web/dashboard/GlobalProgressChart.java | 159 ++++++++++++++++++ .../webapp/dashboard/_dashboardfororder.zul | 53 +----- .../main/webapp/dashboard/_globalProgress.zul | 71 ++++++++ 4 files changed, 240 insertions(+), 190 deletions(-) create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/dashboard/GlobalProgressChart.java create mode 100644 libreplan-webapp/src/main/webapp/dashboard/_globalProgress.zul diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java index 582fe3f47..ea4af45f7 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java @@ -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 - * - */ - 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 current = new LinkedHashMap(); - - private final Map expected = new LinkedHashMap(); - - private static List series = new ArrayList() { - { - 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 array) { - List result = new ArrayList(); - - 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 result = new ArrayList(); - 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 - * - */ - 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 diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/GlobalProgressChart.java b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/GlobalProgressChart.java new file mode 100644 index 000000000..3ab0782f2 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/GlobalProgressChart.java @@ -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 . + */ + +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 +* +*/ +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 current = new LinkedHashMap(); + + private final Map expected = new LinkedHashMap(); + + private static List series = new ArrayList() { + { + 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 array) { + List result = new ArrayList(); + + 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 result = new ArrayList(); + 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 + * + */ + 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); + } + + } + +} diff --git a/libreplan-webapp/src/main/webapp/dashboard/_dashboardfororder.zul b/libreplan-webapp/src/main/webapp/dashboard/_dashboardfororder.zul index 9004d3eb4..fe56f5e16 100644 --- a/libreplan-webapp/src/main/webapp/dashboard/_dashboardfororder.zul +++ b/libreplan-webapp/src/main/webapp/dashboard/_dashboardfororder.zul @@ -120,58 +120,7 @@ var global_progress = { }; - - + diff --git a/libreplan-webapp/src/main/webapp/dashboard/_globalProgress.zul b/libreplan-webapp/src/main/webapp/dashboard/_globalProgress.zul new file mode 100644 index 000000000..cfc3ad06d --- /dev/null +++ b/libreplan-webapp/src/main/webapp/dashboard/_globalProgress.zul @@ -0,0 +1,71 @@ + + + +