Skip to content

Commit

Permalink
globalFilter - panells no relacionats
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Alloza committed Apr 2, 2024
1 parent 69c480a commit b6a62ee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export const PanelInteractionUtils = {
*/
removeColumn: (ebp: EdaBlankPanelComponent, c: Column, list?: string) => {
ebp.disableBtnSave();

console.log(JSON.stringify(ebp));
// Busca de l'array index, la columna a borrar i ho fa
if (list === 'select') {
if (ebp.selectedQueryMode == 'EDA2') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<br><br>

<p-table [value]="filteredPanels">
<p-table [value]="allPanels">
<ng-template pTemplate="header">
<tr>
<th style="width: 40%;">Panel</th>
Expand All @@ -50,7 +50,7 @@
<tr>
<td style="width: 40%;">
<button type="button" pButton class="ui-button" [label]="panel.title"
[style]="{'width': '70%'}"
[style]="{'width': '70%'}" (click)="onAddPanelForFilter(panel)"
[ngClass]="{'ui-button-selected': panel.active, 'ui-button-unselected':!panel.active, 'ui-button-unvaliable':!panel.avaliable}">
</button>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
@Input() dataSource: any;
public modelTables: any[] = [];
@Input() panels: EdaPanel[] = [];

public allPanels: any[] = [];
public filteredPanels: any[] = [];

@Output() close: EventEmitter<any> = new EventEmitter<any>();
Expand Down Expand Up @@ -52,6 +54,12 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
private fileUtils: FileUtiles,
) { }

private sortByTittle = (a: any, b: any) => {
if (a.title < b.title) { return -1; }
if (a.title > b.title) { return 1; }
return 0;
};

public ngOnInit(): void {
this.display = true;
this.modelTables = _.cloneDeep(this.dataSource.model.tables);
Expand Down Expand Up @@ -101,20 +109,12 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
}

public initPanels() {
let panels = this.globalFilterService.filterPanels(this.modelTables, this.panels);

const sortByTittle = (a: any, b: any) => {
if (a.title < b.title) { return -1; }
if (a.title > b.title) { return 1; }
return 0;
};

panels = panels.sort(sortByTittle);

this.filteredPanels = panels.filter((p: any) => p.avaliable === true && p.active === true);

this.allPanels = this.globalFilterService.filterPanels(this.modelTables, this.panels);
this.allPanels = this.allPanels.sort(this.sortByTittle);
this.filteredPanels = this.allPanels.filter((p: any) => p.avaliable === true && p.active === true);

if (this.globalFilter.isnew) {
for (const panel of this.filteredPanels) {
for (const panel of this.allPanels) {
this.globalFilter.pathList[panel.id] = {
selectedTableNodes: {},
path: []
Expand Down Expand Up @@ -148,6 +148,18 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
this.tables.sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
}

public onAddPanelForFilter(panel: any) {
if (!panel.avaliable) {
this.clear();

this.allPanels = this.globalFilterService.filterPanels(this.modelTables, this.panels, panel);
this.allPanels = this.allPanels.sort(this.sortByTittle);
this.filteredPanels = this.allPanels.filter((p: any) => p.avaliable === true && p.active === true);
this.initTablesForFilter();
}

}

public getColumnsByTable() {
this.columns = [];

Expand Down Expand Up @@ -247,9 +259,11 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
private validateGlobalFilter(): boolean {
let valid = true;

const availablePanels = this.filteredPanels.map((p) => p.id);

if (!this.globalFilter.isdeleted) {
for (const key in this.globalFilter.pathList) {
if (_.isEmpty(this.globalFilter.pathList[key].selectedTableNodes)) {
if (availablePanels.includes(key) && _.isEmpty(this.globalFilter.pathList[key].selectedTableNodes)) {
valid = false;
}
}
Expand All @@ -258,6 +272,27 @@ export class GlobalFilterDialogComponent implements OnInit, OnDestroy {
return valid;
}

private clear(): void {
this.tables = [];
this.columns = [];
this.columnValues = [];
this.globalFilter.selectedTable = {};
this.globalFilter.selectedColumn = {};
this.globalFilter.selectedItems = [];
this.globalFilter.panelList = [];
this.globalFilter.pathList = {};
this.globalFilter.type = '';

for (const panel of this.allPanels) {
panel.content.globalFilterPaths = [];

this.globalFilter.pathList[panel.id] = {
selectedTableNodes: {},
path: []
};
}
}

public onApply(): void {
if (this.validateGlobalFilter()) {
this.globalFilterChange.emit(this.globalFilter);
Expand Down
5 changes: 2 additions & 3 deletions eda/eda_app/src/app/services/api/global-filters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class GlobalFiltersService {
return firstPanelRelatedTables;
}

public filterPanels(tables: any[], panels: EdaPanel[]): any[] {
public filterPanels(tables: any[], panels: EdaPanel[], rootPanel?: any): any[] {
const filteredPanels: any[] = panels.filter((panel) => panel.content);

for (const panel of filteredPanels) {
Expand All @@ -146,7 +146,7 @@ export class GlobalFiltersService {
this.assertTable(rootTable, queryTables, tables);
}

const rootPanel = filteredPanels[0];
if (!rootPanel) rootPanel = filteredPanels[0];


if (rootPanel) {
Expand Down Expand Up @@ -176,7 +176,6 @@ export class GlobalFiltersService {
return filteredPanels;
}


public loadTablePaths(tables: any[], rootPanel: EdaPanel) {
const panelQuery = rootPanel.content.query.query;
const rootTable = panelQuery.rootTable;
Expand Down

0 comments on commit b6a62ee

Please sign in to comment.