Commit 80bc235975970f2cbac276cd9a04dbe51ab32a48
1 parent
10dd5c35
Improve entities and alarms table widget title processing.
Showing
2 changed files
with
34 additions
and
15 deletions
@@ -150,7 +150,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -150,7 +150,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
150 | private settings: AlarmsTableWidgetSettings; | 150 | private settings: AlarmsTableWidgetSettings; |
151 | private widgetConfig: WidgetConfig; | 151 | private widgetConfig: WidgetConfig; |
152 | private subscription: IWidgetSubscription; | 152 | private subscription: IWidgetSubscription; |
153 | - private alarmSource: Datasource; | 153 | + |
154 | + private alarmsTitlePattern: string; | ||
154 | 155 | ||
155 | private displayDetails = true; | 156 | private displayDetails = true; |
156 | private allowAcknowledgment = true; | 157 | private allowAcknowledgment = true; |
@@ -215,7 +216,6 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -215,7 +216,6 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
215 | this.settings = this.ctx.settings; | 216 | this.settings = this.ctx.settings; |
216 | this.widgetConfig = this.ctx.widgetConfig; | 217 | this.widgetConfig = this.ctx.widgetConfig; |
217 | this.subscription = this.ctx.defaultSubscription; | 218 | this.subscription = this.ctx.defaultSubscription; |
218 | - this.alarmSource = this.subscription.alarmSource; | ||
219 | this.initializeConfig(); | 219 | this.initializeConfig(); |
220 | this.updateAlarmSource(); | 220 | this.updateAlarmSource(); |
221 | this.ctx.updateWidgetParams(); | 221 | this.ctx.updateWidgetParams(); |
@@ -248,6 +248,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -248,6 +248,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
248 | 248 | ||
249 | public onDataUpdated() { | 249 | public onDataUpdated() { |
250 | this.ngZone.run(() => { | 250 | this.ngZone.run(() => { |
251 | + this.updateTitle(true); | ||
251 | this.alarmsDatasource.updateAlarms(); | 252 | this.alarmsDatasource.updateAlarms(); |
252 | this.ctx.detectChanges(); | 253 | this.ctx.detectChanges(); |
253 | }); | 254 | }); |
@@ -296,15 +297,13 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -296,15 +297,13 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
296 | 297 | ||
297 | this.actionCellDescriptors = this.actionCellDescriptors.concat(this.ctx.actionsApi.getActionDescriptors('actionCellButton')); | 298 | this.actionCellDescriptors = this.actionCellDescriptors.concat(this.ctx.actionsApi.getActionDescriptors('actionCellButton')); |
298 | 299 | ||
299 | - let alarmsTitle: string; | ||
300 | - | ||
301 | if (this.settings.alarmsTitle && this.settings.alarmsTitle.length) { | 300 | if (this.settings.alarmsTitle && this.settings.alarmsTitle.length) { |
302 | - alarmsTitle = this.utils.customTranslation(this.settings.alarmsTitle, this.settings.alarmsTitle); | 301 | + this.alarmsTitlePattern = this.utils.customTranslation(this.settings.alarmsTitle, this.settings.alarmsTitle); |
303 | } else { | 302 | } else { |
304 | - alarmsTitle = this.translate.instant('alarm.alarms'); | 303 | + this.alarmsTitlePattern = this.translate.instant('alarm.alarms'); |
305 | } | 304 | } |
306 | 305 | ||
307 | - this.ctx.widgetTitle = createLabelFromDatasource(this.alarmSource, alarmsTitle); | 306 | + this.updateTitle(false); |
308 | 307 | ||
309 | this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : true; | 308 | this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : true; |
310 | if (!this.allowAcknowledgment && !this.allowClear) { | 309 | if (!this.allowAcknowledgment && !this.allowClear) { |
@@ -353,6 +352,16 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -353,6 +352,16 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
353 | $(this.elementRef.nativeElement).addClass(namespace); | 352 | $(this.elementRef.nativeElement).addClass(namespace); |
354 | } | 353 | } |
355 | 354 | ||
355 | + private updateTitle(updateWidgetParams = false) { | ||
356 | + const newTitle = createLabelFromDatasource(this.subscription.alarmSource, this.alarmsTitlePattern); | ||
357 | + if (this.ctx.widgetTitle !== newTitle) { | ||
358 | + this.ctx.widgetTitle = newTitle; | ||
359 | + if (updateWidgetParams) { | ||
360 | + this.ctx.updateWidgetParams(); | ||
361 | + } | ||
362 | + } | ||
363 | + } | ||
364 | + | ||
356 | private updateAlarmSource() { | 365 | private updateAlarmSource() { |
357 | 366 | ||
358 | if (this.enableSelection) { | 367 | if (this.enableSelection) { |
@@ -361,8 +370,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -361,8 +370,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
361 | 370 | ||
362 | const latestDataKeys: Array<DataKey> = []; | 371 | const latestDataKeys: Array<DataKey> = []; |
363 | 372 | ||
364 | - if (this.alarmSource) { | ||
365 | - this.alarmSource.dataKeys.forEach((alarmDataKey) => { | 373 | + if (this.subscription.alarmSource) { |
374 | + this.subscription.alarmSource.dataKeys.forEach((alarmDataKey) => { | ||
366 | const dataKey: EntityColumn = deepClone(alarmDataKey) as EntityColumn; | 375 | const dataKey: EntityColumn = deepClone(alarmDataKey) as EntityColumn; |
367 | dataKey.entityKey = dataKeyToEntityKey(alarmDataKey); | 376 | dataKey.entityKey = dataKeyToEntityKey(alarmDataKey); |
368 | dataKey.title = this.utils.customTranslation(dataKey.label, dataKey.label); | 377 | dataKey.title = this.utils.customTranslation(dataKey.label, dataKey.label); |
@@ -125,6 +125,8 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | @@ -125,6 +125,8 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | ||
125 | private widgetConfig: WidgetConfig; | 125 | private widgetConfig: WidgetConfig; |
126 | private subscription: IWidgetSubscription; | 126 | private subscription: IWidgetSubscription; |
127 | 127 | ||
128 | + private entitiesTitlePattern: string; | ||
129 | + | ||
128 | private defaultPageSize = 10; | 130 | private defaultPageSize = 10; |
129 | private defaultSortOrder = 'entityName'; | 131 | private defaultSortOrder = 'entityName'; |
130 | 132 | ||
@@ -205,6 +207,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | @@ -205,6 +207,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | ||
205 | 207 | ||
206 | public onDataUpdated() { | 208 | public onDataUpdated() { |
207 | this.ngZone.run(() => { | 209 | this.ngZone.run(() => { |
210 | + this.updateTitle(true); | ||
208 | this.entityDatasource.dataUpdated(); | 211 | this.entityDatasource.dataUpdated(); |
209 | this.ctx.detectChanges(); | 212 | this.ctx.detectChanges(); |
210 | }); | 213 | }); |
@@ -219,16 +222,13 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | @@ -219,16 +222,13 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | ||
219 | 222 | ||
220 | this.actionCellDescriptors = this.ctx.actionsApi.getActionDescriptors('actionCellButton'); | 223 | this.actionCellDescriptors = this.ctx.actionsApi.getActionDescriptors('actionCellButton'); |
221 | 224 | ||
222 | - let entitiesTitle: string; | ||
223 | - | ||
224 | if (this.settings.entitiesTitle && this.settings.entitiesTitle.length) { | 225 | if (this.settings.entitiesTitle && this.settings.entitiesTitle.length) { |
225 | - entitiesTitle = this.utils.customTranslation(this.settings.entitiesTitle, this.settings.entitiesTitle); | 226 | + this.entitiesTitlePattern = this.utils.customTranslation(this.settings.entitiesTitle, this.settings.entitiesTitle); |
226 | } else { | 227 | } else { |
227 | - entitiesTitle = this.translate.instant('entity.entities'); | 228 | + this.entitiesTitlePattern = this.translate.instant('entity.entities'); |
228 | } | 229 | } |
229 | 230 | ||
230 | - const datasource = this.subscription.datasources[0]; | ||
231 | - this.ctx.widgetTitle = createLabelFromDatasource(datasource, entitiesTitle); | 231 | + this.updateTitle(false); |
232 | 232 | ||
233 | this.searchAction.show = isDefined(this.settings.enableSearch) ? this.settings.enableSearch : true; | 233 | this.searchAction.show = isDefined(this.settings.enableSearch) ? this.settings.enableSearch : true; |
234 | this.displayPagination = isDefined(this.settings.displayPagination) ? this.settings.displayPagination : true; | 234 | this.displayPagination = isDefined(this.settings.displayPagination) ? this.settings.displayPagination : true; |
@@ -250,6 +250,16 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | @@ -250,6 +250,16 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | ||
250 | $(this.elementRef.nativeElement).addClass(namespace); | 250 | $(this.elementRef.nativeElement).addClass(namespace); |
251 | } | 251 | } |
252 | 252 | ||
253 | + private updateTitle(updateWidgetParams = false) { | ||
254 | + const newTitle = createLabelFromDatasource(this.subscription.datasources[0], this.entitiesTitlePattern); | ||
255 | + if (this.ctx.widgetTitle !== newTitle) { | ||
256 | + this.ctx.widgetTitle = newTitle; | ||
257 | + if (updateWidgetParams) { | ||
258 | + this.ctx.updateWidgetParams(); | ||
259 | + } | ||
260 | + } | ||
261 | + } | ||
262 | + | ||
253 | private updateDatasources() { | 263 | private updateDatasources() { |
254 | 264 | ||
255 | const displayEntityName = isDefined(this.settings.displayEntityName) ? this.settings.displayEntityName : true; | 265 | const displayEntityName = isDefined(this.settings.displayEntityName) ? this.settings.displayEntityName : true; |