Some improvements
This commit is contained in:
parent
5b26f76f0e
commit
b338dd9baa
@ -49,7 +49,7 @@ export class EntitiesService<E extends IListable, I = E> extends GenericService<
|
||||
loadAll(modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<E[]> {
|
||||
return this.getAll(modelPath, queryParams).pipe(
|
||||
mapEach(entity => new this._entityClass(entity)),
|
||||
tap((entities: E[]) => this.replace(entities)),
|
||||
tap((entities: E[]) => this.setEntities(entities)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -67,7 +67,19 @@ export class EntitiesService<E extends IListable, I = E> extends GenericService<
|
||||
);
|
||||
}
|
||||
|
||||
setEntities(newEntities: E[]): void {
|
||||
setEntities(entities: E[]): void {
|
||||
// Keep old object references for unchanged entities
|
||||
const newEntities = entities.map(entity => {
|
||||
const oldEntity = this.find(entity.id);
|
||||
|
||||
if (oldEntity && JSON.stringify(oldEntity) === JSON.stringify(entity)) {
|
||||
return oldEntity;
|
||||
}
|
||||
|
||||
this.entityChanged$.next(entity);
|
||||
return entity;
|
||||
});
|
||||
|
||||
this._all$.next(newEntities);
|
||||
}
|
||||
|
||||
@ -79,10 +91,9 @@ export class EntitiesService<E extends IListable, I = E> extends GenericService<
|
||||
return this.all.some(entity => entity.id === id);
|
||||
}
|
||||
|
||||
replace(newEntities: E[]): void {
|
||||
const ids = newEntities.map(entity => entity.id);
|
||||
const all = this.all.filter(item => !ids.includes(item.id));
|
||||
this.setEntities([...all, ...newEntities]);
|
||||
newEntities.forEach(entity => this.entityChanged$.next(entity));
|
||||
replace(entity: E): void {
|
||||
const all = this.all.filter(item => item.id !== entity.id);
|
||||
this.setEntities([...all, entity]);
|
||||
this.entityChanged$.next(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ export class TableComponent<T extends IListable> extends AutoUnsubscribe impleme
|
||||
@Input() itemMouseEnterFn?: (entity: T) => void;
|
||||
@Input() itemMouseLeaveFn?: (entity: T) => void;
|
||||
@Output() readonly noDataAction = new EventEmitter<void>();
|
||||
@ViewChild(TableContentComponent, { static: true }) readonly tableContent!: TableContentComponent<T>;
|
||||
@ViewChild(TableContentComponent, { static: true }) private readonly _tableContent!: TableContentComponent<T>;
|
||||
|
||||
constructor(
|
||||
@Inject(forwardRef(() => ListingComponent)) readonly listingComponent: ListingComponent<T>,
|
||||
@ -65,6 +65,10 @@ export class TableComponent<T extends IListable> extends AutoUnsubscribe impleme
|
||||
return this.listingComponent.tableHeaderLabel;
|
||||
}
|
||||
|
||||
scrollToLastIndex(): void {
|
||||
this._tableContent.scrollToLastIndex();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this._setStyles();
|
||||
}
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export const CONFLICT_ERROR_CODE = 409;
|
||||
export const CONFLICT = 409;
|
||||
export const BAD_REQUEST = 400;
|
||||
export const CHANGED_CHECK_INTERVAL = 3000;
|
||||
|
||||
@ -6,7 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { ErrorMessageService } from './error-message.service';
|
||||
import { CONFLICT_ERROR_CODE } from './constants';
|
||||
import { CONFLICT } from './constants';
|
||||
|
||||
const enum NotificationType {
|
||||
SUCCESS = 'SUCCESS',
|
||||
@ -53,7 +53,7 @@ export class Toaster {
|
||||
|
||||
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
|
||||
let resultedMsg;
|
||||
if (options?.error && options.error.status !== CONFLICT_ERROR_CODE) {
|
||||
if (options?.error && options.error.status !== CONFLICT) {
|
||||
resultedMsg = this._errorMessageService.getMessage(options.error, message);
|
||||
} else {
|
||||
resultedMsg = this._translateService.instant(message, options?.params) as string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user