Skip to content

Commit

Permalink
#1704 code formatting, added check on loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii Ivasyshyn committed Nov 7, 2022
1 parent 26872a0 commit 796e23f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="wrapper">
<div [hidden]="!dataSource" class="table-container mat-elevation-z8">
<div [hidden]="!dataSource" *ngIf="isLoaded" class="table-container mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort appStretchTable>
<ng-container *ngFor="let column of displayedColumns; index as i">
<ng-container matColumnDef="{{column}}" sticky>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,54 @@ export class DirectionsInstitutionHierarchiesListComponent implements OnInit, On
@Select(MetaDataState.institutionFieldDesc)
institutionFieldDesc$: Observable<InstitutionFieldDescription[]>;


destroy$: Subject<boolean> = new Subject<boolean>();

displayedColumns: string[];
institutionalHierarchies: InstituitionHierarchy[];
records: string[][];
isLoaded: boolean = false;
dataSource: MatTableDataSource<object> = new MatTableDataSource([{}]);

constructor(private store: Store) {
}

ngOnInit(): void {
this.store.dispatch(new GetFieldDescriptionByInstitutionId(this.institution.id));
this.store.dispatch(new GetAllInstitutionsHierarchy());
this.store.dispatch([new GetFieldDescriptionByInstitutionId(this.institution.id),
new GetAllInstitutionsHierarchy()]);

this.institutionFieldDesc$.pipe(
filter((institutionFieldDesc: InstitutionFieldDescription[]) => !!institutionFieldDesc),
takeUntil(this.destroy$),
distinctUntilChanged()
distinctUntilChanged(),
takeUntil(this.destroy$)
).subscribe((institutionFieldDesc: InstitutionFieldDescription[]) => {
this.store.snapshot
this.displayedColumns = institutionFieldDesc.map((ins: InstitutionFieldDescription) => ins.title);
});
this.institutionsHierarchies$.pipe(
filter((institutiionHierarchies: InstituitionHierarchy[]) => !!institutiionHierarchies),
takeUntil(this.destroy$),
distinctUntilChanged(),
map((institutionHierarchies: InstituitionHierarchy[]) =>
this.createDirectionTableRecords(institutionHierarchies.filter(i => i.institution.title == this.institution.title))
),
).subscribe(() => {this.dataSource = new MatTableDataSource(this.records);});
takeUntil(this.destroy$)
).subscribe(() => {
this.isLoaded = true;
this.dataSource = new MatTableDataSource(this.records)
});
}

createDirectionTableRecords(institutionalHierarchies: InstituitionHierarchy[]) {
private createDirectionTableRecords(institutionalHierarchies: InstituitionHierarchy[]) {
if (institutionalHierarchies) {
this.institutionalHierarchies = institutionalHierarchies;
this.records = [];
let firstLevelInstitutions = this.institutionalHierarchies.filter((ins: InstituitionHierarchy) => ins.hierarchyLevel == 1);
const firstLevelInstitutions = this.institutionalHierarchies.filter((ins: InstituitionHierarchy) => ins.hierarchyLevel == 1);
firstLevelInstitutions.forEach((ins: InstituitionHierarchy) => {
let records: string[] = [];
this.createDirectionTableRecord(ins, [...records]);
});
}
}

createDirectionTableRecord(parent: InstituitionHierarchy, records: string[]) {
private createDirectionTableRecord(parent: InstituitionHierarchy, records: string[]) {
records.push(parent.title);
let children = this.institutionalHierarchies.filter((ins: InstituitionHierarchy) => ins.parentId == parent.id);
if (!children.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ export class DirectionsWrapperComponent implements OnInit, OnDestroy {
constructor(private store: Store) {}

ngOnInit(): void {
this.store.dispatch(new GetAllInstitutions());
this.store.dispatch(
this.store.dispatch([new GetAllInstitutions(),
new PushNavPath({
name: NavBarName.Directions,
isActive: false,
disable: true
})
);
]);
}

ngOnDestroy(): void {
Expand Down

0 comments on commit 796e23f

Please sign in to comment.