Pārlūkot izejas kodu

PRS MOBILE - MainPage changes for task button

Nick 2 gadi atpakaļ
vecāks
revīzija
e5f8bbf8af

+ 15 - 4
prs.mobile/comal.timesheets/CustomControls/Pages/Selection Screens/JobSelectionPage.xaml.cs

@@ -90,14 +90,17 @@ namespace comal.timesheets.CustomControls
     public class JobShell
     {
         public delegate void JobIDChanged(Guid jobid);
+        public delegate void JobNumberChanged(string jobnumber);
 
         public event JobIDChanged OnJobIDChanged;
+        public event JobNumberChanged OnJobNumberChanged;
 
         private Guid id;
-        public Guid ID 
+        private string jobnumber;
+        public Guid ID
         {
             get => id;
-            set 
+            set
             {
                 id = value;
                 OnJobIDChanged?.Invoke(value);
@@ -106,7 +109,15 @@ namespace comal.timesheets.CustomControls
 
         public string Name { get; set; }
 
-        public string JobNumber { get; set; }
+        public string JobNumber
+        {
+            get => jobnumber;
+            set
+            {
+                jobnumber = value;
+                OnJobNumberChanged?.Invoke(value);
+            }
+        }
 
         public string DisplayName { get; set; }
 
@@ -122,6 +133,6 @@ namespace comal.timesheets.CustomControls
             JobStatusDescription = "";
             Color = Color.LightGray;
         }
-        
+
     }
 }

+ 11 - 5
prs.mobile/comal.timesheets/Main/MainPage.xaml

@@ -17,6 +17,7 @@
         <Grid.RowDefinitions>
             <RowDefinition Height="5.5*"/>
             <RowDefinition Height="45"/>
+            <RowDefinition Height="45"/>
             <RowDefinition Height="12*"/>
         </Grid.RowDefinitions>
 
@@ -26,10 +27,10 @@
             HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                 IsEnabled="False"/>
 
-        
+
         <Label Grid.Row="0" x:Name="CurrentLocation"
                Text="Initializing.." HorizontalTextAlignment="Center" HorizontalOptions="Center" VerticalOptions="End" VerticalTextAlignment="End" Margin="0, 0, 0, 25"/>
-        
+
         <!--row 1-->
         <Grid Grid.Row="1" RowSpacing="0" ColumnSpacing="0">
             <Grid.ColumnDefinitions>
@@ -47,9 +48,14 @@
                 HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                 />
         </Grid>
-        
+
+        <Button Grid.Row="2" Clicked="TaskBtn_Tapped" x:Name="taskBtn" IsEnabled="False" Padding="0"
+                Text="Task"  FontAttributes="Bold" TextColor="White" BackgroundColor="#15C7C1" CornerRadius="5" Margin="10, 5, 10, 5"
+                HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
+                />
+
         <!--row 2-->
-        <ScrollView x:Name="flexLayoutScrollView" Grid.Row="2" >
+        <ScrollView x:Name="flexLayoutScrollView" Grid.Row="3" >
             <ScrollView.Margin>
                 <OnPlatform x:TypeArguments="Thickness">
                     <On Platform="Android" Value="1, 5, 3, 10"/>
@@ -67,5 +73,5 @@
 
 
     </Grid>
-    
+
 </ContentPage>

+ 45 - 3
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -48,9 +48,9 @@ namespace comal.timesheets
                 LoadCacheLists();
 
                 //if (GlobalVariables.EmpID == Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac"))
-                //RunCustomScript();
+                RunCustomScript();
             }
-            catch (Exception e) { }           
+            catch (Exception e) { }
         }
         private void RunCustomScript()
         {
@@ -98,6 +98,9 @@ namespace comal.timesheets
                 {
                     var assgn = MainPageUtils.CheckCurrentAssignment();
 
+                    MainPageUtils.OnRequestUserInput += (taskID) => { RequestUserInput(taskID); };
+                    MainPageUtils.OnTaskTitleChanged += (title) => { taskBtn.Text = title; };
+
                     if (assgn == null)
                         return;
 
@@ -114,12 +117,14 @@ namespace comal.timesheets
                                 MainPageUtils.Job.OnJobIDChanged += MainPageUtils.OnJobIDChanged;
                                 break;
                         };
+                        MainPageUtils.Job.OnJobNumberChanged += Job_OnJobNumberChanged;
                     });
                 }
                 catch { }
             });
         }
 
