UI: Refactoring call ngZone in table widgets
This commit is contained in:
parent
43abe75039
commit
10a55ea6d7
@ -260,9 +260,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
|
|||||||
|
|
||||||
public onDataUpdated() {
|
public onDataUpdated() {
|
||||||
this.updateTitle(true);
|
this.updateTitle(true);
|
||||||
this.ngZone.run(() => {
|
|
||||||
this.alarmsDatasource.updateAlarms();
|
this.alarmsDatasource.updateAlarms();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public pageLinkSortDirection(): SortDirection {
|
public pageLinkSortDirection(): SortDirection {
|
||||||
@ -428,7 +426,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
|
|||||||
this.displayedColumns.push('actions');
|
this.displayedColumns.push('actions');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.alarmsDatasource = new AlarmsDatasource(this.subscription, latestDataKeys);
|
this.alarmsDatasource = new AlarmsDatasource(this.subscription, latestDataKeys, this.ngZone);
|
||||||
if (this.enableSelection) {
|
if (this.enableSelection) {
|
||||||
this.alarmsDatasource.selectionModeChanged$.subscribe((selectionMode) => {
|
this.alarmsDatasource.selectionModeChanged$.subscribe((selectionMode) => {
|
||||||
const hideTitlePanel = selectionMode || this.textSearchMode;
|
const hideTitlePanel = selectionMode || this.textSearchMode;
|
||||||
@ -959,7 +957,8 @@ class AlarmsDatasource implements DataSource<AlarmDataInfo> {
|
|||||||
private appliedSortOrderLabel: string;
|
private appliedSortOrderLabel: string;
|
||||||
|
|
||||||
constructor(private subscription: IWidgetSubscription,
|
constructor(private subscription: IWidgetSubscription,
|
||||||
private dataKeys: Array<DataKey>) {
|
private dataKeys: Array<DataKey>,
|
||||||
|
private ngZone: NgZone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(collectionViewer: CollectionViewer): Observable<AlarmDataInfo[] | ReadonlyArray<AlarmDataInfo>> {
|
connect(collectionViewer: CollectionViewer): Observable<AlarmDataInfo[] | ReadonlyArray<AlarmDataInfo>> {
|
||||||
@ -991,6 +990,7 @@ class AlarmsDatasource implements DataSource<AlarmDataInfo> {
|
|||||||
updateAlarms() {
|
updateAlarms() {
|
||||||
const subscriptionAlarms = this.subscription.alarms;
|
const subscriptionAlarms = this.subscription.alarms;
|
||||||
let alarms = new Array<AlarmDataInfo>();
|
let alarms = new Array<AlarmDataInfo>();
|
||||||
|
let isEmptySelection = false;
|
||||||
subscriptionAlarms.data.forEach((alarmData) => {
|
subscriptionAlarms.data.forEach((alarmData) => {
|
||||||
alarms.push(this.alarmDataToInfo(alarmData));
|
alarms.push(this.alarmDataToInfo(alarmData));
|
||||||
});
|
});
|
||||||
@ -1003,7 +1003,7 @@ class AlarmsDatasource implements DataSource<AlarmDataInfo> {
|
|||||||
const toRemove = this.selection.selected.filter(alarmId => alarmIds.indexOf(alarmId) === -1);
|
const toRemove = this.selection.selected.filter(alarmId => alarmIds.indexOf(alarmId) === -1);
|
||||||
this.selection.deselect(...toRemove);
|
this.selection.deselect(...toRemove);
|
||||||
if (this.selection.isEmpty()) {
|
if (this.selection.isEmpty()) {
|
||||||
this.onSelectionModeChanged(false);
|
isEmptySelection = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const alarmsPageData: PageData<AlarmDataInfo> = {
|
const alarmsPageData: PageData<AlarmDataInfo> = {
|
||||||
@ -1012,9 +1012,14 @@ class AlarmsDatasource implements DataSource<AlarmDataInfo> {
|
|||||||
totalElements: subscriptionAlarms.totalElements,
|
totalElements: subscriptionAlarms.totalElements,
|
||||||
hasNext: subscriptionAlarms.hasNext
|
hasNext: subscriptionAlarms.hasNext
|
||||||
};
|
};
|
||||||
|
this.ngZone.run(() => {
|
||||||
|
if (isEmptySelection) {
|
||||||
|
this.onSelectionModeChanged(false);
|
||||||
|
}
|
||||||
this.alarmsSubject.next(alarms);
|
this.alarmsSubject.next(alarms);
|
||||||
this.pageDataSubject.next(alarmsPageData);
|
this.pageDataSubject.next(alarmsPageData);
|
||||||
this.dataLoading = false;
|
this.dataLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private alarmDataToInfo(alarmData: AlarmData): AlarmDataInfo {
|
private alarmDataToInfo(alarmData: AlarmData): AlarmDataInfo {
|
||||||
|
|||||||
@ -221,9 +221,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
|
|||||||
|
|
||||||
public onDataUpdated() {
|
public onDataUpdated() {
|
||||||
this.updateTitle(true);
|
this.updateTitle(true);
|
||||||
this.ngZone.run(() => {
|
|
||||||
this.entityDatasource.dataUpdated();
|
this.entityDatasource.dataUpdated();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public pageLinkSortDirection(): SortDirection {
|
public pageLinkSortDirection(): SortDirection {
|
||||||
@ -417,8 +415,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
|
|||||||
if (this.actionCellDescriptors.length) {
|
if (this.actionCellDescriptors.length) {
|
||||||
this.displayedColumns.push('actions');
|
this.displayedColumns.push('actions');
|
||||||
}
|
}
|
||||||
this.entityDatasource = new EntityDatasource(
|
this.entityDatasource = new EntityDatasource(this.translate, dataKeys, this.subscription, this.ngZone);
|
||||||
this.translate, dataKeys, this.subscription);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private editColumnsToDisplay($event: Event) {
|
private editColumnsToDisplay($event: Event) {
|
||||||
@ -691,7 +688,8 @@ class EntityDatasource implements DataSource<EntityData> {
|
|||||||
constructor(
|
constructor(
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private dataKeys: Array<DataKey>,
|
private dataKeys: Array<DataKey>,
|
||||||
private subscription: IWidgetSubscription
|
private subscription: IWidgetSubscription,
|
||||||
|
private ngZone: NgZone
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,9 +732,11 @@ class EntityDatasource implements DataSource<EntityData> {
|
|||||||
totalElements: datasourcesPageData.totalElements,
|
totalElements: datasourcesPageData.totalElements,
|
||||||
hasNext: datasourcesPageData.hasNext
|
hasNext: datasourcesPageData.hasNext
|
||||||
};
|
};
|
||||||
|
this.ngZone.run(() => {
|
||||||
this.entitiesSubject.next(entities);
|
this.entitiesSubject.next(entities);
|
||||||
this.pageDataSubject.next(entitiesPageData);
|
this.pageDataSubject.next(entitiesPageData);
|
||||||
this.dataLoading = false;
|
this.dataLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private datasourceToEntityData(datasource: Datasource, data: DatasourceData[]): EntityData {
|
private datasourceToEntityData(datasource: Datasource, data: DatasourceData[]): EntityData {
|
||||||
|
|||||||
@ -193,9 +193,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onDataUpdated() {
|
public onDataUpdated() {
|
||||||
this.ngZone.run(() => {
|
|
||||||
this.updateCurrentSourceData();
|
this.updateCurrentSourceData();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private initialize() {
|
private initialize() {
|
||||||
@ -288,7 +286,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
|
|||||||
if (this.actionCellDescriptors.length) {
|
if (this.actionCellDescriptors.length) {
|
||||||
source.displayedColumns.push('actions');
|
source.displayedColumns.push('actions');
|
||||||
}
|
}
|
||||||
const tsDatasource = new TimeseriesDatasource(source, this.hideEmptyLines, this.dateFormatFilter, this.datePipe);
|
const tsDatasource = new TimeseriesDatasource(source, this.hideEmptyLines, this.dateFormatFilter, this.datePipe, this.ngZone);
|
||||||
tsDatasource.dataUpdated(this.data);
|
tsDatasource.dataUpdated(this.data);
|
||||||
this.sources.push(source);
|
this.sources.push(source);
|
||||||
}
|
}
|
||||||
@ -547,7 +545,8 @@ class TimeseriesDatasource implements DataSource<TimeseriesRow> {
|
|||||||
private source: TimeseriesTableSource,
|
private source: TimeseriesTableSource,
|
||||||
private hideEmptyLines: boolean,
|
private hideEmptyLines: boolean,
|
||||||
private dateFormatFilter: string,
|
private dateFormatFilter: string,
|
||||||
private datePipe: DatePipe
|
private datePipe: DatePipe,
|
||||||
|
private ngZone: NgZone
|
||||||
) {
|
) {
|
||||||
this.source.timeseriesDatasource = this;
|
this.source.timeseriesDatasource = this;
|
||||||
}
|
}
|
||||||
@ -570,8 +569,10 @@ class TimeseriesDatasource implements DataSource<TimeseriesRow> {
|
|||||||
catchError(() => of(emptyPageData<TimeseriesRow>())),
|
catchError(() => of(emptyPageData<TimeseriesRow>())),
|
||||||
).subscribe(
|
).subscribe(
|
||||||
(pageData) => {
|
(pageData) => {
|
||||||
|
this.ngZone.run(() => {
|
||||||
this.rowsSubject.next(pageData.data);
|
this.rowsSubject.next(pageData.data);
|
||||||
this.pageDataSubject.next(pageData);
|
this.pageDataSubject.next(pageData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user