Sfoglia il codice sorgente

Auto-generate DF layout button

Kenric Nugteren 2 anni fa
parent
commit
b5ce4e4c8b
1 ha cambiato i file con 60 aggiunte e 8 eliminazioni
  1. 60 8
      prs.desktop/Grids/QAFormLayoutGrid.cs

+ 60 - 8
prs.desktop/Grids/QAFormLayoutGrid.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 using Comal.Classes;
 using InABox.Core;
@@ -19,25 +20,68 @@ namespace PRSDesktop.Configuration
             ActionColumns.Add(new DynamicActionColumn(DesignImage, DesignClick));
             //AddButton("Design", PRSDesktop.Resources.design.AsBitmapImage(), DesignClick);
             HiddenColumns.Add(x => x.Layout);
+
+            AddButton("Auto Generate", null, AutoGenerate_Click);
+        }
+
+        private bool AutoGenerate_Click(Button btn, CoreRow[] rows)
+        {
+            var menu = new ContextMenu();
+
+            menu.AddItem("Desktop Layout", null, AddDesktop_Click);
+            menu.AddItem("Mobile Layout", null, AddMobile_Click);
+
+            menu.IsOpen = true;
+
+            return false;
         }
 
-        private BitmapImage DesignImage(CoreRow row)
+        private BitmapImage? DesignImage(CoreRow? row)
         {
             return row != null ? design : null;
         }
 
-        private bool DesignClick(CoreRow row)
+        private void AddMobile_Click()
         {
-            if (row == null)
-                return false;
+            var item = CreateItem();
+
+            item.Layout = DFLayout.GenerateAutoMobileLayout(GetVariables()).SaveLayout();
+            item.Type = DFLayoutType.Mobile;
+
+            if (EditItems(new[] { item }))
+            {
+                SaveItem(item);
+                Refresh(false, true);
+                OnChanged?.Invoke(this);
+            }
+        }
 
-            var layout = LoadItem(row);
+        private void AddDesktop_Click()
+        {
+            var item = CreateItem();
 
+            item.Layout = DFLayout.GenerateAutoDesktopLayout(GetVariables()).SaveLayout();
+            item.Type = DFLayoutType.Desktop;
+
+            if (EditItems(new[] { item }))
+            {
+                SaveItem(item);
+                Refresh(false, true);
+                OnChanged?.Invoke(this);
+            }
+        }
+
+        private List<DigitalFormVariable> GetVariables()
+        {
             var vPage =
-                EditorGrid.Pages.FirstOrDefault(x => x is DynamicOneToManyGrid<DigitalForm, DigitalFormVariable>) as
+                EditorGrid.Pages?.FirstOrDefault(x => x is DynamicOneToManyGrid<DigitalForm, DigitalFormVariable>) as
                     DynamicOneToManyGrid<DigitalForm, DigitalFormVariable>;
-            var variables = vPage != null ? vPage.Items.ToArray() : Array.Empty<DigitalFormVariable>();
-            var vprops = new Dictionary<string, string>();
+            return vPage?.Items ?? new List<DigitalFormVariable>();
+        }
+
+        private void Design(DigitalFormLayout layout)
+        {
+            var variables = GetVariables();
 
             var form = new DynamicFormDesignWindow
             {
@@ -51,6 +95,14 @@ namespace PRSDesktop.Configuration
                 layout.Layout = form.SaveLayout();
                 SaveItem(layout);
             }
+        }
+
+        private bool DesignClick(CoreRow? row)
+        {
+            if (row == null)
+                return false;
+
+            Design(LoadItem(row));
 
             return false;
         }