19 package org.turro.alliance.client.model;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.alliance.db.AlliancePU;
24 import org.turro.alliance.service.AxConstants;
25 import org.turro.alliance.service.AxServer;
26 import org.turro.elephant.util.Toasts;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.Dao;
29 import org.turro.json.Jsons;
30 import org.turro.member.db.entities.AxChallengeCategory;
31 import org.turro.sql.SqlClause;
32 import org.turro.students.entities.Challenge;
33 import org.turro.ws.WsServer;
34 import org.turro.ws.service.member.Servers;
35 import org.zkoss.bind.annotation.BindingParam;
36 import org.zkoss.bind.annotation.Command;
37 import org.zkoss.bind.annotation.ExecutionArgParam;
38 import org.zkoss.bind.annotation.Init;
39 import org.zkoss.bind.annotation.NotifyChange;
40 import org.zkoss.zk.ui.Executions;
52 if(challenge !=
null) this.challenge = challenge;
53 if(this.challenge ==
null) {
54 this.challenge = (
Challenge) Executions.getCurrent().getAttribute(
"challenge");
63 this.needsSave = needsSave;
66 @NotifyChange(
"model")
69 if(server !=
null && !inModel(server)) {
80 @NotifyChange(
"model")
84 model.stream().filter(pc -> pc.isEmpty())
86 model.removeIf(pc -> pc.isEmpty());
93 @NotifyChange(
"model")
96 deletions.add(category);
97 model.removeIf(pc -> pc.getServerDomain().equals(category.getServerDomain()));
103 private boolean needsSave;
105 private List<AxChallengeCategory> model;
106 private List<AxChallengeCategory> deletions =
new ArrayList<>();
110 model = SqlClause.select(
"pc").from(
"AxChallengeCategory pc")
111 .where().equal(
"pc.challengeId", String.valueOf(challenge.
getId()))
118 private boolean inModel(
WsServer server) {
119 return model.stream().anyMatch(apc -> apc.getServerDomain().equals(server.
getServerDomain()));
131 this.server = server;
List< AxChallengeCategory > getModel()
void init(@ExecutionArgParam("challenge") Challenge challenge)
void delete(@BindingParam("category") AxChallengeCategory category)
void setServer(WsServer server)
Jsons getCategories(AxChallengeCategory pc)
void setNeedsSave(boolean needsSave)
static final String SERVER_SERVICE
static Toasts message(String message)
static String get(String msg)
void deleteEntity(IDaoEntity entity)
void deleteCollection(Collection objs)
void saveEntities(Collection<? extends IDaoEntity > entities)
void setServerDomain(String serverDomain)
void setChallenge(Challenge challenge)
static WsServer from(String serverDomain, String service)