From 9b775a8c63b46ead6d120645d24e9809b7536d86 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Wed, 29 Oct 2025 12:59:20 +0530 Subject: [PATCH] fin --- .../editnewdash/editnewdash.component.ts | 16 +- .../financial-chart.component.ts | 204 +++++++++++++++++- 2 files changed, 211 insertions(+), 9 deletions(-) diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts index 5190c2b..061d6f0 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts @@ -91,14 +91,14 @@ export class EditnewdashComponent implements OnInit { name: 'Scatter Chart', identifier: 'scatter_chart' }, - // { - // name: 'Dynamic Chart', - // identifier: 'dynamic_chart' - // }, - // { - // name: 'Financial Chart', - // identifier: 'financial_chart' - // }, + { + name: 'Dynamic Chart', + identifier: 'dynamic_chart' + }, + { + name: 'Financial Chart', + identifier: 'financial_chart' + }, { name: 'To Do', identifier: 'to_do_chart' diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/financial-chart/financial-chart.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/financial-chart/financial-chart.component.ts index d46da04..2528fba 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/financial-chart/financial-chart.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/financial-chart/financial-chart.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/cor import { Dashboard3Service } from 'src/app/services/builder/dashboard3.service'; import { FilterService } from '../../common-filter/filter.service'; import { Subscription } from 'rxjs'; +import { AlertsService } from 'src/app/services/fnd/alerts.service'; @Component({ selector: 'app-financial-chart', @@ -37,7 +38,8 @@ export class FinancialChartComponent implements OnInit, OnChanges { constructor( private dashboardService: Dashboard3Service, - private filterService: FilterService + private filterService: FilterService, + private alertService: AlertsService ) { } ngOnInit(): void { @@ -59,6 +61,8 @@ export class FinancialChartComponent implements OnInit, OnChanges { // Initialize filter values if they haven't been initialized yet if (!this.filtersInitialized && (changes.baseFilters || changes.drilldownFilters || changes.drilldownLayers)) { this.initializeFilterValues(); + // Load filter options for dropdown/multiselect filters + this.loadFilterOptions(); this.filtersInitialized = true; } @@ -573,6 +577,11 @@ export class FinancialChartComponent implements OnInit, OnChanges { // Initialize base filters if (this.baseFilters) { this.baseFilters.forEach(filter => { + // Ensure filter has required properties + if (!filter.type) filter.type = 'text'; + if (!filter.options) filter.options = ''; + if (!filter.availableValues) filter.availableValues = ''; + if (filter.value === undefined || filter.value === null) { switch (filter.type) { case 'multiselect': @@ -594,6 +603,11 @@ export class FinancialChartComponent implements OnInit, OnChanges { // Initialize drilldown filters if (this.drilldownFilters) { this.drilldownFilters.forEach(filter => { + // Ensure filter has required properties + if (!filter.type) filter.type = 'text'; + if (!filter.options) filter.options = ''; + if (!filter.availableValues) filter.availableValues = ''; + if (filter.value === undefined || filter.value === null) { switch (filter.type) { case 'multiselect': @@ -617,6 +631,11 @@ export class FinancialChartComponent implements OnInit, OnChanges { this.drilldownLayers.forEach(layer => { if (layer.filters) { layer.filters.forEach((filter: any) => { + // Ensure filter has required properties + if (!filter.type) filter.type = 'text'; + if (!filter.options) filter.options = ''; + if (!filter.availableValues) filter.availableValues = ''; + if (filter.value === undefined || filter.value === null) { switch (filter.type) { case 'multiselect': @@ -883,4 +902,187 @@ export class FinancialChartComponent implements OnInit, OnChanges { // Remove document click handler if it exists this.removeDocumentClickHandler(); } + + // Load filter options for dropdown and multiselect filters + private loadFilterOptions(): void { + console.log('Loading filter options'); + + // Load options for base filters + if (this.baseFilters && this.table) { + this.baseFilters.forEach((filter, index) => { + if ((filter.type === 'dropdown' || filter.type === 'multiselect') && filter.field) { + this.loadFilterValuesForField(this.table, this.connection, filter.field, index, 'base'); + } + }); + } + + // Load options for drilldown filters + if (this.drilldownFilters && this.drilldownApiUrl) { + this.drilldownFilters.forEach((filter, index) => { + if ((filter.type === 'dropdown' || filter.type === 'multiselect') && filter.field) { + this.loadFilterValuesForField(this.drilldownApiUrl, this.connection, filter.field, index, 'drilldown'); + } + }); + } + + // Load options for layer filters + if (this.drilldownLayers) { + this.drilldownLayers.forEach((layer, layerIndex) => { + if (layer.filters && layer.apiUrl) { + layer.filters.forEach((filter, filterIndex) => { + if ((filter.type === 'dropdown' || filter.type === 'multiselect') && filter.field) { + this.loadFilterValuesForField(layer.apiUrl, this.connection, filter.field, filterIndex, 'layer', layerIndex); + } + }); + } + }); + } + } + + // Load filter values for a specific field + private loadFilterValuesForField( + apiUrl: string, + connectionId: number | undefined, + field: string, + filterIndex: number, + filterType: 'base' | 'drilldown' | 'layer', + layerIndex?: number + ): void { + if (apiUrl && field) { + this.alertService.getValuesFromUrl(apiUrl, connectionId, field).subscribe( + (values: string[]) => { + console.log(`Loaded filter values for ${filterType} filter ${field}:`, values); + + // Update the filter with available values + if (filterType === 'base') { + const filter = this.baseFilters[filterIndex]; + if (filter) { + filter.availableValues = values.join(', '); + // For dropdown/multiselect types, also update the options + if (filter.type === 'dropdown' || filter.type === 'multiselect') { + filter.options = filter.availableValues; + } + } + } else if (filterType === 'drilldown') { + const filter = this.drilldownFilters[filterIndex]; + if (filter) { + filter.availableValues = values.join(', '); + // For dropdown/multiselect types, also update the options + if (filter.type === 'dropdown' || filter.type === 'multiselect') { + filter.options = filter.availableValues; + } + } + } else if (filterType === 'layer' && layerIndex !== undefined) { + const layer = this.drilldownLayers[layerIndex]; + if (layer && layer.filters) { + const filter = layer.filters[filterIndex]; + if (filter) { + filter.availableValues = values.join(', '); + // For dropdown/multiselect types, also update the options + if (filter.type === 'dropdown' || filter.type === 'multiselect') { + filter.options = filter.availableValues; + } + } + } + } + }, + (error) => { + console.error('Error loading available values for field:', field, error); + } + ); + } + } + + // Handle base filter field change + onBaseFilterFieldChange(index: number, field: string): void { + const filter = this.baseFilters[index]; + if (filter) { + filter.field = field; + // If field changes, reset value and options + filter.value = ''; + filter.options = ''; + filter.availableValues = ''; + + // If we have a field and table URL, load available values + if (field && this.table && (filter.type === 'dropdown' || filter.type === 'multiselect')) { + this.loadFilterValuesForField(this.table, this.connection, field, index, 'base'); + } + } + } + + // Handle base filter type change + onBaseFilterTypeChange(index: number, type: string): void { + const filter = this.baseFilters[index]; + if (filter) { + filter.type = type; + // If type changes to dropdown/multiselect and we have a field, load available values + if ((type === 'dropdown' || type === 'multiselect') && filter.field && this.table) { + this.loadFilterValuesForField(this.table, this.connection, filter.field, index, 'base'); + } + } + } + + // Handle drilldown filter field change + onDrilldownFilterFieldChange(index: number, field: string): void { + const filter = this.drilldownFilters[index]; + if (filter) { + filter.field = field; + // If field changes, reset value and options + filter.value = ''; + filter.options = ''; + filter.availableValues = ''; + + // If we have a field and drilldown API URL, load available values + if (field && this.drilldownApiUrl && (filter.type === 'dropdown' || filter.type === 'multiselect')) { + this.loadFilterValuesForField(this.drilldownApiUrl, this.connection, field, index, 'drilldown'); + } + } + } + + // Handle drilldown filter type change + onDrilldownFilterTypeChange(index: number, type: string): void { + const filter = this.drilldownFilters[index]; + if (filter) { + filter.type = type; + // If type changes to dropdown/multiselect and we have a field, load available values + if ((type === 'dropdown' || type === 'multiselect') && filter.field && this.drilldownApiUrl) { + this.loadFilterValuesForField(this.drilldownApiUrl, this.connection, filter.field, index, 'drilldown'); + } + } + } + + // Handle layer filter field change + onLayerFilterFieldChange(layerIndex: number, filterIndex: number, field: string): void { + const layer = this.drilldownLayers[layerIndex]; + if (layer && layer.filters) { + const filter = layer.filters[filterIndex]; + if (filter) { + filter.field = field; + // If field changes, reset value and options + filter.value = ''; + filter.options = ''; + filter.availableValues = ''; + + // If we have a field and layer API URL, load available values + if (field && layer.apiUrl && (filter.type === 'dropdown' || filter.type === 'multiselect')) { + this.loadFilterValuesForField(layer.apiUrl, this.connection, field, filterIndex, 'layer', layerIndex); + } + } + } + } + + // Handle layer filter type change + onLayerFilterTypeChange(layerIndex: number, filterIndex: number, type: string): void { + const layer = this.drilldownLayers[layerIndex]; + if (layer && layer.filters) { + const filter = layer.filters[filterIndex]; + if (filter) { + filter.type = type; + // If type changes to dropdown/multiselect and we have a field, load available values + if ((type === 'dropdown' || type === 'multiselect') && filter.field && layer.apiUrl) { + this.loadFilterValuesForField(layer.apiUrl, this.connection, filter.field, filterIndex, 'layer', layerIndex); + } + } + } + } } \ No newline at end of file