Selaa lähdekoodia

PRS Mobile - Digital forms refactor to open from Tasks screen, moved jobs cache loading to a cache loader class

Nick-PRSDigital@bitbucket.org 2 vuotta sitten
vanhempi
commit
062c12cc43

+ 102 - 0
prs.mobile/comal.timesheets/CacheLoader.cs

@@ -0,0 +1,102 @@
+using comal.timesheets.CustomControls;
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using iText.Layout.Element;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using Xamarin.Forms;
+
+namespace comal.timesheets
+{
+    public static class CacheLoader
+    {
+        #region Jobs
+        public static async Task LoadJobs()
+        {
+            await Task.Run(() =>
+            {
+                try
+                {
+                    List<JobShell> jobShells = new List<JobShell>();
+
+                    Filter<Job> filter = AssignFilter();
+
+                    CoreTable table = DoJobsQuery(filter);
+
+                    foreach (CoreRow row in table.Rows)
+                        jobShells.Add(CreateJobShell(row));
+
+                    AssignJobShells(jobShells);
+                }
+                catch
+                { }
+            });
+        }
+
+        private static void AssignJobShells(List<JobShell> jobShells)
+        {
+            GlobalVariables.JobShells = jobShells;
+            GlobalVariables.JobShells.Insert(0, new JobShell { ID = Guid.Empty, JobNumber = "No Job", Name = "Empty Job", JobStatusDescription = "Hidden" });
+            GlobalVariables.JobsLoaded = true;
+        }
+
+        private static Filter<Job> AssignFilter()
+        {
+            Filter<Job> filter = new Filter<Job>(x => x.JobStatus.Active).IsEqualTo(true);
+
+            if (!Security.IsAllowed<CanViewAllJobs>())
+            {
+                List<Guid> jobIDs = new List<Guid>();
+                CoreTable jobEmployees = new Client<JobEmployee>().Query(
+                    new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID),
+                    new Columns<JobEmployee>(x => x.JobLink.ID)
+                    );
+                foreach (CoreRow row in jobEmployees.Rows)
+                {
+                    jobIDs.Add(row.Get<JobEmployee, Guid>(x => x.JobLink.ID));
+                }
+                filter = filter.And(x => x.ID).InList(jobIDs.ToArray());
+            }
+
+            return filter;
+        }
+
+        private static CoreTable DoJobsQuery(Filter<Job> filter)
+        {
+            return new Client<Job>().Query(
+                            filter,
+                            new Columns<Job>(x => x.ID, x => x.Name, x => x.JobNumber, x => x.JobStatus.Description, x => x.Color),
+                            new SortOrder<Job>(x => x.JobNumber)
+                            );
+        }
+
+        private static JobShell CreateJobShell(CoreRow row)
+        {
+            Job job = row.ToObject<Job>();
+            if (job.Color == null)
+                job.Color = "";
+            JobShell jobshell = new JobShell
+            {
+                ID = job.ID,
+                Name = job.Name,
+                JobNumber = job.JobNumber,
+                JobStatusDescription = job.JobStatus.Description,
+                Color = Color.FromHex(job.Color)
+            };
+            if (jobshell.JobStatusDescription.Equals("Active Projects"))
+                jobshell.JobStatusDescription = "Active";
+            else if (jobshell.JobStatusDescription.Equals("Projects - Hidden from View"))
+                jobshell.JobStatusDescription = "Hidden";
+            else if (jobshell.JobStatusDescription.Equals("Projects in Defect Liability Period"))
+                jobshell.JobStatusDescription = "Defect Liability";
+
+            jobshell.DisplayName = "(" + jobshell.JobNumber + ") " + jobshell.Name;
+
+            return jobshell;
+        }
+        #endregion
+    }
+}

+ 1 - 1
prs.mobile/comal.timesheets/DigitalForms/DigitalFormHost.xaml.cs

@@ -55,7 +55,7 @@ namespace comal.timesheets
             };
 
             saveBtn.IsEnabled = !Model.ReadOnly;
-            //saveProgressBtn.IsEnabled = !model.ReadOnly;
+            saveProgressBtn.IsEnabled = !Model.ReadOnly;
 
             viewer = new QAFormViewer(Model.DigitalFormDataModel, Model.DFLayout, Model.NewForm, Model.ReadOnly, jobid);
 

+ 4 - 4
prs.mobile/comal.timesheets/DigitalForms/DigitalFormPickerScreen/DigitalFormsPicker.xaml.cs

