123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace PRS.Mobile
- {
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class KanbanList
- {
-
- private ICoreRepository _model;
- //private CoreObservableCollection<IKanbanShell> _itemssource = new CoreObservableCollection<IKanbanShell>();
- public ICoreRepository Model
- {
- get => _model;
- set
- {
- _model = value;
- RefreshData(false,true);
- }
- }
-
- public KanbanList()
- {
- _currentStatus = KanbanStatus.Open;
- InitializeComponent();
- ProgressVisible = true;
- // _tasks.ItemsSource = _itemssource;
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- _tasks.ItemsSource = _model.Items;
- }
- protected override void OnDisappearing()
- {
- _model.SelectNone();
- _tasks.ItemsSource = null;
- base.OnDisappearing();
- }
- private void RefreshData(bool force, bool async)
- {
- if (async)
- _model.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshList));
- else
- {
- _model.Refresh(force);
- RefreshList();
- }
- }
-
- private void RefreshList()
- {
- _model.Search((o) => FilterShell(o as IKanbanShell));
- _tasks.ItemsSource = null;
- _tasks.ItemsSource = _model.Items;
- //_itemssource.Clear();
- //_itemssource.ReplaceRange(_model.Items.OfType<IKanbanShell>().Where(FilterShell));
- _tasks.LastUpdated = _model.LastUpdated;
- ProgressVisible = false;
- }
- private String _currentfilter = "";
-
- private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
- {
- _currentfilter = args.Text;
- RefreshList();
- }
- private KanbanStatus _currentStatus;
- private bool FilterShell(IKanbanShell shell)
- {
- bool bOK = shell.Status == _currentStatus;
-
- bOK = bOK && (
- String.IsNullOrWhiteSpace(_currentfilter)
- || shell.Summary.ToUpper().Contains(_currentfilter.ToUpper())
- || shell.Number.ToString().ToUpper().Contains(_currentfilter.ToUpper())
- || shell.Title.ToUpper().Contains(_currentfilter.ToUpper())
- );
-
- return bOK;
- }
- private void _tasks_OnRefresh(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true,false);
- }
-
- private void Kanban_Clicked(object sender, EventArgs e)
- {
- if ((sender as MobileCard)?.BindingContext is IKanbanShell shell)
- {
- var editor = new KanbanEdit() { Item = shell };
- Navigation.PushAsync(editor);
- }
- }
-
- private void CheckBox_Changed(object sender, EventArgs e)
- {
- if ((sender as MobileCheckBox)?.BindingContext is KanbanShell shell)
- _model.ToggleSelection(shell);
- }
-
- private void SelectEmployee(IEnumerable<IKanbanShell> tasks)
- {
- ShowPopup(() => CreateEmployeeSelection("Select Employee", (employee) =>
- {
- foreach (var task in tasks)
- {
- task.EmployeeID = employee.ID;
- task.EmployeeName = employee.Name;
- }
- _model.SelectNone();
- RefreshList();
- }));
- }
-
- private async void ChangeStatus(IEnumerable<IKanbanShell> tasks)
- {
- var index = await MaterialDialog.Instance.SelectActionAsync(Enum.GetNames(typeof(KanbanStatus)));
- if (index > -1)
- {
- foreach (var task in tasks)
- task.Status = (KanbanStatus)index;
- _model.SelectNone();
- RefreshList();
- }
- }
-
- private View CreateEmployeeSelection(String caption, Action<EmployeeShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- CanSearch = false
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<EmployeeShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption})
- .EndUpdate();
- };
- selection.Refresh += (sender, args) => App.Data.Employees.Refresh(false);
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as EmployeeShell);
- DismissPopup();
- };
- selection.Load();
- return selection;
- }
-
- private void _reassign_OnClicked(object sender, EventArgs e)
- {
- SelectEmployee(SelectedItems());
- }
- private void _setstatus_OnClicked(object sender, EventArgs e)
- {
- ChangeStatus(SelectedItems());
- }
- private void _selectNone_OnClicked(object sender, EventArgs e)
- {
- _model.SelectNone();
- RefreshList();
- }
-
- private void _selectAll_OnClicked(object sender, EventArgs e)
- {
- _model.SelectAll();
- RefreshList();
- }
- private void _addtask_OnClicked(object sender, MobileMenuButtonClickedEventArgs args)
- {
- var shell = _model.AddItem() as IKanbanShell;
- shell.EmployeeID = App.Data.Me.ID;
- shell.DueDate = DateTime.Today;
- var editor = new KanbanEdit() { Item = shell };
- Navigation.PushAsync(editor);
- }
- private void _tabStrip_OnSelectionChanged(object sender, EventArgs e)
- {
- _currentStatus = (KanbanStatus)_tabStrip.SelectedItem.Index;
- RefreshList();
- }
- private void _selectionmenu_OnAppearing(object sender, EventArgs e)
- {
- bool anyselected = SelectedItems().Any();
- bool anyunselected = UnselectedItems().Any();
- _reassign.IsVisible = anyselected;
- _setstatus.IsVisible = anyselected;
- _selectAll.IsVisible = anyunselected;
- _selectNone.IsVisible = anyselected;
- _separator.IsVisible = (_reassign.IsVisible || _setstatus.IsVisible) && (_selectAll.IsVisible || _selectNone.IsVisible);
-
- }
- private IEnumerable<IKanbanShell> SelectedItems()
- {
- return _model.SelectedItems.OfType<IKanbanShell>();
- }
-
- private IEnumerable<IKanbanShell> UnselectedItems()
- {
- return _model.Items.OfType<IKanbanShell>().Except(_model.SelectedItems.OfType<IKanbanShell>());
- }
- }
- }
|