Pārlūkot izejas kodu

PRS MOBILE - Job Documents Viewer adding filters

Nick-PRSDigital@bitbucket.org 2 gadi atpakaļ
vecāks
revīzija
08c1bf62b8

+ 4 - 0
prs.classes/Entities/Job/DocumentSet/IJobDocumentSet.cs

@@ -8,5 +8,9 @@ namespace Comal.Classes
         String Description { get; set; }
         JobLink Job { get; set; }
         JobDocumentSetFolderLink Folder { get; set; }
+        JobDocumentSetDisciplineLink Discipline { get; set; }
+        JobDocumentSetTypeLink Type { get; set; }
+        JobDocumentSetCategoryLink Category { get; set; }
+        JobITPLink Area { get; set; }
     }
 }

+ 8 - 0
prs.classes/Entities/Job/DocumentSet/JobDocumentSetLink.cs

@@ -21,12 +21,20 @@ namespace Comal.Classes
         [TextBoxEditor(Editable = Editable.Hidden)]
         [EditorSequence(2)]
         public string Description { get; set; }
+        public JobDocumentSetDisciplineLink Discipline { get; set; }
+        public JobDocumentSetTypeLink Type { get; set; }
+        public JobDocumentSetCategoryLink Category { get; set; }
+        public JobITPLink Area { get; set; }
 
         protected override void Init()
         {
             base.Init();
             Job = new JobLink();
             Folder = new JobDocumentSetFolderLink();
+            Discipline = new JobDocumentSetDisciplineLink();
+            Category = new JobDocumentSetCategoryLink();
+            Type = new JobDocumentSetTypeLink();
+            Area = new JobITPLink();
         }
     }
 }

+ 19 - 0
prs.mobile/comal.timesheets/JobDocFilterItem.xaml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="comal.timesheets.JobDocFilterItem">
+  <ContentView.Content>
+        <Grid>
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="auto"/>
+            </Grid.ColumnDefinitions>
+            <Label Grid.Column="0" x:Name="textLbl"/>
+            <Image Grid.Column="1" Source="closee.png" HeightRequest="15" WidthRequest="15">
+                <Image.GestureRecognizers>
+                    <TapGestureRecognizer Tapped="Close_Tapped"/>
+                </Image.GestureRecognizers>
+            </Image>
+        </Grid>
+  </ContentView.Content>
+</ContentView>

+ 37 - 0
prs.mobile/comal.timesheets/JobDocFilterItem.xaml.cs

@@ -0,0 +1,37 @@
+using Comal.Classes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace comal.timesheets
+{
+	public delegate void JobDocFilterClosed(string filter, JobDocFilterType type);
+
+	[XamlCompilation(XamlCompilationOptions.Compile)]
+	public partial class JobDocFilterItem : ContentView
+	{
+		public event JobDocFilterClosed OnJobDocFilterClosed;
+		public JobDocFilterType Type { get; set; }
+        public JobDocFilterItem ()
+		{
+			InitializeComponent ();
+		}
+
+		public void Init(string text, JobDocFilterType type)
+		{
+			textLbl.Text = text;
+			Type = type;
+		}
+
+		private void Close_Tapped(object sender, EventArgs e)
+		{
+			OnJobDocFilterClosed?.Invoke(textLbl.Text, Type);
+		}
+
+    }
+}

