Skip to content

Commit

Permalink
Исправлено выделение вновь созданного таска при создании его разными …
Browse files Browse the repository at this point in the history
…способами
  • Loading branch information
TatarPrincess committed Jul 25, 2024
1 parent f24865f commit fd98ba6
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 83 deletions.
3 changes: 2 additions & 1 deletion src/Unlimotion.Interface/TaskItemHubMold.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Unlimotion.Interface
{
Expand All @@ -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; }
}
}
2 changes: 1 addition & 1 deletion src/Unlimotion.Server.Domain/TaskItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
}
Binary file modified src/Unlimotion.Server.ServiceModel/molds/Tasks/TaskItemMold.cs
Binary file not shown.
19 changes: 15 additions & 4 deletions src/Unlimotion.TaskTreeManager/TaskTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ await IsCompletedAsync(async Task<bool> () =>
try
{
change.PrevVersion = false;
change.SortOrder = DateTime.Now;
await Storage.Save(change);
result.Add(change);

Expand Down Expand Up @@ -59,6 +60,7 @@ await IsCompletedAsync(async Task<bool> () =>
if (!parentTask.ContainsTasks.Contains(newTaskId))
{
parentTask.ContainsTasks.Add(newTaskId);
parentTask.SortOrder = DateTime.Now;
await Storage.Save(parentTask);
result.Add(parentTask);
}
Expand All @@ -69,12 +71,14 @@ await IsCompletedAsync(async Task<bool> () =>
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);

Expand Down Expand Up @@ -109,8 +113,12 @@ await IsCompletedAsync(async Task<bool> () =>
}

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);

Expand Down Expand Up @@ -230,6 +238,7 @@ await IsCompletedAsync(async Task<bool> () =>
if (newTaskId is null)
{
change.PrevVersion = false;
change.SortOrder = DateTime.Now;
await Storage.Save(change);
newTaskId = change.Id;
}
Expand All @@ -241,6 +250,7 @@ await IsCompletedAsync(async Task<bool> () =>
if (!parentTask.ContainsTasks.Contains(newTaskId))
{
parentTask.ContainsTasks.Add(newTaskId);
parentTask.SortOrder = DateTime.Now;
await Storage.Save(parentTask);
result.Add(parentTask);
}
Expand All @@ -249,11 +259,12 @@ await IsCompletedAsync(async Task<bool> () =>

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;
}
Expand Down
22 changes: 6 additions & 16 deletions src/Unlimotion.ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ private void RegisterCommands()
Create = ReactiveCommand.CreateFromTask(async () =>
{
var taskRepository = Locator.Current.GetService<ITaskStorage>();
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;
Expand All @@ -94,11 +90,8 @@ private void RegisterCommands()
if (CurrentTaskItem != null && string.IsNullOrWhiteSpace(CurrentTaskItem.Title))
return;
var taskRepository = Locator.Current.GetService<ITaskStorage>();
var taskItem = new TaskItem()
{
IsCurrent = true
};
var task = new TaskItemViewModel(taskItem, taskRepository);

var task = new TaskItemViewModel(new TaskItem(), taskRepository);

if (CurrentTaskItem != null)
{
Expand Down Expand Up @@ -128,11 +121,8 @@ private void RegisterCommands()
if (string.IsNullOrWhiteSpace(CurrentTaskItem.Title))
return;
var taskRepository = Locator.Current.GetService<ITaskStorage>();
var taskItem = new TaskItem()
{
IsCurrent = true
};
var task = new TaskItemViewModel(taskItem, taskRepository);

var task = new TaskItemViewModel(new TaskItem(), taskRepository);

await taskRepository?.AddChild(task, CurrentTaskItem);

Expand Down
2 changes: 1 addition & 1 deletion src/Unlimotion.ViewModel/TaskItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
7 changes: 2 additions & 5 deletions src/Unlimotion.ViewModel/TaskItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ public TaskItem Model
ContainsTasks = Contains.ToList(),
ParentTasks = Parents.ToList(),
Repeater = Repeater?.Model,
IsCurrent = IsCurrent,
};
set
{
Expand Down Expand Up @@ -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<TaskItemViewModel> ContainsTasks => _containsTasks;

Expand Down Expand Up @@ -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);
Expand Down
97 changes: 42 additions & 55 deletions src/Unlimotion/FileTaskStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -51,11 +53,9 @@ public async Task<IEnumerable<TaskItem>> GetAll()
List<TaskItem> 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<TaskItem>(task);
tasks.Add(mapper.Map<TaskItem>(task));
}
}
Expand Down Expand Up @@ -232,44 +232,43 @@ public void SetPause(bool pause)

public async Task<bool> Add(TaskItemViewModel change, TaskItemViewModel? currentTask = null, bool isBlocked = false)
{
var taskItemList = await TaskTreeManager.AddTask(
var taskItemList = (await TaskTreeManager.AddTask(
mapper.Map<Server.Domain.TaskItem>(change.Model),
mapper.Map<Server.Domain.TaskItem>(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<bool> AddChild(TaskItemViewModel change, TaskItemViewModel currentTask)
{
change.Model.IsCurrent = true;

var taskItemList = await TaskTreeManager.AddChildTask(
var taskItemList = (await TaskTreeManager.AddChildTask(
mapper.Map<Server.Domain.TaskItem>(change.Model),
mapper.Map<Server.Domain.TaskItem>(currentTask.Model));
foreach (var task in taskItemList)
mapper.Map<Server.Domain.TaskItem>(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;
}

Expand All @@ -294,26 +293,24 @@ public async Task<bool> Update(TaskItemViewModel change)

public async Task<TaskItemViewModel> Clone(TaskItemViewModel change, params TaskItemViewModel[]? additionalParents)
{
change.Model.IsCurrent = true;

var additionalItemParents = new List<Server.Domain.TaskItem>();
foreach (var newParent in additionalParents)
{
additionalItemParents.Add(mapper.Map<Server.Domain.TaskItem>(newParent.Model));
}
var taskItemList = await TaskTreeManager.CloneTask(
var taskItemList = (await TaskTreeManager.CloneTask(
mapper.Map<Server.Domain.TaskItem>(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;
Expand All @@ -340,20 +337,10 @@ private void UpdateCache(Server.Domain.TaskItem task, TaskItemViewModel? vm = nu
{
var taskItem = mapper.Map<TaskItem>(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<bool> MoveInto(TaskItemViewModel change, TaskItemViewModel[]? additionalParents, TaskItemViewModel? currentTask)
Expand Down

0 comments on commit fd98ba6

Please sign in to comment.