BrightSide Workbench Full Report + Source Code
KanbanVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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.kanban;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.dossier.entity.Category;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.dossier.entity.IssueStatus;
28 import org.turro.dossier.entity.IssueType;
29 import org.turro.dossier.issue.IssueWrapper;
30 import org.turro.dossier.util.DossiersInfo;
31 import org.turro.dossier.workload.WorkloadItem;
32 import org.turro.dossier.workload.WorkloadQuery;
33 import org.turro.dossier.workload.WorkloadSet;
34 import org.turro.dossier.zul.attach.IssueAttachTree;
35 import org.turro.dossier.zul.issue.IssueStage;
36 import org.turro.dossier.zul.menu.DossierMenu;
37 import org.turro.elephant.context.Application;
38 import org.turro.i18n.I_;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.registry.Changes;
41 import org.turro.zkoss.dialog.SelectionDialog;
42 import org.turro.zul.frame.Framework;
43 import org.zkoss.bind.annotation.BindingParam;
44 import org.zkoss.bind.annotation.Command;
45 import org.zkoss.bind.annotation.NotifyChange;
46 import org.zkoss.zul.GroupsModel;
47 import org.zkoss.zul.SimpleGroupsModel;
48 
53 public class KanbanVM {
54 
55  private final WorkloadQuery query;
56  private final long count[];
57 
58  public KanbanVM() {
59  query = new WorkloadQuery();
60  count = new long[4];
61  }
62 
63  @Command
64  public void showInfo(@BindingParam("item") WorkloadItem item) {
66  IssueWrapper iw = new IssueWrapper(item.getIssue());
67  if(app.isInRole("issue:show") &&
68  (app.isInRole("issue:all") || iw.isFullParticipant())) {
69  DossiersInfo.popup(item.getIssue());
70  }
71  }
72 
73  @NotifyChange({"toDoModel", "inProgressModel", "doneModel", "toDoLabel", "inProgressLabel", "doneLabel"})
74  @Command("update")
75  public void update() {
76  _model = null;
77  }
78 
79  @NotifyChange({"toDoModel", "inProgressModel", "doneModel", "toDoLabel", "inProgressLabel", "doneLabel"})
80  @Command
81  public void selectEntity(@BindingParam("entity") Object entity) {
82  if(entity instanceof Category) {
83  setSelectedCategory((Category) entity);
84  setSelectedDossier(null);
85  } else if(entity instanceof Dossier) {
86  setSelectedDossier((Dossier) entity);
87  setSelectedCategory(null);
88  } else {
89  setSelectedCategory(null);
90  setSelectedDossier(null);
91  }
92  }
93 
94  @NotifyChange({"toDoModel", "inProgressModel", "doneModel", "toDoLabel", "inProgressLabel", "doneLabel"})
95  @Command
96  public void selectContact(@BindingParam("contact") IContact contact) {
97  setParticipant(contact);
98  }
99 
100  @Command
101  public void showAttachments(@BindingParam("issue") Issue issue) {
103  IssueWrapper iw = new IssueWrapper(issue);
104  if(app.isInRole("issue:show") &&
105  (app.isInRole("issue:all") || iw.isFullParticipant())) {
106  IssueAttachTree iat = new IssueAttachTree();
107  iat.setEntity(issue);
108  iat.setChanges(new Changes());
109  SelectionDialog.showComponent(Framework.getCurrent().getPage(), I_.get("Attachments"),
110  iat, "80%", "80%", null);
111  }
112  }
113 
114  @Command
115  public void addInformation(@BindingParam("issue") Issue issue) {
116  DossierMenu.addInformation(issue, null);
117  }
118 
119  public void setSearchValue(String searchValue) {
120  query.setSearchValue(searchValue);
121  _model = null;
122  }
123 
124  public String getSearchValue() {
125  return query.getSearchValue();
126  }
127 
128  public void setSelectedCategory(Category category) {
129  query.setCategory(category);
130  _model = null;
131  }
132 
134  return query.getCategory();
135  }
136 
137  public void setSelectedDossier(Dossier dossier) {
138  query.setDossier(dossier);
139  _model = null;
140  }
141 
143  return query.getDossier();
144  }
145 
146  public void setParticipant(IContact contact) {
147  query.setByParticipant(contact);
148  _model = null;
149  }
150 
152  return query.getByParticipant();
153  }
154 
155  public Set<IssueStatus> getStatus() {
156  return query.getStatus();
157  }
158 
159  public void setStatus(Set<IssueStatus> status) {
160  query.setStatus(status);
161  _model = null;
162  }
163 
164  public Set<IssueType> getTypes() {
165  return query.getTypes();
166  }
167 
168  public void setTypes(Set<IssueType> types) {
169  query.setTypes(types);
170  _model = null;
171  }
172 
173  public GroupsModel<WorkloadItem, Object, Object> getToDoModel() {
174  return getColumnModel(1);
175  }
176 
177  public GroupsModel<WorkloadItem, Object, Object> getInProgressModel() {
178  return getColumnModel(2);
179  }
180 
181  public GroupsModel<WorkloadItem, Object, Object> getDoneModel() {
182  return getColumnModel(3);
183  }
184 
185  public String getToDoLabel() {
186  return I_.get("To do") + " (" + count[1] + ")";
187  }
188 
189  public String getInProgressLabel() {
190  return I_.get("In progress") + " (" + count[2] + ")";
191  }
192 
193  public String getDoneLabel() {
194  return I_.get("Done") + " (" + count[3] + ")";
195  }
196 
197  public GroupsModel<WorkloadItem, Object, Object> getColumnModel(int column) {
198  List<List<WorkloadItem>> data = new ArrayList<>();
199  List<String> headers = new ArrayList<>();
200  List<WorkloadItem> loading = null;
201 
202  IssueStage stage = null;
203  count[column] = 0;
204 
205  for(final WorkloadItem item : getModel()) {
206  if(WorkloadSet.getKanbanColumn(item) == column) {
207  IssueStage current = WorkloadSet.getStage(item);
208  if(!(current.equals(stage))) {
209  stage = current;
210  headers.add(stage.toString());
211  loading = new ArrayList<>();
212  data.add(loading);
213  }
214  if(loading != null) {
215  loading.add(item);
216  count[column]++;
217  }
218  }
219  }
220 
221  return new SimpleGroupsModel<>(data, headers);
222  }
223 
224  private WorkloadSet _model;
225 
226  private WorkloadSet getModel() {
227  if(_model == null) {
228  _model = query.getResults();
229  }
230 
231  return _model;
232  }
233 
234 }
Set< IssueStatus > getStatus()
Definition: KanbanVM.java:155
void setSelectedCategory(Category category)
Definition: KanbanVM.java:128
GroupsModel< WorkloadItem, Object, Object > getInProgressModel()
Definition: KanbanVM.java:177
void setTypes(Set< IssueType > types)
Definition: KanbanVM.java:168
void setSelectedDossier(Dossier dossier)
Definition: KanbanVM.java:137
void selectEntity(@BindingParam("entity") Object entity)
Definition: KanbanVM.java:81
GroupsModel< WorkloadItem, Object, Object > getToDoModel()
Definition: KanbanVM.java:173
void showAttachments(@BindingParam("issue") Issue issue)
Definition: KanbanVM.java:101
void setParticipant(IContact contact)
Definition: KanbanVM.java:146
GroupsModel< WorkloadItem, Object, Object > getColumnModel(int column)
Definition: KanbanVM.java:197
void selectContact(@BindingParam("contact") IContact contact)
Definition: KanbanVM.java:96
void addInformation(@BindingParam("issue") Issue issue)
Definition: KanbanVM.java:115
GroupsModel< WorkloadItem, Object, Object > getDoneModel()
Definition: KanbanVM.java:181
void showInfo(@BindingParam("item") WorkloadItem item)
Definition: KanbanVM.java:64
void setStatus(Set< IssueStatus > status)
Definition: KanbanVM.java:159
void setSearchValue(String searchValue)
Definition: KanbanVM.java:119
static void popup(Issue issue)
void setStatus(Set< IssueStatus > status)
void setTypes(Set< IssueType > types)
void setByParticipant(IContact byParticipant)
static void addInformation(Issue issue, final Command command)
static String get(String msg)
Definition: I_.java:41
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
static Framework getCurrent()
Definition: Framework.java:203