Browse Source

Merge remote-tracking branch 'upstream/master' into code-review

pull/5922/head
Volodymyr Babak 5 years ago
parent
commit
e1df82f086
  1. 2
      ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts
  2. 2
      ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts
  3. 15
      ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts
  4. 3
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.html
  5. 8
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts
  6. 61
      ui-ngx/src/app/modules/home/components/entity/entity-details-page.component.ts
  7. 30
      ui-ngx/src/app/modules/home/components/entity/entity-details-panel.component.ts
  8. 17
      ui-ngx/src/app/modules/home/components/event/event-table-config.ts
  9. 2
      ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts
  10. 40
      ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts
  11. 19
      ui-ngx/src/app/modules/home/models/entity/entity-details-page-component.models.ts
  12. 2
      ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts
  13. 25
      ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts
  14. 2
      ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts
  15. 28
      ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts
  16. 6
      ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts
  17. 2
      ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts
  18. 2
      ui-ngx/src/app/modules/home/pages/device/device.component.ts
  19. 24
      ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts
  20. 2
      ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts
  21. 16
      ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts
  22. 2
      ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts
  23. 18
      ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts
  24. 20
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts
  25. 6
      ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts
  26. 2
      ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts
  27. 2
      ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts
  28. 2
      ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts
  29. 4
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts
  30. 9
      ui-ngx/src/app/shared/models/base-data.ts

2
ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts

@ -128,7 +128,7 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
}).afterClosed().subscribe( }).afterClosed().subscribe(
(res) => { (res) => {
if (res) { if (res) {
this.table.updateData(); this.updateData();
} }
} }
); );

2
ui-ngx/src/app/modules/home/components/alarm/alarm-table-header.component.ts

@ -43,6 +43,6 @@ export class AlarmTableHeaderComponent extends EntityTableHeaderComponent<AlarmI
searchStatusChanged(searchStatus: AlarmSearchStatus) { searchStatusChanged(searchStatus: AlarmSearchStatus) {
this.alarmTableConfig.searchStatus = searchStatus; this.alarmTableConfig.searchStatus = searchStatus;
this.alarmTableConfig.table.resetSortAndFilter(true, true); this.alarmTableConfig.getTable().resetSortAndFilter(true, true);
} }
} }

15
ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts

@ -48,7 +48,7 @@ import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component';
import { EdgeService } from '@core/http/edge.service'; import { EdgeService } from '@core/http/edge.service';
import { concatMap, map } from 'rxjs/operators'; import { concatMap, map } from 'rxjs/operators';
import { EntityService } from "@core/http/entity.service"; import { EntityService } from '@core/http/entity.service';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { ActionNotificationShow } from '@core/notification/notification.actions'; import { ActionNotificationShow } from '@core/notification/notification.actions';
@ -94,9 +94,9 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
private onUpdate(attributes: any): void { private onUpdate(attributes: any): void {
this.queueStartTs = 0; this.queueStartTs = 0;
let edge = attributes.reduce(function (map, attribute) { const edge = attributes.reduce((attrMap, attribute) => {
map[attribute.key] = attribute; attrMap[attribute.key] = attribute;
return map; return attrMap;
}, {}); }, {});
this.queueStartTs = edge.queueStartTs && edge.queueStartTs.value ? edge.queueStartTs.value : 0; this.queueStartTs = edge.queueStartTs && edge.queueStartTs.value ? edge.queueStartTs.value : 0;
} }
@ -114,7 +114,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
new EntityTableColumn<EdgeEvent>('status', 'event.status', '10%', new EntityTableColumn<EdgeEvent>('status', 'event.status', '10%',
(entity) => this.updateEdgeEventStatus(entity.createdTime), (entity) => this.updateEdgeEventStatus(entity.createdTime),
entity => ({ 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), }), false),
new EntityActionTableColumn<EdgeEvent>('data', 'event.data', new EntityActionTableColumn<EdgeEvent>('data', 'event.data',
{ {
@ -124,7 +125,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
onAction: ($event, entity) => onAction: ($event, entity) =>
{ {
this.prepareEdgeEventContent(entity).subscribe( this.prepareEdgeEventContent(entity).subscribe(
(content) => this.showEdgeEventContent($event, content,'event.data'), (content) => this.showEdgeEventContent($event, content, 'event.data'),
() => this.showEntityNotFoundError() () => this.showEntityNotFoundError()
); );
} }
@ -132,7 +133,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
'40px'), '40px'),
); );
if (updateTableColumns) { if (updateTableColumns) {
this.table.columnsUpdated(true); this.getTable().columnsUpdated(true);
} }
} }