+ 58 - 0
prs.mobile/comal.timesheets/JobDocsFilterPage.xaml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:timesheets="clr-namespace:comal.timesheets"
+             x:Class="comal.timesheets.JobDocsFilterPage">
+    <NavigationPage.TitleView>
+        <Grid Margin="0" Padding="0">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="*"/>
+            </Grid.ColumnDefinitions>
+            <Button Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center" TextColor="White" BackgroundColor="Transparent" Margin="0" Padding="0"
+                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"
+                Text="Save" Clicked="SaveBtn_Clicked"/>
+        </Grid>
+    </NavigationPage.TitleView>
+
+    <ContentPage.Content>
+        <ScrollView>
+            <Grid>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                    <RowDefinition Height="auto"/>
+                </Grid.RowDefinitions>
+
+                <Label Grid.Row="0" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold"
+                Text="Discipline"/>
+                <timesheets:CustomPickeriOS Grid.Row="1" Margin="5"
+                                        x:Name="disciplinePicker"/>
+
+                <Label Grid.Row="2" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold"
+                Text="Type"/>
+                <timesheets:CustomPickeriOS Grid.Row="3" Margin="5"
+                                        x:Name="typePicker"/>
+
+                <Label Grid.Row="4" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold"
+                Text="Category"/>
+                <timesheets:CustomPickeriOS Grid.Row="5" Margin="5"
+                                        x:Name="categoryPicker"/>
+
+                <Label Grid.Row="6" FontSize="Medium" HorizontalOptions="Center" FontAttributes="Bold"
+                Text="Area"/>
+                <timesheets:CustomPickeriOS Grid.Row="7" Margin="5"
+                                        x:Name="areaPicker"/>
+
+            </Grid>
+        </ScrollView>
+    </ContentPage.Content>
+</ContentPage>

+ 95 - 0
prs.mobile/comal.timesheets/JobDocsFilterPage.xaml.cs

@@ -0,0 +1,95 @@
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace comal.timesheets
+{
+    public delegate void JobDocFiltersPicked(string discipline, string type, string category, string area);
+
+    [XamlCompilation(XamlCompilationOptions.Compile)]
+    public partial class JobDocsFilterPage : ContentPage
+    {
+        Guid JobID = Guid.Empty;
+
+        List<string> Disciplines = new List<string>();
+        List<string> Types = new List<string>();
+        List<string> Categories = new List<string>();
+        List<string> Areas = new List<string>();
+
+        public event JobDocFiltersPicked OnJobDocFiltersPicked;
+        public JobDocsFilterPage(Guid jobid)
+        {
+            InitializeComponent();
+            NavigationPage.SetHasBackButton(this, false);
+            JobID = jobid;
+            LoadFilters();
+        }
+
+        private void CancelBtn_Clicked(object sender, EventArgs e)
+        {
+            Navigation.PopAsync();
+        }
+
+        private void SaveBtn_Clicked(object sender, EventArgs e)
+        {
+            Navigation.PopAsync();
+            OnJobDocFiltersPicked?.Invoke(disciplinePicker.SelectedItem, typePicker.SelectedItem, categoryPicker.SelectedItem, areaPicker.SelectedItem);
+        }
+
+        private void LoadFilters()
+        {
+            LoadTags();
+
+            LoadAreas();
+
+            PopulateLists();
+        }
+
+        private void LoadTags()
+        {
+            CoreTable table = new Client<JobDocumentSetTag>().Query();
+
+            foreach (CoreRow row in table.Rows)
+            {
+                var tag = row.ToObject<JobDocumentSetTag>();
+                if (tag.Job.ID == Guid.Empty || tag.Job.ID == JobID)
+                    CategoriseTag(tag);
+            }
+        }
+
+        private void LoadAreas()
+        {
+            CoreTable table = new Client<JobITP>().Query(
+                new Filter<JobITP>(x => x.Job.ID).IsEqualTo(JobID),
+                new Columns<JobITP>(x => x.Code));
+            foreach (CoreRow row in table.Rows)
+                Areas.Add(row.Get<JobITP, string>(x => x.Code));
+        }
+
+        private void PopulateLists()
+        {
+            disciplinePicker.AddItems(Disciplines);
+            typePicker.AddItems(Types);
+            categoryPicker.AddItems(Categories);
+            areaPicker.AddItems(Areas);
+        }
+
+        private void CategoriseTag(JobDocumentSetTag tag)
+        {
+            if (tag.Type == JobDocumentSetTagType.Discipline)
+                Disciplines.Add(tag.Description);
+            else if (tag.Type == JobDocumentSetTagType.Type)
+                Types.Add(tag.Description);
+            else if (tag.Type == JobDocumentSetTagType.Category)
+                Categories.Add(tag.Description);
+        }
+    }
+}

