123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Reflection;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- 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 org.omg.CORBA;
- using Syncfusion.UI.Xaml.Kanban;
- using Color = System.Drawing.Color;
- namespace PRSDesktop
- {
- public class StatusTasksHeaderTimeConverter : IValueConverter
- {
- public static IEnumerable<TaskModel> Tasks { get; set; }
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (Tasks == null)
- return "0:00";
- var dataContext = value as ColumnTag;
- if (dataContext == null)
- return "0:00";
- var getter = dataContext.GetType().GetProperty("Column", BindingFlags.NonPublic | BindingFlags.Instance);
- if (getter == null)
- return "0:00";
- var column = (KanbanColumn)getter.GetValue(dataContext);
- if (column == null)
- return "0:00";
- double result = 0.0F;
- foreach (var kanban in Tasks.Where(x => Equals(x.Category, column.Categories)))
- result += kanban.EstimatedTime.TotalHours;
- return string.Format("{0:F2}", result);
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- /// <summary>
- /// Interaction logic for KanbanPanel.xaml
- /// </summary>
- public partial class TasksByStatusControlOld : UserControl, ITaskControl
- {
- private enum Suppress
- {
- This
- }
- private BitmapImage _attachimg = PRSDesktop.Resources.attachment.AsBitmapImage();
- private readonly ObservableCollection<EmployeeModel> _employeelist = new();
- private CoreTable _employees;
- public CoreTable _kanbans;
- private BitmapImage _lockimg = PRSDesktop.Resources.lock_sml.AsBitmapImage();
- private ObservableCollection<TaskModel> _models = new();
- private CoreTable _types;
- public List<string> CheckedKanbans = new();
- // CoreUtils.FullGuid => All Staff
- // Guid.Empty => Unallocated
- // Anything Else => Actual Staff Member
- private Guid EmployeeID = Guid.Empty;
- private Guid? MyID;
- private string MyName = "";
- private string searchtext = "";
- private Guid selectedtype = CoreUtils.FullGuid;
- public TasksByStatusControlOld()
- {
- using (new EventSuppressor(Suppress.This))
- InitializeComponent();
- }
- public string SectionName => "Tasks By Status";
- public DataModel DataModel(Selection selection)
- {
- var ids = SelectedModels().Select(x => Guid.Parse(x.ID)).ToArray();
- return new AutoDataModel<Kanban>(new Filter<Kanban>(x => x.ID).InList(ids));
- }
- private void ResizeColumns()
- {
- //if (!bResizeRequired)
- // return;
- using (var d = Dispatcher.DisableProcessing())
- {
- var CollapsedWidth = 50;
- var CollapsedColumns = 0;
- Array.ForEach(Kanban.Columns.ToArray(), x => { CollapsedColumns += x.IsExpanded ? 0 : 1; });
- if (Kanban.Columns.Count > 0 && CollapsedColumns != Kanban.Columns.Count)
- {
- var ColumnWidth = (Kanban.ActualWidth - CollapsedColumns * CollapsedWidth) / (Kanban.Columns.Count - CollapsedColumns) - 2;
- if (ColumnWidth != Kanban.ColumnWidth) Kanban.ColumnWidth = ColumnWidth;
- //bResizeRequired = false;
- }
- }
- }
- private void TaskMenu_Opened(object sender, RoutedEventArgs e)
- {
- Host.PopulateMenu(this, sender as ContextMenu);
- }
- private void Kanban_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
- }
- private void Kanban_CardDragStart(object sender, KanbanDragStartEventArgs e)
- {
- var models = SelectedModels(e.SelectedCard.Content as TaskModel);
- if (models.Any(x => x.Locked))
- e.IsCancel = true;
- }
- private void Kanban_CardDragEnd(object sender, KanbanDragEndEventArgs e)
- {
- using (new WaitCursor())
- {
- var target = e.TargetColumn.Categories;
- var models = SelectedModels(e.SelectedCard.Content as TaskModel).Where(x => !Equals(x.Category, target)).ToArray();
- if (!models.Any())
- return;
- var kanbans = Host.LoadKanbans(models, new Columns<Kanban>(x => x.ID, x => x.Category));
- foreach (var kanban in kanbans)
- kanban.Category = target;
- new Client<Kanban>().Save(kanbans, string.Format("Task Status Updated to {0}", target), (o, err) => { });
- foreach (var model in models)
- {
- model.Checked = false;
- model.Category = target;
- }
- FilterKanbans();
- }
- }
- private void Search_KeyUp(object sender, KeyEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(Search.Text) || e.Key == Key.Return)
- {
- searchtext = Search.Text;
- Refresh(true);
- }
- }
- private void TaskTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!IsReady || EventSuppressor.IsSet(Suppress.This))
- return;
- if (e.AddedItems.Count > 0)
- {
- var item = (KeyValuePair<Guid, string>)e.AddedItems[0];
- selectedtype = item.Key;
- }
- else
- {
- selectedtype = CoreUtils.FullGuid;
- }
- Host.KanbanSettings.StatusSettings.SelectedType = selectedtype;
- Host.SaveSettings();
- ReloadKanbans();
- }
- private void IncludeCompleted_Checked(object sender, RoutedEventArgs e)
- {
- if (!IsReady)
- return;
- Host.KanbanSettings.StatusSettings.IncludeCompleted = IncludeCompleted.IsChecked.Value;
- Host.SaveSettings();
- SetupColumns();
- ReloadKanbans();
- }
- private void IncludeObserved_Checked(object sender, RoutedEventArgs e)
- {
- if (!IsReady)
- return;
- Host.KanbanSettings.StatusSettings.IncludeObserved = IncludeObserved.IsChecked.Value;
- Host.SaveSettings();
- ReloadKanbans();
- }
- private void IncludeLocked_Checked(object sender, RoutedEventArgs e)
- {
- if (!IsReady)
- return;
- Host.KanbanSettings.StatusSettings.IncludeLocked = IncludeLocked.IsChecked.Value;
- Host.SaveSettings();
- ReloadKanbans();
- }
- private void ViewType_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (Kanban != null)
- Kanban.CardTemplate = ViewType.SelectedIndex > 0
- ? Resources["CompactKanban"] as DataTemplate
- : Resources["FullKanban"] as DataTemplate;
- if (!IsReady || EventSuppressor.IsSet(Suppress.This))
- return;
- Host.KanbanSettings.StatusSettings.CompactView = ViewType.SelectedIndex > 0;
- Host.SaveSettings();
- }
- private static bool UpdatingEmployees = false;
- private void Employees_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (UpdatingEmployees || EventSuppressor.IsSet(Suppress.This))
- return;
- if (e.AddedItems.Count == 0)
- {
- EmployeeID = Guid.Empty;
- }
- else
- {
- var model = _employeelist[Employees.SelectedIndex];
- EmployeeID = model.ID;
- }
- CheckedKanbans.Clear();
- if (IsReady)
- Refresh(true);
- }
- private void Export_Click(object sender, RoutedEventArgs e)
- {
- var form = new DynamicExportForm(typeof(Kanban), _kanbans.Columns.Select(x => x.ColumnName));
- if (form.ShowDialog() != true)
- return;
- var export = new Client<Kanban>().Query(
- GetKanbanFilter(),
- new Columns<Kanban>(form.Fields),
- LookupFactory.DefineSort<Kanban>()
- );
- var employee = "Tasks for All Staff";
- if (EmployeeID != CoreUtils.FullGuid)
- {
- if (EmployeeID == Guid.Empty)
- {
- employee = "Unallocated Tasks";
- }
- else
- {
- var model = _employeelist.FirstOrDefault(x => x.ID.Equals(EmployeeID));
- employee = model == null ? "Tasks for (Unknown)" : "Tasks for " + (model.ID == MyID ? MyName : model.Name);
- }
- }
- ExcelExporter.DoExport<Kanban>(
- export,
- string.Format(
- "{0} ({1:dd-MMM-yy})",
- employee,
- DateTime.Today
- )
- );
- }
- #region ITaskControl Support
- public bool IsReady { get; set; }
- public ITaskHost Host { get; set; }
- public KanbanViewType KanbanViewType => KanbanViewType.Status;
- public IEnumerable<TaskModel> SelectedModels(TaskModel sender = null)
- {
- var result = _models.Where(x => x.Checked).ToList();
- if (sender != null && !result.Contains(sender))
- result.Add(sender);
- return result;
- }
- #endregion
- #region Setup
- public void Setup()
- {
- using (new EventSuppressor(Suppress.This))
- {
- SetupToolbar();
- SetupColumns();
- SetupData();
- SetupKanbanTypesLookup(false);
- SetupMyEmployee();
- SetupEmployeeList();
- }
- }
- private void SetupMyEmployee()
- {
- var row = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.UserLink.ID) == ClientFactory.UserGuid);
- if (row != null)
- {
- MyID = row.Get<Employee, Guid>(c => c.ID);
- MyName = row.Get<Employee, string>(x => x.Name);
- }
- }
- private void SetupEmployeeList()
- {
- IEnumerable<CoreRow> active = null;
- var anonymous = PRSDesktop.Resources.anonymous.AsBitmapImage();
- if (Security.IsAllowed<CanViewOthersTasks>())
- {
- active = _employees.Rows.Where(r =>
- r.Get<Employee, bool>(x => x.CanAllocateTasks) && (r.Get<Employee, DateTime>(x => x.FinishDate).IsEmpty() ||
- r.Get<Employee, DateTime>(x => x.FinishDate) > DateTime.Today));
- _employeelist.Add(new EmployeeModel(CoreUtils.FullGuid, "All Staff", Guid.Empty, PRSDesktop.Resources.everyone.AsBitmapImage()));
- _employeelist.Add(new EmployeeModel(Guid.Empty, "Unallocated", Guid.Empty, null));
- }
- else
- {
- active = _employees.Rows.Where(r => r.Get<Employee, Guid>(c => c.UserLink.ID).Equals(ClientFactory.UserGuid));
- }
- EmployeeModel selected = null;
- foreach (var row in active)
- {
- var id = row.Get<Employee, Guid>(x => x.ID);
- var userid = row.Get<Employee, Guid>(x => x.UserLink.ID);
- var thumbnailid = row.Get<Employee, Guid>(x => x.Thumbnail.ID);
- var name = userid.Equals(ClientFactory.UserGuid) ? "My Tasks" : row.Get<Employee, string>(x => x.Name);
- var model = new EmployeeModel(id, name, thumbnailid, anonymous);
- if (userid.Equals(ClientFactory.UserGuid))
- {
- _employeelist.Insert(0, model);
- selected = model;
- }
- else
- {
- _employeelist.Add(model);
- }
- }
- if (Security.IsAllowed<CanViewOthersTasks>())
- {
- EmployeeListColumn.Width = new GridLength(1.0F, GridUnitType.Auto);
- var thumbnails = active
- .Select(r => r.EntityLinkID<Employee, ImageDocumentLink>(x => x.Thumbnail) ?? Guid.Empty)
- .Where(x => x != Guid.Empty).ToArray();
- Employees.ItemsSource = _employeelist;
- Employees.SelectedItem = _employeelist.First();
- EmployeeID = _employeelist.First().ID;
- if (thumbnails.Any())
- new Client<Document>().Query(
- new Filter<Document>(x => x.ID).InList(thumbnails),
- new Columns<Document>(x => x.ID, x => x.Data),
- null,
- (data, error) =>
- {
- if (data != null)
- ProcessThumbnails(data);
- }
- );
- }
- else
- {
- EmployeeListColumn.Width = new GridLength(0.0F, GridUnitType.Pixel);
- Employees.ItemsSource = _employeelist;
- Employees.SelectedItem = _employeelist.First();
- EmployeeID = _employeelist.First().ID;
- }
- }
- private void ProcessThumbnails(CoreTable data)
- {
- Dispatcher.Invoke(() =>
- {
- foreach (var row in data.Rows)
- {
- var id = row.Get<Document, Guid>(x => x.ID);
- var model = _employeelist.FirstOrDefault(x => x.ThumbnailID.Equals(id));
- if (model != null)
- {
- model.Image = new BitmapImage();
- model.Image.LoadImage(row.Get<Document, byte[]>(x => x.Data));
- }
- }
- UpdatingEmployees = true;
- Employees.ItemsSource = null;
- Employees.ItemsSource = _employeelist;
- Employees.SelectedItem = _employeelist.First();
- EmployeeID = _employeelist.First().ID;
- UpdatingEmployees = false;
- });
- }
- private void SetupKanbanTypesLookup(bool reload)
- {
- if (ClientFactory.IsSupported<KanbanType>())
- {
- if (reload)
- {
- _types = new Client<KanbanType>().Query(
- new Filter<KanbanType>(x => x.Hidden).IsEqualTo(false),
- new Columns<KanbanType>(x => x.ID, x => x.Description),
- new SortOrder<KanbanType>(x => x.Description)
- );
- }
- var tasktypes = new Dictionary<Guid, string>
- {
- { CoreUtils.FullGuid, "All Types" },
- { Guid.Empty, "Unallocated Types" }
- };
- _types.IntoDictionary<KanbanType, Guid, string>(tasktypes, x => x.ID, row => row.Get<KanbanType, string>(x => x.Description));
- TaskTypes.ItemsSource = tasktypes;
- if (tasktypes.ContainsKey(Host.KanbanSettings.StatusSettings.SelectedType))
- TaskTypes.SelectedValue = Host.KanbanSettings.StatusSettings.SelectedType;
- else
- TaskTypes.SelectedValue = CoreUtils.FullGuid;
- TaskTypesLabel.Visibility = Visibility.Visible;
- TaskTypes.Visibility = Visibility.Visible;
- }
- else
- {
- TaskTypesLabel.Visibility = Visibility.Collapsed;
- TaskTypes.Visibility = Visibility.Collapsed;
- }
- }
- private void SetupToolbar()
- {
- IncludeCompleted.Visibility = Security.IsAllowed<CanHideTaskCompletedColumn>() ? Visibility.Visible : Visibility.Collapsed;
- IncludeCompleted.IsChecked = IncludeCompleted.Visibility == Visibility.Visible ? Host.KanbanSettings.StatusSettings.IncludeCompleted : true;
- IncludeObserved.IsChecked = Host.KanbanSettings.StatusSettings.IncludeObserved;
- ViewType.SelectedIndex = Host.KanbanSettings.StatusSettings.CompactView ? 1 : 0;
- }
- private void SetupColumns()
- {
- Kanban.Columns.Clear();
- var indicatorColorPalette = new IndicatorColorPalette();
- indicatorColorPalette.Add(new ColorMapping { Key = "Red", Color = Colors.LightSalmon });
- indicatorColorPalette.Add(new ColorMapping { Key = "Orange", Color = Colors.Orange });
- indicatorColorPalette.Add(new ColorMapping { Key = "Yellow", Color = Colors.LightYellow });
- indicatorColorPalette.Add(new ColorMapping { Key = "Green", Color = Colors.LightGreen });
- Kanban.IndicatorColorPalette = indicatorColorPalette;
- Kanban.Columns.Add(new KanbanColumn
- {
- Categories = "Open",
- Title = "To Do"
- });
- Kanban.Columns.Add(new KanbanColumn
- {
- Categories = "In Progress",
- Title = "In Progress"
- });
- Kanban.Columns.Add(new KanbanColumn
- {
- Categories = "Waiting",
- Title = "Waiting for Others"
- });
- if (Host.KanbanSettings.StatusSettings.IncludeCompleted)
- Kanban.Columns.Add(new KanbanColumn
- {
- Categories = "Complete",
- Title = "Completed"
- });
- Kanban.InvalidateVisual();
- foreach (var column in Kanban.Columns)
- {
- var menu = new ContextMenu();
- menu.Tag = column;
- var item = new MenuItem { Header = "New Task" };
- item.Click += CreateTask;
- menu.Items.Add(item);
- menu.Items.Add(new Separator());
- item = new MenuItem { Header = "Select All " + column.Title + " Tasks", Tag = column };
- item.Click += SelectAll_Click;
- menu.Items.Add(item);
- item = new MenuItem { Header = "Unselect All " + column.Title + " Tasks", Tag = column };
- item.Click += UnSelectAll_Click;
- menu.Items.Add(item);
- column.ContextMenu = menu;
- }
- Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
- }
- private void SetupData()
- {
- var query = new MultiQuery();
- query.Add(
- null,
- new Columns<Employee>(x => x.ID, x => x.Name, x => x.Thumbnail.ID, x => x.CanAllocateTasks, x => x.Email, x => x.Mobile,
- x => x.FinishDate, x => x.UserLink.ID),
- new SortOrder<Employee>(x => x.Name)
- );
- if (ClientFactory.IsSupported<KanbanType>())
- query.Add(
- new Filter<KanbanType>(x => x.Hidden).IsEqualTo(false),
- new Columns<KanbanType>(x => x.ID, x => x.Description),
- new SortOrder<KanbanType>(x => x.Description)
- );
- query.Query();
- _employees = query.Get<Employee>();
- _types = ClientFactory.IsSupported<KanbanType>()
- ? query.Get<KanbanType>()
- : null;
- }
- #endregion
- #region Refresh / Reload
- private Filter<T> GetSearchFilter<T>(Expression<Func<T, object>> expression) where T : Entity, new()
- {
- Filter<T> result = null;
- var comps = searchtext.Trim().Split(' ');
- foreach (var comp in comps)
- result = result == null ? new Filter<T>(expression).Contains(comp) : result.And(expression).Contains(comp);
- return result;
- }
- private Filter<KanbanSubscriber> GetKanbanSubscriberFilter()
- {
- var filter = new Filter<KanbanSubscriber>(x => x.Kanban.Closed).IsEqualTo(DateTime.MinValue);
- if (Host.Job != null)
- {
- if (Host.Job.ID != Guid.Empty)
- filter = filter.And(x => x.Kanban.JobLink.ID).IsEqualTo(Host.Job.ID);
- else
- filter = filter.And(x => x.Kanban.JobLink.ID).None();
- }
- // All Tasks (EmployeeID.HasValue == false) or Unallocated (EmployeeID = Guid.Empty) are retrieved directly from the Kanban Table
- // so if we are here, we can assume that we are pulling subscriber data
- var empfilter = new Filter<KanbanSubscriber>(x => x.Employee.ID).IsEqualTo(EmployeeID);
- filter.Ands.Add(empfilter);
- if (EmployeeID != MyID)
- filter = filter.And(x => x.Kanban.Private).IsEqualTo(false);
- //if (!includeobserved)
- // filter = filter.And(new Filter<KanbanSubscriber>(x => x.Assignee).IsEqualTo(true).Or(x => x.Manager).IsEqualTo(true));
- //if (!includecompleted)
- // filter = filter.And(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue);
- //if (selectedtype != CoreUtils.FullGuid)
- // filter = filter.And(x => x.Kanban.Type.ID).IsEqualTo(selectedtype);
- if (!string.IsNullOrWhiteSpace(searchtext))
- {
- var search = GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.Name);
- search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.JobNumber));
- search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Summary));
- search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Title));
- search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.ManagerLink.Name));
- search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.EmployeeLink.Name));
- if (int.TryParse(searchtext.Trim(), out var tasknumber))
- search.Ors.Add(new Filter<KanbanSubscriber>(x => x.Kanban.Number).IsEqualTo(tasknumber));
- filter.Ands.Add(search);
- }
- return filter;
- }
- private Filter<Kanban> GetKanbanFilter()
- {
- var filter = new Filter<Kanban>(x => x.Closed).IsEqualTo(DateTime.MinValue);
- if (Host.Job != null)
- {
- if (Host.Job.ID != Guid.Empty)
- filter = filter.And(x => x.JobLink.ID).IsEqualTo(Host.Job.ID);
- else
- filter = filter.And(x => x.JobLink.ID).None();
- }
- if (EmployeeID != CoreUtils.FullGuid)
- {
- if (EmployeeID != Guid.Empty)
- {
- var empfilter = new Filter<Kanban>(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID).Or(x => x.ManagerLink.ID).IsEqualTo(EmployeeID);
- filter.Ands.Add(empfilter);
- }
- else
- {
- filter = filter.And(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID);
- }
- }
- if (EmployeeID != MyID)
- filter = filter.And(x => x.Private).IsEqualTo(false);
- //if (!includecompleted)
- // filter = filter.And(x => x.Completed).IsEqualTo(DateTime.MinValue);
- //if (selectedtype != CoreUtils.FullGuid)
- // filter = filter.And(x => x.Type.ID).IsEqualTo(selectedtype);
- return filter;
- }
- public void Refresh(bool resetselection)
- {
- Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = Cursors.Wait; });
- if (EmployeeID != CoreUtils.FullGuid && EmployeeID != Guid.Empty)
- {
- _kanbans = new Client<KanbanSubscriber>().Query(
- GetKanbanSubscriberFilter(),
- new Columns<KanbanSubscriber>
- (
- x => x.Kanban.ID,
- x => x.Kanban.DueDate,
- x => x.Kanban.Completed,
- //x => x.Kanban.Description,
- x => x.Kanban.Summary,
- x => x.Kanban.Category,
- x => x.Kanban.EmployeeLink.ID,
- x => x.Kanban.ManagerLink.ID,
- x => x.Kanban.Notes,
- x => x.Kanban.Title,
- x => x.Kanban.JobLink.ID,
- x => x.Kanban.JobLink.JobNumber,
- x => x.Kanban.JobLink.Name,
- x => x.Kanban.Type.ID,
- x => x.Kanban.Type.Code,
- x => x.Kanban.Number,
- x => x.Kanban.Attachments,
- x => x.Kanban.Locked
- ),
- new SortOrder<KanbanSubscriber>(x => x.Kanban.DueDate) { Direction = SortDirection.Ascending }
- );
- foreach (var column in _kanbans.Columns)
- column.ColumnName = column.ColumnName.Replace("Kanban.", "");
- }
- else
- {
- _kanbans = new Client<Kanban>().Query(
- GetKanbanFilter(),
- new Columns<Kanban>
- (
- x => x.ID,
- x => x.DueDate,
- x => x.Completed,
- //x => x.Description,
- x => x.Summary,
- x => x.Category,
- x => x.EmployeeLink.ID,
- x => x.ManagerLink.ID,
- x => x.Notes,
- x => x.Title,
- x => x.JobLink.ID,
- x => x.JobLink.JobNumber,
- x => x.JobLink.Name,
- x => x.Type.ID,
- x => x.Type.Code,
- x => x.Number,
- x => x.Attachments,
- x => x.Locked
- ),
- new SortOrder<Kanban>(x => x.DueDate) { Direction = SortDirection.Ascending }
- );
- }
- ReloadKanbans();
- Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = null; });
- }
- private void ReloadKanbans()
- {
- //SetupColumns();
- //ResizeColumns();
- _models = new ObservableCollection<TaskModel>();
- foreach (var row in _kanbans.Rows)
- try
- {
- var empid = row.Get<IKanban, Guid>(e => e.EmployeeLink.ID);
- var mgrid = row.EntityLinkID<IKanban, EmployeeLink>(x => x.ManagerLink) ?? Guid.Empty;
- var completed = row.Get<IKanban, DateTime>(e => e.Completed);
- var locked = row.Get<IKanban, bool>(e => e.Locked);
- var type = row.Get<IKanban, Guid>(e => e.Type.ID);
- var category = row.Get<IKanban, string>(x => x.Category);
- if (string.IsNullOrWhiteSpace(category))
- category = "Open";
- var bLockedOK = Host.KanbanSettings.StatusSettings.IncludeLocked || locked == false;
- var bObserveOK = EmployeeID == CoreUtils.FullGuid || Host.KanbanSettings.StatusSettings.IncludeObserved || empid == EmployeeID || mgrid == EmployeeID;
- var bCompleteOK = Host.KanbanSettings.StatusSettings.IncludeCompleted || completed.IsEmpty();
- var bTypeOK = selectedtype == CoreUtils.FullGuid || type == selectedtype;
- if (bLockedOK && bCompleteOK && bObserveOK && bTypeOK)
- {
- var model = new TaskModel();
- var EmployeeEntry = _employeelist.Where(x => x.ID.Equals(empid)).FirstOrDefault();
- var empimg = EmployeeEntry?.Image;
- var ManagerEntry = _employeelist.Where(x => x.ID.Equals(mgrid)).FirstOrDefault();
- //var description = row.Get<IKanban, String>(x => x.Summary);
- //if (String.IsNullOrWhiteSpace(description))
- // description = String.Join("\r\n", row.Get<IKanban, String[]>(x => x.Notes)).Split(new String[] { "===============" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
- //if (String.IsNullOrWhiteSpace(description))
- // description = CoreUtils.StripHTML(row.Get<IKanban, String>(x => x.Description));
- //if (String.IsNullOrWhiteSpace(description))
- // description = "";
- var job = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
- model.Title = row.Get<IKanban, string>(x => x.Title);
- model.ID = row.Get<IKanban, Guid>(x => x.ID).ToString();
- model.Description = row.Get<IKanban, string>(x => x.Summary) ?? "";
- model.Category = category;
- var color = EmployeeID == Guid.Empty || empid == EmployeeID || EmployeeID == CoreUtils.FullGuid
- ? TaskModel.KanbanColor(
- row.Get<IKanban, DateTime>(x => x.DueDate),
- row.Get<IKanban, DateTime>(x => x.Completed))
- : mgrid == EmployeeID
- ? Color.Silver
- : Color.Plum;
- if (row.Get<IKanban, bool>(x => x.Locked))
- color = color.MixColors(0.5F, Color.White);
- model.ColorKey = ImageUtils.ColorToString(color);
- model.Image = empimg;
- model.ImageURL = null;
- model.Attachments = row.Get<IKanban, int>(x => x.Attachments) > 0; // ? _attachimg : null;
- model.DueDate = row.Get<IKanban, DateTime>(x => x.DueDate);
- model.CompletedDate = row.Get<IKanban, DateTime>(x => x.Completed);
- model.Locked = row.Get<IKanban, bool>(x => x.Locked); // ? _lockimg : null;
- var notes = new List<List<string>> { new() };
- if ((row.Get<IKanban, string[]>(x => x.Notes) != null))
- {
- foreach (var line in row.Get<IKanban, string[]>(x => x.Notes))
- {
- if (line == "===================================")
- {
- notes.Add(new());
- }
- else
- {
- notes.Last().Add(line);
- }
- }
- model.Notes = string.Join("\n===================================\n", notes.Reverse<List<string>>().Select(x => string.Join('\n', x)));
- }
- model.EmployeeID = empid;
- model.ManagerID = mgrid;
- var sEmp = "";
- if (empid != EmployeeID)
- {
- if (!Entity.IsEntityLinkValid<IKanban, EmployeeLink>(x => x.EmployeeLink, row))
- {
- sEmp = "Unallocated";
- }
- else
- {
- var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(empid));
- sEmp = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
- }
- }
- var sMgr = "";
- if (mgrid != EmployeeID)
- if (mgrid != Guid.Empty)
- {
- var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(mgrid));
- sMgr = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
- }
- if (!string.IsNullOrEmpty(sEmp))
- {
- if (!string.IsNullOrWhiteSpace(sMgr) && !string.Equals(sMgr, sEmp))
- model.AssignedTo = string.Format("Assigned to {0} by {1}", sEmp, sMgr);
- else
- model.AssignedTo = string.Format("Assigned to {0} ", sEmp);
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(sMgr))
- model.AssignedTo = string.Format("Allocated by {0} ", sMgr);
- }
- //model.AssignedTo = String.Format("M: {0} / E: {1}", sMgr, sEmp);
- model.JobID = row.Get<IKanban, Guid>(x => x.JobLink.ID);
- model.JobNumber = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
- if (string.IsNullOrWhiteSpace(model.JobNumber))
- model.JobNumber = "";
- model.JobName = row.Get<IKanban, string>(x => x.JobLink.Name);
- model.Checked = CheckedKanbans.Contains(row.Get<IKanban, Guid>(x => x.ID).ToString());
- model.Type = new KanbanType
- {
- ID = row.Get<IKanban, Guid>(x => x.Type.ID),
- Code = row.Get<IKanban, string>(x => x.Type.Code)
- };
- model.Number = row.Get<IKanban, int>(x => x.Number);
- _models.Add(model);
- }
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
- }
- StatusTasksHeaderTimeConverter.Tasks = _models;
- FilterKanbans();
- }
- private void FilterKanbans()
- {
- Progress.ShowModal("Loading", (progress) =>
- {
- Dispatcher.BeginInvoke(() => { Progress.Show("Loading"); });
- if (JobFilterID == Guid.Empty)
- {
- var list = _models
- .Where(x => x.Search(Search.Text.Split()))
- .OrderBy(x => x.EmployeeID == EmployeeID ? 0 : 1).ThenBy(x => x.DueDate);
- Dispatcher.BeginInvoke(() => { Kanban.ItemsSource = list; });
- }
- else
- {
- var list = _models
- .Where(x => x.Search(Search.Text.Split()) && x.JobSearch(JobFilterID))
- .OrderBy(x => x.EmployeeID == EmployeeID ? 0 : 1).ThenBy(x => x.DueDate);
- Dispatcher.BeginInvoke(() => { Kanban.ItemsSource = list; });
- }
- Task.Run(() =>
- {
- Thread.Sleep(500);
- Dispatcher.BeginInvoke(() =>
- {
- Progress.Close();
- });
- });
- });
- }
- #endregion
- private void TaskTypesLabel_OnClick(object sender, RoutedEventArgs e)
- {
- var list = new MasterList(typeof(KanbanType));
- list.ShowDialog();
- SetupKanbanTypesLookup(true);
- }
- private void JobFilterBtn_OnClick(object sender, RoutedEventArgs e)
- {
- if (JobFilterID != Guid.Empty)
- {
- JobFilterBtn.Content = "Filter Job";
- JobFilterID = Guid.Empty;
- FilterKanbans();
- return;
- }
- var window = new ThemableWindow();
- var grid = new JobGrid();
- grid.Reconfigure(options =>
- {
- options.Remove(DynamicGridOption.EditRows);
- options.Remove(DynamicGridOption.DeleteRows);
- options.Remove(DynamicGridOption.AddRows);
- options.Remove(DynamicGridOption.MultiSelect);
- options.Remove(DynamicGridOption.ExportData);
- options.Remove(DynamicGridOption.ImportData);
- });
- grid.OnSelectItem += (object sender, DynamicGridSelectionEventArgs e) =>
- {
- if ((sender as JobGrid).SelectedRows.Count() == 0)
- return;
- else
- {
- var item = (sender as JobGrid).SelectedRows[0];
- AddJobFilter(item);
- window.Close();
- }
- };
- grid.Refresh(true, true);
- window.Content = grid;
- window.ShowDialog();
- }
- Guid JobFilterID = Guid.Empty;
- private void AddJobFilter(CoreRow item)
- {
- JobFilterID = item.Get<Job, Guid>(x => x.ID);
- JobFilterBtn.Content = item.Get<Job, string>(x => x.JobNumber) + " (click to cancel)";
- FilterKanbans();
- }
- }
- }
|