Skip to content

Commit

Permalink
now tab's bar shows tabs for all applications
Browse files Browse the repository at this point in the history
TODO
- Implement reference data and server admin tabs
- Unit tests
  • Loading branch information
joao4all committed Jul 19, 2024
1 parent 866b055 commit 982d482
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
40 changes: 20 additions & 20 deletions COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@
<div class="panel-view @(this.CssClass)">
@if (this.Handler.CurrentTab is not null)
{
<div class="d-flex gap-2 tabs-row">

@foreach (var tab in this.Tabs)
{
<TabComponent Text="@(GetTabText(tab.ObjectOfInterest))"
Caption="@(this.GetCaptionText(tab.ObjectOfInterest))"
Icon="typeof(FeatherX)"
CustomOptionIcon="typeof(FeatherCopy)"
OnClick="@(() => this.OnTabClick.InvokeAsync((tab, this.Handler)))"
OnIconClick="@(() => this.OnRemoveTabClick.InvokeAsync(tab))"
OnCustomOptionIconClick="@(() => this.OnCreateTabForModel.InvokeAsync(tab))"
IsCurrent="@(tab == this.Handler.CurrentTab)"
ApplicationIcon="@(Applications.ExistingApplications.OfType<TabbedApplication>().First(x => x.ComponentType == tab.ComponentType).IconType)"
@key="tab"/>
}

<TabComponent Text="Select Model"
Icon="typeof(FeatherPlus)"
OnClick="@(() => this.OnOpenTabClick.Invoke())"/>
<div class="d-flex tabs-row justify-content-between">
<div class="d-flex gap-2">
@foreach (var tab in this.Tabs)
{
<TabComponent Text="@(GetTabText(tab.ObjectOfInterest))"
Caption="@(this.GetCaptionText(tab.ObjectOfInterest))"
Icon="typeof(FeatherX)"
CustomOptionIcon="typeof(FeatherCopy)"
OnClick="@(() => this.OnTabClick.InvokeAsync((tab, this.Handler)))"
OnIconClick="@(() => this.OnRemoveTabClick.InvokeAsync(tab))"
OnCustomOptionIconClick="@(() => this.OnCreateTabForModel.InvokeAsync(tab))"
IsCurrent="@(tab == this.Handler.CurrentTab)"
ApplicationIcon="@(Applications.ExistingApplications.OfType<TabbedApplication>().First(x => x.ComponentType == tab.ComponentType).IconType)"
@key="tab"/>
}

<TabComponent Text="Select Model"
Icon="typeof(FeatherPlus)"
OnClick="@(() => this.OnOpenTabClick.Invoke())"/>
</div>
@if (this.IsSidePanelAvailable)
{
<DxButton Click="@(() => this.AddSidePanel())"
RenderStyle="ButtonRenderStyle.None"
Id="new-side-panel-button"
style="position: absolute; right: 10px;">
CssClass="ml-auto p-0">
<FeatherColumns Size="30"
Color="currentColor"
StrokeWidth="1.8f"/>
Expand Down
2 changes: 1 addition & 1 deletion COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void AddSidePanel()

currentTab.Panel = newPanel;
this.ViewModel.SidePanels.Add(newPanel);
this.ViewModel.CurrentTab = this.ViewModel.OpenTabs.Items.LastOrDefault(x => x.ComponentType == this.ViewModel.SelectedApplication.ComponentType && x.Panel == null);
this.ViewModel.CurrentTab = this.ViewModel.OpenTabs.Items.FirstOrDefault(x => x.Panel == null);
}
}
}
6 changes: 3 additions & 3 deletions COMETwebapp/Pages/Tabs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
OnCreateTabForModel="@(tab => this.OnCreateTabForModel(tab))"
OnRemoveTabClick="@(tab => this.OnRemoveTabClick(tab))"
OnOpenTabClick="@(() => this.OnOpenTabClick())"
Tabs="@(this.OpenTabsFromSelectedApplication.Where(x => x.Panel == null).ToList())"
Tabs="@(this.OpenTabs.Where(x => x.Panel == null).ToList())"
IsSidePanelAvailable="true"/>

