123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using InABox.Wpf;
- using Inflector;
- using Color = System.Drawing.Color;
- using InABox.Configuration;
- namespace PRSDesktop
- {
-
- public class JobDocumentSetSettings : BaseObject, IGlobalConfigurationSettings
- {
- [Caption("Milestone Task",IncludePath = false)]
- public KanbanTypeLink DocumentMilestoneKanbanType { get; set; }
- }
-
- public partial class JobDocumentSetPanel : UserControl, IMasterDetailControl<Job>, IDataModelSource, IPanel<Job>
- {
- private enum Suppress
- {
- This
- }
- private JobDocumentSetSettings _settings = new();
- public Job? Master { get; set; }
-
- public JobDocumentSetPanel()
- {
- using (new EventSuppressor(Suppress.This))
- InitializeComponent();
- }
- public string SectionName => "Job Document Set";
- public DataModel DataModel(Selection selection)
- {
- var ids = Documents.Data != null ? Documents.Data.ExtractValues<JobDocumentSet, Guid>(x => x.ID).ToArray() : new Guid[] { };
- return new AutoDataModel<JobDocumentSet>(new Filter<JobDocumentSet>(x => x.ID).InList(ids));
- }
- public event DataModelUpdateEvent? OnUpdateDataModel;
-
- private static bool GetAreas(CoreTable areas, ComboBox target) //, RowDefinition row)
- {
- using (new EventSuppressor(Suppress.This))
- {
- Dictionary<Guid, String> result = new Dictionary<Guid, String>()
- {
- { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" }
- };
- areas.IntoDictionary<JobITP, Guid, String>(result, x => x.ID,
- (r) => $"{r.Get<JobITP, String>(c => c.Code)}: {r.Get<JobITP, String>(c => c.Description)}");
- // row.Height = result.Count > 1
- // ? new GridLength(1, GridUnitType.Auto)
- // : new GridLength(0, GridUnitType.Pixel);
- var value = target.SelectedValue;
- target.ItemsSource = result;
- target.SelectedValue = value;
- return result.Count > 1;
- }
- }
- private static bool GetTags(CoreTable tags, JobDocumentSetTagType type, ComboBox target) //, RowDefinition row)
- {
- using (new EventSuppressor(Suppress.This))
- {
- var result = new Dictionary<Guid, String>()
- {
- { Guid.Empty, "" }
- };
- foreach (var tag in tags.Rows.Where(x => x.Get<JobDocumentSetTag, JobDocumentSetTagType>(x => x.Type).Equals(type)))
- result[tag.Get<JobDocumentSetTag, Guid>(c => c.ID)] = tag.Get<JobDocumentSetTag, String>(c => c.Description);
- // row.Height = result.Count > 1
- // ? new GridLength(1, GridUnitType.Auto)
- // : new GridLength(0, GridUnitType.Pixel);
- var value = target.SelectedValue;
- target.ItemsSource = result;
- target.SelectedValue = value;
- return result.Count > 1;
- }
- }
- public void Setup()
- {
- _settings = new GlobalConfiguration<JobDocumentSetSettings>().Load();
- tasks.Settings = _settings;
- tasks.Refresh(true, false);
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- public void Refresh()
- {
- LoadDocumentTags();
- Folders.Master = Master;
- Folders.Refresh();
-
- Documents.Master = Master;
- Documents.Refresh();
-
- }
- private void LoadDocumentTags()
- {
- // Global tags
- var tagFilter = new Filter<JobDocumentSetTag>(x => x.Job.ID).IsEqualTo(Guid.Empty);
- if(Master is not null && Master.ID != Guid.Empty)
- {
- tagFilter = tagFilter.Or(x => x.Job.ID).IsEqualTo(Master.ID);
- }
- var results = Client.QueryMultiple(
- new KeyedQueryDef<JobDocumentSetTag>(
- tagFilter,
- new Columns<JobDocumentSetTag>(x => x.ID)
- .Add(x => x.Type)
- .Add(x => x.Description),
- new SortOrder<JobDocumentSetTag>(x => x.Description)
- ),
- new KeyedQueryDef<JobITP>(
- new Filter<JobITP>(x => x.Job.ID).IsEqualTo(Master?.ID ?? Guid.Empty),
- new Columns<JobITP>(x => x.ID).Add(x => x.Code).Add(x => x.Description),
- new SortOrder<JobITP>(x => x.Code)));
- var tags = results.Get<JobDocumentSetTag>();
- /* Documents.DisciplineVisible = */
- GetTags(tags, JobDocumentSetTagType.Discipline, Discipline); //, DisciplineRow);
- /* Documents.TypeVisible = */
- GetTags(tags, JobDocumentSetTagType.Type, Type); //, TypeRow);
- /* Documents.CategoryVisible = */
- GetTags(tags, JobDocumentSetTagType.Category, Category); //, CategoryRow);
- /* Documents.AreaVisible = */
- GetAreas(results.Get<JobITP>(), Area); //, AreaRow);
- }
- public bool IsReady { get; set; }
- public void CreateToolbarButtons(IPanelHost host)
- {
- host.CreateSetupAction(new PanelAction() { Caption = "Job Settings", Image = PRSDesktop.Resources.specifications, OnExecute = JobSettingsClick });
- }
- private void JobSettingsClick(PanelAction obj)
- {
- if (DynamicGridUtils.Edit(_settings))
- new GlobalConfiguration<JobDocumentSetSettings>().Save(_settings);
- }
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]>();
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private Guid _folderid = Guid.Empty;
- private void Folders_OnOnSelectItem(CoreTreeNode node)
- {
- _folderid = node != null ? node.ID : Guid.Empty;
- LoadDocuments(_folderid);
- }
- private void LoadDocuments(Guid folderid)
- {
- List<Guid> folders = new List<Guid>();
- this.Folders.Nodes.GetChildren(folders, folderid);
- Documents.FolderIDs = folders.ToArray();
- Documents.Refresh();
- }
- private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
- {
- LoadDocuments(e.View == DynamicSplitPanelView.Detail ? Guid.Empty : _folderid);
- }
- private void Preview_OnSizeChanged(object sender, SizeChangedEventArgs e)
- {
- //throw new NotImplementedException();
- }
- private void Documents_OnMileStoneSelected(JobDocumentSetMileStoneBlock block)
- {
- tasks.JobID = Master?.ID ?? Guid.Empty;
- tasks.MileStoneID = block?.ID ?? Guid.Empty;
- tasks.Refresh(false, true);
-
- if (block != null && block.Attachments > 0)
- {
- var id = block.ID;
- var files = new Client<JobDocumentSetMileStoneFile>().Query(
- new Filter<JobDocumentSetMileStoneFile>(x => x.EntityLink.ID).IsEqualTo(block.ID),
- new Columns<JobDocumentSetMileStoneFile>(x => x.ID)
- .Add(x => x.DocumentLink.ID)
- .Add(x => x.DocumentLink.FileName)
- .Add(x => x.Thumbnail),
- new SortOrder<JobDocumentSetMileStoneFile>(x => x.DocumentLink.FileName)
- );
- preview.ItemsSource = files.Rows
- .Select(r =>
- new Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>(
- r.Get<JobDocumentSetMileStoneFile, Guid>(c => c.ID),
- r.Get<JobDocumentSetMileStoneFile, String>(c => c.DocumentLink.FileName),
- r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail) != null
- ? String.IsNullOrWhiteSpace(block.Watermark)
- ? ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
- : ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
- .AsBitmap().WatermarkImage(block.Watermark, Color.LightSalmon)
- .AsBitmapImage()
- : ImageUtils.BitmapFromColor(Color.White, 256, 192, Color.Transparent)
- .WatermarkImage("No Preview\nAvailable", Color.LightGray).AsBitmapImage(),
- r.ToObject<JobDocumentSetMileStoneFile>()
- )
- ).ToList();
- }
- else
- preview.ItemsSource = new List<Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>>();
- }
- private void Tag_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Documents.DisciplineID = (Guid)(Discipline.SelectedValue ?? Guid.Empty);
- Documents.TypeID = (Guid)(Type.SelectedValue ?? Guid.Empty);
- Documents.CategoryID = (Guid)(Category.SelectedValue ?? Guid.Empty);
- Documents.AreaID = (Guid)(Area.SelectedValue ?? Guid.Empty);
- Documents.Refresh();
- }
- private void PDFDoubleClick(object sender, MouseButtonEventArgs e)
- {
- var image = (sender as ListViewItem).Content as Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>;
- if (image != null)
- {
- var viewer = new DocumentEditor(new JobDocumentSetMileStoneFile[] { image.Item4 });
- viewer.ButtonsVisible = false;
- viewer.ShowDialog();
- }
- }
- private void Search_OnKeyUp(object sender, KeyEventArgs e)
- {
- if ((e.Key == Key.Enter) || (e.Key == Key.Return) || (e.Key == Key.Tab) || (e.Key == Key.OemBackTab))
- {
- Documents.SearchText = Search.Text;
- Documents.Refresh();
- }
- }
- private void EditDocumentTags(JobDocumentSetTagType tagtype)
- {
- var editor = new JobDocumentSetTagEditor()
- {
- TagType = tagtype,
- JobID = Master?.ID ?? Guid.Empty
- };
- editor.Refresh(true, true);
- var window = new DynamicContentDialog(editor, false);
- window.Title = $"{tagtype} Document Tags";
- window.ShowDialog();
- LoadDocumentTags();
- }
- private void DisciplineButton_OnClick(object sender, RoutedEventArgs e)
- {
- EditDocumentTags(JobDocumentSetTagType.Discipline);
- }
- private void TypeButton_OnClick(object sender, RoutedEventArgs e)
- {
- EditDocumentTags(JobDocumentSetTagType.Type);
- }
- private void CategoryButton_OnClick(object sender, RoutedEventArgs e)
- {
- EditDocumentTags(JobDocumentSetTagType.Category);
- }
- private void ShowPreview_OnClick(object sender, RoutedEventArgs e)
- {
- PreviewColumn.Width = new GridLength(260, GridUnitType.Pixel);
- ShowPreview.Visibility = Visibility.Collapsed;
- }
- private void HidePreview_OnClick(object sender, RoutedEventArgs e)
- {
- PreviewColumn.Width = new GridLength(0, GridUnitType.Pixel);
- ShowPreview.Visibility = Visibility.Visible;
- }
- private void Tasks_OnOnChanged(object sender, EventArgs args)
- {
- Documents.Refresh();
- }
-
- }
- }
|