|
|
|
@ -106,19 +106,14 @@ import { ComponentPortal } from '@angular/cdk/portal'; |
|
|
|
import { FormBuilder } from '@angular/forms'; |
|
|
|
import { DEFAULT_OVERLAY_POSITIONS } from '@shared/models/overlay.models'; |
|
|
|
import { DateFormatSettings, ValueFormatProcessor } from '@shared/models/widget-settings.models'; |
|
|
|
|
|
|
|
export enum TabSortKey { |
|
|
|
NAME_ASC = 'NAME_ASC', |
|
|
|
NAME_DESC = 'NAME_DESC', |
|
|
|
TIMESTAMP = 'timestamp' |
|
|
|
} |
|
|
|
import { entityFields } from '@shared/models/entity.models'; |
|
|
|
|
|
|
|
export interface TimeseriesTableWidgetSettings extends TableWidgetSettings { |
|
|
|
showTimestamp: boolean; |
|
|
|
showMilliseconds: boolean; |
|
|
|
hideEmptyLines: boolean; |
|
|
|
dateFormat: DateFormatSettings; |
|
|
|
tabSortKey: TabSortKey; |
|
|
|
sortOrder: SortOrder; |
|
|
|
} |
|
|
|
|
|
|
|
interface TimeseriesWidgetLatestDataKeySettings extends TableWidgetDataKeySettings { |
|
|
|
@ -400,33 +395,39 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI |
|
|
|
this.updateDatasources(); |
|
|
|
} |
|
|
|
|
|
|
|
private getTabLabel(source: Datasource, entityLabelCache:Map<string,string>):string { |
|
|
|
if (entityLabelCache.has(source.entityId)) { |
|
|
|
return entityLabelCache.get(source.entityId); |
|
|
|
} |
|
|
|
|
|
|
|
const value = this.useEntityLabel |
|
|
|
private getTabLabel(source: Datasource):string { |
|
|
|
const value = this.useEntityLabel |
|
|
|
? (source.entityLabel || source.entityName) |
|
|
|
: source.entityName; |
|
|
|
|
|
|
|
const translated = this.utils.customTranslation(value); |
|
|
|
entityLabelCache.set(source.entityId, translated); |
|
|
|
return translated; |
|
|
|
return this.utils.customTranslation(value); |
|
|
|
} |
|
|
|
|
|
|
|
private sortDatasources(source: Datasource[], entityLabelCache:Map<string,string>): Datasource[] { |
|
|
|
source.forEach(ds => this.getTabLabel(ds, entityLabelCache)); |
|
|
|
private sortDatasources(source: TimeseriesTableSource[]) { |
|
|
|
const property = this.settings?.sortOrder?.property; |
|
|
|
const direction = this.settings?.sortOrder?.direction; |
|
|
|
const isAsc = direction === Direction.ASC; |
|
|
|
|
|
|
|
if (property === entityFields.name.keyName) { |
|
|
|
const collator = new Intl.Collator(undefined, { |
|
|
|
sensitivity: "variant", |
|
|
|
numeric: true, |
|
|
|
ignorePunctuation: false |
|
|
|
}); |
|
|
|
|
|
|
|
source.sort((a, b) => { |
|
|
|
const valueA = a.displayName || ''; |
|
|
|
const valueB = b.displayName || ''; |
|
|
|
|
|
|
|
if (this.settings.tabSortKey === TabSortKey.TIMESTAMP) { |
|
|
|
return source; |
|
|
|
return isAsc |
|
|
|
? collator.compare(valueA, valueB) |
|
|
|
: collator.compare(valueB, valueA); |
|
|
|
}); |
|
|
|
} else if (property === entityFields.createdTime.keyName) { |
|
|
|
if (isAsc) { |
|
|
|
source.reverse(); |
|
|
|
} |
|
|
|
} |
|
|
|
return source.sort((a, b) => { |
|
|
|
const valueA = entityLabelCache.get(a.entityId); |
|
|
|
const valueB = entityLabelCache.get(b.entityId); |
|
|
|
return this.settings.tabSortKey === TabSortKey.NAME_ASC |
|
|
|
? valueA.localeCompare(valueB) |
|
|
|
: valueB.localeCompare(valueA); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private updateDatasources() { |
|
|
|
@ -434,11 +435,9 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI |
|
|
|
this.sourceIndex = 0; |
|
|
|
let keyOffset = 0; |
|
|
|
let latestKeyOffset = 0; |
|
|
|
const entityLabelCache = new Map<string,string>(); |
|
|
|
const pageSize = this.displayPagination ? this.defaultPageSize : Number.POSITIVE_INFINITY; |
|
|
|
if (this.datasources) { |
|
|
|
const sortedDatasources = this.sortDatasources(this.datasources, entityLabelCache); |
|
|
|
for (const datasource of sortedDatasources) { |
|
|
|
for (const datasource of this.datasources) { |
|
|
|
const sortOrder: SortOrder = sortOrderFromString(this.defaultSortOrder); |
|
|
|
const source = {} as TimeseriesTableSource; |
|
|
|
source.header = this.prepareHeader(datasource); |
|
|
|
@ -455,7 +454,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI |
|
|
|
source.pageLink = new PageLink(pageSize, 0, null, sortOrder); |
|
|
|
source.rowDataTemplate = {}; |
|
|
|
source.rowDataTemplate.Timestamp = null; |
|
|
|
source.displayName = entityLabelCache.get(datasource.entityId); |
|
|
|
source.displayName = this.getTabLabel(datasource); |
|
|
|
if (this.showTimestamp) { |
|
|
|
source.displayedColumns.push('0'); |
|
|
|
} |
|
|
|
@ -475,6 +474,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.sources.length) { |
|
|
|
this.sortDatasources(this.sources); |
|
|
|
this.sources.forEach((source, index) => { |
|
|
|
this.prepareDisplayedColumn(index); |
|
|
|
source.displayedColumns = this.displayedColumns[index].filter(value => value.display).map(value => value.def); |
|
|
|
|