BrightSide Workbench Full Report + Source Code
IssueSelfSummary.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.dossier.command;
20 
21 import java.util.Collection;
22 import java.util.EnumMap;
23 import java.util.Map;
24 import org.turro.annotation.ElephantPlugin;
25 import org.turro.dossier.issue.IssueWrapper;
26 import org.turro.dossier.search.IssueResults;
27 import org.turro.dossier.zul.issue.IssueStage;
28 import org.turro.dossier.zul.menu.DossierMenu;
29 import org.turro.elephant.context.Application;
30 import org.turro.elephant.util.Images;
31 import org.turro.i18n.I_;
32 import org.turro.plugin.command.SelfSummaryPlugin;
33 import org.turro.zkoss.label.LabelTypes;
34 import org.turro.zkoss.layout.GridLayout;
35 import org.turro.zkoss.layout.GroupboxArrow;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zul.Button;
40 import org.zkoss.zul.Hlayout;
41 import org.zkoss.zul.Image;
42 import org.zkoss.zul.Space;
43 
48 @ElephantPlugin
49 public class IssueSelfSummary extends SelfSummaryPlugin {
50 
51  private Map<IssueStage, Integer> map;
52 
53  @Override
54  protected void executePlugin() {
56  if(app.isInRole("issue:list")) {
57  pendingIssues();
58  if(!map.isEmpty()) {
59  GroupboxArrow gba = new GroupboxArrow() {
60  @Override
61  protected void doFillContent() {
62  }
63  };
64  Hlayout hbox = new Hlayout();
65  gba.setCaption(hbox);
66  hbox.setSclass("z-valign-middle");
67  hbox.setValign("middle");
68  hbox.appendChild(new Image(Images.getImage("issue")));
69  if(map.get(IssueStage.ISSUE_STAGE_DATE_SURPASSED) != null) {
70  hbox.appendChild(LabelTypes.getSoftLabel(I_.byKey(IssueStage.ISSUE_STAGE_DATE_SURPASSED.toString()) + ":"));
71  hbox.appendChild(LabelTypes.getPreLabel(map.get(IssueStage.ISSUE_STAGE_DATE_SURPASSED) + ""));
72  hbox.appendChild(new Space());
73  }
74  if(map.get(IssueStage.ISSUE_STAGE_TO_DO) != null) {
75  hbox.appendChild(LabelTypes.getSoftLabel(I_.byKey(IssueStage.ISSUE_STAGE_TO_DO.toString()) + ":"));
76  hbox.appendChild(LabelTypes.getPreLabel(map.get(IssueStage.ISSUE_STAGE_TO_DO) + ""));
77  hbox.appendChild(new Space());
78  }
79  Button visit = new Button(I_.get("My issues"));
80  visit.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
81  @Override
82  public void onEvent(Event event) throws Exception {
83  DossierMenu.showMyIssues();
84  }
85  });
86  hbox.appendChild(visit);
87  GridLayout gl = new GridLayout("min,1");
88  gba.appendChild(gl);
89  for(IssueStage is : map.keySet()) {
90  gl.addCaption(I_.byKey(is.toString()));
91  gl.addValue(map.get(is) + "");
92  gl.addRow();
93  }
94  gba.setOpen(false);
95  addResult("issue", gba);
96  }
97  }
98  }
99 
100  private void pendingIssues() {
101  map = new EnumMap<>(IssueStage.class);
102  IssueResults ir = new IssueResults();
103  Collection<IssueWrapper> iwl = ir.getIssueList();
104  for(IssueWrapper iw : iwl) {
105  IssueStage is = getStage(iw);
106  Integer i = map.get(is);
107  if(i == null) {
108  map.put(is, 1);
109  } else {
110  map.put(is, i + 1);
111  }
112  }
113  }
114 
115  //TODO: move to IssueWrapper. Also from IssueGrid.
116  private IssueStage getStage(IssueWrapper wissue) {
117 
118  if(wissue.isUnrelated()) {
119  return IssueStage.ISSUE_STAGE_UNRELATED;
120  }
121 
122  if(wissue.hasPassedNow()) {
123  return IssueStage.ISSUE_STAGE_DATE_SURPASSED;
124  }
125 
126  if(!wissue.hasPassedStartDate() || !wissue.canStartBySources()) {
127  return IssueStage.ISSUE_STAGE_TO_COME;
128  }
129 
130  int stage = wissue.getRelevanceOrderByContact();
131 
132  switch(stage) {
133  case 1: return IssueStage.ISSUE_STAGE_TO_DO;
134  case 2: return IssueStage.ISSUE_STAGE_REUNION;
135  case 5: return IssueStage.ISSUE_STAGE_FROZEN;
136  }
137 
138  return IssueStage.ISSUE_STAGE_TO_MONITOR;
139  }
140 
141 }
Object addResult(String key, Object value)
static String getImage(String image)
Definition: Images.java:36
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
static Label getPreLabel(String value)
Definition: LabelTypes.java:52
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28
GridLayout addCaption(String label)
GridLayout addValue(String value)