diff --git a/src/Unlimotion.Interface/TaskItemHubMold.cs b/src/Unlimotion.Interface/TaskItemHubMold.cs index 21e7c3a..e3a2d45 100644 --- a/src/Unlimotion.Interface/TaskItemHubMold.cs +++ b/src/Unlimotion.Interface/TaskItemHubMold.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; namespace Unlimotion.Interface { @@ -23,6 +24,6 @@ public class TaskItemHubMold public int Importance { get; set; } public bool Wanted { get; set; } public bool PrevVersion { get; set; } = true; - public bool IsCurrent { get; set; } = false; + public DateTime SortOrder { get; set; } } } diff --git a/src/Unlimotion.Server.Domain/TaskItem.cs b/src/Unlimotion.Server.Domain/TaskItem.cs index e719750..965ecb8 100644 --- a/src/Unlimotion.Server.Domain/TaskItem.cs +++ b/src/Unlimotion.Server.Domain/TaskItem.cs @@ -25,7 +25,7 @@ public class TaskItem public int Importance { get; set; } public bool Wanted { get; set; } public bool PrevVersion { get; set; } = true; - public bool IsCurrent { get; set; } = false; + public DateTime SortOrder { get; set; } } } diff --git a/src/Unlimotion.Server.ServiceModel/molds/Tasks/TaskItemMold.cs b/src/Unlimotion.Server.ServiceModel/molds/Tasks/TaskItemMold.cs index d68afe0..b0a7721 100644 Binary files a/src/Unlimotion.Server.ServiceModel/molds/Tasks/TaskItemMold.cs and b/src/Unlimotion.Server.ServiceModel/molds/Tasks/TaskItemMold.cs differ diff --git a/src/Unlimotion.TaskTreeManager/TaskTreeManager.cs b/src/Unlimotion.TaskTreeManager/TaskTreeManager.cs index ab3687d..9ebe1b6 100644 --- a/src/Unlimotion.TaskTreeManager/TaskTreeManager.cs +++ b/src/Unlimotion.TaskTreeManager/TaskTreeManager.cs @@ -23,6 +23,7 @@ await IsCompletedAsync(async Task () => try { change.PrevVersion = false; + change.SortOrder = DateTime.Now; await Storage.Save(change); result.Add(change); @@ -59,6 +60,7 @@ await IsCompletedAsync(async Task () => if (!parentTask.ContainsTasks.Contains(newTaskId)) { parentTask.ContainsTasks.Add(newTaskId); + parentTask.SortOrder = DateTime.Now; await Storage.Save(parentTask); result.Add(parentTask); } @@ -69,12 +71,14 @@ await IsCompletedAsync(async Task () => TaskItem currentTaskItem = await Storage.Load(currentTask.Id); if (!currentTaskItem.BlocksTasks.Contains(newTaskId)) currentTask.BlocksTasks.Add(newTaskId); + currentTask.SortOrder = DateTime.Now; await Storage.Save(currentTask); result.Add(currentTask); change.BlockedByTasks.Add(currentTask.Id); } + change.SortOrder = DateTime.Now; await Storage.Save(change); result.Add(change); @@ -109,8 +113,12 @@ await IsCompletedAsync(async Task () => } currentTask.ContainsTasks.Add(change.Id); + currentTask.SortOrder = DateTime.Now; await Storage.Save(currentTask); + change.SortOrder = DateTime.Now; + await Storage.Save(change); + result.Add(change); result.Add(currentTask); @@ -230,6 +238,7 @@ await IsCompletedAsync(async Task () => if (newTaskId is null) { change.PrevVersion = false; + change.SortOrder = DateTime.Now; await Storage.Save(change); newTaskId = change.Id; } @@ -241,6 +250,7 @@ await IsCompletedAsync(async Task () => if (!parentTask.ContainsTasks.Contains(newTaskId)) { parentTask.ContainsTasks.Add(newTaskId); + parentTask.SortOrder = DateTime.Now; await Storage.Save(parentTask); result.Add(parentTask); } @@ -249,11 +259,12 @@ await IsCompletedAsync(async Task () => if (!changeTask.ParentTasks.Contains(parent.Id)) { - changeTask.ParentTasks.Add(parent.Id); - await Storage.Save(changeTask); - result.Add(changeTask); + changeTask.ParentTasks.Add(parent.Id); } - } + changeTask.SortOrder = DateTime.Now; + await Storage.Save(changeTask); + result.Add(changeTask); + } return true; } diff --git a/src/Unlimotion.ViewModel/MainWindowViewModel.cs b/src/Unlimotion.ViewModel/MainWindowViewModel.cs index 795ddb2..f935ba2 100644 --- a/src/Unlimotion.ViewModel/MainWindowViewModel.cs +++ b/src/Unlimotion.ViewModel/MainWindowViewModel.cs @@ -77,12 +77,8 @@ private void RegisterCommands() Create = ReactiveCommand.CreateFromTask(async () => { var taskRepository = Locator.Current.GetService(); - var taskItem = new TaskItem() - { - IsCurrent = true - }; - - var task = new TaskItemViewModel(taskItem, taskRepository); + + var task = new TaskItemViewModel(new TaskItem(), taskRepository); await taskRepository?.Add(task); CurrentTaskItem = task; @@ -94,11 +90,8 @@ private void RegisterCommands() if (CurrentTaskItem != null && string.IsNullOrWhiteSpace(CurrentTaskItem.Title)) return; var taskRepository = Locator.Current.GetService(); - var taskItem = new TaskItem() - { - IsCurrent = true - }; - var task = new TaskItemViewModel(taskItem, taskRepository); + + var task = new TaskItemViewModel(new TaskItem(), taskRepository); if (CurrentTaskItem != null) { @@ -128,11 +121,8 @@ private void RegisterCommands() if (string.IsNullOrWhiteSpace(CurrentTaskItem.Title)) return; var taskRepository = Locator.Current.GetService(); - var taskItem = new TaskItem() - { - IsCurrent = true - }; - var task = new TaskItemViewModel(taskItem, taskRepository); + + var task = new TaskItemViewModel(new TaskItem(), taskRepository); await taskRepository?.AddChild(task, CurrentTaskItem); diff --git a/src/Unlimotion.ViewModel/TaskItem.cs b/src/Unlimotion.ViewModel/TaskItem.cs index baa150d..e0a9244 100644 --- a/src/Unlimotion.ViewModel/TaskItem.cs +++ b/src/Unlimotion.ViewModel/TaskItem.cs @@ -25,6 +25,6 @@ public class TaskItem public int Importance { get; set; } public bool Wanted { get; set; } public bool PrevVersion { get; set; } = true; - public bool IsCurrent { get; set; } = false; + public DateTime SortOrder { get; set; } } } diff --git a/src/Unlimotion.ViewModel/TaskItemViewModel.cs b/src/Unlimotion.ViewModel/TaskItemViewModel.cs index cd9f742..e45118f 100644 --- a/src/Unlimotion.ViewModel/TaskItemViewModel.cs +++ b/src/Unlimotion.ViewModel/TaskItemViewModel.cs @@ -442,7 +442,6 @@ public TaskItem Model ContainsTasks = Contains.ToList(), ParentTasks = Parents.ToList(), Repeater = Repeater?.Model, - IsCurrent = IsCurrent, }; set { @@ -474,8 +473,7 @@ public TimeSpan? PlannedPeriod public TimeSpan? PlannedDuration { get; set; } public int Importance { get; set; } - public bool Wanted { get; set; } - public bool IsCurrent { get; set; } + public bool Wanted { get; set; } public ReadOnlyObservableCollection ContainsTasks => _containsTasks; @@ -646,8 +644,7 @@ public void Update(TaskItem taskItem) if (PlannedDuration != taskItem.PlannedDuration) PlannedDuration = taskItem.PlannedDuration; if (Importance != taskItem.Importance) Importance = taskItem.Importance; if (Wanted != taskItem.Wanted) Wanted = taskItem.Wanted; - if (IsCompleted != taskItem.IsCompleted) IsCompleted = taskItem.IsCompleted; - if (IsCurrent != taskItem.IsCurrent) IsCurrent = taskItem.IsCurrent; + if (IsCompleted != taskItem.IsCompleted) IsCompleted = taskItem.IsCompleted; SynchronizeCollections(Blocks, taskItem.BlocksTasks); SynchronizeCollections(BlockedBy, taskItem.BlockedByTasks); diff --git a/src/Unlimotion/FileTaskStorage.cs b/src/Unlimotion/FileTaskStorage.cs index c0bc502..998d505 100644 --- a/src/Unlimotion/FileTaskStorage.cs +++ b/src/Unlimotion/FileTaskStorage.cs @@ -22,6 +22,8 @@ using static System.Reflection.Metadata.BlobBuilder; using Unlimotion.Views.Graph; using JsonSerializer = Newtonsoft.Json.JsonSerializer; +using Unlimotion.Server.Domain; +using TaskItem = Unlimotion.ViewModel.TaskItem; namespace Unlimotion { @@ -51,11 +53,9 @@ public async Task> GetAll() List tasks = []; foreach (var fileInfo in directoryInfo.EnumerateFiles()) { - //var task = Load(fileInfo.FullName).Result; var task = await TaskTreeManager.LoadTask(fileInfo.FullName); if (task != null) { - //yield return mapper.Map(task); tasks.Add(mapper.Map(task)); } } @@ -232,44 +232,43 @@ public void SetPause(bool pause) public async Task Add(TaskItemViewModel change, TaskItemViewModel? currentTask = null, bool isBlocked = false) { - var taskItemList = await TaskTreeManager.AddTask( + var taskItemList = (await TaskTreeManager.AddTask( mapper.Map(change.Model), mapper.Map(currentTask?.Model), - isBlocked); + isBlocked)).OrderBy(t => t.SortOrder); - foreach (var task in taskItemList) - { - if (task.IsCurrent) UpdateCache(task, change); - else UpdateCache(task); + var newTask = taskItemList.Last(); + change.Id = newTask.Id; + if (newTask.BlockedByTasks != null) + TaskItemViewModel.SynchronizeCollections(change.BlockedBy, newTask.BlockedByTasks); + if (newTask.ParentTasks != null) + TaskItemViewModel.SynchronizeCollections(change.Parents, newTask.ParentTasks); + UpdateCache(newTask, change); - if (currentTask is null || (!currentTask.Parents.Contains(task.Id) && currentTask.Id != task.Id)) - change.Id = task.Id; + foreach (var task in taskItemList.SkipLast(1)) + { + UpdateCache(task); } return true; } public async Task AddChild(TaskItemViewModel change, TaskItemViewModel currentTask) { - change.Model.IsCurrent = true; - - var taskItemList = await TaskTreeManager.AddChildTask( + var taskItemList = (await TaskTreeManager.AddChildTask( mapper.Map(change.Model), - mapper.Map(currentTask.Model)); - foreach (var task in taskItemList) + mapper.Map(currentTask.Model))) + .OrderBy(t => t.SortOrder); + + var newTask = taskItemList.Last(); + change.Id = newTask.Id; + TaskItemViewModel.SynchronizeCollections(change.Parents, newTask.ParentTasks!); + UpdateCache(newTask, change); + + foreach (var task in taskItemList.SkipLast(1)) { - if (task.IsCurrent) UpdateCache(task, change); - else UpdateCache(task); - - if (task.Id != currentTask.Id) - { - change.Id = task.Id; - foreach (var parent in task.ParentTasks!) - { - change.Parents.Add(parent); - } - - } - } + UpdateCache(task); + } + return true; } @@ -294,26 +293,24 @@ public async Task Update(TaskItemViewModel change) public async Task Clone(TaskItemViewModel change, params TaskItemViewModel[]? additionalParents) { - change.Model.IsCurrent = true; - var additionalItemParents = new List(); foreach (var newParent in additionalParents) { additionalItemParents.Add(mapper.Map(newParent.Model)); } - var taskItemList = await TaskTreeManager.CloneTask( + var taskItemList = (await TaskTreeManager.CloneTask( mapper.Map(change.Model), - additionalItemParents); - foreach (var task in taskItemList) + additionalItemParents)).OrderBy(t => t.SortOrder); + + var newTask = taskItemList.Last(); + change.Id = newTask.Id; + if (newTask.ParentTasks != null) + TaskItemViewModel.SynchronizeCollections(change.Parents, newTask.ParentTasks); + UpdateCache(newTask, change); + + foreach (var task in taskItemList.SkipLast(1)) { - if (task.IsCurrent) UpdateCache(task, change); - else UpdateCache(task); - - if (!task.ContainsTasks.Any()) - { - change.Id = task.Id; - change.Parents.Add(task.ParentTasks!); - } + UpdateCache(task); } return change; @@ -340,20 +337,10 @@ private void UpdateCache(Server.Domain.TaskItem task, TaskItemViewModel? vm = nu { var taskItem = mapper.Map(task); - if (taskItem.IsCurrent) - { - ArgumentNullException.ThrowIfNull(vm); - vm.Id = task.Id; - - TaskItemViewModel.SynchronizeCollections(vm.Blocks, taskItem.BlocksTasks); - TaskItemViewModel.SynchronizeCollections(vm.BlockedBy, taskItem.BlockedByTasks); - TaskItemViewModel.SynchronizeCollections(vm.Contains, taskItem.ContainsTasks); - TaskItemViewModel.SynchronizeCollections(vm.Parents, taskItem.ParentTasks); - - Tasks.AddOrUpdate(vm); - } - else - Tasks.AddOrUpdate(new TaskItemViewModel(taskItem, this)); + if (vm is not null) + Tasks.AddOrUpdate(vm); + else + Tasks.AddOrUpdate(new TaskItemViewModel(taskItem, this)); } public async Task MoveInto(TaskItemViewModel change, TaskItemViewModel[]? additionalParents, TaskItemViewModel? currentTask)