Skip to content

Commit

Permalink
Reverted TabStrip and Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
leigh-pointer committed Nov 26, 2024
1 parent f5cc613 commit 9d7549d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Oqtane.Client/Modules/Admin/Modules/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@
}
else
{
_activetab = "Settings";
//_activetab = "Settings";
AddModuleMessage(Localizer["Message.Required.Title"], MessageType.Warning);
}
}
else
{
_activetab = "Settings";
//_activetab = "Settings";
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
}
}
Expand Down
8 changes: 7 additions & 1 deletion Oqtane.Client/Modules/Admin/Pages/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@

private async Task SavePage()
{
_activetab = "Settings";
//_activetab = "Settings";
validated = true;
var interop = new Interop(JSRuntime);
if (await interop.FormValid(form))
Expand Down Expand Up @@ -672,17 +672,23 @@
}
else
{
_activetab = "Settings";
_refresh = true;
AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning);
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Saving Page {Page} {Error}", _page, ex.Message);
_activetab = "Settings";
_refresh = true;
AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error);
}
}
else
{
_activetab = "Settings";
_refresh = true;
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
}
}
Expand Down
6 changes: 5 additions & 1 deletion Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@
protected override void OnInitialized()
{
_interop = new QuillEditorInterop(JSRuntime);

if (string.IsNullOrEmpty(Placeholder))
{
Placeholder = Localizer["Placeholder"];
}
// _activetab = "Rich";
}

protected override void OnParametersSet()
Expand All @@ -269,6 +269,10 @@
{
_activetab = "Raw";
}
// else
// {
// _activetab = "Rich";
// }
}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand Down
11 changes: 8 additions & 3 deletions Oqtane.Client/Modules/Controls/TabPanel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ else
[Parameter]
public SecurityAccessLevel? Security { get; set; } // optional - can be used to specify SecurityAccessLevel
public bool IsActive { get; set; }

protected override void OnParametersSet()
{
base.OnParametersSet();

Parent.AddTabPanel((TabPanel)this);

Heading = string.IsNullOrEmpty(Heading) ? Localize(nameof(Name), Name) : Localize(nameof(Heading), Heading);
if (string.IsNullOrEmpty(Heading))
{
Heading = Localize(nameof(Name), Name);
}
else
{
Heading = Localize(nameof(Heading), Heading);
}
}

public string DisplayHeading()
Expand Down
60 changes: 17 additions & 43 deletions Oqtane.Client/Modules/Controls/TabStrip.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
@foreach (TabPanel tabPanel in _tabPanels)
{
<li class="nav-item" @key="tabPanel.Name">
<a class="nav-link @(tabPanel.IsActive ? "active" : "")" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick:preventDefault="true" @onclick="() => SetActiveTab(tabPanel.Name)">
@tabPanel.DisplayHeading()
</a>
@if (tabPanel.Name.ToLower() == ActiveTab.ToLower())
{
<a class="nav-link active" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick:preventDefault="true">
@tabPanel.DisplayHeading()
</a>
}
else
{
<a class="nav-link" data-bs-toggle="tab" href="#@(Id + tabPanel.Name)" role="tab" @onclick:preventDefault="true">
@tabPanel.DisplayHeading()
</a>
}
</li>
}
</ul>
Expand Down Expand Up @@ -50,64 +59,29 @@
}
}

protected override void OnParametersSet()
protected override void OnParametersSet()
{
base.OnParametersSet();

if (PageState.QueryString.ContainsKey("tab"))
{
ActiveTab = PageState.QueryString["tab"];
}

if (_tabPanels == null || Refresh)
{
_tabPanels = new List<TabPanel>();
}

// Ensure the active tab is valid and exists
if (!string.IsNullOrEmpty(ActiveTab) && _tabPanels.Any())
{
var activeTabExists = _tabPanels.Any(tp => tp.Name.Equals(ActiveTab, StringComparison.OrdinalIgnoreCase));
if (!activeTabExists)
{
ActiveTab = _tabPanels[0].Name;
}
}

// Update the active tab in the UI
UpdateActiveTab();
}

private void UpdateActiveTab()
{
if (!string.IsNullOrEmpty(ActiveTab) && _tabPanels != null)
{
foreach (var tabPanel in _tabPanels)
{
tabPanel.IsActive = tabPanel.Name.Equals(ActiveTab, StringComparison.OrdinalIgnoreCase);
}
}
}

internal void AddTabPanel(TabPanel tabPanel)
{
if (!_tabPanels.Exists(item => item.Name == tabPanel.Name) && IsAuthorized(tabPanel))
{
_tabPanels.Add(tabPanel);
if (string.IsNullOrEmpty(ActiveTab))
{
ActiveTab = tabPanel.Name;
}
UpdateActiveTab();
StateHasChanged();
}
}

private void SetActiveTab(string tabName)
{
ActiveTab = tabName;
UpdateActiveTab();
StateHasChanged();
if (string.IsNullOrEmpty(ActiveTab))
{
ActiveTab = tabPanel.Name;
}
}

private bool IsAuthorized(TabPanel tabPanel)
Expand Down

0 comments on commit 9d7549d

Please sign in to comment.