JobDocumentSetPanel.xaml.cs 11 KB

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