+ 31 - 2
prs.mobile/comal.timesheets/Site/JobDocViewer.xaml

@@ -22,6 +22,7 @@
             <Grid RowSpacing="0">
                 <Grid.RowDefinitions>
                     <RowDefinition Height="auto"/>
+                    <RowDefinition Height="45"/>
                     <RowDefinition Height="auto"/>
                     <RowDefinition Height="*"/>
                 </Grid.RowDefinitions>
@@ -66,11 +67,39 @@
                     </Grid>
                 </Frame>
 
-                <Frame Grid.Row="1" Padding="0" BorderColor="#a2006d" Margin="1, 0, 1, 0" CornerRadius="10" VerticalOptions="Start">
+                <Frame Grid.Row="1" Padding="5" BorderColor="#a2006d" Margin="1, 0, 1, 0" CornerRadius="10" VerticalOptions="Start">
+                    <Grid>
+                        <Grid.ColumnDefinitions>
+                            <ColumnDefinition Width="auto"/>
+                            <ColumnDefinition Width="*"/>
+                            <ColumnDefinition Width="auto"/>
+                        </Grid.ColumnDefinitions>
+
+                        <Label Grid.Column="0" Text="Filters:" FontAttributes="Bold" FontSize="Medium" Margin="2, 0, 0, 0"
+                               HorizontalOptions="Start" VerticalOptions="Center"/>
+
+                        <FlexLayout Grid.Column="1" x:Name="filterLayout"
+                                    Wrap="Wrap"
+                                    Direction="Row"
+                                    JustifyContent="SpaceEvenly"
+                                    AlignItems="Start"
+                                    AlignContent="Start"/>
+
+                        <Image Grid.Column="2" Source="filter.png"
+                               HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" WidthRequest="40">
+                            <Image.GestureRecognizers>
+                                <TapGestureRecognizer Tapped="FilterButton_Tapped"/>
+                            </Image.GestureRecognizers>
+                        </Image>
+
+                    </Grid>
+                </Frame>
+
+                <Frame Grid.Row="2" Padding="0" BorderColor="#a2006d" Margin="1, 0, 1, 0" CornerRadius="10" VerticalOptions="Start">
                     <Entry x:Name="searchEnt" Placeholder="Search" VerticalOptions="Center" FontSize="Medium" Margin="5" TextChanged="SearchEnt_Changed" HeightRequest="40"/>
                 </Frame>
 
-                <Frame Grid.Row="2" Padding="1, 7, 1, 7" BorderColor="#a2006d" Margin="1, 1, 1, 0" CornerRadius="10" VerticalOptions="FillAndExpand">
+                <Frame Grid.Row="3" Padding="1, 7, 1, 7" BorderColor="#a2006d" Margin="1, 1, 1, 0" CornerRadius="10" VerticalOptions="FillAndExpand">
                     <Grid>
                         <Grid.ColumnDefinitions>
                             <ColumnDefinition x:Name="filesColumn" Width="*"/>

+ 79 - 12
prs.mobile/comal.timesheets/Site/JobDocViewer.xaml.cs

@@ -36,7 +36,8 @@ namespace comal.timesheets
         Guid jobID = Guid.Empty;
         List<Guid> loadedFolders = new List<Guid>();
         List<MileStoneShell> mileStoneShells = new List<MileStoneShell>();
-        List<JobDocSetFileShell> shells = new List<JobDocSetFileShell>();
+        List<JobDocSetFileShell> fullListShells = new List<JobDocSetFileShell>();
+        List<JobDocSetFileShell> filteredShells = new List<JobDocSetFileShell>();
         List<JobDocSetFileShell> searchList = new List<JobDocSetFileShell>();
         List<MileStoneShell> specificQueryMileStones = new List<MileStoneShell>();
         List<JobDocSetFileShell> specificQueryFileShells = new List<JobDocSetFileShell>();