+
         private void NotifyChanges()
         {
             Task.Run(() =>
@@ -301,6 +306,7 @@ namespace comal.timesheets
                     if (clockOnButton.Text == "CLOCK OFF")
                     {
                         addNoteBtn.IsEnabled = true;
+                        taskBtn.IsEnabled = true;
                         if (GlobalVariables.JobsLoaded)
                             jobBtn.IsEnabled = true;
                     }
@@ -308,6 +314,7 @@ namespace comal.timesheets
                     {
                         addNoteBtn.IsEnabled = false;
                         jobBtn.IsEnabled = false;
+                        taskBtn.IsEnabled = false;
                     }
                     //if (firstLoad)
                     //    RefreshJobFromTimeSheet(timesheet);
@@ -327,6 +334,11 @@ namespace comal.timesheets
             //CurrentLocation.IsEnabled = PRSReady && GateReady;
         }
 
+        private void Job_OnJobNumberChanged(string jobnumber)
+        {
+            jobBtn.Text = "Job: " + jobnumber;
+        }
+
         private void RefreshJobBtn()
         {
             if (MainPageUtils.Job.ID == Guid.Empty)
@@ -931,6 +943,36 @@ namespace comal.timesheets
             }
             catch { }
         }
+
+        private void TaskBtn_Tapped(object sender, EventArgs e)
+        {
+            ListSelectionPage page = new ListSelectionPage(MainPageUtils.GetTasks());
+            page.OnDictionaryItemTapped += (id, title) =>
+            {
+                MainPageUtils.OnTaskSelected(id, title);
+            };
+            Navigation.PushAsync(page);
+        }
+
+        private async void RequestUserInput(Guid taskID)
+        {
+            const string addtask = "Change current assignment task";
+            const string newassignment = "Start a new assignment with this task";
+            string chosenOption = await DisplayActionSheet("Choose an option", "Cancel", null, addtask, newassignment);
+            switch (chosenOption)
+            {
+                case addtask:
+                    MainPageUtils.ChangeAssignmentTask(taskID);
+                    break;
+                case newassignment:
+                    MainPageUtils.SaveCurrentAssignment("PRS Mobile main screen - saving assignment on task change", true);
+                    MainPageUtils.CreateNewAssignment(Guid.Empty, taskID);
+                    break;
+                default:
+                    break;
+            }
+        }
+
         private void JobBtn_Tapped(object sender, EventArgs e)
         {
             try
@@ -1702,4 +1744,4 @@ namespace comal.timesheets
         }
         #endregion
     }
-}
+}

+ 76 - 6
prs.mobile/comal.timesheets/Main/MainPageUtils.cs

@@ -23,10 +23,14 @@ namespace comal.timesheets
 {
     public delegate void MainPageNotificationsChanged();
     public delegate void RefreshScreen();
+    public delegate void RequestUserInputForTask(Guid taskID);
+    public delegate void TaskTitleChanged(string title);
     public static class MainPageUtils
     {
         public static event MainPageNotificationsChanged OnMainPageNotificationsChanged;
         public static event RefreshScreen OnRefreshScreen;
+        public static event RequestUserInputForTask OnRequestUserInput;
+        public static event TaskTitleChanged OnTaskTitleChanged;
 
         public static Assignment CurrentAssignment = null;
         public static JobShell Job = new JobShell();
@@ -40,6 +44,7 @@ namespace comal.timesheets
         public static bool firstLoad = true;
         public static bool recentlyAskedToUpdate = true;
         public static int updateCounter;
+        public static Kanban CurrentTask = null;
 
         public static void Init()
         {
@@ -58,7 +63,7 @@ namespace comal.timesheets
                 App.Data.DataRefreshed += () => { OnRefreshScreen?.Invoke(); };
             }
             catch { }
-            }
+        }
 
         private static void InitData()
         {
@@ -106,6 +111,7 @@ namespace comal.timesheets
             SearchForNewNotifications();
         }
 
+        #region Assignments
         public static Assignment CheckCurrentAssignment()
         {
             Thread.Sleep(5000);
@@ -169,33 +175,62 @@ namespace comal.timesheets
                 Job.Name = job.Name;
                 Job.OnJobIDChanged += OnJobIDChanged;
             }
