From 805f65b9eaf8a10595ea4287281dae10c1a97e05 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Mon, 26 Nov 2012 18:03:16 +0100 Subject: [PATCH] Add new field to configure seconds for planning warning FEA: ItEr77S03Community --- .../common/entities/Configuration.java | 13 +++++ .../src/main/resources/db.changelog-1.3.xml | 15 +++++ .../common/entities/Configuration.hbm.xml | 3 + .../web/common/ConfigurationController.java | 8 +++ .../web/common/ConfigurationModel.java | 10 ++++ .../web/common/ConfirmCloseUtil.java | 55 ++++++++++--------- .../web/common/IConfigurationModel.java | 5 ++ .../src/main/webapp/common/configuration.zul | 11 ++++ 8 files changed, 95 insertions(+), 25 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java index 5635becf3..2f05f98d4 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Configuration.java @@ -23,6 +23,7 @@ package org.libreplan.business.common.entities; import org.apache.commons.lang.StringUtils; import org.hibernate.validator.AssertTrue; +import org.hibernate.validator.Min; import org.hibernate.validator.NotEmpty; import org.hibernate.validator.NotNull; import org.libreplan.business.calendars.entities.BaseCalendar; @@ -113,6 +114,8 @@ public class Configuration extends BaseEntity { private PersonalTimesheetsPeriodicityEnum personalTimesheetsPeriodicity = PersonalTimesheetsPeriodicityEnum.MONTHLY; + private Integer secondsPlanningWarning = 30; + /** * Maximum users configurable directly in database for SaaS products. If * zero it means that there isn't any limitation. @@ -490,4 +493,14 @@ public class Configuration extends BaseEntity { return maxResources; } + @Min(value = 0, message = "seconds planning warning cannot be negative") + @NotNull(message = "seconds planning warning not specified") + public Integer getSecondsPlanningWarning() { + return secondsPlanningWarning; + } + + public void setSecondsPlanningWarning(Integer secondsPlanningWarning) { + this.secondsPlanningWarning = secondsPlanningWarning; + } + } diff --git a/libreplan-business/src/main/resources/db.changelog-1.3.xml b/libreplan-business/src/main/resources/db.changelog-1.3.xml index a4dbcdcdf..8da319d91 100644 --- a/libreplan-business/src/main/resources/db.changelog-1.3.xml +++ b/libreplan-business/src/main/resources/db.changelog-1.3.xml @@ -193,4 +193,19 @@ constraintName="order_element_code_key" /> + + Add seconds_planning_warning column to configuration + + + + + + + + + diff --git a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml index 0a4ee5f13..afc2a504c 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Configuration.hbm.xml @@ -91,6 +91,9 @@ + + diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index 218cb25c7..6389d0781 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -915,4 +915,12 @@ public class ConfigurationController extends GenericForwardComposer { return ""; } + public Integer getSecondsPlanningWarning() { + return configurationModel.getSecondsPlanningWarning(); + } + + public void setSecondsPlanningWarning(Integer secondsPlanningWarning) { + configurationModel.setSecondsPlanningWarning(secondsPlanningWarning); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java index ccb6d75df..8227a0788 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java @@ -657,4 +657,14 @@ public class ConfigurationModel implements IConfigurationModel { return !workReportDAO.isAnyPersonalTimesheetAlreadySaved(); } + @Override + public Integer getSecondsPlanningWarning() { + return configuration.getSecondsPlanningWarning(); + } + + @Override + public void setSecondsPlanningWarning(Integer secondsPlanningWarning) { + configuration.setSecondsPlanningWarning(secondsPlanningWarning); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfirmCloseUtil.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfirmCloseUtil.java index 23e2cb2c6..0b1617a7a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfirmCloseUtil.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfirmCloseUtil.java @@ -18,6 +18,7 @@ */ package org.libreplan.web.common; +import org.libreplan.business.common.Registry; import org.zkoss.ganttz.util.LongOperationFeedback; import org.zkoss.ganttz.util.LongOperationFeedback.IBackGroundOperation; import org.zkoss.ganttz.util.LongOperationFeedback.IDesktopUpdate; @@ -32,37 +33,41 @@ import org.zkoss.zk.ui.util.Clients; */ public class ConfirmCloseUtil { - private static final int WARNING_ON_EXIT_MS = 30000; // 30 seconds - public static void resetConfirmClose() { Clients.confirmClose(null); } public static void setConfirmClose(Desktop desktop, final String message) { - LongOperationFeedback - .progressive( - desktop, - new IBackGroundOperation() { + final Integer seconds = Registry.getConfigurationDAO() + .getConfigurationWithReadOnlyTransaction() + .getSecondsPlanningWarning(); - @Override - public void doOperation( - IDesktopUpdatesEmitter desktopUpdateEmitter) { - try { - Thread.sleep(WARNING_ON_EXIT_MS); - } catch (InterruptedException e) { - throw new RuntimeException(e); + if (seconds > 0) { + LongOperationFeedback + .progressive( + desktop, + new IBackGroundOperation() { + + @Override + public void doOperation( + IDesktopUpdatesEmitter desktopUpdateEmitter) { + try { + Thread.sleep(seconds * 1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + desktopUpdateEmitter + .doUpdate(new IDesktopUpdate() { + + @Override + public void doUpdate() { + resetConfirmClose(); + Clients.confirmClose(message); + } + }); } - desktopUpdateEmitter - .doUpdate(new IDesktopUpdate() { - - @Override - public void doUpdate() { - resetConfirmClose(); - Clients.confirmClose(message); - } - }); - } - }); + }); + } } -} +} \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java index 6430a17b8..ab8e0a22f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java @@ -180,4 +180,9 @@ public interface IConfigurationModel { boolean isAnyPersonalTimesheetAlreadySaved(); + Integer getSecondsPlanningWarning(); + + void setSecondsPlanningWarning( + Integer planningWarningExitWithoutSavingSeconds); + } diff --git a/libreplan-webapp/src/main/webapp/common/configuration.zul b/libreplan-webapp/src/main/webapp/common/configuration.zul index 0c09fbb82..411a78169 100644 --- a/libreplan-webapp/src/main/webapp/common/configuration.zul +++ b/libreplan-webapp/src/main/webapp/common/configuration.zul @@ -209,6 +209,17 @@ label="${i18n:_('MonteCarlo method')}" checked="@{configurationController.monteCarloMethodTabVisible}" /> + +