@@ -63,6 +64,38 @@ namespace comal.timesheets
         {
             Navigation.PopAsync();
         }
+
+        private void FilterButton_Tapped(object sender, EventArgs e)
+        {
+            var page = new JobDocsFilterPage(jobID);
+            page.OnJobDocFiltersPicked += Page_OnJobDocFiltersPicked;
+            Navigation.PushAsync(page);
+        }
+
+        private void Page_OnJobDocFiltersPicked(string discipline, string type, string category, string area)
+        {
+            filterLayout.Children.Clear();
+
+            if (!string.IsNullOrWhiteSpace(discipline))
+                AddFilter(discipline, JobDocFilterType.Discipline);
+            if (!string.IsNullOrWhiteSpace(type))
+                AddFilter(type, JobDocFilterType.Type);
+            if (!string.IsNullOrWhiteSpace(discipline))
+                AddFilter(category, JobDocFilterType.Category);
+            if (!string.IsNullOrWhiteSpace(area))
+                AddFilter(area, JobDocFilterType.Area);
+        }
+
+        private void AddFilter(string text, JobDocFilterType type)
+        {
+            JobDocFilterItem item = new JobDocFilterItem();
+            item.Init(text, type);
+            item.OnJobDocFilterClosed += ((filter, type) => 
+            {
+                filterLayout.Children.Remove(item);
+            });
+            filterLayout.Children.Add(item);
+        }
         #endregion
 
         #region TreeView / Folder Interaction
@@ -79,11 +112,11 @@ namespace comal.timesheets
             {
                 if (folder.ItemName == "All")
                 {
-                    AddSearchItems(shells);
+                    AddSearchItems(fullListShells);
                 }
                 else
                 {
-                    var list = shells.Where(x => x.FolderID == folder.ID);
+                    var list = fullListShells.Where(x => x.FolderID == folder.ID);
                     AddSearchItems(list);
                 }
             }
@@ -215,6 +248,10 @@ namespace comal.timesheets
                                 x => x.ID,
                                 x => x.DocumentSet.Folder.Name,
                                 x => x.DocumentSet.Folder.ID,
+                                x => x.DocumentSet.Type.Description,
+                                x => x.DocumentSet.Category.Description,
+                                x => x.DocumentSet.Discipline.Description,
+                                x => x.DocumentSet.Area.Description,
                                 x => x.Submitted,
                                 x => x.Employee.Name,
                                 x => x.Type.Description,
@@ -242,8 +279,8 @@ namespace comal.timesheets
                                 else
                                 {
                                     filesLoaded = true;
-                                    displayList.Insert(0, new FolderViewItem { ItemName = "All", Documents = shells.Count });
-                                    folderList.Insert(0, new FolderViewItem { ItemName = "All", Documents = shells.Count });
+                                    displayList.Insert(0, new FolderViewItem { ItemName = "All", Documents = fullListShells.Count });
+                                    folderList.Insert(0, new FolderViewItem { ItemName = "All", Documents = fullListShells.Count });
                                     treeView.ItemsSource = null;
                                     treeView.ItemsSource = displayList;
                                 }
