From fb53b79249286099056a0cb73f11923487a0f8f6 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 16 May 2012 16:48:20 +0200 Subject: [PATCH] First implementation of my tasks area Pending to add the operations column FEA: ItEr76S28UserDashboard --- .../planner/daos/IResourceAllocationDAO.java | 4 + .../planner/daos/ResourceAllocationDAO.java | 3 +- .../users/dashboard/IUserDashboardModel.java | 43 +++++++ .../dashboard/UserDashboardController.java | 109 ++++++++++++++++++ .../users/dashboard/UserDashboardModel.java | 98 ++++++++++++++++ .../main/webapp/myaccount/userDashboard.zul | 24 +++- 6 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IUserDashboardModel.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardController.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardModel.java diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java index c1899ca42..45e61b0d0 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java @@ -51,6 +51,10 @@ public interface IResourceAllocationDAO extends List resources, LocalDate intervalFilterStartDate, LocalDate intervalFilterEndDate); + List findSpecificAllocationsRelatedTo( + Scenario onScenario, List resources, + LocalDate intervalFilterStartDate, LocalDate intervalFilterEndDate); + List> findAllocationsRelatedTo(Scenario onScenario, Resource resource, LocalDate intervalFilterStartDate, LocalDate intervalFilterEndDate); diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java index a143fc824..f7d2eff22 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java @@ -123,8 +123,9 @@ public class ResourceAllocationDAO extends return query.list(); } + @Override @SuppressWarnings("unchecked") - private List findSpecificAllocationsRelatedTo( + public List findSpecificAllocationsRelatedTo( final Scenario onScenario, final List resources, final LocalDate intervalFilterStartDate, diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IUserDashboardModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IUserDashboardModel.java new file mode 100644 index 000000000..c06b760a4 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/IUserDashboardModel.java @@ -0,0 +1,43 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 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.users.dashboard; + +import java.util.List; + +import org.libreplan.business.planner.entities.SpecificResourceAllocation; +import org.libreplan.business.planner.entities.Task; +import org.libreplan.business.planner.entities.TaskElement; +import org.libreplan.business.users.entities.User; + +/** + * Interface for user dashboard model + * + * @author Manuel Rego Casasnovas + */ +public interface IUserDashboardModel { + + /** + * Returns the list of {@link TaskElement TaskElements} assigned to the + * resource bound to current {@link User} through a + * {@link SpecificResourceAllocation}. + */ + List getTasks(); + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardController.java new file mode 100644 index 000000000..6095421d2 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardController.java @@ -0,0 +1,109 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 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.users.dashboard; + +import static org.libreplan.web.I18nHelper._; + +import java.text.MessageFormat; +import java.util.List; + +import org.libreplan.business.advance.entities.AdvanceMeasurement; +import org.libreplan.business.advance.entities.DirectAdvanceAssignment; +import org.libreplan.business.orders.entities.OrderElement; +import org.libreplan.business.planner.entities.Task; +import org.libreplan.web.common.Util; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.util.GenericForwardComposer; +import org.zkoss.zul.Row; +import org.zkoss.zul.RowRenderer; + +/** + * Controller for user dashboard + * + * @author Manuel Rego Casasnovas + */ +@SuppressWarnings("serial") +public class UserDashboardController extends GenericForwardComposer { + + private IUserDashboardModel userDashboardModel; + + private RowRenderer tasksRenderer = new RowRenderer() { + + @Override + public void render(Row row, Object data) throws Exception { + Task task = (Task) data; + row.setValue(task); + + Util.appendLabel(row, task.getName()); + + OrderElement orderElement = task.getOrderElement(); + Util.appendLabel(row, orderElement.getCode()); + Util.appendLabel(row, orderElement.getOrder().getName()); + + Util.appendLabel(row, task.getStartAsLocalDate().toString()); + Util.appendLabel(row, task.getEndAsLocalDate().toString()); + + Util.appendLabel(row, getProgress(orderElement)); + + Util.appendLabel( + row, + _("{0} h", orderElement.getSumChargedEffort() + .getTotalChargedEffort().toFormattedString())); + } + + private String getProgress(OrderElement orderElement) { + + AdvanceMeasurement lastAdvanceMeasurement = getLastAdvanceMeasurement(orderElement); + if (lastAdvanceMeasurement != null) { + return MessageFormat.format("[{0} %] ({1})", + lastAdvanceMeasurement.getValue(), + lastAdvanceMeasurement.getDate()); + } + return ""; + } + + private AdvanceMeasurement getLastAdvanceMeasurement( + OrderElement orderElement) { + DirectAdvanceAssignment advanceAssignment = orderElement + .getReportGlobalAdvanceAssignment(); + if (advanceAssignment == null) { + return null; + } + return advanceAssignment + .getLastAdvanceMeasurement(); + } + + }; + + @Override + public void doAfterCompose(Component comp) throws Exception { + super.doAfterCompose(comp); + comp.setAttribute("controller", this); + } + + public List getTasks() { + return userDashboardModel.getTasks(); + } + + public RowRenderer getTasksRenderer() { + return tasksRenderer; + } + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardModel.java new file mode 100644 index 000000000..e6c2c2205 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/dashboard/UserDashboardModel.java @@ -0,0 +1,98 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 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.users.dashboard; + +import java.util.ArrayList; +import java.util.List; + +import org.libreplan.business.advance.entities.AdvanceMeasurement; +import org.libreplan.business.advance.entities.DirectAdvanceAssignment; +import org.libreplan.business.planner.daos.IResourceAllocationDAO; +import org.libreplan.business.planner.entities.SpecificResourceAllocation; +import org.libreplan.business.planner.entities.Task; +import org.libreplan.business.resources.entities.Resource; +import org.libreplan.business.scenarios.IScenarioManager; +import org.libreplan.business.users.entities.User; +import org.libreplan.web.UserUtil; +import org.libreplan.web.common.concurrentdetection.OnConcurrentModification; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Model for operations of user dashboard window + * + * @author Manuel Rego Casasnovas + */ +@Service +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +@OnConcurrentModification(goToPage = "/myaccount/userDashboard.zul") +public class UserDashboardModel implements IUserDashboardModel { + + @Autowired + private IResourceAllocationDAO resourceAllocationDAO; + + @Autowired + private IScenarioManager scenarioManager; + + @Override + @Transactional(readOnly = true) + public List getTasks() { + User user = UserUtil.getUserFromSession(); + if (!user.isBound()) { + return new ArrayList(); + } + + List resourceAllocations = resourceAllocationDAO + .findSpecificAllocationsRelatedTo(scenarioManager.getCurrent(), + getBoundResourceAsList(user), null, null); + + List tasks = new ArrayList(); + for (SpecificResourceAllocation each : resourceAllocations) { + Task task = each.getTask(); + forceLoad(task); + tasks.add(task); + } + return tasks; + } + + private void forceLoad(Task task) { + task.getName(); + task.getOrderElement().getOrder().getName(); + DirectAdvanceAssignment advanceAssignment = task.getOrderElement() + .getReportGlobalAdvanceAssignment(); + if (advanceAssignment != null) { + AdvanceMeasurement advanceMeasurement = advanceAssignment + .getLastAdvanceMeasurement(); + if (advanceMeasurement != null) { + advanceMeasurement.getValue(); + } + } + } + + private List getBoundResourceAsList(User user) { + List resource = new ArrayList(); + resource.add(user.getWorker()); + return resource; + } + +} diff --git a/libreplan-webapp/src/main/webapp/myaccount/userDashboard.zul b/libreplan-webapp/src/main/webapp/myaccount/userDashboard.zul index 9232fc967..7985d2c34 100644 --- a/libreplan-webapp/src/main/webapp/myaccount/userDashboard.zul +++ b/libreplan-webapp/src/main/webapp/myaccount/userDashboard.zul @@ -27,7 +27,25 @@ - - TODO + + + + + + + + + + + + + + + + + + - + \ No newline at end of file