@@ -64,7 +64,7 @@ namespace comal.timesheets
                 _searching = false;
                 if (RetainedResults.IsFormRetained)
                 {
-                    DigitalFormHost host = new DigitalFormHost(LoadModel(RetainedResults.LastDigitalFormLayout, CheckType()), JobID);
+                    DigitalFormHost host = new DigitalFormHost(DigitalFormsHelper.LoadModel(RetainedResults.LastDigitalFormLayout, CheckType(), addToTaskKanban, JobID, null, addingToTask), JobID);
                     Navigation.PushAsync(host);
                 }
                 LoadExistingForms();
@@ -361,7 +361,7 @@ namespace comal.timesheets
                 else
                     JobID = Guid.Empty;
 
-                DigitalFormHost host = new DigitalFormHost(LoadModel(layout, form.Type, form), JobID);
+                DigitalFormHost host = new DigitalFormHost(DigitalFormsHelper.LoadModel(layout, form.Type, addToTaskKanban, JobID, form, addingToTask), JobID);
                 Navigation.PushAsync(host);
             }
         }
@@ -380,7 +380,7 @@ namespace comal.timesheets
                 else
                     JobID = Guid.Empty;
 
-                DigitalFormHost host = new DigitalFormHost(LoadModel(layout, form.Type, form), JobID);
+                DigitalFormHost host = new DigitalFormHost(DigitalFormsHelper.LoadModel(layout, form.Type, addToTaskKanban, JobID, form, addingToTask), JobID);
                 Navigation.PushAsync(host);
             }
         }
@@ -444,7 +444,7 @@ namespace comal.timesheets
 
                     RetainedResults.LastDigitalFormLayout = digitalFormLayout;
                 }
-                DigitalFormHost host = new DigitalFormHost(LoadModel(digitalFormLayout, CheckType()), JobID);
+                DigitalFormHost host = new DigitalFormHost(DigitalFormsHelper.LoadModel(digitalFormLayout, CheckType(), addToTaskKanban, JobID, null, addingToTask), JobID);
                 Navigation.PushAsync(host);
             }
             catch { }

+ 60 - 0
prs.mobile/comal.timesheets/DigitalFormsHelper.cs

@@ -0,0 +1,60 @@
+using Comal.Classes;
+using comal.timesheets.QAForms;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace comal.timesheets
+{
+    public static class DigitalFormsHelper
+    {
+        public static IDigitalFormHostModel LoadModel(DigitalFormLayout layout, Type type, Kanban addToTaskKanban, Guid JobID = new Guid(), ExistingFormShell form = null, bool addingToTask = false)
+        {
+            if (type == typeof(JobForm))
+            {
+                var model = new DigitalFormHostModel<Job, JobLink, JobForm>();
+                var job = new Job();
+
+                var jobForm = new JobForm();
+                jobForm.Form.ID = layout.Form.ID;
+
+                if (form == null)
+                {
+                    job.ID = JobID;
+                }
+                else
+                {
+                    jobForm.ID = form.ID;
+                    job.ID = form.ParentID;
+                }
+
+                model.LoadItems(job, jobForm, layout);
+                return model;
+            }
+            else
+            {
+                var model = new DigitalFormHostModel<Kanban, KanbanLink, KanbanForm>();
+                var kanban = new Kanban();
+
+                var kanbanForm = new KanbanForm();
+
+                kanbanForm.Form.ID = layout.Form.ID;
+                if (form != null)
+                {
+                    kanbanForm.ID = form.ID;
+                    kanban.ID = form.ParentID;
+                }
+
+                if (addingToTask)
+                {
+                    kanbanForm.Parent.ID = addToTaskKanban.ID;
+                    kanban.ID = addToTaskKanban.ID;
+                }
+
+                model.LoadItems(kanban, kanbanForm, layout);
+                return model;
+            }
+        }
+    }
+}

+ 8 - 55
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -1,11 +1,9 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using Xamarin.Forms;
-using Xamarin.Forms.Maps;
 using InABox.Core;
 using InABox.Configuration;
 using InABox.Clients;
@@ -77,6 +75,7 @@ namespace comal.timesheets
                 deviceName = MobileUtils.GetDeviceID();
 
                 LoadCacheLists();
+
                 InitToolEntryList();
 
                 Timer t = new Timer(RecentlyAskedToUpdateTimer, null, 600000, 600000); //user is reminded to update when opening screen after timer of 10 minutes
@@ -88,8 +87,8 @@ namespace comal.timesheets
                 InitNotificationCentre();
                 firstLoad = false;
                 //if (GlobalVariables.EmpID == Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac"))