@@ -289,12 +326,15 @@ namespace comal.timesheets
             MileStoneShell shell = new MileStoneShell
             {
                 ID = milestonerow.Get<Guid>("ID"),
-                FolderName = milestonerow.Get<string>("DocumentSet.Folder.Name"),
-                FolderID = milestonerow.Get<Guid>("DocumentSet.Folder.ID"),
-                EmployeeName = milestonerow.Get<string>("Employee.Name"),
-                Type = milestonerow.Get<string>("Type.Description"),
-                DocSetDescription = milestonerow.Get<string>("DocumentSet.Description"),
-                Issued = "Issued: " + milestonerow.Get<DateTime>("Issued").ToString("dd MMM yy")
+                FolderName = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Folder.Name),
+                FolderID = milestonerow.Get<JobDocumentSetMileStone, Guid>(x => x.DocumentSet.Folder.ID),
+                EmployeeName = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.Employee.Name),
+                Type = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.Type.Description),
+                DocSetDescription = milestonerow.Get<JobDocumentSetMileStone, string>(x => x.DocumentSet.Description),
+                Issued = "Submitted: " + milestonerow.Get<JobDocumentSetMileStone, DateTime>(x => x.Submitted).ToString("dd MMM yy"),
+                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),
             };
             if (specificQuery)
                 specificQueryMileStones.Add(shell);
@@ -319,6 +359,9 @@ namespace comal.timesheets
             file.Type = mileStone.Type;
             file.DocSetDescription = mileStone.DocSetDescription;
             file.Issued = mileStone.Issued;
+            file.DocSetCategory = mileStone.DocSetCategory;
+            file.DocSetType = mileStone.DocSetType;
+            file.DocSetDiscipline = mileStone.DocSetDiscipline;
 
             file.TrimmedIssued = TrimWhiteSpace(file.Issued);
 
@@ -340,7 +383,7 @@ namespace comal.timesheets
                 currentQueryFileShells.Add(file);
             }
             else
-                shells.Add(file);
+                fullListShells.Add(file);
         }
 
         private void ShowFiles()
@@ -524,6 +567,10 @@ namespace comal.timesheets
         public string Type { get; set; }
         public string DocSetDescription { get; set; }
         public string Issued { get; set; }
+        public string DocSetType { get; set; }
+        public string DocSetDiscipline { get; set; }
+        public string DocSetCategory { get; set; }
+        public string DocSetArea { get; set; }
         public MileStoneShell()
         {
             ID = Guid.Empty;
@@ -533,6 +580,10 @@ namespace comal.timesheets
             Type = "";
             DocSetDescription = "";
             Issued = "";
+            DocSetCategory = "";
+            DocSetDiscipline = "";
+            DocSetType = "";
+            DocSetArea = "";
         }
     }
 
@@ -552,6 +603,10 @@ namespace comal.timesheets
         public double WidthRequest { get; set; }
         public byte[] Thumbnail { get; set; }
         public Guid MileStoneID { get; set; }
+        public string DocSetType { get; set; }
+        public string DocSetDiscipline { get; set; }
+        public string DocSetCategory { get; set; }
+        public string DocSetArea { get; set; }
 
         public JobDocSetFileShell()
         {
@@ -569,7 +624,19 @@ namespace comal.timesheets
             Thumbnail = null;
             MileStoneID = Guid.Empty;
             FolderID = Guid.Empty;
+            DocSetCategory = "";
+            DocSetDiscipline = "";
+            DocSetType = "";
+            DocSetArea = "";
         }
     }
+
+    public enum JobDocFilterType
+    {
+        Discipline,
+        Type,
+        Category,
+        Area
+    }
     #endregion
 }

+ 20 - 0
prs.mobile/comal.timesheets/comal.timesheets.projitems

@@ -216,6 +216,14 @@
     <Compile Include="$(MSBuildThisFileDirectory)DigitalForms\DataModels\IDigitalFormHostModel.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)DigitalForms\DataModels\FormPickerQueryLoader.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)DigitalForms\DataModels\IFormPickerQueryLoader.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)JobDocFilterItem.xaml.cs">
+      <DependentUpon>JobDocFilterItem.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)JobDocsFilterPage.xaml.cs">
+      <DependentUpon>JobDocsFilterPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)Main\MainPageUtils.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)MyHR\MyDetailsPage.xaml.cs">
       <DependentUpon>MyDetailsPage.xaml</DependentUpon>
@@ -989,4 +997,16 @@
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)JobDocsFilterPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)JobDocFilterItem.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
 </Project>