Column profile save solved for Invoices
authorVásáry Dániel <vasary@elgekko.net>
Tue, 27 Feb 2024 16:23:15 +0000 (17:23 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Tue, 27 Feb 2024 16:23:15 +0000 (17:23 +0100)
sly-crm-ui/src/main/java/hu/user/lis/ui/view/InvoicesViewModel.java
sly-crm-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java
sly-crm-ui/src/main/java/hu/user/lis/ui/view/renderer/ReorderedItemsRenderer.java
sly-crm-ui/src/main/resources/web/invoices.zul
sly-crm-ui/src/main/resources/web/partners.zul

index 5d0dbdc34ad80005f801a43631954a86ed82cd85..8ffaea5e2a173d005c0a53c9ab711a91fccc1cd9 100644 (file)
@@ -1,6 +1,5 @@
 package hu.user.lis.ui.view;
 
-import com.google.common.collect.ImmutableMap;
 import hu.user.lis.db.*;
 import hu.user.lis.db.repository.filter.DateType;
 import hu.user.lis.db.repository.filter.InvoiceFilter;
@@ -8,6 +7,7 @@ import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.InvoiceDataModel;
 import hu.user.lis.ui.data.InvoicesDataModel;
 import hu.user.lis.ui.data.common.CachedSpringDataModel;
+import hu.user.lis.ui.data.common.ColDef;
 import hu.user.lis.ui.editor.common.Editors;
 import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
 import hu.user.lis.ui.event.EventBus;
@@ -16,16 +16,19 @@ import hu.user.lis.ui.view.common.EntityViewModel;
 import lombok.Getter;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.transaction.annotation.Transactional;
+import org.zkoss.bind.BindContext;
 import org.zkoss.bind.BindUtils;
 import org.zkoss.bind.PropertyChangeEvent;
 import org.zkoss.bind.annotation.*;
 import org.zkoss.zk.ui.Component;
+import org.zkoss.zk.ui.event.DropEvent;
 import org.zkoss.zk.ui.event.Event;
 import org.zkoss.zk.ui.event.EventListener;
 import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zul.Listheader;
+import org.zkoss.zul.event.ColSizeEvent;
 
-import static hu.user.lis.ui.data.common.CachedDataModel.ASCENDING;
-import static hu.user.lis.ui.data.common.CachedDataModel.NATURAL;
+import java.util.Arrays;
 
 @Log4j2
 public class InvoicesViewModel extends EntityViewModel<Invoice> implements EventListener<Event> {
@@ -57,17 +60,19 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
                 .build();
         eventBus.register(this);
         eventBus.registerForBinding(this);
-        addColumns(ImmutableMap.of(
-                "planned", NATURAL,
-                "humanId", NATURAL,
-                "partner.name", NATURAL,
-                "project.humanId", NATURAL,
-                "project.name", NATURAL,
-                "paymentDeadline", ASCENDING,
-                "grossAmount", NATURAL,
-                "currency", NATURAL,
-                "incoming", NATURAL
+
+        addColumns(Arrays.asList(
+                "planned,Terv,ascending,left,true",
+                "humanId,Sorszám,natural,left,true",
+                "partner.name,Partner név,natural,left,true",
+                "project.humanId,Projekt azonosító,natural,left,true",
+                "project.name,Projekt név,natural,left,true",
+                "paymentDeadline,Fizetési határidő,ascending,right,true",
+                "grossAmount,Bruttó összeg,natural,right,true",
+                "currency,Pénznem,natural,left,true",
+                "incoming,Költség/Bevétel,natural,left,true"
         ));
+
         refresh();
     }
 
@@ -174,4 +179,23 @@ public class InvoicesViewModel extends EntityViewModel<Invoice> implements Event
     public void onInvoicePayment() {
         eventBus.showInvoicePayment(getSelectedEntity().getId());
     }
+
+    public void onHeaderMenuClicked(@BindingParam("node") ColDef node) {
+        invoicesDataModel.onHeaderMenuClicked(node);
+    }
+
+    @Command
+    public void onHeaderSizeChanged(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx, @BindingParam("node") ColDef node) {
+        ColSizeEvent evt = (ColSizeEvent) ctx.getTriggerEvent();
+        invoicesDataModel.onHeaderSizeChanged(evt.getColIndex(), evt.getWidth());
+    }
+
+    @Command
+    public void onHeaderReorder(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
+        DropEvent ev = (DropEvent) ctx.getTriggerEvent();
+        Listheader dragged = (Listheader) ev.getDragged();
+        Listheader dropped = (Listheader) ev.getTarget();
+        invoicesDataModel.onHeaderReorder(dragged, dropped);
+    }
+
 }
index 9179d29506a831f90aabdac420a0dc3aa5025422..769025759db51861791a019752049d5310489757 100644 (file)
@@ -108,17 +108,6 @@ public class PartnersViewModel extends FilterActiveViewModel<Partner> {
         Listheader dragged = (Listheader) ev.getDragged();
         Listheader dropped = (Listheader) ev.getTarget();
         partnersDataModel.onHeaderReorder(dragged, dropped);
-//        int from = lHead.getChildren().indexOf(dragged);
-//        int to = lHead.getChildren().indexOf(droppedOn);
-//
-//        // swap the positions
-//        lHead.insertBefore(dragged, droppedOn);
-//
-//        // swap related Listcell in all Listitem instances
-//        for (Listitem item : lbox.getItems()) {
-//            item.insertBefore(item.getChildren().get(from), item.getChildren().get(to));
-//        }
-
     }
 
 
index f90cdc05624377984b6caa5473f632f4671b8e29..57ffb57e4937ee690868b462d683fda0f6cde285 100644 (file)
@@ -30,7 +30,6 @@ public class ReorderedItemsRenderer extends BindListitemRenderer {
 
     @Override
     public void render(Listitem item, final Object data, final int index) throws Exception {
-        log.info("Rendering item index {}, index {}", item.getIndex(), index);
         final Listbox listbox = (Listbox) item.getParent();
         final int size = listbox.getModel().getSize();
         String subtype = item instanceof Listgroup ? "group" : (item instanceof Listgroupfoot ? "groupfoot" : null);
@@ -117,10 +116,6 @@ public class ReorderedItemsRenderer extends BindListitemRenderer {
 
             List<org.zkoss.zk.ui.Component> children = new ArrayList<>(nli.getChildren());
             nli.getChildren().clear();
-//            nli.appendChild(children.get(3));
-//            nli.appendChild(children.get(2));
-//            nli.appendChild(children.get(1));
-//            nli.appendChild(children.get(0));
 
             for (int i = 0; i < columnSettings.length; i++) {
                 int mappedIndex = columnSettings[i].getIndex();
index db81ddb4e925d5ed70cf59ddc0822ac08adaa066..f1820772c52310521fe3d6f1c335946898eec0dd 100644 (file)
                     </toolbar>
                 </vlayout>
             </north>
-            <center border="none" hflex="true" vflex="true">
-                <listbox id="invoicesList" vflex="true" model="@load(vm.invoicesDataModel)"
-                         autopaging="true" mold="paging" pagingPosition="top" multiple="false"
-                         onSelect="@command('onListSelection')">
-                    <listhead sizable="true">
-                        <listheader width="30px" label="Terv" sort="auto(planned)" align="left"
-                                    sortDirection="@load(vm.cols['planned'].sortDirection)"/>
-                        <listheader label="Sorszám" sort="auto(humanId)" align="left"
-                                    sortDirection="@load(vm.cols['humanId'].sortDirection)"/>
-                        <listheader label="Partner név" sort="auto(partner.name)" align="left"
-                                    sortDirection="@load(vm.cols['partner.name'].sortDirection)"/>
-                        <listheader label="Projekt azonosító" sort="auto(project.humanId)" align="left"
-                                    sortDirection="@load(vm.cols['project.humanId'].sortDirection)"/>
-                        <listheader label="Projekt név" sort="auto(project.name)" align="left"
-                                    sortDirection="@load(vm.cols['project.name'].sortDirection)"/>
-                        <listheader label="Fizetési határidő" sort="auto(paymentDeadline)" align="left"
-                                    sortDirection="@load(vm.cols['paymentDeadline'].sortDirection)"/>
-                        <listheader label="Bruttó összeg" sort="auto(grossAmount)" align="right"
-                                    style="text-align: center"
-                                    sortDirection="@load(vm.cols['grossAmount'].sortDirection)"/>
-                        <listheader label="Pénznem" sort="auto(currency)" align="left"
-                                    sortDirection="@load(vm.cols['currency'].sortDirection)"/>
-                        <listheader label="Költség/Bevétel" sort="auto(incoming)" align="left"
-                                    sortDirection="@load(vm.cols['incoming'].sortDirection)"/>
-                    </listhead>
-                    <template name="model">
-                        <listitem onDoubleClick="@command('onEdit')">
-                            <listcell>
-                                <a iconSclass="z-icon-map-marker" visible="@load(each.planned)"
-                                   style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            </listcell>
-                            <listcell label="@load(each.humanId)"
-                                      style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell label="@load(each.partner.name)"
-                                      style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell label="@load(each.project.humanId)"
-                                      style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell label="@load(each.project.name)"
-                                      style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell
-                                    label="@load(each.paymentDeadline) @converter('hu.user.lis.ui.converter.DateToStringConverter')"
-                                    style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell
-                                    label="@load(each.grossAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"
-                                    style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell label="@load(each.currency)"
-                                      style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            <listcell>
-                                <a iconSclass="z-icon-external-link" visible="@load(each.incoming)"
-                                   style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                                <a iconSclass="z-icon-sign-in" visible="@load(!each.incoming)"
-                                   style="@load(each.planned ? 'color: gray' : 'color: black')"/>
-                            </listcell>
-                        </listitem>
-                    </template>
-                </listbox>
+            <center border="none">
+                <vlayout vflex="true" hflex="true">
+                    <menupopup id="editPopup"
+                               children="@bind(vm.invoicesDataModel.renderer.columnSettings) @template('menu-item')">
+                        <template name="menu-item" var="node">
+                            <menuitem label="@load(node.label)" checked="@load(node.visible)"
+                                      onClick="@command('onHeaderMenuClicked', node=node)"/>
+                        </template>
+                    </menupopup>
+                    <listbox id="invoicesList" vflex="true" model="@load(vm.invoicesDataModel)" multiple="false"
+                             itemRenderer="@load(vm.invoicesDataModel.renderer)" onSelect="@command('onListSelection')">
+                        <listhead sizable="true" menupopup="editPopup"
+                                  onColSize="@command('onHeaderSizeChanged', node=node)"
+                                  children="@bind(vm.invoicesDataModel.renderer.columnSettings) @template('head-item')">
+                            <template name="head-item" var="node">
+                                <listheader label="@load(node.label)" sort="@load(node.sort)" align="@load(node.align)"
+                                            visible="@load(node.visible)" width="@load(node.width)" draggable="head"
+                                            droppable="head" sortDirection="@load(node.sortDirection)"
+                                            onDrop="@command('onHeaderReorder')"/>
+                            </template>
+                        </listhead>
+                        <template name="model">
+                            <listitem onDoubleClick="@command('onEdit')">
+                                <listcell>
+                                    <a iconSclass="z-icon-map-marker" visible="@load(each.planned)"
+                                       style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                </listcell>
+                                <listcell label="@load(each.humanId)"
+                                          style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell label="@load(each.partner.name)"
+                                          style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell label="@load(each.project.humanId)"
+                                          style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell label="@load(each.project.name)"
+                                          style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell
+                                        label="@load(each.paymentDeadline) @converter('hu.user.lis.ui.converter.DateToStringConverter')"
+                                        style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell
+                                        label="@load(each.grossAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"
+                                        style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell label="@load(each.currency)"
+                                          style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                <listcell>
+                                    <a iconSclass="z-icon-external-link" visible="@load(each.incoming)"
+                                       style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                    <a iconSclass="z-icon-sign-in" visible="@load(!each.incoming)"
+                                       style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+                                </listcell>
+                            </listitem>
+                        </template>
+                    </listbox>
+                </vlayout>
             </center>
         </borderlayout>
     </window>
index 30ee8843aa1fad7d7f2547466c619302b5587ec9..cc797bc843f4d48f634a20bd9ee4f5725870d033 100644 (file)
@@ -19,8 +19,8 @@
                 </toolbar>
 
             </north>
-            <center border="none" flex="true">
-                <vlayout>
+            <center border="none">
+                <vlayout vflex="true" hflex="true">
                     <menupopup id="editPopup"
                                children="@bind(vm.partnersDataModel.renderer.columnSettings) @template('menu-item')">
                         <template name="menu-item" var="node">
                                       onClick="@command('onHeaderMenuClicked', node=node)"/>
                         </template>
                     </menupopup>
-                    <listbox vflex="true" model="@load(vm.partnersDataModel)"
-                             itemRenderer="@load(vm.partnersDataModel.renderer)"
-                             autopaging="true" multiple="false"
-                             onSelect="@command('onListSelection')">
+                    <listbox vflex="true" model="@load(vm.partnersDataModel)" multiple="false"
+                             itemRenderer="@load(vm.partnersDataModel.renderer)" onSelect="@command('onListSelection')">
                         <listhead sizable="true" menupopup="editPopup"
                                   onColSize="@command('onHeaderSizeChanged', node=node)"
                                   children="@bind(vm.partnersDataModel.renderer.columnSettings) @template('head-item')">