First implementation of my tasks area

Pending to add the operations column

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-05-16 16:48:20 +02:00
parent 06fc5b7be6
commit fb53b79249
6 changed files with 277 additions and 4 deletions

View file

@ -51,6 +51,10 @@ public interface IResourceAllocationDAO extends
List<Resource> resources, LocalDate intervalFilterStartDate,
LocalDate intervalFilterEndDate);
List<SpecificResourceAllocation> findSpecificAllocationsRelatedTo(
Scenario onScenario, List<Resource> resources,
LocalDate intervalFilterStartDate, LocalDate intervalFilterEndDate);
List<ResourceAllocation<?>> findAllocationsRelatedTo(Scenario onScenario,
Resource resource,
LocalDate intervalFilterStartDate, LocalDate intervalFilterEndDate);

View file

@ -123,8 +123,9 @@ public class ResourceAllocationDAO extends
return query.list();
}
@Override
@SuppressWarnings("unchecked")
private List<SpecificResourceAllocation> findSpecificAllocationsRelatedTo(
public List<SpecificResourceAllocation> findSpecificAllocationsRelatedTo(
final Scenario onScenario,
final List<Resource> resources,
final LocalDate intervalFilterStartDate,

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <mrego@igalia.com>
*/
public interface IUserDashboardModel {
/**
* Returns the list of {@link TaskElement TaskElements} assigned to the
* resource bound to current {@link User} through a
* {@link SpecificResourceAllocation}.
*/
List<Task> getTasks();
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <mrego@igalia.com>
*/
@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<Task> getTasks() {
return userDashboardModel.getTasks();
}
public RowRenderer getTasksRenderer() {
return tasksRenderer;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <mrego@igalia.com>
*/
@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<Task> getTasks() {
User user = UserUtil.getUserFromSession();
if (!user.isBound()) {
return new ArrayList<Task>();
}
List<SpecificResourceAllocation> resourceAllocations = resourceAllocationDAO
.findSpecificAllocationsRelatedTo(scenarioManager.getCurrent(),
getBoundResourceAsList(user), null, null);
List<Task> tasks = new ArrayList<Task>();
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<Resource> getBoundResourceAsList(User user) {
List<Resource> resource = new ArrayList<Resource>();
resource.add(user.getWorker());
return resource;
}
}

View file

@ -27,7 +27,25 @@
<?link rel="stylesheet" type="text/css" href="/common/css/libreplan_zk.css"?>
<zk>
<window self="@{define(content)}" title="${i18n:_('My dashboard')}">
TODO
<window self="@{define(content)}" title="${i18n:_('My dashboard')}"
apply="org.libreplan.web.users.dashboard.UserDashboardController">
<groupbox>
<caption label="${i18n:_('My tasks')}" />
<grid id="listing" model="@{controller.tasks}" mold="paging"
pageSize="10" rowRenderer="@{controller.tasksRenderer}">
<columns sizable="true">
<column label="${i18n:_('Name')}" />
<column label="${i18n:_('Code')}" />
<column label="${i18n:_('Project')}" />
<column label="${i18n:_('Start date')}" />
<column label="${i18n:_('End date')}" />
<column label="${i18n:_('Progress')}" />
<column label="${i18n:_('Work done')}" />
</columns>
</grid>
</groupbox>
</window>
</zk>
</zk>