diff --git a/frontend/src/app/modules/core/user/table-settings.service.ts b/frontend/src/app/modules/core/user/table-settings.service.ts index ab1e6aac50..d49cee7fcb 100644 --- a/frontend/src/app/modules/core/user/table-settings.service.ts +++ b/frontend/src/app/modules/core/user/table-settings.service.ts @@ -20,6 +20,7 @@ import { Injectable } from '@angular/core'; import { PartTableType } from '@shared/components/table/table.model'; import { Subject } from 'rxjs'; +import {TableViewConfig} from "@shared/components/parts-table/table-view-config.model"; @Injectable({ providedIn: 'root', @@ -28,7 +29,7 @@ export class TableSettingsService { private settingsKey = 'TableViewSettings'; private changeEvent = new Subject(); - storeTableSettings(partTableType: PartTableType, tableSettingsList: any ): void { + storeTableSettings(tableSettingsList: any ): void { // before setting anything, all maps in new tableSettingList should be stringified Object.keys(tableSettingsList).forEach(tableSetting => { console.log(tableSetting, "settings"); @@ -52,6 +53,19 @@ export class TableSettingsService { return settingsObject; } + storedTableSettingsInvalid(tableViewConfig: TableViewConfig, tableType: PartTableType):boolean{ + let isInvalid = false; + const storage = this.getStoredTableSettings(); + for (const col of tableViewConfig.displayedColumns.values()){ + if (!storage[tableType].columnsForDialog.include(col)){ + console.warn("Found issue in tablesettings", col); + isInvalid = true; + } + } + localStorage.removeItem(this.settingsKey); + return isInvalid; + } + emitChangeEvent() { this.changeEvent.next(); } diff --git a/frontend/src/app/modules/shared/components/parts-table/parts-table.component.ts b/frontend/src/app/modules/shared/components/parts-table/parts-table.component.ts index c65e34d97c..0ce227e83c 100644 --- a/frontend/src/app/modules/shared/components/parts-table/parts-table.component.ts +++ b/frontend/src/app/modules/shared/components/parts-table/parts-table.component.ts @@ -68,6 +68,7 @@ import { } from "@shared/components/parts-table/parts-as-planned-customer-configuration.model"; import {Router} from "@angular/router"; import {ALERT_BASE_ROUTE, INVESTIGATION_BASE_ROUTE} from "@core/known-route"; +import {ToastService} from "@shared/components/toasts/toast.service"; @Component({ @@ -138,7 +139,11 @@ export class PartsTableComponent implements OnInit { @Output() clickSelectAction = new EventEmitter(); @Output() filterActivated = new EventEmitter(); - constructor(private readonly tableSettingsService: TableSettingsService, private dialog: MatDialog, private router: Router) { + constructor( + private readonly tableSettingsService: TableSettingsService, + private dialog: MatDialog, + private router: Router, + private toastService: ToastService) { } @@ -246,6 +251,10 @@ export class PartsTableComponent implements OnInit { private setupTableViewSettings() { const tableSettingsList = this.tableSettingsService.getStoredTableSettings(); + + if (this.tableSettingsService.storedTableSettingsInvalid(this.tableViewConfig, this.tableType)){ + + } // check if there are table settings list if (tableSettingsList) { // if yes, check if there is a table-setting for this table type @@ -260,7 +269,7 @@ export class PartsTableComponent implements OnInit { columnsForTable: this.tableViewConfig.displayedColumns, filterColumnsForTable: this.tableViewConfig.filterColumns }; - this.tableSettingsService.storeTableSettings(this.tableType, tableSettingsList); + this.tableSettingsService.storeTableSettings(tableSettingsList); this.setupTableConfigurations(this.tableViewConfig.displayedColumns, this.tableViewConfig.filterColumns, this.tableViewConfig.sortableColumns, this.tableViewConfig.displayFilterColumnMappings, this.tableViewConfig.filterFormGroup); } } else { @@ -273,7 +282,7 @@ export class PartsTableComponent implements OnInit { filterColumnsForTable: this.tableViewConfig.filterColumns } } - this.tableSettingsService.storeTableSettings(this.tableType, newTableSettingsList); + this.tableSettingsService.storeTableSettings(newTableSettingsList); this.setupTableConfigurations(this.tableViewConfig.displayedColumns, this.tableViewConfig.filterColumns, this.tableViewConfig.sortableColumns, this.tableViewConfig.displayFilterColumnMappings, this.tableViewConfig.filterFormGroup); } } diff --git a/frontend/src/app/modules/shared/components/table-settings/table-settings.component.ts b/frontend/src/app/modules/shared/components/table-settings/table-settings.component.ts index e50d1ec4c5..2870512f33 100644 --- a/frontend/src/app/modules/shared/components/table-settings/table-settings.component.ts +++ b/frontend/src/app/modules/shared/components/table-settings/table-settings.component.ts @@ -102,7 +102,7 @@ export class TableSettingsComponent { } as TableViewSettings; // save all values back to localstorage - this.tableSettingsService.storeTableSettings(this.tableType, tableSettingsList); + this.tableSettingsService.storeTableSettings(tableSettingsList); // trigger action that table will refresh this.tableSettingsService.emitChangeEvent();