3
ui-ngx/src/app/modules/home/components/entity/entities-table.component.html

@ -23,8 +23,9 @@
position="end" position="end"
[opened]="isDetailsOpen"> [opened]="isDetailsOpen">
<tb-entity-details-panel <tb-entity-details-panel
#entityDetailsPanel
[entitiesTableConfig]="entitiesTableConfig" [entitiesTableConfig]="entitiesTableConfig"
[entityId]="dataSource.currentEntity?.id" [entityId]="isDetailsOpen ? dataSource.currentEntity?.id : null"
(closeEntityDetails)="isDetailsOpen = false; detailsPanelOpened.emit(isDetailsOpen);" (closeEntityDetails)="isDetailsOpen = false; detailsPanelOpened.emit(isDetailsOpen);"
(entityUpdated)="onEntityUpdated($event)" (entityUpdated)="onEntityUpdated($event)"
(entityAction)="onEntityAction($event)" (entityAction)="onEntityAction($event)"

8
ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts

@ -64,6 +64,7 @@ import { HasUUID } from '@shared/models/id/has-uuid';
import { ResizeObserver } from '@juggle/resize-observer'; import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants'; import { hidePageSizePixelValue } from '@shared/models/constants';
import { IEntitiesTableComponent } from '@home/models/entity/entity-table-component.models'; import { IEntitiesTableComponent } from '@home/models/entity/entity-table-component.models';
import { EntityDetailsPanelComponent } from '@home/components/entity/entity-details-panel.component';
@Component({ @Component({
selector: 'tb-entities-table', selector: 'tb-entities-table',
@ -118,6 +119,8 @@ export class EntitiesTableComponent extends PageComponent implements IEntitiesTa
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ViewChild('entityDetailsPanel') entityDetailsPanel: EntityDetailsPanelComponent;
private updateDataSubscription: Subscription; private updateDataSubscription: Subscription;
private viewInited = false; private viewInited = false;
@ -182,7 +185,7 @@ export class EntitiesTableComponent extends PageComponent implements IEntitiesTa
headerComponent.entitiesTableConfig = this.entitiesTableConfig; headerComponent.entitiesTableConfig = this.entitiesTableConfig;
} }
this.entitiesTableConfig.table = this; this.entitiesTableConfig.setTable(this);
this.translations = this.entitiesTableConfig.entityTranslations; this.translations = this.entitiesTableConfig.entityTranslations;
this.headerActionDescriptors = [...this.entitiesTableConfig.headerActionDescriptors]; this.headerActionDescriptors = [...this.entitiesTableConfig.headerActionDescriptors];
@ -392,6 +395,9 @@ export class EntitiesTableComponent extends PageComponent implements IEntitiesTa
} }
} }
this.dataSource.loadEntities(this.pageLink); this.dataSource.loadEntities(this.pageLink);
if (this.isDetailsOpen && this.entityDetailsPanel) {
this.entityDetailsPanel.reloadEntity();
}
} }
private dataLoaded(col?: number, row?: number) { private dataLoaded(col?: number, row?: number) {

61
ui-ngx/src/app/modules/home/components/entity/entity-details-page.component.ts

@ -32,10 +32,11 @@ import { ActivatedRoute, Router } from '@angular/router';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { AssetId } from '@shared/models/id/asset-id'; import { AssetId } from '@shared/models/id/asset-id';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { deepClone, mergeDeep } from '@core/utils'; import { deepClone } from '@core/utils';
import { BroadcastService } from '@core/services/broadcast.service'; import { BroadcastService } from '@core/services/broadcast.service';
import { EntityDetailsPanelComponent } from '@home/components/entity/entity-details-panel.component'; import { EntityDetailsPanelComponent } from '@home/components/entity/entity-details-panel.component';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
import { IEntityDetailsPageComponent } from '@home/models/entity/entity-details-page-component.models';
@Component({ @Component({
selector: 'tb-entity-details-page', selector: 'tb-entity-details-page',
@ -43,7 +44,7 @@ import { DialogService } from '@core/services/dialog.service';
styleUrls: ['./entity-details-page.component.scss'], styleUrls: ['./entity-details-page.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class EntityDetailsPageComponent extends EntityDetailsPanelComponent implements OnInit, OnDestroy { export class EntityDetailsPageComponent extends EntityDetailsPanelComponent implements IEntityDetailsPageComponent, OnInit, OnDestroy {
headerTitle: string; headerTitle: string;
headerSubtitle: string; headerSubtitle: string;
@ -54,6 +55,7 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
if (this.entitiesTableConfigValue !== entitiesTableConfig) { if (this.entitiesTableConfigValue !== entitiesTableConfig) {
this.entitiesTableConfigValue = entitiesTableConfig; this.entitiesTableConfigValue = entitiesTableConfig;
if (this.entitiesTableConfigValue) { if (this.entitiesTableConfigValue) {
this.entitiesTableConfigValue.setEntityDetailsPage(this);
this.isEdit = false; this.isEdit = false;
this.entity = null; this.entity = null;
} }
@ -81,9 +83,6 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
ngOnInit() { ngOnInit() {
this.headerSubtitle = ''; this.headerSubtitle = '';
this.route.paramMap.subscribe( paramMap => {
this.entityId = new AssetId(paramMap.get('entityId'));
});
this.headerSubtitle = this.translate.instant(this.entitiesTableConfig.entityTranslations.details); this.headerSubtitle = this.translate.instant(this.entitiesTableConfig.entityTranslations.details);
super.init(); super.init();
this.entityComponent.isDetailsPage = true; this.entityComponent.isDetailsPage = true;
@ -92,6 +91,15 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
this.deleteEntity(action.event, action.entity); 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() { ngOnDestroy() {
@ -99,20 +107,9 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
} }
reload(): void { reload(): void {
this.isEdit = false; this.reloadEntity().subscribe(() => {
this.entitiesTableConfig.loadEntity(this.currentEntityId).subscribe( this.onUpdateEntity();
(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;
}
}
);
} }
onToggleDetailsEditMode() { onToggleDetailsEditMode() {
@ -136,29 +133,23 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
} }
onApplyDetails() { onApplyDetails() {
if (this.detailsForm && this.detailsForm.valid) { this.saveEntity(false).subscribe((entity) => {
const editingEntity = {...this.editingEntity, ...this.entityComponent.entityFormValue()}; if (entity) {
if (this.editingEntity.hasOwnProperty('additionalInfo')) { this.onUpdateEntity();
editingEntity.additionalInfo =
mergeDeep((this.editingEntity as any).additionalInfo, this.entityComponent.entityFormValue()?.additionalInfo);
} }
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 { confirmForm(): FormGroup {
return this.detailsForm; 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<HasId>) { private deleteEntity($event: Event, entity: BaseData<HasId>) {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();

30
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 { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; 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 { EntityType, EntityTypeResource, EntityTypeTranslation } from '@shared/models/entity-type.models';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { EntityComponent } from './entity.component'; import { EntityComponent } from './entity.component';
import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
import { EntityAction } from '@home/models/entity/entity-component.models'; 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 { MatTab, MatTabGroup } from '@angular/material/tabs';
import { EntityTabsComponent } from '@home/components/entity/entity-tabs.component'; import { EntityTabsComponent } from '@home/components/entity/entity-tabs.component';
import { deepClone, mergeDeep } from '@core/utils'; import { deepClone, mergeDeep } from '@core/utils';
import { entityIdEquals } from '@shared/models/id/entity-id';
@Component({ @Component({
selector: 'tb-entity-details-panel', selector: 'tb-entity-details-panel',
@ -102,9 +103,11 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV
@Input() @Input()
set entityId(entityId: HasId) { set entityId(entityId: HasId) {
if (entityId && entityId !== this.currentEntityId) { if (!hasIdEquals(entityId, this.currentEntityId)) {
this.currentEntityId = entityId; 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; return this.isEditValue && this.entitiesTableConfig.hideDetailsTabsOnEdit;
} }
reload(): void { reloadEntity(): Observable<BaseData<HasId>> {
const loadEntitySubject = new ReplaySubject<BaseData<HasId>>();
this.isEdit = false; this.isEdit = false;
this.entitiesTableConfig.loadEntity(this.currentEntityId).subscribe( this.entitiesTableConfig.loadEntity(this.currentEntityId).subscribe(
(entity) => { (entity) => {
@ -237,8 +241,11 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV
if (this.entityTabsComponent) { if (this.entityTabsComponent) {
this.entityTabsComponent.entity = entity; this.entityTabsComponent.entity = entity;
} }
loadEntitySubject.next(entity);
loadEntitySubject.complete();
} }
); );
return loadEntitySubject;
} }
onCloseEntityDetails() { onCloseEntityDetails() {
@ -273,7 +280,8 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV
} }
} }
saveEntity() { saveEntity(emitEntityUpdated = true): Observable<BaseData<HasId>> {
const saveEntitySubject = new ReplaySubject<BaseData<HasId>>();
if (this.detailsForm.valid) { if (this.detailsForm.valid) {
const editingEntity = {...this.editingEntity, ...this.entityComponent.entityFormValue()}; const editingEntity = {...this.editingEntity, ...this.entityComponent.entityFormValue()};
if (this.editingEntity.hasOwnProperty('additionalInfo')) { if (this.editingEntity.hasOwnProperty('additionalInfo')) {
@ -288,10 +296,18 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV
this.entityTabsComponent.entity = entity; this.entityTabsComponent.entity = entity;
} }
this.isEdit = false; 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 { ngAfterViewInit(): void {

17
ui-ngx/src/app/modules/home/components/event/event-table-config.ts

@ -142,10 +142,11 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
icon: 'delete', icon: 'delete',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => { 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.getTable().paginator.pageIndex = 0;
this.table.updateData(); this.updateData();
} }
); );
} }
@ -275,7 +276,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
break; break;
} }
if (updateTableColumns) { if (updateTableColumns) {
this.table.columnsUpdated(true); this.getTable().columnsUpdated(true);
} }
} }
@ -345,8 +346,8 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
} }
this.filterParams = {}; this.filterParams = {};
this.table.paginator.pageIndex = 0; this.getTable().paginator.pageIndex = 0;
this.table.updateData(); this.updateData();
} }
private editEventFilter($event: MouseEvent) { private editEventFilter($event: MouseEvent) {
@ -389,8 +390,8 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
componentRef.onDestroy(() => { componentRef.onDestroy(() => {
if (componentRef.instance.result && !isEqual(this.filterParams, componentRef.instance.result.filterParams)) { if (componentRef.instance.result && !isEqual(this.filterParams, componentRef.instance.result.filterParams)) {
this.filterParams = componentRef.instance.result.filterParams; this.filterParams = componentRef.instance.result.filterParams;
this.table.paginator.pageIndex = 0; this.getTable().paginator.pageIndex = 0;
this.table.updateData(); this.updateData();
} }
}); });
this.cd.detectChanges(); this.cd.detectChanges();

2
ui-ngx/src/app/modules/home/components/event/event-table-header.component.ts

@ -40,6 +40,6 @@ export class EventTableHeaderComponent extends EntityTableHeaderComponent<Event>
eventTypeChanged(eventType: EventType | DebugEventType) { eventTypeChanged(eventType: EventType | DebugEventType) {
this.eventTableConfig.eventType = eventType; this.eventTableConfig.eventType = eventType;
this.eventTableConfig.table.resetSortAndFilter(true, true); this.eventTableConfig.getTable().resetSortAndFilter(true, true);
} }
} }

40
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 { EntityTabsComponent } from '../../components/entity/entity-tabs.component';
import { DAY, historyInterval } from '@shared/models/time/time.models'; import { DAY, historyInterval } from '@shared/models/time/time.models';
import { IEntitiesTableComponent } from '@home/models/entity/entity-table-component.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<T extends BaseData<HasId>> = (entity: T) => boolean; export type EntityBooleanFunction<T extends BaseData<HasId>> = (entity: T) => boolean;
export type EntityStringFunction<T extends BaseData<HasId>> = (entity: T) => string; export type EntityStringFunction<T extends BaseData<HasId>> = (entity: T) => string;
@ -136,11 +138,13 @@ export class EntityTableConfig<T extends BaseData<HasId>, P extends PageLink = P
constructor() {} constructor() {}
private table: IEntitiesTableComponent = null;
private entityDetailsPage: IEntityDetailsPageComponent = null;
componentsData: any = null; componentsData: any = null;
loadDataOnInit = true; loadDataOnInit = true;
onLoadAction: (route: ActivatedRoute) => void = null; onLoadAction: (route: ActivatedRoute) => void = null;
table: IEntitiesTableComponent = null;
useTimePageLink = false; useTimePageLink = false;
defaultTimewindowInterval = historyInterval(DAY); defaultTimewindowInterval = historyInterval(DAY);
entityType: EntityType = null; entityType: EntityType = null;
@ -189,6 +193,40 @@ export class EntityTableConfig<T extends BaseData<HasId>, P extends PageLink = P
entityAdded: EntityVoidFunction<T> = () => {}; entityAdded: EntityVoidFunction<T> = () => {};
entityUpdated: EntityVoidFunction<T> = () => {}; entityUpdated: EntityVoidFunction<T> = () => {};
entitiesDeleted: EntityIdsVoidFunction<T> = () => {}; entitiesDeleted: EntityIdsVoidFunction<T> = () => {};
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 { export function checkBoxCell(value: boolean): string {

19
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;
}

2
ui-ngx/src/app/modules/home/pages/asset/asset-table-header.component.ts

@ -36,7 +36,7 @@ export class AssetTableHeaderComponent extends EntityTableHeaderComponent<AssetI
assetTypeChanged(assetType: string) { assetTypeChanged(assetType: string) {
this.entitiesTableConfig.componentsData.assetType = assetType; this.entitiesTableConfig.componentsData.assetType = assetType;
this.entitiesTableConfig.table.resetSortAndFilter(true); this.entitiesTableConfig.getTable().resetSortAndFilter(true);
} }
} }

25
ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts

@ -104,7 +104,8 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
)); ));
}; };
this.config.onEntityAction = action => this.onAssetAction(action, this.config); this.config.onEntityAction = action => 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; this.config.headerComponent = AssetTableHeaderComponent;
@ -295,7 +296,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
name: this.translate.instant('asset.add-asset-text'), name: this.translate.instant('asset.add-asset-text'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('asset.import'), name: this.translate.instant('asset.import'),
@ -332,7 +333,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
this.homeDialogs.importEntities(EntityType.ASSET).subscribe((res) => { this.homeDialogs.importEntities(EntityType.ASSET).subscribe((res) => {
if (res) { if (res) {
this.broadcast.broadcast('assetSaved'); this.broadcast.broadcast('assetSaved');
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -341,7 +342,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([asset.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([asset.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }
@ -360,7 +361,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -379,7 +380,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if (res) { if (res) {
this.assetService.makeAssetPublic(asset.id.id).subscribe( this.assetService.makeAssetPublic(asset.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -402,7 +403,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -431,7 +432,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if (res) { if (res) {
this.assetService.unassignAssetFromCustomer(asset.id.id).subscribe( this.assetService.unassignAssetFromCustomer(asset.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.assetScope !== 'tenant');
} }
); );
} }
@ -459,7 +460,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -503,7 +504,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -522,7 +523,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if (res) { if (res) {
this.assetService.unassignAssetFromEdge(this.config.componentsData.edgeId, asset.id.id).subscribe( this.assetService.unassignAssetFromEdge(this.config.componentsData.edgeId, asset.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.assetScope !== 'tenant');
} }
); );
} }
@ -550,7 +551,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

2
ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts

@ -141,7 +141,7 @@ export class CustomersTableConfigResolver implements Resolve<EntityTableConfig<C
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([customer.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([customer.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }

28
ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts

@ -103,7 +103,8 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
return this.dashboardService.saveDashboard(dashboard as Dashboard); return this.dashboardService.saveDashboard(dashboard as Dashboard);
}; };
this.config.onEntityAction = action => this.onDashboardAction(action); this.config.onEntityAction = action => 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<EntityTableConfig<DashboardInfo | Dashboard>> { resolve(route: ActivatedRouteSnapshot): Observable<EntityTableConfig<DashboardInfo | Dashboard>> {
@ -147,7 +148,8 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.dashboardScope); this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.dashboardScope);
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.dashboardScope); this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.dashboardScope);
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.dashboardScope); this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.dashboardScope);
this.config.addEnabled = !(this.config.componentsData.dashboardScope === 'customer_user' || this.config.componentsData.dashboardScope === 'edge_customer_user'); this.config.addEnabled = !(this.config.componentsData.dashboardScope === 'customer_user' ||
this.config.componentsData.dashboardScope === 'edge_customer_user');
this.config.entitiesDeleteEnabled = this.config.componentsData.dashboardScope === 'tenant'; this.config.entitiesDeleteEnabled = this.config.componentsData.dashboardScope === 'tenant';
this.config.deleteEnabled = () => this.config.componentsData.dashboardScope === 'tenant'; this.config.deleteEnabled = () => this.config.componentsData.dashboardScope === 'tenant';
return this.config; return this.config;
@ -322,7 +324,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
name: this.translate.instant('dashboard.create-new-dashboard'), name: this.translate.instant('dashboard.create-new-dashboard'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('dashboard.import'), name: this.translate.instant('dashboard.import'),
@ -372,7 +374,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.importExport.importDashboard().subscribe( this.importExport.importDashboard().subscribe(
(dashboard) => { (dashboard) => {
if (dashboard) { if (dashboard) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );
@ -400,7 +402,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -420,7 +422,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
} }
}).afterClosed() }).afterClosed()
.subscribe(() => { .subscribe(() => {
this.config.table.updateData(); this.config.updateData();
}); });
} }
); );
@ -440,7 +442,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.dashboardService.makeDashboardPrivate(dashboard.id.id).subscribe( this.dashboardService.makeDashboardPrivate(dashboard.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -480,7 +482,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -499,7 +501,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.dashboardService.unassignDashboardFromCustomer(customerId, dashboard.id.id).subscribe( this.dashboardService.unassignDashboardFromCustomer(customerId, dashboard.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant');
} }
); );
} }
@ -527,7 +529,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -577,7 +579,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -596,7 +598,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id).subscribe( this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant');
} }
); );
} }
@ -624,7 +626,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

6
ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts

@ -151,7 +151,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve<EntityTableCon
}).afterClosed().subscribe( }).afterClosed().subscribe(
(res) => { (res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );
@ -171,7 +171,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve<EntityTableCon
if (res) { if (res) {
this.deviceProfileService.setDefaultDeviceProfile(deviceProfile.id.id).subscribe( this.deviceProfileService.setDefaultDeviceProfile(deviceProfile.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -191,7 +191,7 @@ export class DeviceProfilesTableConfigResolver implements Resolve<EntityTableCon
this.importExport.importDeviceProfile().subscribe( this.importExport.importDeviceProfile().subscribe(
(deviceProfile) => { (deviceProfile) => {
if (deviceProfile) { if (deviceProfile) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );

2
ui-ngx/src/app/modules/home/pages/device/device-table-header.component.ts

@ -37,7 +37,7 @@ export class DeviceTableHeaderComponent extends EntityTableHeaderComponent<Devic
deviceProfileChanged(deviceProfileId: DeviceProfileId) { deviceProfileChanged(deviceProfileId: DeviceProfileId) {
this.entitiesTableConfig.componentsData.deviceProfileId = deviceProfileId; this.entitiesTableConfig.componentsData.deviceProfileId = deviceProfileId;
this.entitiesTableConfig.table.resetSortAndFilter(true); this.entitiesTableConfig.getTable().resetSortAndFilter(true);
} }
} }

2
ui-ngx/src/app/modules/home/pages/device/device.component.ts

@ -140,7 +140,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> {
} }
onDeviceProfileUpdated() { onDeviceProfileUpdated() {
this.entitiesTableConfig.table.updateData(false); this.entitiesTableConfig.updateData(false);
} }
onDeviceProfileChanged(deviceProfile: DeviceProfileInfo) { onDeviceProfileChanged(deviceProfile: DeviceProfileInfo) {

24
ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts

@ -375,7 +375,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([device.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([device.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }
@ -383,7 +383,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
this.homeDialogs.importEntities(EntityType.DEVICE).subscribe((res) => { this.homeDialogs.importEntities(EntityType.DEVICE).subscribe((res) => {
if (res) { if (res) {
this.broadcast.broadcast('deviceSaved'); this.broadcast.broadcast('deviceSaved');
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -394,12 +394,12 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
entitiesTableConfig: this.config.table.entitiesTableConfig entitiesTableConfig: this.config
} }
}).afterClosed().subscribe( }).afterClosed().subscribe(
(res) => { (res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );
@ -420,7 +420,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -439,7 +439,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
if (res) { if (res) {
this.deviceService.makeDevicePublic(device.id.id).subscribe( this.deviceService.makeDevicePublic(device.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -462,7 +462,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -491,7 +491,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
if (res) { if (res) {
this.deviceService.unassignDeviceFromCustomer(device.id.id).subscribe( this.deviceService.unassignDeviceFromCustomer(device.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.deviceScope !== 'tenant');
} }
); );
} }
@ -519,7 +519,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -586,7 +586,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -605,7 +605,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
if (res) { if (res) {
this.deviceService.unassignDeviceFromEdge(this.config.componentsData.edgeId, device.id.id).subscribe( this.deviceService.unassignDeviceFromEdge(this.config.componentsData.edgeId, device.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.deviceScope !== 'tenant');
} }
); );
} }
@ -633,7 +633,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

2
ui-ngx/src/app/modules/home/pages/edge/edge-table-header.component.ts

@ -36,7 +36,7 @@ export class EdgeTableHeaderComponent extends EntityTableHeaderComponent<EdgeInf
edgeTypeChanged(edgeType: string) { edgeTypeChanged(edgeType: string) {
this.entitiesTableConfig.componentsData.edgeType = edgeType; this.entitiesTableConfig.componentsData.edgeType = edgeType;
this.entitiesTableConfig.table.resetSortAndFilter(true); this.entitiesTableConfig.getTable().resetSortAndFilter(true);
} }
} }

16
ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts

@ -318,7 +318,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
name: this.translate.instant('edge.add-edge-text'), name: this.translate.instant('edge.add-edge-text'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('edge.import'), name: this.translate.instant('edge.import'),
@ -345,7 +345,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
this.homeDialogs.importEntities(EntityType.EDGE).subscribe((res) => { this.homeDialogs.importEntities(EntityType.EDGE).subscribe((res) => {
if (res) { if (res) {
this.broadcast.broadcast('edgeSaved'); this.broadcast.broadcast('edgeSaved');
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -365,7 +365,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -374,7 +374,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([edge.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([edge.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }
@ -392,7 +392,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
if (res) { if (res) {
this.edgeService.makeEdgePublic(edge.id.id).subscribe( this.edgeService.makeEdgePublic(edge.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -443,7 +443,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -472,7 +472,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
if (res) { if (res) {
this.edgeService.unassignEdgeFromCustomer(edge.id.id).subscribe( this.edgeService.unassignEdgeFromCustomer(edge.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.edgeScope !== 'tenant');
} }
); );
} }
@ -500,7 +500,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

2
ui-ngx/src/app/modules/home/pages/entity-view/entity-view-table-header.component.ts

@ -36,7 +36,7 @@ export class EntityViewTableHeaderComponent extends EntityTableHeaderComponent<E
entityViewTypeChanged(entityViewType: string) { entityViewTypeChanged(entityViewType: string) {
this.entitiesTableConfig.componentsData.entityViewType = entityViewType; this.entitiesTableConfig.componentsData.entityViewType = entityViewType;
this.entitiesTableConfig.table.resetSortAndFilter(true); this.entitiesTableConfig.getTable().resetSortAndFilter(true);
} }
} }

18
ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts

@ -328,7 +328,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -337,7 +337,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([entityView.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([entityView.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }
@ -355,7 +355,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
if (res) { if (res) {
this.entityViewService.makeEntityViewPublic(entityView.id.id).subscribe( this.entityViewService.makeEntityViewPublic(entityView.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -378,7 +378,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -407,7 +407,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
if (res) { if (res) {
this.entityViewService.unassignEntityViewFromCustomer(entityView.id.id).subscribe( this.entityViewService.unassignEntityViewFromCustomer(entityView.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.entityViewScope !== 'tenant');
} }
); );
} }
@ -435,7 +435,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -479,7 +479,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}).afterClosed() }).afterClosed()
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.config.table.updateData(); this.config.updateData();
} }
}); });
} }
@ -498,7 +498,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
if (res) { if (res) {
this.entityViewService.unassignEntityViewFromEdge(this.config.componentsData.edgeId, entityView.id.id).subscribe( this.entityViewService.unassignEntityViewFromEdge(this.config.componentsData.edgeId, entityView.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.entityViewScope !== 'tenant');
} }
); );
} }
@ -526,7 +526,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

20
ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

@ -151,7 +151,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
name: this.translate.instant('rulechain.create-new-rulechain'), name: this.translate.instant('rulechain.create-new-rulechain'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('rulechain.import'), name: this.translate.instant('rulechain.import'),
@ -343,13 +343,13 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.ruleChainService.setEdgeRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( this.ruleChainService.setEdgeRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe(
(edge) => { (edge) => {
this.config.componentsData.edge = edge; this.config.componentsData.edge = edge;
this.config.table.updateData(); this.config.updateData();
} }
); );
} else { } else {
this.ruleChainService.setRootRuleChain(ruleChain.id.id).subscribe( this.ruleChainService.setRootRuleChain(ruleChain.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -399,7 +399,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.ruleChainService.setEdgeTemplateRootRuleChain(ruleChain.id.id).subscribe( this.ruleChainService.setEdgeTemplateRootRuleChain(ruleChain.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -436,11 +436,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.dialogService.alert(this.translate.instant('edge.missing-related-rule-chains-title'), this.dialogService.alert(this.translate.instant('edge.missing-related-rule-chains-title'),
message, this.translate.instant('action.close'), true).subscribe( message, this.translate.instant('action.close'), true).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} else { } else {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );
@ -463,7 +463,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData(this.config.componentsData.ruleChainScope !== 'tenant');
} }
); );
} }
@ -491,7 +491,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -513,7 +513,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.ruleChainService.setAutoAssignToEdgeRuleChain(ruleChain.id.id).subscribe( this.ruleChainService.setAutoAssignToEdgeRuleChain(ruleChain.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -535,7 +535,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if (res) { if (res) {
this.ruleChainService.unsetAutoAssignToEdgeRuleChain(ruleChain.id.id).subscribe( this.ruleChainService.unsetAutoAssignToEdgeRuleChain(ruleChain.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }

6
ui-ngx/src/app/modules/home/pages/tenant-profile/tenant-profiles-table-config.resolver.ts

@ -106,7 +106,7 @@ export class TenantProfilesTableConfigResolver implements Resolve<EntityTableCon
name: this.translate.instant('tenant-profile.create-tenant-profile'), name: this.translate.instant('tenant-profile.create-tenant-profile'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('tenant-profile.import'), name: this.translate.instant('tenant-profile.import'),
@ -140,7 +140,7 @@ export class TenantProfilesTableConfigResolver implements Resolve<EntityTableCon
if (res) { if (res) {
this.tenantProfileService.setDefaultTenantProfile(tenantProfile.id.id).subscribe( this.tenantProfileService.setDefaultTenantProfile(tenantProfile.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.updateData();
} }
); );
} }
@ -152,7 +152,7 @@ export class TenantProfilesTableConfigResolver implements Resolve<EntityTableCon
this.importExport.importTenantProfile().subscribe( this.importExport.importTenantProfile().subscribe(
(deviceProfile) => { (deviceProfile) => {
if (deviceProfile) { if (deviceProfile) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );

2
ui-ngx/src/app/modules/home/pages/tenant/tenant.component.ts

@ -99,6 +99,6 @@ export class TenantComponent extends ContactBasedComponent<TenantInfo> {
} }
onTenantProfileUpdated() { onTenantProfileUpdated() {
this.entitiesTableConfig.table.updateData(false); this.entitiesTableConfig.updateData(false);
} }
} }

2
ui-ngx/src/app/modules/home/pages/tenant/tenants-table-config.resolver.ts

@ -91,7 +91,7 @@ export class TenantsTableConfigResolver implements Resolve<EntityTableConfig<Ten
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const url = this.router.createUrlTree([tenant.id.id], {relativeTo: config.table.route}); const url = this.router.createUrlTree([tenant.id.id], {relativeTo: config.getActivatedRoute()});
this.router.navigateByUrl(url); this.router.navigateByUrl(url);
} }

2
ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts

@ -178,7 +178,7 @@ export class UsersTableConfigResolver implements Resolve<EntityTableConfig<User>
if ($event) { if ($event) {
$event.stopPropagation(); $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); this.router.navigateByUrl(url);
} }

4
ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts

@ -76,7 +76,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableCon
name: this.translate.instant('widgets-bundle.create-new-widgets-bundle'), name: this.translate.instant('widgets-bundle.create-new-widgets-bundle'),
icon: 'insert_drive_file', icon: 'insert_drive_file',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event) onAction: ($event) => this.config.getTable().addEntity($event)
}, },
{ {
name: this.translate.instant('widgets-bundle.import'), name: this.translate.instant('widgets-bundle.import'),
@ -137,7 +137,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableCon
this.importExport.importWidgetsBundle().subscribe( this.importExport.importWidgetsBundle().subscribe(
(widgetsBundle) => { (widgetsBundle) => {
if (widgetsBundle) { if (widgetsBundle) {
this.config.table.updateData(); this.config.updateData();
} }
} }
); );

9
ui-ngx/src/app/shared/models/base-data.ts

@ -16,6 +16,7 @@
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { HasUUID } from '@shared/models/id/has-uuid'; import { HasUUID } from '@shared/models/id/has-uuid';
import { isDefinedAndNotNull } from '@core/utils';
export declare type HasId = EntityId | HasUUID; export declare type HasId = EntityId | HasUUID;
@ -25,3 +26,11 @@ export interface BaseData<T extends HasId> {
name?: string; name?: string;
label?: 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;
}
}

Loading…
Cancel
Save