@using Rms.Risk.Mango.Pivot.Core @using System.Threading @using Rms.Risk.Mango.Pivot.Core.Models @inject IJSRuntime _jsRuntime @* * 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. *@
@if ( PivotDef != null ) {
} @if (PivotService != null) {
}
@*
*@ @*
*@ @*
*@ @*
*@ @code { [CascadingParameter] public IModalService Modal { get; set; } = null!; [Parameter] public string Class { get; set; } = ""; [Parameter] public PivotDefinition? Pivot { get => _pivot; set { if (_pivot == value) return; _pivot = value; InvokeAsync(StateHasChanged); } } [Parameter] public IPivotTableDataSource? PivotService { get; set; } [Parameter] public string? Collection { get; set; } [Parameter] public FilterExpressionTree.ExpressionGroup? ExtraFilter { get; set; } [Parameter] public Func> GetQueryText { get; set; } = (_, _, _, _) => Task.FromResult(""); private string SimpleClass => PivotDef?.PivotType == PivotTypeEnum.SimpleAggregation ? "" : "d-none"; private string CustomClass => PivotDef?.PivotType is PivotTypeEnum.CustomQuery or PivotTypeEnum.AggregationForHumans ? "" : "d-none"; private string _rowClass = ""; private string PivotTypeName => PivotDef?.PivotType switch { PivotTypeEnum.CustomQuery => "Custom query", PivotTypeEnum.SimpleAggregation => "Simple aggregation", PivotTypeEnum.AggregationForHumans => "Aggregation for Humans", _ => "unsupported" }; private PivotDefinition? _pivot; private PivotDefinition? PivotDef => _pivot; // private DotNetObjectReference _objRef; // private ElementReference _simpleBeforeGrouping; // private ElementReference _simpleAdditionalGrouping; // private ElementReference _simpleAfterGrouping; // private ElementReference _customQuery; protected override Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { // _objRef = DotNetObjectReference.Create(this); // // await _jsRuntime.InvokeVoidAsync("DashboardUtils.LoadCodeEditor", "SimpleBeforeGrouping", "application/json", _simpleBeforeGrouping, _objRef, "UpdateBeforeGroupingField", false); // await _jsRuntime.InvokeVoidAsync("DashboardUtils.LoadCodeEditor", "SimpleAdditionalGrouping", "application/json", _simpleAdditionalGrouping, _objRef, "UpdateAdditionalGroupingField", false); // await _jsRuntime.InvokeVoidAsync("DashboardUtils.LoadCodeEditor", "SimpleAfterGrouping", "application/json", _simpleAfterGrouping, _objRef, "UpdateAfterGroupingField", false); // await _jsRuntime.InvokeVoidAsync("DashboardUtils.LoadCodeEditor", "CustomQuery", "application/json", _customQuery, _objRef, "UpdateCustomQueryField", false); return InvokeAsync(StateHasChanged); } return Task.CompletedTask; } private Task SelectPivotType(PivotTypeEnum t) { PivotDef!.PivotType = t; return InvokeAsync(StateHasChanged); } [JSInvokable(nameof(UpdateBeforeGroupingField))] public Task UpdateBeforeGroupingField(string text) { if (PivotDef == null || PivotDef.BeforeGrouping == text) return Task.CompletedTask; PivotDef.BeforeGrouping = text; return InvokeAsync(StateHasChanged); } [JSInvokable(nameof(UpdateAdditionalGroupingField))] public Task UpdateAdditionalGroupingField(string text) { if (PivotDef == null || PivotDef.WithinGrouping == text) return Task.CompletedTask; PivotDef.WithinGrouping = text; return InvokeAsync(StateHasChanged); } [JSInvokable(nameof(UpdateCustomQueryField))] public Task UpdateCustomQueryField(string text) { if (PivotDef == null || PivotDef.CustomQuery == text) return Task.CompletedTask; PivotDef.CustomQuery = text; return InvokeAsync(StateHasChanged); } private async Task RevealTheQuery() { if (PivotService == null || string.IsNullOrWhiteSpace(Collection) || Pivot == null) return; try { var text = GetQueryText == null ? await PivotService.GetQueryTextAsync(Collection, Pivot, ExtraFilter) : await GetQueryText(Collection, Pivot, ExtraFilter, CancellationToken.None) ; await ShowQueryDialog(Modal, "Query", text); } catch (Exception ex) { await ModalDialogUtils.ShowExceptionDialog(Modal, "Exception", ex); } } private async Task ShowQueryDialog(IModalService service, string header, string text) { var parameters = new ModalParameters(); if (!string.IsNullOrWhiteSpace(text)) parameters.Add(Pivot!.PivotType != PivotTypeEnum.AggregationForHumans ? "TextJson" : "Text", text); parameters.Add("ShowJson", Collection?.StartsWith("BFG:") != true); var options = new ModalOptions { HideCloseButton = true, DisableBackgroundCancel = true }; var form = service.Show(header, parameters, options); await form.Result; } }