Selaa lähdekoodia

PRS MOBILE - further changes to job docs viewer

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

+ 1 - 0
prs.mobile/comal.timesheets/DigitalForms/CustomUserControls/CustomPickeriOS.xaml.cs

@@ -23,6 +23,7 @@ namespace comal.timesheets
         public string SelectedItem { get; set; }
         List<PickerOption> Options = new List<PickerOption>();
         double fixedHeight = 0;
+        public JobDocFilterType Type { get; set; }
         public CustomPickeriOS()
         {
             InitializeComponent();

+ 1 - 1
prs.mobile/comal.timesheets/JobDocFilterItem.xaml.cs

@@ -22,7 +22,7 @@ namespace comal.timesheets
 			InitializeComponent ();
 		}
 
-		public void Init(string text, JobDocFilterType type)
+		public void Init(JobDocFilterType type, string text)
 		{
 			textLbl.Text = text;
 			Type = type;

+ 6 - 6
prs.mobile/comal.timesheets/JobDocsFilterPage.xaml

@@ -13,14 +13,14 @@
                 Text="Cancel" Clicked="CancelBtn_Clicked"/>
             <Label Grid.Column="1"  Text="Filters" VerticalOptions="Center" x:Name="titleLbl"
                    HorizontalOptions="Center" HorizontalTextAlignment="Center" TextColor="White" FontSize="Medium" FontAttributes="Bold"/>
-            <Button Grid.Column="2" HorizontalOptions="Start" VerticalOptions="Center" TextColor="White" BackgroundColor="Transparent" Margin="0" Padding="0"
+            <Button Grid.Column="2" HorizontalOptions="End" VerticalOptions="Center" TextColor="White" BackgroundColor="Transparent" Margin="0" Padding="0"
                 Text="Save" Clicked="SaveBtn_Clicked"/>
         </Grid>
     </NavigationPage.TitleView>
 
     <ContentPage.Content>
         <ScrollView>
-            <Grid>
+            <Grid x:Name="filterGrid" Margin="5, 5, 5, 20">
                 <Grid.RowDefinitions>
                     <RowDefinition Height="auto"/>
                     <RowDefinition Height="auto"/>
@@ -34,22 +34,22 @@
 
                 <Label Grid.Row="0" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold" Margin="5, 10, 5, 0"
                 Text="Discipline"/>
-                <timesheets:CustomPickeriOS Grid.Row="1" Margin="5"
+                <timesheets:CustomPickeriOS Grid.Row="1" Margin="5" Type="Discipline"
                                         x:Name="disciplinePicker"/>
 
                 <Label Grid.Row="2" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold" Margin="0"
                 Text="Type"/>
-                <timesheets:CustomPickeriOS Grid.Row="3" Margin="5"
+                <timesheets:CustomPickeriOS Grid.Row="3" Margin="5" Type="Type"
                                         x:Name="typePicker"/>
 
                 <Label Grid.Row="4" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold" Margin="0"
                 Text="Category"/>
-                <timesheets:CustomPickeriOS Grid.Row="5" Margin="5"
+                <timesheets:CustomPickeriOS Grid.Row="5" Margin="5" Type="Category"
                                         x:Name="categoryPicker"/>
 
                 <Label Grid.Row="6" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold" Margin="0"
                 Text="Area"/>
-                <timesheets:CustomPickeriOS Grid.Row="7" Margin="5"
+                <timesheets:CustomPickeriOS Grid.Row="7" Margin="5" Type="Area"
                                         x:Name="areaPicker"/>
 
             </Grid>

+ 22 - 4
prs.mobile/comal.timesheets/JobDocsFilterPage.xaml.cs

@@ -12,7 +12,7 @@ using Xamarin.Forms.Xaml;
 
 namespace comal.timesheets
 {
-    public delegate void JobDocFiltersPicked(string discipline, string type, string category, string area);
+    public delegate void JobDocFiltersPicked(Dictionary<JobDocFilterType, string> filters);
 
     [XamlCompilation(XamlCompilationOptions.Compile)]
     public partial class JobDocsFilterPage : ContentPage
@@ -43,7 +43,25 @@ namespace comal.timesheets
         private void SaveBtn_Clicked(object sender, EventArgs e)
         {
             Navigation.PopAsync();
-            OnJobDocFiltersPicked?.Invoke(disciplinePicker.SelectedItem, typePicker.SelectedItem, categoryPicker.SelectedItem, areaPicker.SelectedItem);
+            OnJobDocFiltersPicked?.Invoke(CreateFilters());
+        }
+
+        private Dictionary<JobDocFilterType, string> CreateFilters()
+        {
+            Dictionary<JobDocFilterType, string> filters = new Dictionary<JobDocFilterType, string>();
+            foreach (var child in filterGrid.Children)
+            {
+                if (child is CustomPickeriOS)
+                {
+                    var picker = child as CustomPickeriOS;
+                    if (!string.IsNullOrWhiteSpace(picker.SelectedItem))
+                    {
+                        filters.Add(picker.Type, picker.SelectedItem);
+                    }
+                }
+            }
+
+            return filters;
         }
 
         private void LoadFilters()
@@ -71,9 +89,9 @@ namespace comal.timesheets
         {
             CoreTable table = new Client<JobITP>().Query(
                 new Filter<JobITP>(x => x.Job.ID).IsEqualTo(JobID),
-                new Columns<JobITP>(x => x.Code));
+                new Columns<JobITP>(x => x.Description));
             foreach (CoreRow row in table.Rows)
-                Areas.Add(row.Get<JobITP, string>(x => x.Code));
+                Areas.Add(row.Get<JobITP, string>(x => x.Description));
         }
 
         private void PopulateLists()

+ 21 - 62
prs.mobile/comal.timesheets/Site/JobDocViewer.xaml.cs

@@ -73,44 +73,37 @@ namespace comal.timesheets
             Navigation.PushAsync(page);
         }
 
