From 6509a6d6202629f98bab20ebeca6592702c01c6b Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Mon, 22 Jul 2024 17:58:54 +0100 Subject: [PATCH] now tabs move between panels TODO - Document SortableList and download its js file - A todo in tab panel information - Refactors - Unit tests --- .../Components/Tabs/TabsPanelComponent.razor | 8 +++++-- .../Tabs/TabsPanelComponent.razor.cs | 21 +++++++++++++++++++ COMETwebapp/Pages/Tabs.razor.cs | 3 +++ COMETwebapp/ViewModels/Pages/TabsViewModel.cs | 18 +++++++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor index 47d878f8..f791ba6a 100644 --- a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor +++ b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor @@ -29,8 +29,12 @@ {
- - + + /// Handles the logic to organize data when a tab is moved from one panel to another + /// + /// The dragged tab old panel index + /// The dragged tab new panel index + private void OnMovedTab(int oldIndex, int newIndex) + { + var tab = this.Panel.OpenTabs.Items.ElementAt(oldIndex); + + if (this.Panel == this.ViewModel.MainPanel) + { + this.ViewModel.SidePanel.OpenTabs.Insert(newIndex, tab); + } + else + { + this.ViewModel.MainPanel.OpenTabs.Insert(newIndex, tab); + } + + this.Panel.OpenTabs.Remove(tab); + } + /// /// Gets the tab text for the given object of interest /// diff --git a/COMETwebapp/Pages/Tabs.razor.cs b/COMETwebapp/Pages/Tabs.razor.cs index bc5ab1bc..433e26d2 100644 --- a/COMETwebapp/Pages/Tabs.razor.cs +++ b/COMETwebapp/Pages/Tabs.razor.cs @@ -93,6 +93,9 @@ protected override void OnInitialized() x => x.ViewModel.MainPanel.CurrentTab, x => x.ViewModel.SidePanel.CurrentTab) .SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged))); + + this.Disposables.Add(this.ViewModel.MainPanel.OpenTabs.Connect().SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged))); + this.Disposables.Add(this.ViewModel.SidePanel.OpenTabs.Connect().SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged))); } /// diff --git a/COMETwebapp/ViewModels/Pages/TabsViewModel.cs b/COMETwebapp/ViewModels/Pages/TabsViewModel.cs index 75d1e270..13dad907 100644 --- a/COMETwebapp/ViewModels/Pages/TabsViewModel.cs +++ b/COMETwebapp/ViewModels/Pages/TabsViewModel.cs @@ -147,7 +147,23 @@ private void OnSelectedApplicationChange() return; } - this.MainPanel.CurrentTab = this.MainPanel.OpenTabs.Items.FirstOrDefault(x => x.ComponentType == this.SelectedApplication.ComponentType); + var mainPanelTabForCurrentApplication = this.MainPanel.OpenTabs.Items.FirstOrDefault(x => x.ComponentType == this.SelectedApplication.ComponentType); + var sidePanelTabForCurrentApplication = this.SidePanel.OpenTabs.Items.FirstOrDefault(x => x.ComponentType == this.SelectedApplication.ComponentType); + + if (mainPanelTabForCurrentApplication != null) + { + this.MainPanel.CurrentTab = mainPanelTabForCurrentApplication; + } + + if (sidePanelTabForCurrentApplication != null) + { + this.SidePanel.CurrentTab = sidePanelTabForCurrentApplication; + } + + if (sidePanelTabForCurrentApplication == null && mainPanelTabForCurrentApplication == null) + { + this.MainPanel.CurrentTab = null; + } } ///