|
|
@ -20,8 +20,8 @@ import { |
|
|
Component, |
|
|
Component, |
|
|
ComponentFactoryResolver, |
|
|
ComponentFactoryResolver, |
|
|
ElementRef, |
|
|
ElementRef, |
|
|
Input, |
|
|
Input, OnChanges, |
|
|
OnInit, |
|
|
OnInit, SimpleChanges, |
|
|
ViewChild |
|
|
ViewChild |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
@ -51,7 +51,7 @@ import { EntityTypeTranslation } from '@shared/models/entity-type.models'; |
|
|
import { DialogService } from '@core/services/dialog.service'; |
|
|
import { DialogService } from '@core/services/dialog.service'; |
|
|
import { AddEntityDialogComponent } from './add-entity-dialog.component'; |
|
|
import { AddEntityDialogComponent } from './add-entity-dialog.component'; |
|
|
import { AddEntityDialogData, EntityAction } from '@home/models/entity/entity-component.models'; |
|
|
import { AddEntityDialogData, EntityAction } from '@home/models/entity/entity-component.models'; |
|
|
import { historyInterval, HistoryWindowType, Timewindow } from '@shared/models/time/time.models'; |
|
|
import { DAY, historyInterval, HistoryWindowType, Timewindow } from '@shared/models/time/time.models'; |
|
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; |
|
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; |
|
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; |
|
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; |
|
|
import { isDefined, isUndefined } from '@core/utils'; |
|
|
import { isDefined, isUndefined } from '@core/utils'; |
|
|
@ -62,7 +62,7 @@ import { isDefined, isUndefined } from '@core/utils'; |
|
|
styleUrls: ['./entities-table.component.scss'], |
|
|
styleUrls: ['./entities-table.component.scss'], |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
}) |
|
|
}) |
|
|
export class EntitiesTableComponent extends PageComponent implements AfterViewInit, OnInit { |
|
|
export class EntitiesTableComponent extends PageComponent implements AfterViewInit, OnInit, OnChanges { |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
entitiesTableConfig: EntityTableConfig<BaseData<HasId>>; |
|
|
entitiesTableConfig: EntityTableConfig<BaseData<HasId>>; |
|
|
@ -112,7 +112,27 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
ngOnInit() { |
|
|
this.entitiesTableConfig = this.entitiesTableConfig || this.route.snapshot.data.entitiesTableConfig; |
|
|
if (this.entitiesTableConfig) { |
|
|
|
|
|
this.init(this.entitiesTableConfig); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.init(this.route.snapshot.data.entitiesTableConfig); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
|
|
|
for (const propName of Object.keys(changes)) { |
|
|
|
|
|
const change = changes[propName]; |
|
|
|
|
|
if (!change.firstChange && change.currentValue !== change.previousValue) { |
|
|
|
|
|
if (propName === 'entitiesTableConfig' && change.currentValue) { |
|
|
|
|
|
this.init(change.currentValue); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private init(entitiesTableConfig: EntityTableConfig<BaseData<HasId>>) { |
|
|
|
|
|
this.isDetailsOpen = false; |
|
|
|
|
|
this.entitiesTableConfig = entitiesTableConfig; |
|
|
if (this.entitiesTableConfig.headerComponent) { |
|
|
if (this.entitiesTableConfig.headerComponent) { |
|
|
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.entitiesTableConfig.headerComponent); |
|
|
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.entitiesTableConfig.headerComponent); |
|
|
const viewContainerRef = this.entityTableHeaderAnchor.viewContainerRef; |
|
|
const viewContainerRef = this.entityTableHeaderAnchor.viewContainerRef; |
|
|
@ -138,17 +158,16 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn |
|
|
onAction: ($event, entity) => this.deleteEntity($event, entity) |
|
|
onAction: ($event, entity) => this.deleteEntity($event, entity) |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
this.groupActionDescriptors.push( |
|
|
|
|
|
{ |
|
|
|
|
|
name: this.translate.instant('action.delete'), |
|
|
|
|
|
icon: 'delete', |
|
|
|
|
|
isEnabled: true, |
|
|
|
|
|
onAction: ($event, entities) => this.deleteEntities($event, entities) |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.groupActionDescriptors.push( |
|
|
|
|
|
{ |
|
|
|
|
|
name: this.translate.instant('action.delete'), |
|
|
|
|
|
icon: 'delete', |
|
|
|
|
|
isEnabled: this.entitiesTableConfig.entitiesDeleteEnabled, |
|
|
|
|
|
onAction: ($event, entities) => this.deleteEntities($event, entities) |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const enabledGroupActionDescriptors = |
|
|
const enabledGroupActionDescriptors = |
|
|
this.groupActionDescriptors.filter((descriptor) => descriptor.isEnabled); |
|
|
this.groupActionDescriptors.filter((descriptor) => descriptor.isEnabled); |
|
|
|
|
|
|
|
|
@ -156,24 +175,25 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn |
|
|
|
|
|
|
|
|
this.columnsUpdated(); |
|
|
this.columnsUpdated(); |
|
|
|
|
|
|
|
|
const sortOrder: SortOrder = { property: this.entitiesTableConfig.defaultSortOrder.property, |
|
|
let sortOrder: SortOrder = null; |
|
|
direction: this.entitiesTableConfig.defaultSortOrder.direction }; |
|
|
if (this.entitiesTableConfig.defaultSortOrder) { |
|
|
|
|
|
sortOrder = { |
|
|
|
|
|
property: this.entitiesTableConfig.defaultSortOrder.property, |
|
|
|
|
|
direction: this.entitiesTableConfig.defaultSortOrder.direction |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (this.entitiesTableConfig.useTimePageLink) { |
|
|
if (this.entitiesTableConfig.useTimePageLink) { |
|
|
this.timewindow = historyInterval(24 * 60 * 60 * 1000); |
|
|
this.timewindow = historyInterval(DAY); |
|
|
const currentTime = Date.now(); |
|
|
const currentTime = Date.now(); |
|
|
this.pageLink = new TimePageLink(10, 0, null, sortOrder, |
|
|
this.pageLink = new TimePageLink(10, 0, null, sortOrder, |
|
|
currentTime - this.timewindow.history.timewindowMs, currentTime); |
|
|
currentTime - this.timewindow.history.timewindowMs, currentTime); |
|
|
} else { |
|
|
} else { |
|
|
this.pageLink = new PageLink(10, 0, null, sortOrder); |
|
|
this.pageLink = new PageLink(10, 0, null, sortOrder); |
|
|
} |
|
|
} |
|
|
this.dataSource = new EntitiesDataSource<BaseData<HasId>>( |
|
|
this.dataSource = this.entitiesTableConfig.dataSource(() => { |
|
|
this.entitiesTableConfig.entitiesFetchFunction, |
|
|
this.dataLoaded(); |
|
|
this.entitiesTableConfig.entitySelectionEnabled, |
|
|
}); |
|
|
() => { |
|
|
|
|
|
this.dataLoaded(); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
if (this.entitiesTableConfig.onLoadAction) { |
|
|
if (this.entitiesTableConfig.onLoadAction) { |
|
|
this.entitiesTableConfig.onLoadAction(this.route); |
|
|
this.entitiesTableConfig.onLoadAction(this.route); |
|
|
} |
|
|
} |
|
|
@ -214,8 +234,14 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn |
|
|
} |
|
|
} |
|
|
this.pageLink.page = this.paginator.pageIndex; |
|
|
this.pageLink.page = this.paginator.pageIndex; |
|
|
this.pageLink.pageSize = this.paginator.pageSize; |
|
|
this.pageLink.pageSize = this.paginator.pageSize; |
|
|
this.pageLink.sortOrder.property = this.sort.active; |
|
|
if (this.sort.active) { |
|
|
this.pageLink.sortOrder.direction = Direction[this.sort.direction.toUpperCase()]; |
|
|
this.pageLink.sortOrder = { |
|
|
|
|
|
property: this.sort.active, |
|
|
|
|
|
direction: Direction[this.sort.direction.toUpperCase()] |
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.pageLink.sortOrder = null; |
|
|
|
|
|
} |
|
|
if (this.entitiesTableConfig.useTimePageLink) { |
|
|
if (this.entitiesTableConfig.useTimePageLink) { |
|
|
const timePageLink = this.pageLink as TimePageLink; |
|
|
const timePageLink = this.pageLink as TimePageLink; |
|
|
if (this.timewindow.history.historyType === HistoryWindowType.LAST_INTERVAL) { |
|
|
if (this.timewindow.history.historyType === HistoryWindowType.LAST_INTERVAL) { |
|
|
|