@foreach (var panelsGrouping in this.OpenTabsFromSelectedApplication.Where(x => x.Panel is not null).GroupBy(x => x.Panel))
@foreach (var panelsGrouping in this.OpenTabs.Where(x => x.Panel is not null).GroupBy(x => x.Panel))
{
<TabsPanelComponent Handler="panelsGrouping.Key"
ViewModel="@(this.ViewModel)"
OnTabClick="@(tuple => OnTabClick(tuple.Item1, tuple.Item2))"
OnRemoveTabClick="@(tab => this.OnRemoveTabClick(tab))"
OnOpenTabClick="@(() => this.OnOpenTabClick(panelsGrouping.Key))"
Tabs="@(this.OpenTabsFromSelectedApplication.Where(x => x.Panel == panelsGrouping.Key).ToList())"
Tabs="@(this.OpenTabs.Where(x => x.Panel == panelsGrouping.Key).ToList())"
@key="panelsGrouping.Key"/>
}
}
Expand Down
4 changes: 2 additions & 2 deletions COMETwebapp/Pages/Tabs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public partial class Tabs
private TabPanelInformation SelectedSidePanel { get; set; }

/// <summary>
/// Collection of open tabs that belong from the selected application
/// Collection of open tabs that belong from view model sourcelist
/// </summary>
private IEnumerable<TabbedApplicationInformation> OpenTabsFromSelectedApplication => this.ViewModel.OpenTabs.Items.Where(x => x.ComponentType == this.ViewModel.SelectedApplication?.ComponentType);
private IEnumerable<TabbedApplicationInformation> OpenTabs => this.ViewModel.OpenTabs.Items;

/// <summary>
/// The model id to fill the opentab form, if needed
Expand Down
6 changes: 5 additions & 1 deletion COMETwebapp/Shared/SideBarEntry/ApplicationsSideBar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected override void OnInitialized()
{
base.OnInitialized();
this.NavigationManager.LocationChanged += this.OnLocationChanged;
this.Disposables.Add(this.WhenAnyValue(x => x.TabsViewModel.SelectedApplication).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

this.Disposables.Add(this.WhenAnyValue(x =>
x.TabsViewModel.SelectedApplication,
x => x.TabsViewModel.CurrentTab
).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions COMETwebapp/ViewModels/Pages/TabsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public TabsViewModel(ISessionService sessionService, IServiceProvider servicePro
this.sessionService = sessionService;
this.serviceProvider = serviceProvider;
this.Disposables.Add(this.WhenAnyValue(x => x.SelectedApplication).Subscribe(_ => this.OnSelectedApplicationChange()));
this.Disposables.Add(this.WhenAnyValue(x => x.CurrentTab).Subscribe(_ => this.OnSelectedApplicationChange()));
this.Disposables.Add(this.WhenAnyValue(x => x.CurrentTab).Subscribe(_ => this.OnCurrentTabChange()));
this.Disposables.Add(this.sessionService.OpenIterations.CountChanged.Subscribe(this.CloseTabIfIterationClosed));
this.Disposables.Add(this.OpenTabs.Connect().WhereReasonsAre(ListChangeReason.Remove, ListChangeReason.RemoveRange).Subscribe(this.OnOpenTabRemoved));
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public void CreateNewTab(TabbedApplication application, Guid objectOfInterestId,
/// </summary>
private void OnSelectedApplicationChange()
{
if (this.SelectedApplication == null)
if (this.SelectedApplication == null || this.CurrentTab?.ComponentType == this.SelectedApplication?.ComponentType)
{
return;
}
Expand All @@ -181,7 +181,7 @@ private void OnCurrentTabChange()
return;
}

this.SelectedApplication = Applications.ExistingApplications.OfType<TabbedApplication>().First(x => x.ComponentType == this.CurrentTab.ComponentType);
this.SelectedApplication = Applications.ExistingApplications.OfType<TabbedApplication>().FirstOrDefault(x => x.ComponentType == this.CurrentTab.ComponentType);
}

/// <summary>
Expand Down Expand Up @@ -250,7 +250,7 @@ private void SetCurrentTabAfterTabRemoval(IChangeSet<TabbedApplicationInformatio

if (wasCurrentTabRemoved)
{
handler.CurrentTab = this.OpenTabs.Items.FirstOrDefault(x => x.ComponentType == this.SelectedApplication.ComponentType && x.Panel == selectedSidePanel);
handler.CurrentTab = this.OpenTabs.Items.FirstOrDefault(x => x.Panel == selectedSidePanel);
}

if (selectedSidePanel != null && handler.CurrentTab == null)
Expand Down

0 comments on commit 982d482

Please sign in to comment.