19 package org.turro.web.funnel.model;
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import java.util.Collections;
24 import java.util.List;
25 import org.turro.elephant.db.ElephantPU;
26 import org.turro.elephant.entities.web.WebGoal;
27 import org.turro.elephant.entities.web.WebItem;
28 import org.turro.elephant.util.Messages;
29 import org.turro.elephant.util.Toasts;
30 import org.turro.elephant.web.actions.WebActionType;
31 import org.turro.elephant.entities.web.WebItemType;
32 import org.turro.i18n.I_;
33 import org.turro.jpa.Dao;
34 import org.turro.sql.SqlClause;
35 import org.turro.string.Strings;
36 import org.turro.util.Cached;
37 import org.turro.web.funnel.graph.FunnelGraph;
38 import org.turro.web.funnel.graph.FunnelGraphDOT;
39 import org.turro.zkoss.dialog.DialogField;
40 import org.turro.zkoss.dialog.Dialogs;
41 import org.zkoss.bind.BindUtils;
42 import org.zkoss.bind.annotation.BindingParam;
43 import org.zkoss.bind.annotation.NotifyChange;
44 import org.zkoss.zk.ui.Executions;
45 import org.zkoss.zul.Textbox;
58 this.selected = selected;
61 "selected",
"behaveString",
"showForm",
"nextsModel");
65 if(selected ==
null || behaveAs ==
null)
return "wrong";
66 if(selected.
getType().equals(behaveAs))
return "equal";
68 return behaveAs.toString();
72 Writer writer =
new StringWriter();
74 return writer.toString();
78 return selected !=
null;
87 WebItemTypeListbox wit = new WebItemTypeListbox();
88 wit.setMold(
"select");
89 wit.setObjectValue(WebItemType.TARGET);
93 String webTag = dialogs.<Textbox>getEditor(
"WebTag").getValue();
94 if(notInModel(webTag)) {
102 "model",
"selected",
"showForm");
104 Toasts.
message(
"WebTags should not include spaces or punctuation characters.").
show();
114 @NotifyChange({
"model",
"selected",
"showForm"})
116 model.stream().filter(wi -> wi.isEmpty() && !wi.isNew())
117 .forEach(wi -> dao.get().deleteEntity(wi));
118 model.removeIf(wi -> wi.isEmpty());
119 model.forEach(wi -> wi.compose());
120 dao.get().saveEntities(model);
121 Executions.getCurrent().sendRedirect(
null);
124 @NotifyChange({
"selected",
"nextsModel"})
129 @NotifyChange({
"selected",
"goalsModel"})
139 .help(
"https://www.turro.org/docs/elephant/components/webactions")
141 WebActionTypeListbox wat = new WebActionTypeListbox();
142 wat.setMold(
"select");
143 wat.setObjectValue(WebActionType.NAVIGATE);
150 String value = dialogs.<Textbox>getEditor(
"Value").getValue();
151 String image = dialogs.<Textbox>getEditor(
"Icon").getValue();
152 if(type !=
null && !Strings.isBlank(value)) {
154 (Strings.isBlank(image) ?
"" :
"{" + image +
"}"));
163 public void delete() {
165 dao.get().deleteObject(selected);
166 Executions.getCurrent().sendRedirect(
null);
174 "model",
"selected");
182 "model",
"selected");
186 public void deleteExt(@BindingParam(
"ext") String item) {
196 private boolean notInModel(String webTag) {
197 return !
getModel().stream().anyMatch(wi -> wi.getWebTag().equals(webTag));
200 private List<WebItemType> getPossibleNextTypes() {
201 if(behaveAs ==
null)
return Collections.EMPTY_LIST;
202 return switch(behaveAs) {
203 case TARGET -> List.of(WebItemType.SOLUTION, WebItemType.CHAIN);
204 case SOLUTION -> List.of(WebItemType.SERVICE, WebItemType.CHAIN);
205 case SERVICE -> List.of(WebItemType.CHAIN);
206 default -> Collections.EMPTY_LIST;
212 private WebItem selected;
213 private WebItemType behaveAs;
215 private List<WebItem> model;
219 model = SqlClause.select(
"wi").from(
"WebItem wi")
220 .orderBy(
"type, ordering, webTag")
228 if(selected ==
null)
return Collections.EMPTY_LIST;
229 return SqlClause.select(
"wi").from(
"WebItem wi")
230 .where().in(
"type", getPossibleNextTypes())
231 .and().notEqual(
"webTag", selected.getWebTag())
232 .and().notIn(
"webTag", selected.getNexts().stream().map(wi -> wi.getWebTag()).toList())
238 if(selected ==
null)
return Collections.EMPTY_LIST;
239 return SqlClause.select(
"wg").from(
"WebGoal wg")
240 .where().notIn(
"goalAction", selected.getGoals().stream().map(wi -> wi.getGoalAction()).toList())
247 private final Cached<Dao> dao = Cached.instance(() ->
new ElephantPU());
void setWebTag(String webTag)
Set< WebItem > getNexts()
Set< WebGoal > getGoals()
Set< String > getExternals()
void setType(WebItemType type)
static Messages confirmDeletion()
Messages add(String word)
static Toasts message(String message)
static String get(String msg)
static void DOT(Writer writer)
static WebItemType behaveAs(WebItem item)
List< WebGoal > getGoalsModel()
void deleteNext(@BindingParam("next") WebItem item)
void setSelected(WebItem selected)
void addGoal(@BindingParam("goal") WebGoal goal)
void deleteExt(@BindingParam("ext") String item)
void deleteGoal(@BindingParam("goal") WebGoal goal)
List< WebItem > getModel()
void addNext(@BindingParam("next") WebItem item)
List< WebItem > getNextsModel()
static DialogField field(String label)
Dialogs width(String width)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
static Dialogs title(String title)
Dialogs addField(DialogField field)