BrightSide Workbench Full Report + Source Code
IssueGraphVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.graph;
20 
21 import java.util.Set;
22 import java.util.stream.Collectors;
23 import org.turro.command.Context;
24 import org.turro.dossier.entity.Dossier;
25 import org.turro.dossier.zul.menu.DossierMenu;
26 import org.turro.elephant.context.Application;
27 import org.turro.util.Cached;
28 import org.zkoss.bind.BindUtils;
29 import org.zkoss.bind.annotation.BindingParam;
30 import org.zkoss.bind.annotation.Command;
31 import org.zkoss.bind.annotation.ExecutionArgParam;
32 import org.zkoss.bind.annotation.Init;
33 import org.zkoss.bind.annotation.NotifyChange;
34 
39 public class IssueGraphVM {
40 
41  private final boolean show, all, addNew;
42  private Dossier dossier;
43  private IssueVertex selected;
44  private boolean onlyOpen = false, onlyMilestones = true;
45 
46  public IssueGraphVM() {
48  show = app.isInRole("issue:show");
49  all = app.isInRole("issue:all");
50  addNew = app.isInRole("issue:new");
51  }
52 
53  @Init
54  public void init(@ExecutionArgParam("dossier") Dossier dossier) {
55  selectDossier(dossier);
56  }
57 
58  @NotifyChange("leafs")
59  @Command("update")
60  public void update() {}
61 
62  @NotifyChange("leafs")
63  @Command
64  public void selectDossier(@BindingParam("dossier") Dossier dossier) {
65  this.dossier = dossier;
66  graph.reset();
67  }
68 
69  @NotifyChange("leafs")
70  @Command
71  public void setOnlyMilestones(@BindingParam("onlyMilestones") Boolean onlyMilestones) {
72  this.onlyMilestones = onlyMilestones;
73  graph.reset();
74  }
75 
76  @NotifyChange("leafs")
77  @Command
78  public void setOnlyOpen(@BindingParam("onlyOpen") Boolean onlyOpen) {
79  this.onlyOpen = onlyOpen;
80  }
81 
82  @Command
83  public void addIssue() {
84  if(all || addNew) {
85  DossierMenu.addDossierInformation(dossier, (Context context) -> {
86  BindUtils.postNotifyChange(null, null, IssueGraphVM.this, "leafs");
87  return null;
88  });
89  }
90  }
91 
92  public boolean isOnlyOpen() {
93  return onlyOpen;
94  }
95 
96  public boolean isOnlyMilestones() {
97  return onlyMilestones;
98  }
99 
100  public Dossier getDossier() {
101  return dossier;
102  }
103 
104  public Set<IssueVertex> getLeafs() {
105  return graph.get().vertexSet().stream()
106  .filter(m -> m.isLeaf() && (!onlyOpen || !m.isAchieved()))
107  .collect(Collectors.toSet());
108  }
109 
111  return selected;
112  }
113 
114  private final Cached<IssueGraph> graph = Cached.instance(() -> {
115  return dossier == null ? IssueGraph.all() :
116  (onlyMilestones ? IssueGraph.milestones(dossier) : IssueGraph.load(dossier));
117  });
118 
119 }
void selectDossier(@BindingParam("dossier") Dossier dossier)
void setOnlyOpen(@BindingParam("onlyOpen") Boolean onlyOpen)
void init(@ExecutionArgParam("dossier") Dossier dossier)
void setOnlyMilestones(@BindingParam("onlyMilestones") Boolean onlyMilestones)
static IssueGraph milestones(Dossier dossier)
static IssueGraph load(Dossier dossier)
static void addDossierInformation(Dossier dossier, Command command)