-        private void Page_OnJobDocFiltersPicked(string discipline, string type, string category, string area)
+        private void Page_OnJobDocFiltersPicked(Dictionary<JobDocFilterType, string> newfilters)
         {
             filterLayout.Children.Clear();
             filteredShells.Clear();
             filters.Clear();
 
-            if (!string.IsNullOrWhiteSpace(discipline))
-                AddFilter(discipline, JobDocFilterType.Discipline);
-            if (!string.IsNullOrWhiteSpace(type))
-                AddFilter(type, JobDocFilterType.Type);
-            if (!string.IsNullOrWhiteSpace(category))
-                AddFilter(category, JobDocFilterType.Category);
-            if (!string.IsNullOrWhiteSpace(area))
-                AddFilter(area, JobDocFilterType.Area);
-
+            filters = new Dictionary<JobDocFilterType, string>(newfilters);
+                 
+            AddFilters();
+            
             DisplayFolderContents();
         }
 
-        private void AddFilter(string text, JobDocFilterType type)
+        private void AddFilters()
         {
-            if (!filters.ContainsKey(type))
-                filters.Add(type, text);
-
-            JobDocFilterItem item = new JobDocFilterItem();
-            item.Init(text, type);
-            item.OnJobDocFilterClosed += ((filter, type) =>
+            foreach (var filter in filters)
             {
-                filterLayout.Children.Remove(item);
-                filters.Remove(type);
-                RemoveShells(filter, type);
-                DisplayFolderContents();
-            });
-            filterLayout.Children.Add(item);
+                JobDocFilterItem item = new JobDocFilterItem();
+                item.Init(filter.Key, filter.Value);
+                item.OnJobDocFilterClosed += ((filter, type) =>
+                {
+                    filters.Remove(type);                  
+                    Page_OnJobDocFiltersPicked(new Dictionary<JobDocFilterType, string>(filters));
+                });
+                filterLayout.Children.Add(item);
 
-            FilterList(text, type);
+                FilterList(filter.Key, filter.Value);
+            }           
         }
 
-        private void FilterList(string text, JobDocFilterType type)
+        private void FilterList(JobDocFilterType type, string text)
         {
             if (type == JobDocFilterType.Discipline)
             {
@@ -143,43 +136,7 @@ namespace comal.timesheets
             var duplicate = filteredShells.FirstOrDefault(x => x.ID == v.ID);
             if (duplicate == null)
                 filteredShells.Add(v);
-        }
-
-        private void RemoveShells(string filter, JobDocFilterType type)
-        {
-            if (type == JobDocFilterType.Discipline)
-            {
-                while (filteredShells.Find(x => x.DocSetDiscipline == filter) != null)
-                {
-                    var shell = filteredShells.FirstOrDefault(x => x.DocSetDiscipline == filter);
-                    filteredShells.Remove(shell);
-                }
-            }
-            else if (type == JobDocFilterType.Type)
-            {
-                while (filteredShells.Find(x => x.DocSetType == filter) != null)
-                {
-                    var shell = filteredShells.FirstOrDefault(x => x.DocSetType == filter);
-                    filteredShells.Remove(shell);
-                }
-            }
-            else if (type == JobDocFilterType.Category)
-            {
-                while (filteredShells.Find(x => x.DocSetCategory == filter) != null)
-                {
-                    var shell = filteredShells.FirstOrDefault(x => x.DocSetCategory == filter);
-                    filteredShells.Remove(shell);
-                }
-            }
-            else if (type == JobDocFilterType.Area)
-            {
-                while (filteredShells.Find(x => x.DocSetArea == filter) != null)
-                {
-                    var shell = filteredShells.FirstOrDefault(x => x.DocSetArea == filter);
-                    filteredShells.Remove(shell);
-                }
-            }
-        }
+        }        
         #endregion
 
         #region TreeView / Folder Interaction
@@ -443,6 +400,7 @@ namespace comal.timesheets
                 DocSetType = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Type.Description),
                 DocSetCategory = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Category.Description),
                 DocSetDiscipline = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Discipline.Description),
+                DocSetArea = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Area.Description),
             };
             if (specificQuery)
                 specificQueryMileStones.Add(shell);
@@ -471,6 +429,7 @@ namespace comal.timesheets
             file.DocSetCategory = mileStone.DocSetCategory;
             file.DocSetType = mileStone.DocSetType;
             file.DocSetDiscipline = mileStone.DocSetDiscipline;
+            file.DocSetArea = mileStone.DocSetArea;
 
             file.TrimmedIssued = TrimWhiteSpace(file.Issued);