From 820ec3a0424d90d98790c0a48a8a6496f349179b Mon Sep 17 00:00:00 2001 From: Franta Pribyl Date: Tue, 16 Sep 2014 15:36:43 +0200 Subject: [PATCH] =?UTF-8?q?Skupiny=20materi=C3=A1lu=20a=20slu=C5=BEeb=20lz?= =?UTF-8?q?e=20nyn=C3=AD=20zad=C3=A1vat=20pomoc=C3=AD=20k=C3=B3du.=20Polo?= =?UTF-8?q?=C5=BEku=20lze=20p=C5=99idat=20bez=20v=C3=BDb=C4=9Bru=20materi?= =?UTF-8?q?=C3=A1lu=20a=20slu=C5=BEeb.=20Upraveny=20styly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #138 --- .../isspst/data/RequirementSubject.java | 16 ++++ .../requirement/RequirementService.java | 2 +- .../requirement/RequirementServiceImpl.java | 53 +++++++++++++ .../main/orders/material/ReqMaterialForm.java | 19 ++++- .../orders/requirements/RequirementForm.java | 78 +++++++++++++++---- .../main/orders/services/ReqServicesForm.java | 18 ++++- .../WEB-INF/locales/zk-label.properties | 1 + src/main/webapp/app/index.zul | 2 +- src/main/webapp/app/info.zul | 9 ++- .../main/orders/material/reqHeadForm.zul | 6 +- .../main/orders/material/selectMaterial.zul | 4 +- .../main/orders/requirements/reqForm.zul | 29 +++++-- .../main/orders/services/reqHeadForm.zul | 6 +- 13 files changed, 209 insertions(+), 34 deletions(-) diff --git a/src/main/java/info/bukova/isspst/data/RequirementSubject.java b/src/main/java/info/bukova/isspst/data/RequirementSubject.java index cd4d6268..08f81012 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementSubject.java +++ b/src/main/java/info/bukova/isspst/data/RequirementSubject.java @@ -131,4 +131,20 @@ public abstract class RequirementSubject implements OwnedDataModel { this.valid = valid; } + @Override + public boolean equals(Object obj) + { + if (obj != null) + { + if (obj instanceof RequirementSubject) + { + RequirementSubject item = (RequirementSubject) obj; + + return (this.getId() == item.getId()); + } + } + + return false; + } + } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java index e743d507..1b841c8d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java @@ -4,5 +4,5 @@ import info.bukova.isspst.data.Requirement; public interface RequirementService extends RequirementBaseService { - + public void loadGroups(Requirement req); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index a34559ab..dcc9ba11 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -2,14 +2,18 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.Constants; import info.bukova.isspst.data.Requirement; +import info.bukova.isspst.data.RequirementItem; import info.bukova.isspst.data.RequirementState; +import info.bukova.isspst.data.RequirementSubject; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workflow; +import info.bukova.isspst.services.LazyLoader; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; public class RequirementServiceImpl extends RequirementBaseServiceImpl implements RequirementService, @@ -46,4 +50,53 @@ public class RequirementServiceImpl extends return false; } + /* + * Lazy load pro načtení seznamu skupin materiálu nebo služeb do comba. + * Ošetřuje se zde případné neexistující vazby na ID smazaných skupin + * materiálu nebo služeb. + * + * @see + * info.bukova.isspst.services.requirement.RequirementService#loadGroups + * (info.bukova.isspst.data.Requirement) + */ + @Transactional + @LazyLoader("form") + @Override + public void loadGroups(Requirement req) + { + if (req == null) + { + return; + } + + Requirement reqDb = this.getById(req.getId()); + + // Načíst položky požadavku + List items = reqDb.getItems(); + + for (int i = 0; i < items.size(); i++) + { + RequirementItem item = items.get(i); + + try + { + // K položce získat skupinu materiálnu nebo služby + RequirementSubject subject = item.getReqSubject(); + // Pokud ID skupiny nebylo nalezeno, padá do výjimky + // Pokud ID skupiny bylo nalezeno, přinutí zavolání metody + // načíst záznam se skupinou = lazy load + subject.getCode(); + // Zapsat načtená data o skupině + item.setReqSubject(subject); + } + catch (Throwable e) + { + item.setReqSubject(null); + } + } + + // Zaktualizovat položky záznamu tak, aby byly odkazy na skupiny + // materiálů a služeb konzistentní + req.setItems(items); + } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java index b6c0fcf1..37819778 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java @@ -1,21 +1,34 @@ package info.bukova.isspst.ui.main.orders.material; +import info.bukova.isspst.data.RequirementSubject; +import info.bukova.isspst.services.reqsubjects.MaterialService; import info.bukova.isspst.ui.main.orders.requirements.RequirementForm; +import info.bukova.isspst.ui.main.orders.services.ReqServicesForm; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; public class ReqMaterialForm extends RequirementForm { - // private final static Logger log = - // LoggerFactory.getLogger(ReqServicesForm.class.getName()); + @SuppressWarnings("unused") + private final static Logger log = LoggerFactory.getLogger(ReqServicesForm.class.getName()); + + @WireVariable + private MaterialService materialService; + @SuppressWarnings("unchecked") @Init(superclass = true) public void init() { - super.init(); + // Získat seznam všech skupin materiálu pro výběr z comba + this.setRequirementGroups((List) (List) materialService.getAll()); } @Command diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index f809d82f..8b276556 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -38,13 +38,28 @@ public class RequirementForm extends FormViewModel @WireVariable private WorkgroupService workgroupService; - + @WireVariable private RequirementTypeService reqTypeService; - + @WireVariable private RequirementService requirementService; + /** + * Seznam obsahující kód a název skupiny materálu/služby + */ + private List requirementGroups; + + public List getRequirementGroups() + { + return requirementGroups; + } + + public void setRequirementGroups(List requirementGroups) + { + this.requirementGroups = requirementGroups; + } + private RequirementItem selectedItem; private int selItemIndex; @@ -54,7 +69,7 @@ public class RequirementForm extends FormViewModel private RequirementFormValidator requirementFormValidator; private List syncItems; - + private List centres; public List getCentres() @@ -101,16 +116,16 @@ public class RequirementForm extends FormViewModel { this.requirementFormValidator = requirementFormValidator; } - + @Init(superclass = true) - public void init() + public void initRequirementForm() { this.setSelItemIndex(-1); this.setBigDecimalConverter(new BigDecimalConverter()); this.setRequirementFormValidator(new RequirementFormValidator()); this.setSyncItems(this.getDataBean().getItems()); requirementService.loadType(getDataBean()); - this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); } public List getSyncItems() @@ -123,14 +138,6 @@ public class RequirementForm extends FormViewModel this.syncItems = syncItems; } - @Command - public void addSelectedItem() - { - // Window window = (Window) - // Executions.createComponents("/main/selectItems.zul", null, null); - // window.doModal(); - } - @Command public void onFocusItem(@BindingParam("item") RequirementItem item, @BindingParam("ctrl") InputElement ctrl) { @@ -230,4 +237,47 @@ public class RequirementForm extends FormViewModel BindUtils.postNotifyChange(null, null, form, "*"); } } + + @Command + @NotifyChange({ "selectedItem", "syncItems" }) + public void onChangeGroup() + { + // Někdo změnil skupinu materiálu nebo služby + if (this.selectedItem == null) + { + log.warn("Zavolat z formuláře onFocus pro nastavení vybrané položky!"); + return; + } + + // Zjistit, zda je propojená skupina materiálu nebo služeb + RequirementSubject subject = this.selectedItem.getReqSubject(); + + if (subject != null) + { + // Skupina materiálu nebo služeb je propojená, nastavit k zadanému + // kódu i správný název skupiny materiálu nebo služby + this.selectedItem.setName(subject.getName()); + } + } + + @Command + @NotifyChange({ "selectedItem", "syncItems" }) + public void addNewItem() + { + RequirementItem item = new RequirementItem(); + + item.setReqSubject(null); + + item.setCode(""); + item.setName(""); + item.setQuantity(BigDecimal.valueOf(1)); + item.setUnitPrice(BigDecimal.valueOf(0)); + item.setTotal(BigDecimal.valueOf(0)); + item.setDescription(""); + item.setMunit(null); + + this.setSelectedItem(item); + this.getDataBean().getItems().add(item); + this.setSelItemIndex(this.getDataBean().getItems().indexOf(item)); + } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java index bd017a4d..e9922c35 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java @@ -1,21 +1,33 @@ package info.bukova.isspst.ui.main.orders.services; +import info.bukova.isspst.data.RequirementSubject; +import info.bukova.isspst.services.reqsubjects.ServiceItemService; import info.bukova.isspst.ui.main.orders.requirements.RequirementForm; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; public class ReqServicesForm extends RequirementForm { - // private final static Logger log = - // LoggerFactory.getLogger(ReqServicesForm.class.getName()); + @SuppressWarnings("unused") + private final static Logger log = LoggerFactory.getLogger(ReqServicesForm.class.getName()); + + @WireVariable + private ServiceItemService serviceItemService; + @SuppressWarnings("unchecked") @Init(superclass = true) public void init() { - super.init(); + // Získat seznam všech skupin služeb pro výběr z comba + this.setRequirementGroups((List) (List) serviceItemService.getAll()); } @Command diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 9e9ead4f..30deb6fa 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -287,6 +287,7 @@ LoginViaGoogle=Přihlásit účtem Google DateFormat=dd. MM. yyyy AddItem=Přidat položku +SelectGroup=Vybrat skupinu... RemoveItem=Smazat Amount=Částka diff --git a/src/main/webapp/app/index.zul b/src/main/webapp/app/index.zul index 22368533..0574bdf3 100644 --- a/src/main/webapp/app/index.zul +++ b/src/main/webapp/app/index.zul @@ -1,4 +1,4 @@ - + diff --git a/src/main/webapp/app/info.zul b/src/main/webapp/app/info.zul index b1a6f57b..ac5216c7 100644 --- a/src/main/webapp/app/info.zul +++ b/src/main/webapp/app/info.zul @@ -1,4 +1,4 @@ - + - - + + - + \ No newline at end of file diff --git a/src/main/webapp/main/orders/material/selectMaterial.zul b/src/main/webapp/main/orders/material/selectMaterial.zul index 53ed73db..2059b768 100644 --- a/src/main/webapp/main/orders/material/selectMaterial.zul +++ b/src/main/webapp/main/orders/material/selectMaterial.zul @@ -5,13 +5,14 @@ closable="true" border="normal" position="center" + vflex="1" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('info.bukova.isspst.ui.main.orders.material.SelectMaterialItems')"> - + diff --git a/src/main/webapp/main/orders/requirements/reqForm.zul b/src/main/webapp/main/orders/requirements/reqForm.zul index 459555ac..3b871242 100644 --- a/src/main/webapp/main/orders/requirements/reqForm.zul +++ b/src/main/webapp/main/orders/requirements/reqForm.zul @@ -1,6 +1,7 @@ + hflex="1" + vflex="1"> +