diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts index 8a3b3a3748..d35f82daf8 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts @@ -128,7 +128,7 @@ export class AlarmTableConfig extends EntityTableConfig }).afterClosed().subscribe( (res) => { if (res) { - this.table.updateData(); + this.updateData(); } } ); diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts index e50bc5f3b7..7378aec16c 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts @@ -43,6 +43,6 @@ export class AlarmTableHeaderComponent extends EntityTableHeaderComponent { + attrMap[attribute.key] = attribute; + return attrMap; }, {}); this.queueStartTs = edge.queueStartTs && edge.queueStartTs.value ? edge.queueStartTs.value : 0; } @@ -114,7 +114,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig('status', 'event.status', '10%', (entity) => this.updateEdgeEventStatus(entity.createdTime), entity => ({ - color: this.isPending(entity.createdTime) ? edgeEventStatusColor.get(EdgeEventStatus.PENDING) : edgeEventStatusColor.get(EdgeEventStatus.DEPLOYED) + color: this.isPending(entity.createdTime) ? edgeEventStatusColor.get(EdgeEventStatus.PENDING) : + edgeEventStatusColor.get(EdgeEventStatus.DEPLOYED) }), false), new EntityActionTableColumn('data', 'event.data', { @@ -124,7 +125,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig { this.prepareEdgeEventContent(entity).subscribe( - (content) => this.showEdgeEventContent($event, content,'event.data'), + (content) => this.showEdgeEventContent($event, content, 'event.data'), () => this.showEntityNotFoundError() ); } @@ -132,7 +133,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig { - this.entityId = new AssetId(paramMap.get('entityId')); - }); this.headerSubtitle = this.translate.instant(this.entitiesTableConfig.entityTranslations.details); super.init(); this.entityComponent.isDetailsPage = true; @@ -92,6 +91,15 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl this.deleteEntity(action.event, action.entity); } })); + this.subscriptions.push(this.route.paramMap.subscribe( paramMap => { + if (this.entitiesTableConfig) { + const entityType = this.entitiesTableConfig.entityType; + const id = paramMap.get('entityId'); + this.currentEntityId = { id, entityType }; + this.reload(); + this.selectedTab = 0; + } + })); } ngOnDestroy() { @@ -99,20 +107,9 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl } reload(): void { - this.isEdit = false; - this.entitiesTableConfig.loadEntity(this.currentEntityId).subscribe( - (entity) => { - this.entity = entity; - this.broadcast.broadcast('updateBreadcrumb'); - this.isReadOnly = this.entitiesTableConfig.detailsReadonly(entity); - this.headerTitle = this.entitiesTableConfig.entityTitle(entity); - this.entityComponent.entity = entity; - this.entityComponent.isEdit = false; - if (this.entityTabsComponent) { - this.entityTabsComponent.entity = entity; - } - } - ); + this.reloadEntity().subscribe(() => { + this.onUpdateEntity(); + }); } onToggleDetailsEditMode() { @@ -136,29 +133,23 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl } onApplyDetails() { - if (this.detailsForm && this.detailsForm.valid) { - const editingEntity = {...this.editingEntity, ...this.entityComponent.entityFormValue()}; - if (this.editingEntity.hasOwnProperty('additionalInfo')) { - editingEntity.additionalInfo = - mergeDeep((this.editingEntity as any).additionalInfo, this.entityComponent.entityFormValue()?.additionalInfo); + this.saveEntity(false).subscribe((entity) => { + if (entity) { + this.onUpdateEntity(); } - this.entitiesTableConfig.saveEntity(editingEntity, this.editingEntity).subscribe( - (entity) => { - this.entity = entity; - this.entityComponent.entity = entity; - if (this.entityTabsComponent) { - this.entityTabsComponent.entity = entity; - } - this.isEdit = false; - } - ); - } + }); } confirmForm(): FormGroup { return this.detailsForm; } + private onUpdateEntity() { + this.broadcast.broadcast('updateBreadcrumb'); + this.isReadOnly = this.entitiesTableConfig.detailsReadonly(this.entity); + this.headerTitle = this.entitiesTableConfig.entityTitle(this.entity); + } + private deleteEntity($event: Event, entity: BaseData) { if ($event) { $event.stopPropagation(); diff --git a/ui-ngx/src/app/modules/home/components/entity/entity-details-panel.component.ts b/ui-ngx/src/app/modules/home/components/entity/entity-details-panel.component.ts index fed309fabc..d5bf971d93 100644 --- a/ui-ngx/src/app/modules/home/components/entity/entity-details-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/entity/entity-details-panel.component.ts @@ -34,16 +34,17 @@ import { PageComponent } from '@shared/components/page.component'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; -import { BaseData, HasId } from '@shared/models/base-data'; +import { BaseData, HasId, hasIdEquals } from '@shared/models/base-data'; import { EntityType, EntityTypeResource, EntityTypeTranslation } from '@shared/models/entity-type.models'; import { FormGroup } from '@angular/forms'; import { EntityComponent } from './entity.component'; import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; import { EntityAction } from '@home/models/entity/entity-component.models'; -import { Subscription } from 'rxjs'; +import { Observable, ReplaySubject, Subscription } from 'rxjs'; import { MatTab, MatTabGroup } from '@angular/material/tabs'; import { EntityTabsComponent } from '@home/components/entity/entity-tabs.component'; import { deepClone, mergeDeep } from '@core/utils'; +import { entityIdEquals } from '@shared/models/id/entity-id'; @Component({ selector: 'tb-entity-details-panel', @@ -102,9 +103,11 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV @Input() set entityId(entityId: HasId) { - if (entityId && entityId !== this.currentEntityId) { + if (!hasIdEquals(entityId, this.currentEntityId)) { this.currentEntityId = entityId; - this.reload(); + if (this.currentEntityId) { + this.reloadEntity(); + } } } @@ -228,7 +231,8 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV return this.isEditValue && this.entitiesTableConfig.hideDetailsTabsOnEdit; } - reload(): void { + reloadEntity(): Observable> { + const loadEntitySubject = new ReplaySubject>(); this.isEdit = false; this.entitiesTableConfig.loadEntity(this.currentEntityId).subscribe( (entity) => { @@ -237,8 +241,11 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV if (this.entityTabsComponent) { this.entityTabsComponent.entity = entity; } + loadEntitySubject.next(entity); + loadEntitySubject.complete(); } ); + return loadEntitySubject; } onCloseEntityDetails() { @@ -273,7 +280,8 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV } } - saveEntity() { + saveEntity(emitEntityUpdated = true): Observable> { + const saveEntitySubject = new ReplaySubject>(); if (this.detailsForm.valid) { const editingEntity = {...this.editingEntity, ...this.entityComponent.entityFormValue()}; if (this.editingEntity.hasOwnProperty('additionalInfo')) { @@ -288,10 +296,18 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV this.entityTabsComponent.entity = entity; } this.isEdit = false; - this.entityUpdated.emit(this.entity); + if (emitEntityUpdated) { + this.entityUpdated.emit(this.entity); + } + saveEntitySubject.next(entity); + saveEntitySubject.complete(); } ); + } else { + saveEntitySubject.next(null); + saveEntitySubject.complete(); } + return saveEntitySubject; } ngAfterViewInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts index 9921bdda4d..02bd9d2ad0 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts @@ -142,10 +142,11 @@ export class EventTableConfig extends EntityTableConfig { icon: 'delete', isEnabled: () => true, onAction: ($event) => { - this.eventService.clearEvents(this.entityId, this.eventType, this.filterParams, this.tenantId, this.table.pageLink as TimePageLink).subscribe( + this.eventService.clearEvents(this.entityId, this.eventType, this.filterParams, this.tenantId, + this.getTable().pageLink as TimePageLink).subscribe( () => { - this.table.paginator.pageIndex = 0; - this.table.updateData(); + this.getTable().paginator.pageIndex = 0; + this.updateData(); } ); } @@ -275,7 +276,7 @@ export class EventTableConfig extends EntityTableConfig { break; } if (updateTableColumns) { - this.table.columnsUpdated(true); + this.getTable().columnsUpdated(true); } } @@ -345,8 +346,8 @@ export class EventTableConfig extends EntityTableConfig { } this.filterParams = {}; - this.table.paginator.pageIndex = 0; - this.table.updateData(); + this.getTable().paginator.pageIndex = 0; + this.updateData(); } private editEventFilter($event: MouseEvent) { @@ -389,8 +390,8 @@ export class EventTableConfig extends EntityTableConfig { componentRef.onDestroy(() => { if (componentRef.instance.result && !isEqual(this.filterParams, componentRef.instance.result.filterParams)) { this.filterParams = componentRef.instance.result.filterParams; - this.table.paginator.pageIndex = 0; - this.table.updateData(); + this.getTable().paginator.pageIndex = 0; + this.updateData(); } }); this.cd.detectChanges(); diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts b/ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts index b33076739e..e600d14a75 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts @@ -40,6 +40,6 @@ export class EventTableHeaderComponent extends EntityTableHeaderComponent eventTypeChanged(eventType: EventType | DebugEventType) { this.eventTableConfig.eventType = eventType; - this.eventTableConfig.table.resetSortAndFilter(true, true); + this.eventTableConfig.getTable().resetSortAndFilter(true, true); } } diff --git a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts index fcfc72f745..b9517ad4cb 100644 --- a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts +++ b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts @@ -31,6 +31,8 @@ import { ActivatedRoute } from '@angular/router'; import { EntityTabsComponent } from '../../components/entity/entity-tabs.component'; import { DAY, historyInterval } from '@shared/models/time/time.models'; import { IEntitiesTableComponent } from '@home/models/entity/entity-table-component.models'; +import { IEntityDetailsPageComponent } from '@home/models/entity/entity-details-page-component.models'; +import { templateJitUrl } from '@angular/compiler'; export type EntityBooleanFunction> = (entity: T) => boolean; export type EntityStringFunction> = (entity: T) => string; @@ -136,11 +138,13 @@ export class EntityTableConfig, P extends PageLink = P constructor() {} + private table: IEntitiesTableComponent = null; + private entityDetailsPage: IEntityDetailsPageComponent = null; + componentsData: any = null; loadDataOnInit = true; onLoadAction: (route: ActivatedRoute) => void = null; - table: IEntitiesTableComponent = null; useTimePageLink = false; defaultTimewindowInterval = historyInterval(DAY); entityType: EntityType = null; @@ -189,6 +193,40 @@ export class EntityTableConfig, P extends PageLink = P entityAdded: EntityVoidFunction = () => {}; entityUpdated: EntityVoidFunction = () => {}; entitiesDeleted: EntityIdsVoidFunction = () => {}; + + getTable(): IEntitiesTableComponent { + return this.table; + } + + setTable(table: IEntitiesTableComponent) { + this.table = table; + this.entityDetailsPage = null; + } + + getEntityDetailsPage(): IEntityDetailsPageComponent { + return this.entityDetailsPage; + } + + setEntityDetailsPage(entityDetailsPage: IEntityDetailsPageComponent) { + this.entityDetailsPage = entityDetailsPage; + this.table = null; + } + + updateData(closeDetails = false) { + if (this.table) { + this.table.updateData(closeDetails); + } else if (this.entityDetailsPage) { + this.entityDetailsPage.reload(); + } + } + + getActivatedRoute(): ActivatedRoute { + if (this.table) { + return this.table.route; + } else { + return null; + } + } } export function checkBoxCell(value: boolean): string { diff --git a/ui-ngx/src/app/modules/home/models/entity/entity-details-page-component.models.ts b/ui-ngx/src/app/modules/home/models/entity/entity-details-page-component.models.ts new file mode 100644 index 0000000000..64977ff250 --- /dev/null +++ b/ui-ngx/src/app/modules/home/models/entity/entity-details-page-component.models.ts @@ -0,0 +1,19 @@ +/// +/// Copyright © 2016-2022 The Thingsboard Authors +/// +/// 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. +/// + +export interface IEntityDetailsPageComponent { + reload(): void; +} diff --git a/ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts b/ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts index e87952b39f..bd09efb8d5 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts @@ -36,7 +36,7 @@ export class AssetTableHeaderComponent extends EntityTableHeaderComponent this.onAssetAction(action, this.config); - this.config.detailsReadonly = () => (this.config.componentsData.assetScope === 'customer_user' || this.config.componentsData.assetScope === 'edge_customer_user'); + this.config.detailsReadonly = () => (this.config.componentsData.assetScope === 'customer_user' || + this.config.componentsData.assetScope === 'edge_customer_user'); this.config.headerComponent = AssetTableHeaderComponent; @@ -295,7 +296,7 @@ export class AssetsTableConfigResolver implements Resolve true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('asset.import'), @@ -332,7 +333,7 @@ export class AssetsTableConfigResolver implements Resolve { if (res) { this.broadcast.broadcast('assetSaved'); - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -341,7 +342,7 @@ export class AssetsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -379,7 +380,7 @@ export class AssetsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -402,7 +403,7 @@ export class AssetsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -431,7 +432,7 @@ export class AssetsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.assetScope !== 'tenant'); } ); } @@ -459,7 +460,7 @@ export class AssetsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -503,7 +504,7 @@ export class AssetsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -522,7 +523,7 @@ export class AssetsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.assetScope !== 'tenant'); } ); } @@ -550,7 +551,7 @@ export class AssetsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts index 79daaaaa5b..a3716823e1 100644 --- a/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts @@ -141,7 +141,7 @@ export class CustomersTableConfigResolver implements Resolve this.onDashboardAction(action); - this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' || this.config.componentsData.dashboardScope === 'edge_customer_user'); + this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' || + this.config.componentsData.dashboardScope === 'edge_customer_user'); } resolve(route: ActivatedRouteSnapshot): Observable> { @@ -147,7 +148,8 @@ export class DashboardsTableConfigResolver implements Resolve this.config.componentsData.dashboardScope === 'tenant'; return this.config; @@ -322,7 +324,7 @@ export class DashboardsTableConfigResolver implements Resolve true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('dashboard.import'), @@ -372,7 +374,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (dashboard) { - this.config.table.updateData(); + this.config.updateData(); } } ); @@ -400,7 +402,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -420,7 +422,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); }); } ); @@ -440,7 +442,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -480,7 +482,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -499,7 +501,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant'); } ); } @@ -527,7 +529,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -577,7 +579,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -596,7 +598,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant'); } ); } @@ -624,7 +626,7 @@ export class DashboardsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts index ba60a85835..2434f50151 100644 --- a/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts @@ -151,7 +151,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } } ); @@ -171,7 +171,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -191,7 +191,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve { if (deviceProfile) { - this.config.table.updateData(); + this.config.updateData(); } } ); diff --git a/ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts b/ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts index 858049737a..e2a1cd7bde 100644 --- a/ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts @@ -37,7 +37,7 @@ export class DeviceTableHeaderComponent extends EntityTableHeaderComponent { } onDeviceProfileUpdated() { - this.entitiesTableConfig.table.updateData(false); + this.entitiesTableConfig.updateData(false); } onDeviceProfileChanged(deviceProfile: DeviceProfileInfo) { diff --git a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts index 1f49a853ed..4d320b6926 100644 --- a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts @@ -375,7 +375,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { this.broadcast.broadcast('deviceSaved'); - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -394,12 +394,12 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } } ); @@ -420,7 +420,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -439,7 +439,7 @@ export class DevicesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -462,7 +462,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -491,7 +491,7 @@ export class DevicesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.deviceScope !== 'tenant'); } ); } @@ -519,7 +519,7 @@ export class DevicesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -586,7 +586,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -605,7 +605,7 @@ export class DevicesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.deviceScope !== 'tenant'); } ); } @@ -633,7 +633,7 @@ export class DevicesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts index 5ba46704ec..d956094458 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts @@ -36,7 +36,7 @@ export class EdgeTableHeaderComponent extends EntityTableHeaderComponent true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('edge.import'), @@ -345,7 +345,7 @@ export class EdgesTableConfigResolver implements Resolve { if (res) { this.broadcast.broadcast('edgeSaved'); - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -365,7 +365,7 @@ export class EdgesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -374,7 +374,7 @@ export class EdgesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -443,7 +443,7 @@ export class EdgesTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -472,7 +472,7 @@ export class EdgesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.edgeScope !== 'tenant'); } ); } @@ -500,7 +500,7 @@ export class EdgesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts b/ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts index 9729e16e0f..b4dd01c0bc 100644 --- a/ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts +++ b/ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts @@ -36,7 +36,7 @@ export class EntityViewTableHeaderComponent extends EntityTableHeaderComponent { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -337,7 +337,7 @@ export class EntityViewsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -378,7 +378,7 @@ export class EntityViewsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -407,7 +407,7 @@ export class EntityViewsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.entityViewScope !== 'tenant'); } ); } @@ -435,7 +435,7 @@ export class EntityViewsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -479,7 +479,7 @@ export class EntityViewsTableConfigResolver implements Resolve { if (res) { - this.config.table.updateData(); + this.config.updateData(); } }); } @@ -498,7 +498,7 @@ export class EntityViewsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.entityViewScope !== 'tenant'); } ); } @@ -526,7 +526,7 @@ export class EntityViewsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index 6743cb4601..99070807e2 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -151,7 +151,7 @@ export class RuleChainsTableConfigResolver implements Resolve true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('rulechain.import'), @@ -343,13 +343,13 @@ export class RuleChainsTableConfigResolver implements Resolve { this.config.componentsData.edge = edge; - this.config.table.updateData(); + this.config.updateData(); } ); } else { this.ruleChainService.setRootRuleChain(ruleChain.id.id).subscribe( () => { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -399,7 +399,7 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -436,11 +436,11 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } else { - this.config.table.updateData(); + this.config.updateData(); } } ); @@ -463,7 +463,7 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(this.config.componentsData.ruleChainScope !== 'tenant'); } ); } @@ -491,7 +491,7 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -513,7 +513,7 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -535,7 +535,7 @@ export class RuleChainsTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } diff --git a/ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts index ac02908ba9..3b1773842d 100644 --- a/ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts @@ -106,7 +106,7 @@ export class TenantProfilesTableConfigResolver implements Resolve true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('tenant-profile.import'), @@ -140,7 +140,7 @@ export class TenantProfilesTableConfigResolver implements Resolve { - this.config.table.updateData(); + this.config.updateData(); } ); } @@ -152,7 +152,7 @@ export class TenantProfilesTableConfigResolver implements Resolve { if (deviceProfile) { - this.config.table.updateData(); + this.config.updateData(); } } ); diff --git a/ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts b/ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts index 927a564a65..676e3734c8 100644 --- a/ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts +++ b/ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts @@ -99,6 +99,6 @@ export class TenantComponent extends ContactBasedComponent { } onTenantProfileUpdated() { - this.entitiesTableConfig.table.updateData(false); + this.entitiesTableConfig.updateData(false); } } diff --git a/ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts index cdeab0163f..444ce1624d 100644 --- a/ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts @@ -91,7 +91,7 @@ export class TenantsTableConfigResolver implements Resolve if ($event) { $event.stopPropagation(); } - const url = this.router.createUrlTree([user.id.id], {relativeTo: config.table.route}); + const url = this.router.createUrlTree([user.id.id], {relativeTo: config.getActivatedRoute()}); this.router.navigateByUrl(url); } diff --git a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts index b43aeab70a..9533af5782 100644 --- a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts @@ -76,7 +76,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve true, - onAction: ($event) => this.config.table.addEntity($event) + onAction: ($event) => this.config.getTable().addEntity($event) }, { name: this.translate.instant('widgets-bundle.import'), @@ -137,7 +137,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve { if (widgetsBundle) { - this.config.table.updateData(); + this.config.updateData(); } } ); diff --git a/ui-ngx/src/app/shared/models/base-data.ts b/ui-ngx/src/app/shared/models/base-data.ts index 32cc1c05f5..3af9bb9059 100644 --- a/ui-ngx/src/app/shared/models/base-data.ts +++ b/ui-ngx/src/app/shared/models/base-data.ts @@ -16,6 +16,7 @@ import { EntityId } from '@shared/models/id/entity-id'; import { HasUUID } from '@shared/models/id/has-uuid'; +import { isDefinedAndNotNull } from '@core/utils'; export declare type HasId = EntityId | HasUUID; @@ -25,3 +26,11 @@ export interface BaseData { name?: string; label?: string; } + +export function hasIdEquals(id1: HasId, id2: HasId): boolean { + if (isDefinedAndNotNull(id1) && isDefinedAndNotNull(id2)) { + return id1.id === id2.id; + } else { + return id1 === id2; + } +}