BrightSide Workbench Full Report + Source Code
DossierMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.zul.menu;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.turro.annotation.ExternalMenu;
23 import org.turro.command.Command;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.DossierType;
27 import org.turro.dossier.entity.Issue;
28 import org.turro.dossier.entity.IssuePredecessorType;
29 import org.turro.dossier.task.Subtask;
30 import org.turro.dossier.task.SubtaskTypeSelection;
31 import org.turro.entities.EntityCombobox;
32 import org.turro.i18n.I_;
33 import org.turro.jpa.Dao;
34 import org.turro.menu.ElephantMenu;
35 import org.turro.menu.ElephantMenuBar;
36 import org.turro.security.Permission;
37 import org.turro.zkoss.dialog.DialogField;
38 import org.turro.zkoss.dialog.Dialogs;
39 import org.turro.zul.frame.Framework;
40 import org.zkoss.zk.ui.event.Event;
41 import org.zkoss.zk.ui.event.EventListener;
42 
48 public class DossierMenu extends ElephantMenu {
49 
50  @Override
51  public void addToMenu(ElephantMenuBar bar) {
52  bar.addMenu("Dossiers", Permission.from("dossier:list", "issue:list"))
53  .addSubmenu()
54  .addMenuitem("My dossiers", "dossier", "/dossier/dossiers.zul", true, Permission.from("dossier:list"))
55  .addMenuitem("Knowledge base", "kbase", "/issue/knowledgeBase.zul", true)
56  .addMenuitem("My issues", "issue", "/issue/workload.zul", true, Permission.from("issue:list"))
57  .addMenuitem("Kanban", "/issue/kanban.zul", Permission.from("issue:list"))
58  .addMenuitem("Gantt", "gantt", "/dossier/gantt.zul", Permission.from("issue:list"))
59  .addMenuitem("Task view", "task", "/dossier/taskView.zul", Permission.from("issue:list"))
60  .addMenuitem("Graph", "graph", "/dossier/issueGraph.zul", Permission.from("issue:list"))
61  .addMenuitem("Pending votes", "ok", "/dossier/pendingVotes.zul", Permission.from("issue:list"))
62  .addMenuitem("Pending petitions", "/dossier/pendingPetitions.zul", Permission.from("dossier:all"))
63  .addMenuitem("Worksheets", "issue", "/issue/worksheet.zul", false, Permission.from("worksheet:list"))
64  .addMenuitem("Workload", "piechart", "/dossier/workload.zul")
66  .addMenuitem("Categories", "/dossier/categories.zul", Permission.from("category:list"))
67  .addMenuitem("Project grants", "handshelp", "/dossier/projectGrants.zul", Permission.from("dossier:all"))
68  .addMenuitem("Field definitions", "/dossier/fielddefs.zul", Permission.from("dossier-field:list"))
69  .addMenuitem("Pending to register", (EventListener) (Event event) -> {
70  Framework frame = Framework.getCurrent();
71  frame.getDesktop().removeAttribute("dossierId");
72  frame.addContent(I_.get("Pending to register"), "/issue/registry.zul");
73  }, Permission.from("register:list"))
75  .addMenuitem("New Dossier", "dossier_new", (EventListener) (Event event) -> {
77  }, Permission.from("dossier:new"))
78  .addMenuitem("New Issue", "issue_new", (EventListener) (Event event) -> {
79  addInformation(null, null);
80  }, true, Permission.from("issue:new"))
81  .addToolbarSeparator(true);
82  }
83 
84  public static void showDossier(Dossier dossier) {
85  HashMap<String, Object> map = new HashMap<>();
86  map.put("dossierGenerated", dossier);
87  if(DossierType.TYPE_PROJECT.equals(dossier.getType())) {
88  showEntity(dossier.getId(), "dossierId", "Project", "/dossier/project.zul");
89  } else {
90  showEntity(dossier.getId(), "dossierId", "Dossier", "/dossier/dossier.zul", map);
91  }
92  }
93 
94  public static void showDossier(Long id) {
95  DossierType type = checkType(id);
96  if(DossierType.TYPE_PROJECT.equals(type)) {
97  showEntity(id, "dossierId", "Project", "/dossier/project.zul");
98  } else {
99  showEntity(id, "dossierId", "Dossier", "/dossier/dossier.zul");
100  }
101  }
102 
103  public static void showDossierActivity(Long id) {
104  showEntity(id, "dossierId", "Activity", "/dossier/activity.zul");
105  }
106 
107 // public static void showIssue(Issue issue) {
108 // HashMap<String, Object> map = new HashMap<String, Object>();
109 // map.put("issueGenerated", issue);
110 // showEntity(issue.getId(), "issueId", "Issue", "/issue/issue.zul", map);
111 // }
112 
113  public static void showIssue(Long id) {
114  showEntity(id, "issueId", "Issue", "/issue/issue.zul");
115  }
116 
117  public static void showCategory(Long id) {
118  showEntityModal(id, "categoryId", "/dossier/categoryEdit.zul", null);
119  }
120 
121  public static void showProjectGrant(Long id) {
122  showEntity(id, "projectGrantId", "Project grant", "/dossier/projectGrant.zul", null);
123  }
124 
125  public static void showMyDossiers() {
126  showZulFile("My dossiers", "/dossier/dossiers.zul");
127  }
128 
129  public static void showMyIssues() {
130  showZulFile("My issues", "/issue/workload.zul");
131  }
132 
133  public static void addSubtask(Issue issue, final Command command) {
134  Dialogs.title(I_.get("Subtask"))
135  .width("550px")
136  .height("220px")
137  .addField(DialogField.field("Type").onEditor(() -> new SubtaskTypeSelection()))
138  .onOk(dialogs -> {
139  Issue nissue = Issue.getDefaultIssue();
140  nissue.setDossier(issue.getDossier());
141  IssuePredecessorType type = dialogs.<SubtaskTypeSelection>getEditor("Type").getValue();
142  if(type != null) {
143  Subtask subtask = new Subtask(issue, type);
144  showModalZulFile("Issue", "/issue/addInformation.zul",
145  Map.of("issue", nissue, "subtask", subtask), command);
146  }
147  }).emptyCancel().show();
148  }
149 
150  public static void addRelation(Issue issue, final Command command) {
151  EntityCombobox issuebox = new EntityCombobox();
152  issuebox.setRoot("issue");
153  Dialogs.title(I_.get("Relation"))
154  .width("550px")
155  .height("250px")
156  .addField(DialogField.field("Type").onEditor(() -> new SubtaskTypeSelection()))
157  .addField(DialogField.field("Issue").onEditor(() -> issuebox))
158  .onOk(dialogs -> {
159  Issue nissue = Issue.getDefaultIssue();
160  nissue.setDossier(issue.getDossier());
161  IssuePredecessorType type = dialogs.<SubtaskTypeSelection>getEditor("Type").getValue();
162  Issue rissue = (Issue) dialogs.<EntityCombobox>getEditor("Issue").getEntity();
163  if(type != null && rissue != null) {
164  Subtask subtask = new Subtask(issue, type);
165  subtask.save(new DossierPU(), rissue);
166  }
167  }).emptyCancel().show();
168  }
169 
170  public static void addInformation(Issue issue, final Command command) {
171  HashMap<String, Object> map = new HashMap<>();
172  map.put("issue", issue == null ? Issue.getDefaultIssue() : issue);
173  showModalZulFile("Issue", "/issue/addInformation.zul", map, command);
174  }
175 
176  public static void addDossierInformation(Dossier dossier, Command command) {
177  HashMap<String, Object> map = new HashMap<>();
178  Issue issue = Issue.getDefaultIssue();
179  issue.setDossier(dossier);
180  map.put("issue", issue);
181  showModalZulFile("Issue", "/issue/addInformation.zul", map, command);
182  }
183 
184  public static void showPending() {
185  showZulFile("Pending petitions", "/dossier/pendingPetitions.zul");
186  }
187 
188  private static DossierType checkType(Long id) {
189  if(id == null || id == 0) {
190  return null;
191  }
192  Dao dao = new DossierPU();
193  return (DossierType) dao.getSingleResultOrNull(
194  "select d.type from Dossier d where d.id = ?",
195  new Object[] { id }
196  );
197  }
198 
199 }
static Issue getDefaultIssue()
Definition: Issue.java:503
void setDossier(Dossier dossier)
Definition: Issue.java:162
IssuePredecessor save(Dao dao, Issue task)
Definition: Subtask.java:42
void addToMenu(ElephantMenuBar bar)
static void addSubtask(Issue issue, final Command command)
static void addRelation(Issue issue, final Command command)
static void showDossierActivity(Long id)
static void addDossierInformation(Dossier dossier, Command command)
static void addInformation(Issue issue, final Command command)
static void showDossier(Dossier dossier)
static String get(String msg)
Definition: I_.java:41
ElephantMenu addMenu(String label)
static void showModalZulFile(String label, String source, Command command)
static void showEntityModal(Object id, String attribute, String include, Command command)
static void showEntity(Object id, String attribute, String label, String include)
ElephantSubmenu addSubmenu()
static void showZulFile(String label, String include)
ElephantSubmenu addMenuitem(String label, String include)
static Permission from(String... roles)
Definition: Permission.java:79
static DialogField field(String label)
Dialogs width(String width)
Definition: Dialogs.java:70
Dialogs height(String height)
Definition: Dialogs.java:75
Dialogs onOk(Consumer< Dialogs > onOk)
Definition: Dialogs.java:85
static Dialogs title(String title)
Definition: Dialogs.java:161
Dialogs addField(DialogField field)
Definition: Dialogs.java:110
void addContent(String label, String src)
Definition: Framework.java:69
static Framework getCurrent()
Definition: Framework.java:203