|
|
@@ -1,4 +1,13 @@
|
|
|
-using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Media;
|
|
|
+using Comal.Classes;
|
|
|
+using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using CommunityToolkit.Mvvm.Input;
|
|
|
+using InABox.Avalonia;
|
|
|
+using InABox.Avalonia.Components;
|
|
|
+using InABox.Avalonia.Dialogs;
|
|
|
+using InABox.Core;
|
|
|
+using PRS.Avalonia.Components;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
@@ -12,5 +21,224 @@ internal partial class TaskEditViewModel : ModuleViewModel
|
|
|
public override string Title => "Task Details";
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private IKanbanShell? _shell;
|
|
|
+ private IKanbanShell _shell = null!;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _canEditDescription;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private KanbanTypeModel _kanbanTypes;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private EmployeeModel _employees;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private int _selectedTab;
|
|
|
+
|
|
|
+ private AvaloniaMenuItem SaveButton;
|
|
|
+ private AvaloniaMenuItem ShareButton;
|
|
|
+ private AvaloniaMenuItem AddNoteButton;
|
|
|
+ private AvaloniaMenuItem ImageMenuButton;
|
|
|
+ private AvaloniaMenuItem NewFormButton;
|
|
|
+
|
|
|
+ public TaskEditViewModel()
|
|
|
+ {
|
|
|
+ SaveButton = new AvaloniaMenuItem(Images.save, Save) { IsVisible = false };
|
|
|
+ ShareButton = new AvaloniaMenuItem(Images.share, () =>
|
|
|
+ {
|
|
|
+ var menu = new CoreMenu<IImage>();
|
|
|
+ menu.AddItem("Email", SendEmail);
|
|
|
+ return menu;
|
|
|
+ }) { IsVisible = false };
|
|
|
+ AddNoteButton = new AvaloniaMenuItem(Images.plus, AddNote) { IsVisible = false };
|
|
|
+ ImageMenuButton = new AvaloniaMenuItem(Images.plus, () =>
|
|
|
+ {
|
|
|
+ var menu = new CoreMenu<IImage>();
|
|
|
+ menu.AddItem("Take Photo", TakePhoto);
|
|
|
+ menu.AddItem("Browse Library", BrowseLibrary);
|
|
|
+ return menu;
|
|
|
+ }) { IsVisible = false };
|
|
|
+ NewFormButton = new AvaloniaMenuItem(Images.plus, NewForm) { IsVisible = false };
|
|
|
+ PrimaryMenu.Add(SaveButton);
|
|
|
+ PrimaryMenu.Add(ShareButton);
|
|
|
+ PrimaryMenu.Add(AddNoteButton);
|
|
|
+ PrimaryMenu.Add(ImageMenuButton);
|
|
|
+ PrimaryMenu.Add(NewFormButton);
|
|
|
+
|
|
|
+ KanbanTypes = new KanbanTypeModel(DataAccess,
|
|
|
+ () => new Filter<KanbanType>().All(),
|
|
|
+ () => DefaultCacheFileName<KanbanTypeShell>());
|
|
|
+ Employees = Repositories.Employees();
|
|
|
+ }
|
|
|
+
|
|
|
+ partial void OnSelectedTabChanged(int value)
|
|
|
+ {
|
|
|
+ Changed();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> TakePhoto()
|
|
|
+ {
|
|
|
+ await MessageDialog.ShowMessage("Unimplemented");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> BrowseLibrary()
|
|
|
+ {
|
|
|
+ await MessageDialog.ShowMessage("Unimplemented");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> NewForm()
|
|
|
+ {
|
|
|
+ await MessageDialog.ShowMessage("Unimplemented");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AddNote()
|
|
|
+ {
|
|
|
+ Navigation.Navigate<NotesPageViewModel>(model =>
|
|
|
+ {
|
|
|
+ model.Confirm = note =>
|
|
|
+ {
|
|
|
+ Shell.Notes = Shell.Notes.Append(note).ToArray();
|
|
|
+ Changed();
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> SendEmail()
|
|
|
+ {
|
|
|
+ await MessageDialog.ShowMessage("Unimplemented");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> Save()
|
|
|
+ {
|
|
|
+ await MessageDialog.ShowMessage("Unimplemented");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override Task<TimeSpan> OnRefresh()
|
|
|
+ {
|
|
|
+ CanEditDescription = Shell.ManagerID == Repositories.Me.ID;
|
|
|
+ return Task.FromResult(TimeSpan.Zero);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Changed()
|
|
|
+ {
|
|
|
+ var changed = Shell.IsChanged();
|
|
|
+ SaveButton.IsVisible = changed;
|
|
|
+ ShareButton.IsVisible = !changed && SelectedTab == 0;
|
|
|
+ AddNoteButton.IsVisible = SelectedTab == 1;
|
|
|
+ ImageMenuButton.IsVisible = SelectedTab == 2;
|
|
|
+ NewFormButton.IsVisible = SelectedTab == 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private async Task SelectJob()
|
|
|
+ {
|
|
|
+ var job = (await SelectionViewModel.ExecutePopup<JobShell>(model =>
|
|
|
+ {
|
|
|
+ model.Columns.BeginUpdate()
|
|
|
+ .Add(new AvaloniaDataGridTextColumn<JobShell>
|
|
|
+ {
|
|
|
+ Column = x => x.JobNumber,
|
|
|
+ Caption = "Number",
|
|
|
+ Width = GridLength.Auto
|
|
|
+ })
|
|
|
+ .Add(new AvaloniaDataGridTextColumn<JobShell>
|
|
|
+ {
|
|
|
+ Column = x => x.Name,
|
|
|
+ Caption = "Name",
|
|
|
+ Width = GridLength.Star
|
|
|
+ })
|
|
|
+ .EndUpdate();
|
|
|
+ model.AddFilters(Repositories.Jobs.AvailableFilters.Select(x => x.Name).NotNull());
|
|
|
+ }, args =>
|
|
|
+ {
|
|
|
+ Repositories.Jobs.SelectFilter(args.Filter);
|
|
|
+ return Repositories.Jobs.Refresh(args.Force);
|
|
|
+ }))?.FirstOrDefault();
|
|
|
+ if(job is not null)
|
|
|
+ {
|
|
|
+ Shell.JobID = job.ID;
|
|
|
+ Shell.JobNumber = job.JobNumber;
|
|
|
+ Shell.JobName = job.Name;
|
|
|
+ Changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private async Task SelectType()
|
|
|
+ {
|
|
|
+ var type = (await SelectionViewModel.ExecutePopup<KanbanTypeShell>(model =>
|
|
|
+ {
|
|
|
+ model.Columns.BeginUpdate()
|
|
|
+ .Add(new AvaloniaDataGridTextColumn<KanbanTypeShell>
|
|
|
+ {
|
|
|
+ Column = x => x.Description,
|
|
|
+ Caption = "Type",
|
|
|
+ Width = GridLength.Star
|
|
|
+ })
|
|
|
+ .EndUpdate();
|
|
|
+ }, args =>
|
|
|
+ {
|
|
|
+ return KanbanTypes.Refresh(args.Force);
|
|
|
+ }))?.FirstOrDefault();
|
|
|
+ if(type is not null)
|
|
|
+ {
|
|
|
+ Shell.TypeID = type.ID;
|
|
|
+ Shell.TypeName = type.Description;
|
|
|
+ Changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private async Task SelectEmployee()
|
|
|
+ {
|
|
|
+ var employee = (await SelectionViewModel.ExecutePopup<EmployeeShell>(model =>
|
|
|
+ {
|
|
|
+ model.Columns.BeginUpdate()
|
|
|
+ .Add(new AvaloniaDataGridTextColumn<EmployeeShell>
|
|
|
+ {
|
|
|
+ Column = x => x.Name,
|
|
|
+ Caption = "Employee",
|
|
|
+ Width = GridLength.Star
|
|
|
+ })
|
|
|
+ .EndUpdate();
|
|
|
+ }, args =>
|
|
|
+ {
|
|
|
+ return Employees.Refresh(args.Force);
|
|
|
+ }))?.FirstOrDefault();
|
|
|
+ if(employee is not null)
|
|
|
+ {
|
|
|
+ Shell.EmployeeID = employee.ID;
|
|
|
+ Shell.EmployeeName = employee.Name;
|
|
|
+ Changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [RelayCommand]
|
|
|
+ private async Task ChangeStatus()
|
|
|
+ {
|
|
|
+ var status = (await SelectionViewModel.ExecutePopup<KanbanStatus>(model =>
|
|
|
+ {
|
|
|
+ model.Columns.BeginUpdate()
|
|
|
+ .Add(new AvaloniaDataGridTextColumn<KanbanStatus>
|
|
|
+ {
|
|
|
+ ColumnName = ".",
|
|
|
+ Caption = "Status",
|
|
|
+ Width = GridLength.Star
|
|
|
+ })
|
|
|
+ .EndUpdate();
|
|
|
+ }, args =>
|
|
|
+ {
|
|
|
+ return Enum.GetValues<KanbanStatus>();
|
|
|
+ }))?.FirstOrDefault();
|
|
|
+ if(status is not null)
|
|
|
+ {
|
|
|
+ Shell.Status = status.Value;
|
|
|
+ Changed();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|