Commit 80bc235975970f2cbac276cd9a04dbe51ab32a48

Authored by Igor Kulikov
1 parent 10dd5c35

Improve entities and alarms table widget title processing.

... ... @@ -150,7 +150,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
150 150 private settings: AlarmsTableWidgetSettings;
151 151 private widgetConfig: WidgetConfig;
152 152 private subscription: IWidgetSubscription;
153   - private alarmSource: Datasource;
  153 +
  154 + private alarmsTitlePattern: string;
154 155
155 156 private displayDetails = true;
156 157 private allowAcknowledgment = true;
... ... @@ -215,7 +216,6 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
215 216 this.settings = this.ctx.settings;
216 217 this.widgetConfig = this.ctx.widgetConfig;
217 218 this.subscription = this.ctx.defaultSubscription;
218   - this.alarmSource = this.subscription.alarmSource;
219 219 this.initializeConfig();
220 220 this.updateAlarmSource();
221 221 this.ctx.updateWidgetParams();
... ... @@ -248,6 +248,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
248 248
249 249 public onDataUpdated() {
250 250 this.ngZone.run(() => {
  251 + this.updateTitle(true);
251 252 this.alarmsDatasource.updateAlarms();
252 253 this.ctx.detectChanges();
253 254 });
... ... @@ -296,15 +297,13 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
296 297
297 298 this.actionCellDescriptors = this.actionCellDescriptors.concat(this.ctx.actionsApi.getActionDescriptors('actionCellButton'));
298 299
299   - let alarmsTitle: string;
300   -
301 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 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 308 this.enableSelection = isDefined(this.settings.enableSelection) ? this.settings.enableSelection : true;
310 309 if (!this.allowAcknowledgment && !this.allowClear) {
... ... @@ -353,6 +352,16 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
353 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 365 private updateAlarmSource() {
357 366
358 367 if (this.enableSelection) {
... ... @@ -361,8 +370,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
361 370
362 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 375 const dataKey: EntityColumn = deepClone(alarmDataKey) as EntityColumn;
367 376 dataKey.entityKey = dataKeyToEntityKey(alarmDataKey);
368 377 dataKey.title = this.utils.customTranslation(dataKey.label, dataKey.label);
... ...
... ... @@ -125,6 +125,8 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
125 125 private widgetConfig: WidgetConfig;
126 126 private subscription: IWidgetSubscription;
127 127
  128 + private entitiesTitlePattern: string;
  129 +
128 130 private defaultPageSize = 10;
129 131 private defaultSortOrder = 'entityName';
130 132
... ... @@ -205,6 +207,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
205 207
206 208 public onDataUpdated() {
207 209 this.ngZone.run(() => {
  210 + this.updateTitle(true);
208 211 this.entityDatasource.dataUpdated();
209 212 this.ctx.detectChanges();
210 213 });
... ... @@ -219,16 +222,13 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
219 222
220 223 this.actionCellDescriptors = this.ctx.actionsApi.getActionDescriptors('actionCellButton');
221 224
222   - let entitiesTitle: string;
223   -
224 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 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 233 this.searchAction.show = isDefined(this.settings.enableSearch) ? this.settings.enableSearch : true;
234 234 this.displayPagination = isDefined(this.settings.displayPagination) ? this.settings.displayPagination : true;
... ... @@ -250,6 +250,16 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
250 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 263 private updateDatasources() {
254 264
255 265 const displayEntityName = isDefined(this.settings.displayEntityName) ? this.settings.displayEntityName : true;
... ...