UI: Entities table improvements

This commit is contained in:
Igor Kulikov 2020-04-15 13:00:32 +03:00
parent e103d5a88b
commit ac963baa62
6 changed files with 20 additions and 3 deletions

View File

@ -225,9 +225,12 @@
'tb-current-entity': dataSource.isCurrentEntity(entity)}" 'tb-current-entity': dataSource.isCurrentEntity(entity)}"
*matRowDef="let entity; columns: displayedColumns;" (click)="onRowClick($event, entity)"></mat-row> *matRowDef="let entity; columns: displayedColumns;" (click)="onRowClick($event, entity)"></mat-row>
</table> </table>
<span [fxShow]="!(isLoading$ | async) && (dataSource.isEmpty() | async)" <span [fxShow]="!(isLoading$ | async) && (dataSource.isEmpty() | async) && !dataSource.dataLoading"
fxLayoutAlign="center center" fxLayoutAlign="center center"
class="no-data-found">{{ translations.noEntities | translate }}</span> class="no-data-found">{{ translations.noEntities | translate }}</span>
<span [fxShow]="dataSource.dataLoading"
fxLayoutAlign="center center"
class="no-data-found">{{ 'common.loading' | translate }}</span>
</div> </div>
<mat-divider *ngIf="displayPagination"></mat-divider> <mat-divider *ngIf="displayPagination"></mat-divider>
<mat-paginator *ngIf="displayPagination" <mat-paginator *ngIf="displayPagination"

View File

@ -345,6 +345,7 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
(entity) => { (entity) => {
if (entity) { if (entity) {
this.updateData(); this.updateData();
this.entitiesTableConfig.entityAdded(entity);
} }
} }
); );
@ -352,6 +353,7 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
onEntityUpdated(entity: BaseData<HasId>) { onEntityUpdated(entity: BaseData<HasId>) {
this.updateData(false); this.updateData(false);
this.entitiesTableConfig.entityUpdated(entity);
} }
onEntityAction(action: EntityAction<BaseData<HasId>>) { onEntityAction(action: EntityAction<BaseData<HasId>>) {
@ -375,6 +377,7 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
this.entitiesTableConfig.deleteEntity(entity.id).subscribe( this.entitiesTableConfig.deleteEntity(entity.id).subscribe(
() => { () => {
this.updateData(); this.updateData();
this.entitiesTableConfig.entitiesDeleted([entity.id]);
} }
); );
} }
@ -402,6 +405,7 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
() => { () => {
this.updateData(); this.updateData();
this.entitiesTableConfig.entitiesDeleted(entities.map((e) => e.id));
} }
); );
} }

View File

@ -35,6 +35,8 @@ export class EntitiesDataSource<T extends BaseData<HasId>, P extends PageLink =
public currentEntity: T = null; public currentEntity: T = null;
public dataLoading = true;
constructor(private fetchFunction: EntitiesFetchFunction<T, P>, constructor(private fetchFunction: EntitiesFetchFunction<T, P>,
protected selectionEnabledFunction: EntityBooleanFunction<T>, protected selectionEnabledFunction: EntityBooleanFunction<T>,
protected dataLoadedFunction: (col?: number, row?: number) => void) {} protected dataLoadedFunction: (col?: number, row?: number) => void) {}
@ -56,6 +58,7 @@ export class EntitiesDataSource<T extends BaseData<HasId>, P extends PageLink =
} }
loadEntities(pageLink: P): Observable<PageData<T>> { loadEntities(pageLink: P): Observable<PageData<T>> {
this.dataLoading = true;
const result = new ReplaySubject<PageData<T>>(); const result = new ReplaySubject<PageData<T>>();
this.fetchFunction(pageLink).pipe( this.fetchFunction(pageLink).pipe(
tap(() => { tap(() => {
@ -68,6 +71,7 @@ export class EntitiesDataSource<T extends BaseData<HasId>, P extends PageLink =
this.pageDataSubject.next(pageData); this.pageDataSubject.next(pageData);
result.next(pageData); result.next(pageData);
this.dataLoadedFunction(); this.dataLoadedFunction();
this.dataLoading = false;
} }
); );
return result; return result;

View File

@ -33,6 +33,8 @@ import { EntityTabsComponent } from '../../components/entity/entity-tabs.compone
export type EntityBooleanFunction<T extends BaseData<HasId>> = (entity: T) => boolean; export type EntityBooleanFunction<T extends BaseData<HasId>> = (entity: T) => boolean;
export type EntityStringFunction<T extends BaseData<HasId>> = (entity: T) => string; export type EntityStringFunction<T extends BaseData<HasId>> = (entity: T) => string;
export type EntityVoidFunction<T extends BaseData<HasId>> = (entity: T) => void;
export type EntityIdsVoidFunction<T extends BaseData<HasId>> = (ids: HasUUID[]) => void;
export type EntityCountStringFunction = (count: number) => string; export type EntityCountStringFunction = (count: number) => string;
export type EntityTwoWayOperation<T extends BaseData<HasId>> = (entity: T) => Observable<T>; export type EntityTwoWayOperation<T extends BaseData<HasId>> = (entity: T) => Observable<T>;
export type EntityByIdOperation<T extends BaseData<HasId>> = (id: HasUUID) => Observable<T>; export type EntityByIdOperation<T extends BaseData<HasId>> = (id: HasUUID) => Observable<T>;
@ -175,6 +177,9 @@ export class EntityTableConfig<T extends BaseData<HasId>, P extends PageLink = P
onEntityAction: EntityActionFunction<T> = () => false; onEntityAction: EntityActionFunction<T> = () => false;
handleRowClick: EntityRowClickFunction<L> = () => false; handleRowClick: EntityRowClickFunction<L> = () => false;
entityTitle: EntityStringFunction<T> = (entity) => entity?.name; entityTitle: EntityStringFunction<T> = (entity) => entity?.name;
entityAdded: EntityVoidFunction<T> = () => {};
entityUpdated: EntityVoidFunction<T> = () => {};
entitiesDeleted: EntityIdsVoidFunction<T> = () => {};
} }
export function checkBoxCell(value: boolean): string { export function checkBoxCell(value: boolean): string {

View File

@ -43,7 +43,7 @@ export interface NavTreeEditCallbacks {
nodeIsLoaded?: (id: string) => boolean; nodeIsLoaded?: (id: string) => boolean;
refreshNode?: (id: string) => void; refreshNode?: (id: string) => void;
updateNode?: (id: string, newName: string) => void; updateNode?: (id: string, newName: string) => void;
createNode?: (parentId: string, node: NavTreeNode, pos: number) => void; createNode?: (parentId: string, node: NavTreeNode, pos: number | string) => void;
deleteNode?: (id: string) => void; deleteNode?: (id: string) => void;
disableNode?: (id: string) => void; disableNode?: (id: string) => void;
enableNode?: (id: string) => void; enableNode?: (id: string) => void;

View File

@ -380,7 +380,8 @@
"enter-username": "Enter username", "enter-username": "Enter username",
"enter-password": "Enter password", "enter-password": "Enter password",
"enter-search": "Enter search", "enter-search": "Enter search",
"created-time": "Created time" "created-time": "Created time",
"loading": "Loading..."
}, },
"content-type": { "content-type": {
"json": "Json", "json": "Json",