JobDocumentSetPanel.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. using System.Windows.Media.Imaging;
  9. using Comal.Classes;
  10. using InABox.Clients;
  11. using InABox.Core;
  12. using InABox.DynamicGrid;
  13. using InABox.WPF;
  14. using Inflector;
  15. using Color = System.Drawing.Color;
  16. namespace PRSDesktop
  17. {
  18. public partial class JobDocumentSetPanel : UserControl, IJobControl, IDataModelSource, IPanel<Job>
  19. {
  20. private enum Suppress
  21. {
  22. This
  23. }
  24. public Guid ParentID { get; set; }
  25. public JobPanelSettings Settings { get; set; }
  26. public JobDocumentSetPanel()
  27. {
  28. using (new EventSuppressor(Suppress.This))
  29. InitializeComponent();
  30. // Dictionary<String, BitmapImage> images = new Dictionary<string, BitmapImage>()
  31. // {
  32. // { "Sample", PRSDesktop.Resources.localfile.AsBitmapImage() },
  33. // { "Another File", PRSDesktop.Resources.tick.AsBitmapImage() }
  34. // };
  35. // preview.ItemsSource = images;
  36. }
  37. public string SectionName => "Job Document Set";
  38. public DataModel DataModel(Selection selection)
  39. {
  40. var ids = Documents.Data != null ? Documents.Data.ExtractValues<JobDocumentSet, Guid>(x => x.ID).ToArray() : new Guid[] { };
  41. return new AutoDataModel<JobDocumentSet>(new Filter<JobDocumentSet>(x => x.ID).InList(ids));
  42. }
  43. public event DataModelUpdateEvent OnUpdateDataModel;
  44. private bool GetAreas(CoreTable areas, ComboBox target) //, RowDefinition row)
  45. {
  46. using (new EventSuppressor(Suppress.This))
  47. {
  48. Dictionary<Guid, String> result = new Dictionary<Guid, String>()
  49. {
  50. { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" }
  51. };
  52. areas.IntoDictionary<JobITP, Guid, String>(result, x => x.ID,
  53. (r) => $"{r.Get<JobITP, String>(c => c.Code)}: {r.Get<JobITP, String>(c => c.Description)}");
  54. // row.Height = result.Count > 1
  55. // ? new GridLength(1, GridUnitType.Auto)
  56. // : new GridLength(0, GridUnitType.Pixel);
  57. var value = target.SelectedValue;
  58. target.ItemsSource = result;
  59. target.SelectedValue = value;
  60. return result.Count > 1;
  61. }
  62. }
  63. private bool GetTags(CoreTable tags, JobDocumentSetTagType type, ComboBox target) //, RowDefinition row)
  64. {
  65. using (new EventSuppressor(Suppress.This))
  66. {
  67. Dictionary<Guid, String> result = new Dictionary<Guid, String>()
  68. {
  69. { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" }
  70. };
  71. foreach (var tag in tags.Rows.Where(x => x.Get<JobDocumentSetTag, JobDocumentSetTagType>(x => x.Type).Equals(type)))
  72. result[tag.Get<JobDocumentSetTag, Guid>(c => c.ID)] = tag.Get<JobDocumentSetTag, String>(c => c.Description);
  73. // row.Height = result.Count > 1
  74. // ? new GridLength(1, GridUnitType.Auto)
  75. // : new GridLength(0, GridUnitType.Pixel);
  76. var value = target.SelectedValue;
  77. target.ItemsSource = result;
  78. target.SelectedValue = value;
  79. return result.Count > 1;
  80. }
  81. }
  82. public void Setup()
  83. {
  84. tasks.Refresh(true, false);
  85. }
  86. public void Shutdown()
  87. {
  88. }
  89. public void Refresh()
  90. {
  91. LoadDocumentTags();
  92. Folders.JobID = this.ParentID;
  93. Folders.Refresh();
  94. Documents.JobID = this.ParentID;
  95. Documents.Refresh();
  96. }
  97. private void LoadDocumentTags()
  98. {
  99. MultiQuery query = new MultiQuery();
  100. query.Add<JobDocumentSetTag>(
  101. new Filter<JobDocumentSetTag>(x => x.Job.ID).IsEqualTo(ParentID).Or(x => x.Job.ID).IsEqualTo(Guid.Empty),
  102. null,
  103. new SortOrder<JobDocumentSetTag>(x => x.Description)
  104. );
  105. query.Add<JobITP>(
  106. new Filter<JobITP>(x => x.Job.ID).IsEqualTo(ParentID),
  107. new Columns<JobITP>(x => x.ID).Add(x => x.Code).Add(x => x.Description),
  108. new SortOrder<JobITP>(x => x.Code)
  109. );
  110. query.Query();
  111. var tags = query.Get<JobDocumentSetTag>();
  112. /* Documents.DisciplineVisible = */
  113. GetTags(tags, JobDocumentSetTagType.Discipline, Discipline); //, DisciplineRow);
  114. /* Documents.TypeVisible = */
  115. GetTags(tags, JobDocumentSetTagType.Type, Type); //, TypeRow);
  116. /* Documents.CategoryVisible = */
  117. GetTags(tags, JobDocumentSetTagType.Category, Category); //, CategoryRow);
  118. /* Documents.AreaVisible = */
  119. GetAreas(query.Get<JobITP>(), Area); //, AreaRow);
  120. }
  121. public bool IsReady { get; set; }
  122. public void CreateToolbarButtons(IPanelHost host)
  123. {
  124. // Check In
  125. // Check Out
  126. // Issue
  127. }
  128. public Dictionary<string, object[]> Selected()
  129. {
  130. return new Dictionary<string, object[]>();
  131. }
  132. public void Heartbeat(TimeSpan time)
  133. {
  134. }
  135. private Guid _folderid = Guid.Empty;
  136. private void Folders_OnOnSelectItem(CoreTreeNode node)
  137. {
  138. _folderid = node != null ? node.ID : Guid.Empty;
  139. LoadDocuments(_folderid);
  140. }
  141. private void LoadDocuments(Guid folderid)
  142. {
  143. List<Guid> folders = new List<Guid>();
  144. this.Folders.Nodes.GetChildren(folders, folderid);
  145. Documents.FolderIDs = folders.ToArray();
  146. Documents.Refresh();
  147. }
  148. private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
  149. {
  150. LoadDocuments(e.View == DynamicSplitPanelView.Detail ? Guid.Empty : _folderid);
  151. }
  152. private void Preview_OnSizeChanged(object sender, SizeChangedEventArgs e)
  153. {
  154. //throw new NotImplementedException();
  155. }
  156. private void Documents_OnMileStoneSelected(JobDocumentSetMileStoneBlock block)
  157. {
  158. tasks.JobID = ParentID;
  159. tasks.MileStoneID = block?.ID ?? Guid.Empty;
  160. tasks.Refresh(false, true);
  161. if (block != null && block.Attachments > 0)
  162. {
  163. var id = block.ID;
  164. var files = new Client<JobDocumentSetMileStoneFile>().Query(
  165. new Filter<JobDocumentSetMileStoneFile>(x => x.EntityLink.ID).IsEqualTo(block.ID),
  166. new Columns<JobDocumentSetMileStoneFile>(x => x.ID)
  167. .Add(x => x.DocumentLink.ID)
  168. .Add(x => x.DocumentLink.FileName)
  169. .Add(x => x.Thumbnail),
  170. new SortOrder<JobDocumentSetMileStoneFile>(x => x.DocumentLink.FileName)
  171. );
  172. preview.ItemsSource = files.Rows
  173. .Select(r =>
  174. new Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>(
  175. r.Get<JobDocumentSetMileStoneFile, Guid>(c => c.ID),
  176. r.Get<JobDocumentSetMileStoneFile, String>(c => c.DocumentLink.FileName),
  177. r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail) != null
  178. ? String.IsNullOrWhiteSpace(block.Watermark)
  179. ? ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
  180. : ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
  181. .AsBitmap().WatermarkImage(block.Watermark, Color.LightSalmon)
  182. .AsBitmapImage()
  183. : ImageUtils.BitmapFromColor(Color.White, 256, 192, Color.Transparent)
  184. .WatermarkImage("No Preview\nAvailable", Color.LightGray).AsBitmapImage(),
  185. r.ToObject<JobDocumentSetMileStoneFile>()
  186. )
  187. ).ToList();
  188. }
  189. else
  190. preview.ItemsSource = new List<Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>>();
  191. }
  192. private void Tag_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  193. {
  194. Documents.DisciplineID = (Guid)(Discipline.SelectedValue ?? Guid.Empty);
  195. Documents.TypeID = (Guid)(Type.SelectedValue ?? Guid.Empty);
  196. Documents.CategoryID = (Guid)(Category.SelectedValue ?? Guid.Empty);
  197. Documents.AreaID = (Guid)(Area.SelectedValue ?? Guid.Empty);
  198. Documents.Refresh();
  199. }
  200. private void PDFDoubleClick(object sender, MouseButtonEventArgs e)
  201. {
  202. var image = (sender as ListViewItem).Content as Tuple<Guid, String, BitmapImage, JobDocumentSetMileStoneFile>;
  203. if (image != null)
  204. {
  205. var viewer = new DocumentEditor(new JobDocumentSetMileStoneFile[] { image.Item4 });
  206. viewer.ButtonsVisible = false;
  207. viewer.ShowDialog();
  208. }
  209. }
  210. private void Search_OnKeyUp(object sender, KeyEventArgs e)
  211. {
  212. if ((e.Key == Key.Enter) || (e.Key == Key.Return) || (e.Key == Key.Tab) || (e.Key == Key.OemBackTab))
  213. {
  214. Documents.SearchText = Search.Text;
  215. Documents.Refresh();
  216. }
  217. }
  218. private void EditDocumentTags(JobDocumentSetTagType tagtype)
  219. {
  220. var editor = new JobDocumentSetTagEditor()
  221. {
  222. TagType = tagtype,
  223. JobID = ParentID
  224. };
  225. editor.Refresh(true, true);
  226. var window = new DynamicContentDialog(editor, false);
  227. window.Title = $"{tagtype.ToString()} Document Tags";
  228. window.ShowDialog();
  229. LoadDocumentTags();
  230. }
  231. private void DisciplineButton_OnClick(object sender, RoutedEventArgs e)
  232. {
  233. EditDocumentTags(JobDocumentSetTagType.Discipline);
  234. }
  235. private void TypeButton_OnClick(object sender, RoutedEventArgs e)
  236. {
  237. EditDocumentTags(JobDocumentSetTagType.Type);
  238. }
  239. private void CategoryButton_OnClick(object sender, RoutedEventArgs e)
  240. {
  241. EditDocumentTags(JobDocumentSetTagType.Category);
  242. }
  243. private void ShowPreview_OnClick(object sender, RoutedEventArgs e)
  244. {
  245. PreviewColumn.Width = new GridLength(260, GridUnitType.Pixel);
  246. ShowPreview.Visibility = Visibility.Collapsed;
  247. }
  248. private void HidePreview_OnClick(object sender, RoutedEventArgs e)
  249. {
  250. PreviewColumn.Width = new GridLength(0, GridUnitType.Pixel);
  251. ShowPreview.Visibility = Visibility.Visible;
  252. }
  253. private void Tasks_OnOnChanged(IDynamicGrid sender)
  254. {
  255. Documents.Refresh();
  256. }
  257. private JobPanelSettings Tasks_OnGetJobPanelSettings()
  258. {
  259. return Settings;
  260. }
  261. }
  262. }