-                //    RunCustomScript();
-                NotifyChanges();              
+                //RunCustomScript();
+                NotifyChanges();
             }
             catch (Exception e)
             {
@@ -98,12 +97,12 @@ namespace comal.timesheets
             NavigationPage.SetHasBackButton(this, false);
         }
 
-        
+
 
         private void RunCustomScript()
         {
-
-        }
+            
+        }      
 
         private void NotifyChanges()
         {
@@ -1306,12 +1305,12 @@ namespace comal.timesheets
         }
 
         #region Background Loading
-        private void LoadCacheLists()
+        private async Task LoadCacheLists()
         {
             GlobalVariables.ProductsLoaded = false;
             GlobalVariables.JobsLoaded = false;
             GlobalVariables.GetXamarinWidth();
-            LoadJobShells();
+            await CacheLoader.LoadJobs();
             LoadEmployeeShells();
             LoadProducts();
             LoadCompanyDevices();
@@ -1418,52 +1417,6 @@ namespace comal.timesheets
 
         }
 
-        async void LoadJobShells()
-        {
-            try
-            {
-                await Task.Run(() =>
-                {
-                    List<JobShell> jobShells = new List<JobShell>();
-                    CoreTable table = new Client<Job>().Query(
-                        new Filter<Job>(x => x.JobStatus.Active).IsEqualTo(true),
-                        new Columns<Job>(x => x.ID, x => x.Name, x => x.JobNumber, x => x.JobStatus.Description, x => x.Color),
-                        new SortOrder<Job>(x => x.JobNumber)
-                        );
-                    foreach (CoreRow row in table.Rows)
-                    {
-                        List<object> list = row.Values;
-                        if (list[0] == null) { list[0] = Guid.Empty; } //0
-                        if (list[1] == null) { list[1] = ""; } //1
-                        if (list[2] == null) { list[2] = ""; } //2
-                        if (list[3] == null) { list[3] = ""; } //3
-                        if (list[4] == null) { list[4] = ""; } //4
-                        JobShell jobshell = new JobShell
-                        {
-                            ID = Guid.Parse(list[0].ToString()),
-                            Name = list[1].ToString(),
-                            JobNumber = list[2].ToString(),
-                            JobStatusDescription = list[3].ToString(),
-                            Color = Color.FromHex(list[4].ToString())
-                        };
-                        if (jobshell.JobStatusDescription.Equals("Active Projects"))
-                            jobshell.JobStatusDescription = "Active";
-                        else if (jobshell.JobStatusDescription.Equals("Projects - Hidden from View"))
-                            jobshell.JobStatusDescription = "Hidden";
-                        else if (jobshell.JobStatusDescription.Equals("Projects in Defect Liability Period"))
-                            jobshell.JobStatusDescription = "Defect Liability";
-
-                        jobshell.DisplayName = "(" + jobshell.JobNumber + ") " + jobshell.Name;
-                        jobShells.Add(jobshell);
-                    }
-                    GlobalVariables.JobShells = jobShells;
-                    GlobalVariables.JobShells.Insert(0, new JobShell { ID = Guid.Empty, JobNumber = "No Job", Name = "Empty Job", JobStatusDescription = "Hidden" });
-                    GlobalVariables.JobsLoaded = true;
-                });
-            }
-            catch { }
-        }
-
         private async void LoadHRToDos()
         {
             try

+ 12 - 10
prs.mobile/comal.timesheets/Tasks/AddEditTask.xaml.cs

@@ -799,16 +799,18 @@ namespace comal.timesheets.Tasks
                             );
                         CoreRow row = table.Rows.FirstOrDefault();
                         DigitalFormLayout layout = row.ToObject<DigitalFormLayout>();
-                        //if (form.FormCompleted == DateTime.MinValue)
-                        //{
-                        //    QAFormHost digitalFormHost = new QAFormHost(layout, form, false);
-                        //    Navigation.PushAsync(digitalFormHost);
-                        //}
-                        //else
-                        //{
-                        //    QAFormHost digitalFormHost = new QAFormHost(layout, form, true);
-                        //    Navigation.PushAsync(digitalFormHost);
-                        //}
+                        DigitalFormHost host = new DigitalFormHost(
+                            DigitalFormsHelper.LoadModel(
+                                layout, typeof(KanbanForm), kanban, Guid.Empty,
+                                new ExistingFormShell 
+                                { 
+                                    ID = form.ID,
+                                    ParentID = kanban.ID,
+                                    Type = typeof(KanbanForm),
+                                    FormID = form.ID,
+                                }
+                                ));
+                        Navigation.PushAsync(host);
                     }
                 }
             }