JobDocumentSetPanel.xaml.cs 11 KB

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