@using System.Text @using Newtonsoft.Json @using Rms.Risk.Mango.Pivot.Core @using Rms.Risk.Mango.Pivot.Core.Models @inject IPivotSharingService PivotSharingService @inject IJSRuntime Js @* * dbMango * * Copyright 2025 Deutsche Bank AG * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *@
Last refresh @LastRefresh.ToLongTimeString() took @LastRefreshElapsed.ToString("g")
} @code { private const string SavePivotDialogHeader = "Save Pivot"; private const string SharePivotDialogHeader = "Share Pivot"; [CascadingParameter] public IModalService Modal { get; set; } = null!; [Inject] public IUserService UserSession { get; set; } = null!; #region Parameters // ================================================= PARAMETERS ======================================================== // = = // = = // = = // ================================================= PARAMETERS ======================================================== [Parameter] public IPivotTableDataSource.PivotType PivotType { get; set; } = IPivotTableDataSource.PivotType.Predefined; [Parameter] public RenderFragment ExtraFilter { get; set; } = null!; [Parameter] public IPivotedData? PivotData { get; set { if (field == value) return; field = value; PivotDataChanged.InvokeAsync(field); InvokeAsync(StateHasChanged); } } [Parameter] public EventCallbackNote that you can always make your own copy by pressing Save As button.
", "Magic word" ); if ( string.IsNullOrWhiteSpace(answer) ) return; var magic = Base64Encode(DateTime.Now.ToString( "yyyy-MM-dd" )); if ( answer != magic ) { await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, "Nope!" ); return; } } else { var res = await ModalDialogUtils.ShowConfirmationDialog( Modal, SavePivotDialogHeader, $"Do you want to save Pivot \"{pivotDef.Name}\" to group \"{pivotDef.Group}\"?" ); if ( res.Cancelled ) return; } // update filter pivotDef.DrilldownFilter = ""; await PivotService.UpdatePivotAsync(Collection!, pivotDef, user, new CancellationTokenSource(5000).Token ); await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, $"Pivot \"{pivotDef.Name}\" updated." ); } protected async Task OnShare() { if (Collection == null || CurrentPivot == null) { await ModalDialogUtils.ShowInfoDialog(Modal, SharePivotDialogHeader, "Please select collection and pivot to share."); return; } var def = new SharedPivotDef { PivotDef = CurrentPivot!, Collection = Collection!, ExtraFilter = GetExtraFilter()?.ToJson(GetAllFields()) ?? "", SharedBy = await GetUserName(), SharedAtUTC = DateTime.UtcNow }; await SharePivot(def); } protected async Task OnDelete() { if (IsDeleteDisabled) return; var myself = await GetUserName(); if (string.IsNullOrWhiteSpace(myself)) return; var pivotDef = SelectedPivotNode!.Pivot; var user = SelectedPivotNode.Pivot.Owner; if (!user.Equals(myself, StringComparison.OrdinalIgnoreCase)) { await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, $"Pivot \"{pivotDef.Name}\" can only be deleted by user \"{user}\"." ); return; } var res = await ModalDialogUtils.ShowConfirmationDialog( Modal, SavePivotDialogHeader, $"Do you want to delete Pivot \"{pivotDef.Name}\" from group \"{pivotDef.Group}\" for user \"{user}\"?" ); if ( res.Cancelled ) return; await PivotService.DeletePivotAsync(Collection!, pivotDef.Name, pivotDef.Group, user, new CancellationTokenSource(5000).Token ); Pivot = SelectedCollectionNode!.Pivots.FirstOrDefault(x => x is { IsGroup: false, Pivot.Name: "Summary" })?.Text ?? SelectedCollectionNode.Pivots.FirstOrDefault(x => !x.IsGroup)?.Text ; await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, $"Pivot \"{pivotDef.Name}\" deleted." ); } protected async Task OnSaveAs() { if (IsSaveDisabled) return; var user = await GetUserName(); if (string.IsNullOrWhiteSpace(user)) return; var pivotDef = SelectedPivotNode!.Pivot; var groups = new[] {PivotDefinition.UserPivotsGroup} .Concat(SelectedCollectionNode!.Pivots .Where(x => x is { IsGroup: false, Pivot.IsPredefined: true }) .Select(x => x.Pivot.Group) .Distinct() ) .ToArray() ; var res = await PivotSaveAsComponent.ShowDialog(Modal, pivotDef, groups); if (res == null) return; var (name, group, answer) = res; if (string.IsNullOrWhiteSpace(name)) return; var needMagic = group != PivotDefinition.UserPivotsGroup; var magic = Base64Encode(DateTime.Now.ToString( "yyyy-MM-dd" )); if ( needMagic && answer != magic) { await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, "Nope!" ); return; } pivotDef = SelectedPivotNode.Pivot.Clone(); pivotDef.Name = name; pivotDef.Group = group; pivotDef.Owner = user; // update filter pivotDef.DrilldownFilter = ""; await PivotService.UpdatePivotAsync(Collection!, pivotDef, user, new CancellationTokenSource(5000).Token); Pivot = SelectedCollectionNode.Pivots.FirstOrDefault(x => !x.IsGroup && x.Pivot.Group == pivotDef.Group && x.Pivot.Name == pivotDef.Name)?.Text ?? SelectedCollectionNode.Pivots.FirstOrDefault(x => !x.IsGroup)?.Text ; await ModalDialogUtils.ShowInfoDialog( Modal, SavePivotDialogHeader, $"Pivot \"{pivotDef.Name}\" (group \"{pivotDef.Group}\") updated." ); } private Task SharePivot(SharedPivotDef data) => ModalDialogUtils.SafeCall(Modal, "Share Pivot", () => SharePivotUnsafe(data)); private ValueTaskThis function allows you to share the exact pivot you've just ran even if you made any modification to it.
" + $"Pivot \"{data.PivotDef.Name}\" with all modifications applied will be available using this URL:
{url}.
Please copy this URL and send it using instant messaging or by E-Mail." + "This URL will be valid for 7 days.