001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.wicket;
018:
019: import info.jtrac.domain.Counts;
020: import info.jtrac.domain.CountsHolder;
021: import info.jtrac.domain.ItemSearch;
022: import info.jtrac.domain.User;
023: import info.jtrac.domain.UserSpaceRole;
024: import java.util.ArrayList;
025: import java.util.List;
026: import org.apache.wicket.markup.html.WebMarkupContainer;
027: import org.apache.wicket.markup.html.basic.Label;
028: import org.apache.wicket.markup.html.link.Link;
029: import org.apache.wicket.markup.html.list.ListItem;
030: import org.apache.wicket.markup.html.list.ListView;
031: import org.apache.wicket.model.PropertyModel;
032:
033: /**
034: * dashboard page
035: */
036: public class DashboardPage extends BasePage {
037:
038: public DashboardPage() {
039:
040: final User user = getPrincipal();
041: List<UserSpaceRole> spaceRoles = new ArrayList(user
042: .getSpaceRoles());
043:
044: WebMarkupContainer table = new WebMarkupContainer("table");
045: WebMarkupContainer message = new WebMarkupContainer("message");
046:
047: add(table);
048: add(message);
049:
050: if (spaceRoles.size() > 0) {
051: final CountsHolder countsHolder = getJtrac()
052: .loadCountsForUser(user);
053:
054: WebMarkupContainer hideLogged = new WebMarkupContainer(
055: "hideLogged");
056: WebMarkupContainer hideAssigned = new WebMarkupContainer(
057: "hideAssigned");
058: if (user.getId() == 0) {
059: hideLogged.setVisible(false);
060: hideAssigned.setVisible(false);
061: }
062: table.add(hideLogged);
063: table.add(hideAssigned);
064:
065: table.add(new ListView("dashboardRows", spaceRoles) {
066: protected void populateItem(final ListItem listItem) {
067: UserSpaceRole usr = (UserSpaceRole) listItem
068: .getModelObject();
069: Counts counts = countsHolder.getCounts().get(
070: usr.getSpace().getId());
071: if (counts == null) {
072: counts = new Counts(false); // this can happen if fresh space
073: }
074: DashboardRowPanel dashboardRow = new DashboardRowPanel(
075: "dashboardRow", usr, counts);
076: listItem.add(dashboardRow);
077: }
078: });
079:
080: // TODO panelize totals row and reduce redundant code
081: WebMarkupContainer total = new WebMarkupContainer("total");
082:
083: if (spaceRoles.size() > 1) {
084:
085: total.add(new Link("search") {
086: public void onClick() {
087: setCurrentSpace(null);
088: setResponsePage(ItemSearchFormPage.class);
089: }
090: });
091:
092: if (user.getId() > 0) {
093: total.add(new Link("loggedByMe") {
094: public void onClick() {
095: setCurrentSpace(null);
096: ItemSearch itemSearch = new ItemSearch(
097: user, DashboardPage.this );
098: itemSearch.setLoggedBy(user);
099: setCurrentItemSearch(itemSearch);
100: setResponsePage(ItemListPage.class);
101: }
102: }.add(new Label("loggedByMe", new PropertyModel(
103: countsHolder, "totalLoggedByMe"))));
104:
105: total.add(new Link("assignedToMe") {
106: public void onClick() {
107: setCurrentSpace(null);
108: ItemSearch itemSearch = new ItemSearch(
109: user, DashboardPage.this );
110: itemSearch.setAssignedTo(user);
111: setCurrentItemSearch(itemSearch);
112: setResponsePage(ItemListPage.class);
113: }
114: }.add(new Label("assignedToMe", new PropertyModel(
115: countsHolder, "totalAssignedToMe"))));
116: } else {
117: total.add(new WebMarkupContainer("loggedByMe")
118: .setVisible(false));
119: total.add(new WebMarkupContainer("assignedToMe")
120: .setVisible(false));
121: }
122:
123: total.add(new Link("total") {
124: public void onClick() {
125: setCurrentSpace(null);
126: ItemSearch itemSearch = new ItemSearch(user,
127: DashboardPage.this );
128: setCurrentItemSearch(itemSearch);
129: setResponsePage(ItemListPage.class);
130: }
131: }.add(new Label("total", new PropertyModel(
132: countsHolder, "totalTotal"))));
133:
134: } else {
135: total.setVisible(false);
136: }
137: table.add(total);
138: message.setVisible(false);
139: } else {
140: table.setVisible(false);
141: }
142:
143: }
144:
145: }
|