| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Mobile;
- using InABox.Mobile.Shared;
- using Xamarin.Essentials;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- public class SiteDocumentsSettings : BaseObject, ILocalConfigurationSettings
- {
- public Guid CategoryID { get; set; }
- public Guid TypeID { get; set; }
- public Guid DisciplineID { get; set; }
- public Guid ItpID { get; set; }
- public Guid FolderID { get; set; }
- }
- public class SiteDocumentCachedColorConverter : AbstractConverter<JobDocumentShell, Color>
- {
- protected override Color Convert(JobDocumentShell value, object? parameter = null)
- {
- return App.Data.IsConnected() || CoreRepository.IsCached($"{value.ID}.document")
- ? Color.White
- : Color.Gainsboro;
- }
- }
-
- public class SiteDocumentCachedImageConverter : AbstractConverter<JobDocumentShell, ImageSource>
- {
-
- private static readonly ImageSource _cloud = ImageSource.FromFile("cloud");
- private static readonly ImageSource _cache = ImageSource.FromFile("cache");
-
- protected override ImageSource Convert(JobDocumentShell value, object? parameter = null)
- {
- return value == null
- ? null
- : CoreRepository.IsCached($"{value.ID}.document")
- ? _cache
- : _cloud;
- }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SiteDocuments
- {
- private readonly SiteDocumentsSettings _settings;
- private readonly JobDocumentModel _documentmodel;
- private readonly JobDocumentFolderModel _foldermodel;
-
- public SiteDocuments(JobShell job) : base(job)
- {
- _documentmodel = new JobDocumentModel(App.Data,() =>
- new Filter<JobDocumentSetMileStoneFile>(x=>x.EntityLink.DocumentSet.Job.ID).IsEqualTo(Job.ID)
- .And(x=>x.EntityLink.Type.SiteVisible).IsEqualTo(true)
- .And(x=>x.EntityLink.Status).IsEqualTo(JobDocumentSetMileStoneStatus.Approved),
- () => $"JobDocuments_{Job.ID}"
- );
- _foldermodel = new JobDocumentFolderModel(App.Data, () =>
- new Filter<JobDocumentSetFolder>(x => x.Job.ID).IsEqualTo(Job.ID),
- () => $"JobFolders_{Job.ID}"
- );
- _settings = new LocalConfiguration<SiteDocumentsSettings>().Load();
- InitializeComponent();
- ProgressVisible = true;
- RefreshData(false,true);
- }
-
- private void RefreshData(bool force, bool async)
- {
- if (async)
- {
- Task[] tasks = new Task[]
- {
- Task.Run(() => _documentmodel.Refresh(force)),
- Task.Run(() => _foldermodel.Refresh(force))
- };
- Task.WhenAll(tasks).BeginInvokeOnMainThread((_) => RefreshScreen());
- }
- else
- {
- _documentmodel.Refresh(force);
- RefreshScreen();
- }
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- RefreshScreen();
- }
-
- private readonly List<Guid> _folders = new List<Guid>();
-
- private void RefreshScreen()
- {
- _folders.Clear();
- var flist = _foldermodel.DocumentFolders.GetChildren(_settings.FolderID).Select(x=>x.ID).ToList();
- _folders.AddRange(flist);
-
- _files.ItemsSource = null;
- _documentmodel.Search(FilterShell);
- _files.ItemsSource = _documentmodel.Items;
- _files.LastUpdated = _documentmodel.LastUpdated;
- Title = Job.DisplayName;
- ProgressVisible = false;
- }
- private bool FilterShell(JobDocumentShell x)
- {
- var result =
- ((_settings.CategoryID == Guid.Empty) || (x.CategoryID == _settings.CategoryID))
- && ((_settings.DisciplineID == Guid.Empty) || (x.DisciplineID == _settings.DisciplineID))
- && ((_settings.TypeID == Guid.Empty) || (x.TypeID == _settings.TypeID))
- && ((_settings.ItpID == Guid.Empty) || (x.ItpID == _settings.ItpID))
- && ((_settings.FolderID == Guid.Empty) || (_settings.FolderID == CoreUtils.FullGuid) || _folders.Contains(x.FolderID))
- && (String.IsNullOrWhiteSpace(_currentFilter)
- || x.FileName.ToUpper().Contains(_currentFilter)
- || x.Name.ToUpper().Contains(_currentFilter)
- || x.Code.ToUpper().Contains(_currentFilter)
- );
- return result;
- }
-
- private void SiteDocument_Clicked(object sender, EventArgs e)
- {
- if ((sender is MobileCard card) && (card.BindingContext is JobDocumentShell shell))
- {
- ProgressVisible = true;
- Navigation.PushAsync(new DocumentPage() { DocumentID = shell.ID });
- RefreshScreen();
- ProgressVisible = false;
- }
- }
- private void _filter_Clicked(object sender, MobileMenuButtonClickedEventArgs args)
- {
- var filterpage = new SiteDocumentsFilter(_documentmodel, _settings, Job.ID, _foldermodel);
- filterpage.Changed += (_,_) =>
- {
- new LocalConfiguration<SiteDocumentsSettings>().Save(_settings);
- RefreshScreen();
- };
- Navigation.PushAsync(filterpage);
- }
- private string _currentFilter;
- private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
- {
- _currentFilter = args.Text.ToUpper();
- RefreshScreen();
- }
- private void _files_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true,false);
- RefreshScreen();
- }
- }
- }
|