+            if (CurrentAssignment.Task.ID != Guid.Empty)
+            {
+                var task = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(CurrentAssignment.Task.ID)).Rows.FirstOrDefault().ToObject<Kanban>();
+                OnTaskTitleChanged?.Invoke(task.Title);
+            }
         }
 
         public static void OnJobIDChanged(Guid jobid)
         {
             if (CurrentAssignment == null)
-                CreateNewAssignment(jobid);
+                CreateNewAssignment(jobid, Guid.Empty);
 
             else
             {
                 SaveCurrentAssignment("PRS Mobile main screen - saving assignment on job change", true);
-                CreateNewAssignment(jobid);
+                CreateNewAssignment(jobid, Guid.Empty);
             }
         }
 
-        private static void CreateNewAssignment(Guid jobid)
+        public static void CreateNewAssignment(Guid jobid, Guid taskID)
         {
             CurrentAssignment = new Assignment { Date = DateTime.Now.Date };
             CurrentAssignment.EmployeeLink.ID = GlobalVariables.EmpID;
-            CurrentAssignment.JobLink.ID = jobid;
+
             CurrentAssignment.Actual.Start = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
             CurrentAssignment.Booked.Start = CurrentAssignment.Actual.Start;
             CurrentAssignment.Booked.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay.Add(new TimeSpan(0, 5, 0));
+
+            if (jobid != Guid.Empty)
+                AddJobDetails(jobid);
+
+            if (taskID != Guid.Empty)
+                AddTaskDetails(taskID);
+        }
+
+        private static void AddJobDetails(Guid jobid)
+        {
+            CurrentAssignment.JobLink.ID = jobid;
             var job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(jobid)).Rows.FirstOrDefault().ToObject<Job>();
             CurrentAssignment.Title = "Clocking on to job " + job.Name + " (" + job.JobNumber + ") on PRS Mobile";
+            OnTaskTitleChanged?.Invoke("Task");
             new Client<Assignment>().Save(CurrentAssignment, "Changed job on mobile - creating new assignment");
         }
 
+        private static void AddTaskDetails(Guid taskID)
+        {
+            CurrentAssignment.Task.ID = taskID;
+            var task = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(taskID)).Rows.FirstOrDefault().ToObject<Kanban>();
+            CurrentAssignment.Title = "Clocking on to task " + task.Title + " on PRS Mobile";
+            OnTaskTitleChanged?.Invoke(task.Title);
+            if (!string.IsNullOrWhiteSpace(task.JobLink.JobNumber))
+                Job.JobNumber = task.JobLink.JobNumber;
+            new Client<Assignment>().Save(CurrentAssignment, "Changed task on mobile - creating new assignment");
+        }
+        #endregion
+
         #region Notifications
 
         public static Page DetermineCorrectPage(Plugin.LocalNotification.EventArgs.NotificationActionEventArgs e)
@@ -321,6 +356,7 @@ namespace comal.timesheets
 
         #endregion
 
+        #region Location / Bluetooth
         private static void LocationFound(LocationServices sender)
         {
             //if (bSharedDevice)
@@ -472,5 +508,39 @@ namespace comal.timesheets
             }
             catch { }
         }
+        #endregion
+
+        public static Dictionary<Guid, string> GetTasks()
+        {
+            Dictionary<Guid, string> dict = new Dictionary<Guid, string>();
+
+            CoreTable table = new Client<Kanban>().Query(
+                new Filter<Kanban>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
+                .And(x => x.Category).IsNotEqualTo("Complete"),
+                new Columns<Kanban>(x => x.ID, x => x.Title)
+                );
+            foreach (CoreRow row in table.Rows)
+            {
+                dict.Add
+                    (
+                        row.Get<Kanban, Guid>(x => x.ID),
+                        row.Get<Kanban, string>(x => x.Title)
+                    );
+            }
+            return dict;
+        }
+
+        public static void OnTaskSelected(Guid ID, string title)
+        {
+            if (CurrentAssignment != null)
+                OnRequestUserInput?.Invoke(ID);
+            else
+                CreateNewAssignment(Guid.Empty, ID);
+        }
+
+        public static void ChangeAssignmentTask(Guid taskID)
+        {
+            AddTaskDetails(taskID);
+        }
     }
-}
+}