From 9787f0a22474e4cb8f8221958e9ad810fb7bdd98 Mon Sep 17 00:00:00 2001 From: rene Date: Wed, 24 May 2023 11:29:31 +0200 Subject: [PATCH 1/5] Feature Abschluss --- BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs b/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs index 499ddfb60..c7f6c9094 100644 --- a/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs +++ b/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs @@ -874,13 +874,8 @@ namespace BeWo.View.Detail parent.Items.Add(child); // Setze child Parent Entry - parent.GoalEntryDC = parent.GoalEntryVM.CommitToDataContract(); child.GoalEntryVM.ParentEntry = parent.GoalEntryDC; child.ParentGoal = parent; - - - //CopyTreeItem(parent, child, true); - //DeleteIndividualGoal(child); } private SupportConceptGoalTreeItem GetNearestContainer(UIElement element) From 1e57ccb9a2e62cef8b39941eddb1cbce95abf0bc Mon Sep 17 00:00:00 2001 From: rene Date: Wed, 24 May 2023 14:30:09 +0200 Subject: [PATCH 2/5] Live sorting + basic history objects --- BeWo/BeWo.csproj | 2 + .../View/Detail/MassnahmenActionParameters.cs | 37 ++++ BeWo/View/Detail/MassnahmenHistory.cs | 103 +++++++++++ BeWo/View/Detail/MassnahmenTreeViewView.xaml | 2 +- .../Detail/MassnahmenTreeViewView.xaml.cs | 160 +++++++++++++----- 5 files changed, 261 insertions(+), 43 deletions(-) create mode 100644 BeWo/View/Detail/MassnahmenActionParameters.cs create mode 100644 BeWo/View/Detail/MassnahmenHistory.cs diff --git a/BeWo/BeWo.csproj b/BeWo/BeWo.csproj index 1bf91a13a..9d7bc08df 100644 --- a/BeWo/BeWo.csproj +++ b/BeWo/BeWo.csproj @@ -1055,6 +1055,8 @@ DebugMessageLogView.xaml + + ServiceRecordCreationView.xaml diff --git a/BeWo/View/Detail/MassnahmenActionParameters.cs b/BeWo/View/Detail/MassnahmenActionParameters.cs new file mode 100644 index 000000000..17e185653 --- /dev/null +++ b/BeWo/View/Detail/MassnahmenActionParameters.cs @@ -0,0 +1,37 @@ +using BeWo.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.View.Detail +{ + public abstract class MassnahmenActionRecord + { + + } + + public class MassnahmenAddParameter : MassnahmenActionRecord + { + public SupportConceptGoalTreeItem NewTreeItem { get; set; } + public SupportConceptGoalTreeItem Parent { get; set; } + } + + public class MassnahmenDeleteParameter : MassnahmenActionRecord + { + public SupportConceptGoalTreeItem Current { get; set; } + public SupportConceptGoalTreeItem Parent { get; set; } + } + + + public class MassnahmenMoveParameter : MassnahmenActionRecord + { + + } + + public class MassnahmenCopyParameter : MassnahmenActionRecord + { + + } +} diff --git a/BeWo/View/Detail/MassnahmenHistory.cs b/BeWo/View/Detail/MassnahmenHistory.cs new file mode 100644 index 000000000..3d29cd3e8 --- /dev/null +++ b/BeWo/View/Detail/MassnahmenHistory.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.View.Detail +{ + //public class MassnahmenTreeViewHistoryManager + //{ + // public MassnahmenTreeViewHistoryManager() + // { + // History = new Stack(); + // } + + // public Stack History { get; set; } + + // internal void RecordAction(MassnahmenActionParameters param) + // { + // History.Push(param); + // } + + // internal void UndoAction() + // { + + // } + + // internal void UndoAddAction() + // { + + // } + + // internal void UndoDeleteAction() + // { + + // } + + // internal void UndoMoveAction() + // { + + // } + + // internal void UndoCopyAction() + // { + + // } + //} + + public class MassnahmenHistory + { + public Action Refresh { get; set; } + public LinkedList History { get; set; } + public LinkedListNode LastChange { get; set; } + + public MassnahmenHistory(Action refresh) + { + History = new LinkedList(); + LastChange = null; + Refresh = refresh; + } + + public bool GotPrevAction => LastChange.Previous is object; + public bool GotNextAction => LastChange.Next is object; + + public void RecordAction(MassnahmenActionRecord[] val) + { + while(LastChange != History.Last) + { + History.RemoveLast(); + } + + History.AddLast(val); + + LastChange = History.Last; + + Refresh(); + } + + public void UndoPrevAction() + { + var action = LastChange.Value; + + if (action is MassnahmenAddParameter[] addparam) + UndoAddAction(addparam); + + LastChange = LastChange.Previous; + } + + public void UndoAddAction(MassnahmenAddParameter[] addParam) + { + + } + + public void RedoNextAction() + { + var action = LastChange.Next.Value; + + + + LastChange = LastChange.Next; + } + } +} diff --git a/BeWo/View/Detail/MassnahmenTreeViewView.xaml b/BeWo/View/Detail/MassnahmenTreeViewView.xaml index 22cdbd327..21b0536c9 100644 --- a/BeWo/View/Detail/MassnahmenTreeViewView.xaml +++ b/BeWo/View/Detail/MassnahmenTreeViewView.xaml @@ -116,7 +116,7 @@ - + diff --git a/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs b/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs index c7f6c9094..44f157a07 100644 --- a/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs +++ b/BeWo/View/Detail/MassnahmenTreeViewView.xaml.cs @@ -35,7 +35,6 @@ namespace BeWo.View.Detail private TreeViewItem _SelectedGoalTreeNode; private GenericValueListEntryListVM _ViewModel; - private List _Children2Delete; private List _TreeViewItemsList; private MassnahmenTreeCopyType _CopyType; @@ -44,6 +43,8 @@ namespace BeWo.View.Detail private SupportConceptGoalTreeItem _draggedItem; private SupportConceptGoalTreeItem _parent; + private MassnahmenHistory _History; + public MassnahmenTreeViewView(GenericValueListEntryListVM pViewModel) { InitializeComponent(); @@ -53,8 +54,14 @@ namespace BeWo.View.Detail DataContext = this; Bearbeitungsmodus = false; + + _History = new MassnahmenHistory(SortGoalTree); + + TreeView.Items.IsLiveSorting = true; } + public ObservableSortCollection GoalTree { get; private set; } + public override bool IsDirty => ViewModel != null && ViewModel.IsDirty; public static bool IsAllowedToEditGoals => BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_AllowEditGoals); public GenericValueListEntryListVM ViewModel @@ -67,7 +74,6 @@ namespace BeWo.View.Detail TreeView.ItemsSource = GoalTree; } } - public bool Bearbeitungsmodus { get @@ -86,10 +92,6 @@ namespace BeWo.View.Detail } } - public ObservableSortCollection GoalTree { get; private set; } - - public override bool IsDirty => ViewModel != null && ViewModel.IsDirty; - private void GoalTreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { var source = e.OriginalSource as DependencyObject; @@ -198,6 +200,8 @@ namespace BeWo.View.Detail foreach (var menuitem in menu.Items.OfType().Select(item => item)) { + menuitem.IsEnabled = goal != null; + if (menuitem.Header.Equals("Neue Maßnahme")) { menuitem.IsEnabled = goal != null && !goal.IsGoal; @@ -265,7 +269,7 @@ namespace BeWo.View.Detail GoalTree.Add(newItem); - GoalTree.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal)); + SortGoalTree(); } private void IcfImport_Click(object sender, RoutedEventArgs e) { @@ -291,7 +295,12 @@ namespace BeWo.View.Detail control2.ButtonImportClicked += () => { - ImportIcf(control2.TreeViewGoalItem); + var records = new List(); + + ImportIcf(control2.TreeViewGoalItem, records); + + _History.RecordAction(records.ToArray()); + beWoWindow2.Close(); }; @@ -344,8 +353,11 @@ namespace BeWo.View.Detail if (ContainsTreeItem(_copy, _item)) MessageBox.Show("Kopieren in tiefere Ziele/Maßnamhen nicht möglich!"); else - CopyTreeItem(_item, _copy, false); - + { + var records = new List(); + CopyTreeItem(_item, _copy, false, ref records); + _History.RecordAction(records.ToArray()); + } } private void StartMoveItem(SupportConceptGoalTreeItem _draggedItem, SupportConceptGoalTreeItem _parent) { @@ -381,7 +393,7 @@ namespace BeWo.View.Detail if ((finalDropEffect == DragDropEffects.Move) && (_parent != null) && _parent != _draggedItem) { StartMoveItem(_draggedItem, _parent); - + //var origin_parent = _draggedItem.ParentGoal as SupportConceptGoalTreeItem; //var parent = _parent; @@ -451,6 +463,28 @@ namespace BeWo.View.Detail } } + private void SortGoalTree() + { + foreach (var item in GoalTree) + { + SortRec(item); + } + + GoalTree.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal)); + } + private void SortRec(SupportConceptGoalTreeItem item) + { + if (item is object && item.Items is object && item.Items.Any()) + { + foreach (var child in item.Items) + { + SortRec(child); + } + + item.Items.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal)); + } + } + public List GetAllChildren(SupportConceptGoalTreeItem treeItem, SupportConceptGoalDC dcItem) { List returnThis = new List(); @@ -495,7 +529,6 @@ namespace BeWo.View.Detail { var neueVMs = ViewModel.VMList.Where(w => w.IsNew).ToList(); - _TreeViewItemsList = new List(); GetAllTreeViewItems(); var obersteZiele = neueVMs.Where(w => w.IsNew && (w.ParentEntry != null && w.ParentEntry.ValueListEntryOid != null) || w.ParentEntry == null); @@ -512,8 +545,10 @@ namespace BeWo.View.Detail if (ViewModel.RemovedCount > 0) { - var entfernte = _Children2Delete.Where(w => w.ValueListEntryOid != null).ToList(); - var entfernteDic = entfernte.ToDictionary(k => k.ValueListEntryOid.Value, v => v.ValueListEntryVersion.Value); + var ent = ViewModel.GetRemoved(); + //var entfernte = _Children2Delete.Where(w => w.ValueListEntryOid != null).ToList(); + //var entfernteDic = entfernte.ToDictionary(k => k.ValueListEntryOid.Value, v => v.ValueListEntryVersion.Value); + var entfernteDic = ent.ToDictionary(k => k.ValueListEntryOid.Value, v => v.ValueListEntryVersion.Value); entfernteDic.AddAndIgnoreDuplicates(ViewModel.GetRemoved().ToDictionary(dc => dc.ValueListEntryOid.Value, dc => dc.ValueListEntryVersion.Value)); lToDos.Add(s => s.DeactivateValueListEntries(entfernteDic)); @@ -694,9 +729,10 @@ namespace BeWo.View.Detail GoalTree = iGoalList; } - + private void GetAllTreeViewItems() { + _TreeViewItemsList = new List(); foreach (var parent in GoalTree) { TraverseTreeViewItem(parent); @@ -710,16 +746,16 @@ namespace BeWo.View.Detail TraverseTreeViewItem(child); } } - private void ImportIcf(SupportConceptGoalDC goal) + private void ImportIcf(SupportConceptGoalDC goal, List records) { if (goal == null) return; - goal.Children?.ForEach(ImportIcf); + goal.Children?.ForEach(x => ImportIcf(x, records)); if (goal.IsChecked) - AddIcf(goal); + AddIcf(goal, records); } - private SupportConceptGoalTreeItem AddIcf(SupportConceptGoalDC goal) + private SupportConceptGoalTreeItem AddIcf(SupportConceptGoalDC goal, List records) { if (goal == null) return null; @@ -732,11 +768,12 @@ namespace BeWo.View.Detail if (goal.ParentGoal == null) { var treeItem = AddTreeItem(null, ValueListEntryType.SupportConceptGoalCategoryType, - goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice); + goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice, records, false); GoalTree.Add(treeItem); - GoalTree.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal)); + SortGoalTree(); + //GoalTree.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal)); return treeItem; } @@ -747,13 +784,13 @@ namespace BeWo.View.Detail var similarParentGoal = SearchGoalTreeItem(goalTreeItem, goal.ParentGoal.GoalEntryDC.TypeDescription, goal.ParentGoal.GoalEntryDC.Abbreviation, goal.ParentGoal.GoalEntryDC.Notice); if (similarParentGoal == null) continue; - return AddTreeItem(similarParentGoal, ValueListEntryType.SupportConceptGoalCategoryType, goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice); + return AddTreeItem(similarParentGoal, ValueListEntryType.SupportConceptGoalCategoryType, goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice, records, false); } // Fügt den Parent hinzu - var parent = AddIcf(goal.ParentGoal); + var parent = AddIcf(goal.ParentGoal, records); return AddTreeItem(parent, ValueListEntryType.SupportConceptGoalCategoryType, - goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice); + goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice, records, false); } public void AddTreeItemWithControl(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string viewHeader) @@ -775,8 +812,10 @@ namespace BeWo.View.Detail control.SaveButtonClicked += () => { + var records = new List(); var vm = control.ValueListEntry; - AddTreeItem(parent, valueListEntryType, vm.Description, vm.Abbreviation, vm.Notice); + AddTreeItem(parent, valueListEntryType, vm.Description, vm.Abbreviation, vm.Notice, records, false); + _History.RecordAction(records.ToArray()); beWoWindow.Close(); }; @@ -788,8 +827,8 @@ namespace BeWo.View.Detail beWoWindow.rootGroupBox.Header = viewHeader; beWoWindow.ShowDialog(); } - - private SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice) + + private SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice, List records, bool copy) { if (!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalCategoryType) && !valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalType)) @@ -808,55 +847,85 @@ namespace BeWo.View.Detail ParentGoal = parent }; + if (copy) + { + records.Add(new MassnahmenCopyParameter + { + + }); + } + else + { + records.Add(new MassnahmenAddParameter + { + NewTreeItem = newItem, + Parent = parent + }); + } + + + ViewModel.AddNewVMToList(); if (parent == null) return newItem; vm.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract(); - parent.GoalEntryVM = parent.GoalEntryVM; + parent.Items.Add(newItem); parent.IsExpanded = true; return newItem; } + private void DeleteTreeItem(SupportConceptGoalTreeItem selectedItem) { - _Children2Delete = new List(); - DeleteTreeItemRec(selectedItem); + var stack = new Stack(); + var queue = new Queue(); + + DeleteTreeRec(selectedItem, ref stack, ref queue); + + // Queue löschen + foreach (var item in queue) + { + ViewModel.VMList.Remove(item.GoalEntryVM); + } var parent = selectedItem.ParentGoal as SupportConceptGoalTreeItem; - if (parent != null && parent.Items != null) + if (parent != null) parent.Items.Remove(selectedItem); else GoalTree.Remove(selectedItem); - ViewModel.VMList.Remove(selectedItem.GoalEntryVM); + _History.RecordAction(stack.Select(x => new MassnahmenDeleteParameter + { + Current = x, + Parent = GetParent(x) + }).ToArray()); } - private void DeleteTreeItemRec(SupportConceptGoalTreeItem item) + private void DeleteTreeRec(SupportConceptGoalTreeItem item, ref Stack stack, ref Queue queue) { - var result = new List { item.GoalEntryDC ?? item.GoalEntryVM.CommitToDataContract() }; - foreach (var child in item.Items) { - DeleteTreeItemRec(child); + DeleteTreeRec(child, ref stack, ref queue); } - _Children2Delete.AddRange(result); + stack.Push(item); + queue.Enqueue(item); } - private void CopyTreeItem(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem source, bool force_deep_copy) + private void CopyTreeItem(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem source, bool force_deep_copy, ref List records) { if (source == null || parent == null) throw new NotImplementedException("#43298467891364987"); var wm = source.GoalEntryVM; var childs = source.Items.ToList(); - var node = AddTreeItem(parent, wm.Type, wm.Description, wm.Abbreviation, wm.Notice); + var node = AddTreeItem(parent, wm.Type, wm.Description, wm.Abbreviation, wm.Notice, records, true); if (_CopyType == MassnahmenTreeCopyType.Subtree || force_deep_copy) { foreach (var child in childs) { - CopyTreeItem(node, child, force_deep_copy); + CopyTreeItem(node, child, force_deep_copy, ref records); } } } @@ -869,13 +938,20 @@ namespace BeWo.View.Detail // Entferne child aus Ex-Parent ex_parent.Items.Remove(child); - + // Füge child parent hinzu parent.Items.Add(child); // Setze child Parent Entry child.GoalEntryVM.ParentEntry = parent.GoalEntryDC; child.ParentGoal = parent; + + _History.RecordAction( + new MassnahmenActionRecord[] { + new MassnahmenMoveParameter { + + } + }); } private SupportConceptGoalTreeItem GetNearestContainer(UIElement element) @@ -948,7 +1024,7 @@ namespace BeWo.View.Detail foreach (var current_child in current.Items) { - if(FindParent(current, current_child, lostchild, out foundchild)) + if (FindParent(current, current_child, lostchild, out foundchild)) { return true; } From 545d29289b4a730e7d0c9733be12fcc185aefcac Mon Sep 17 00:00:00 2001 From: rene Date: Thu, 25 May 2023 13:03:05 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Basic=20Tree=20Manipulation=20eingef=C3=BCh?= =?UTF-8?q?rt.=20Button=20eingef=C3=BChrt,=20lassen=20sich=20mit=20Pfeilen?= =?UTF-8?q?=20navigieren.=20Tree=20Sortierung=20eindeutiger,=20Anzahl=20de?= =?UTF-8?q?r=20Kinder=20als=202tes=20Sortkriterium.=20Zukunft:=20rekursiv?= =?UTF-8?q?=20sortieren=20Add=20Undo=20und=20Redo=20implementiert,=20fehlt?= =?UTF-8?q?=20nur=20noch=20import,=20move,=20del=20und=20copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeWo/BeWo.csproj | 1 + .../View/Detail/MassnahmenActionParameters.cs | 85 ++++++++-- BeWo/View/Detail/MassnahmenHistory.cs | 71 +++++--- BeWo/View/Detail/MassnahmenTreeTrimmer.cs | 116 ++++++++++++++ BeWo/View/Detail/MassnahmenTreeViewView.xaml | 14 +- .../Detail/MassnahmenTreeViewView.xaml.cs | 151 ++++++++++++------ 6 files changed, 350 insertions(+), 88 deletions(-) create mode 100644 BeWo/View/Detail/MassnahmenTreeTrimmer.cs diff --git a/BeWo/BeWo.csproj b/BeWo/BeWo.csproj index 9d7bc08df..6d2948564 100644 --- a/BeWo/BeWo.csproj +++ b/BeWo/BeWo.csproj @@ -1057,6 +1057,7 @@ + ServiceRecordCreationView.xaml diff --git a/BeWo/View/Detail/MassnahmenActionParameters.cs b/BeWo/View/Detail/MassnahmenActionParameters.cs index 17e185653..502bd09d1 100644 --- a/BeWo/View/Detail/MassnahmenActionParameters.cs +++ b/BeWo/View/Detail/MassnahmenActionParameters.cs @@ -7,31 +7,88 @@ using System.Threading.Tasks; namespace BeWo.View.Detail { - public abstract class MassnahmenActionRecord + public abstract class MassnahmenHistoryRecord { - } - public class MassnahmenAddParameter : MassnahmenActionRecord + public class MassnahmenHistoryRecordOrigin : MassnahmenHistoryRecord + { + + } + + public class MassnahmenHistoryRecordAdd : MassnahmenHistoryRecord { public SupportConceptGoalTreeItem NewTreeItem { get; set; } public SupportConceptGoalTreeItem Parent { get; set; } + + public MassnahmenHistoryRecordAdd(SupportConceptGoalTreeItem newitem, SupportConceptGoalTreeItem parent) + { + NewTreeItem = newitem; + Parent = parent; + } + } + + public class MassnahmenHistoryRecordImport : MassnahmenHistoryRecord + { + public List Parameters { get; set; } + + public MassnahmenHistoryRecordImport(List list) + { + Parameters = list; + } } - public class MassnahmenDeleteParameter : MassnahmenActionRecord + public class MassnahmenHistoryRecordDelete : MassnahmenHistoryRecord + { + public List Parameters { get; set; } + + public MassnahmenHistoryRecordDelete(List list) + { + Parameters = list; + } + } + + public class MassnahmenHistoryRecordMove : MassnahmenHistoryRecord + { + + } + + public class MassnahmenHistoryRecordCopy : MassnahmenHistoryRecord + { + public List Parameters { get; set; } + + public MassnahmenHistoryRecordCopy(List list) + { + Parameters = list; + } + } + + public abstract class MassnahmenHistoryParameter + { + + } + + public class MassnahmenHistoryParameter1 : MassnahmenHistoryParameter + { + public SupportConceptGoalTreeItem NewTreeItem { get; set; } + public SupportConceptGoalTreeItem Parent { get; set; } + + public MassnahmenHistoryParameter1(SupportConceptGoalTreeItem newitem, SupportConceptGoalTreeItem parent) + { + NewTreeItem = newitem; + Parent = parent; + } + } + + public class MassnahmenHistoryParameter2 : MassnahmenHistoryParameter { public SupportConceptGoalTreeItem Current { get; set; } public SupportConceptGoalTreeItem Parent { get; set; } - } - - - public class MassnahmenMoveParameter : MassnahmenActionRecord - { - - } - - public class MassnahmenCopyParameter : MassnahmenActionRecord - { + public MassnahmenHistoryParameter2(SupportConceptGoalTreeItem current, SupportConceptGoalTreeItem parent) + { + Current = current; + Parent = parent; + } } } diff --git a/BeWo/View/Detail/MassnahmenHistory.cs b/BeWo/View/Detail/MassnahmenHistory.cs index 3d29cd3e8..7d26f31ac 100644 --- a/BeWo/View/Detail/MassnahmenHistory.cs +++ b/BeWo/View/Detail/MassnahmenHistory.cs @@ -1,4 +1,7 @@ -using System; +using BeWo.Core; +using BeWo.ViewModel.ListViewModel; +using BS.Shared.Core; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -48,21 +51,34 @@ namespace BeWo.View.Detail public class MassnahmenHistory { - public Action Refresh { get; set; } - public LinkedList History { get; set; } - public LinkedListNode LastChange { get; set; } + public Action RefreshTree { get; set; } + public Action RefreshButton { get; set; } - public MassnahmenHistory(Action refresh) + public MassnahmenHistoryRecordOrigin Origin { get; set; } + public LinkedList History { get; set; } + public LinkedListNode LastChange { get; set; } + + public MassnahmenTreeTrimmer TreeTrimmer { get; set; } + + + + public MassnahmenHistory(MassnahmenTreeTrimmer trimmer, Action refresh, Action button) { - History = new LinkedList(); - LastChange = null; - Refresh = refresh; + Origin = new MassnahmenHistoryRecordOrigin(); + History = new LinkedList(); + History.AddLast(Origin); + + LastChange = History.Last; + + TreeTrimmer = trimmer; + RefreshTree = refresh; + RefreshButton = button; } - public bool GotPrevAction => LastChange.Previous is object; - public bool GotNextAction => LastChange.Next is object; + public bool GotPrevAction => LastChange is object && LastChange.Value != Origin; + public bool GotNextAction => LastChange is object && LastChange.Next is object; - public void RecordAction(MassnahmenActionRecord[] val) + public void RecordAction(MassnahmenHistoryRecord val) { while(LastChange != History.Last) { @@ -73,31 +89,42 @@ namespace BeWo.View.Detail LastChange = History.Last; - Refresh(); + RefreshTree(); + RefreshButton(); + } + + public void ClearHistory() + { + while(History.Last != History.First) + { + History.RemoveLast(); + } + + LastChange = History.Last; + + RefreshButton(); } public void UndoPrevAction() { var action = LastChange.Value; + + TreeTrimmer.UndoAction(action); - if (action is MassnahmenAddParameter[] addparam) - UndoAddAction(addparam); - LastChange = LastChange.Previous; + RefreshButton(); + RefreshTree(); } - - public void UndoAddAction(MassnahmenAddParameter[] addParam) - { - - } - + public void RedoNextAction() { var action = LastChange.Next.Value; - + TreeTrimmer.RedoAction(action); LastChange = LastChange.Next; + RefreshButton(); + RefreshTree(); } } } diff --git a/BeWo/View/Detail/MassnahmenTreeTrimmer.cs b/BeWo/View/Detail/MassnahmenTreeTrimmer.cs new file mode 100644 index 000000000..119b9a3fb --- /dev/null +++ b/BeWo/View/Detail/MassnahmenTreeTrimmer.cs @@ -0,0 +1,116 @@ +using BeWo.Core; +using BeWo.ViewModel.ListViewModel; +using BS.Shared.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.View.Detail +{ + public class MassnahmenTreeTrimmer + { + public Dictionary, Action>> Type2Actions { get; set; } + + public MassnahmenTreeViewView View{ get; set; } + + public GenericValueListEntryListVM ViewModel => View.ViewModel; + public ObservableSortCollection GoalTree => View.GoalTree; + + public MassnahmenTreeTrimmer(MassnahmenTreeViewView view) + { + View = view; + + Type2Actions = new Dictionary, Action>> + { + { typeof(MassnahmenHistoryRecordAdd), GetTuple(UndoAddAction, RedoAddAction) }, + { typeof(MassnahmenHistoryRecordCopy), GetTuple(UndoCopyAction, RedoCopyAction) }, + { typeof(MassnahmenHistoryRecordDelete), GetTuple(UndoDeleteAction, RedoDeleteAction) }, + { typeof(MassnahmenHistoryRecordImport), GetTuple(UndoImportAction, RedoImportAction) }, + { typeof(MassnahmenHistoryRecordMove), GetTuple(UndoMoveAction, RedoMoveAction) }, + }; + } + + public void UndoAction(MassnahmenHistoryRecord action) + { + Type2Actions[action.GetType()].Item1(action); + } + + public void RedoAction(MassnahmenHistoryRecord action) + { + Type2Actions[action.GetType()].Item2(action); + } + + public void UndoAddAction(MassnahmenHistoryRecord param) + { + var addParam = param as MassnahmenHistoryRecordAdd; + var newItem = addParam.NewTreeItem; + var parent = addParam.Parent; + + ViewModel.VMList.Remove(newItem.GoalEntryVM); + + if (parent != null) + parent.Items.Remove(newItem); + else + GoalTree.Remove(newItem); + } + + public void RedoAddAction(MassnahmenHistoryRecord param) + { + var addParam = param as MassnahmenHistoryRecordAdd; + var newItem = addParam.NewTreeItem; + var parent = addParam.Parent; + + ViewModel.VMList.Add(newItem.GoalEntryVM); + + if (parent != null) + parent.Items.Add(newItem); + else + GoalTree.Add(newItem); + } + + private void UndoCopyAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void RedoCopyAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void UndoDeleteAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void RedoDeleteAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void UndoImportAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void RedoImportAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void UndoMoveAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private void RedoMoveAction(MassnahmenHistoryRecord obj) + { + throw new NotImplementedException(); + } + + private Tuple, Action> GetTuple(Action a, Action b) + => new Tuple, Action>(x => a(x), x => b(x)); + } +} diff --git a/BeWo/View/Detail/MassnahmenTreeViewView.xaml b/BeWo/View/Detail/MassnahmenTreeViewView.xaml index 21b0536c9..7ac7401ca 100644 --- a/BeWo/View/Detail/MassnahmenTreeViewView.xaml +++ b/BeWo/View/Detail/MassnahmenTreeViewView.xaml @@ -11,7 +11,7 @@ - + @@ -70,13 +70,23 @@ + - + + + + +