-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #1704 added pulling of institution descriptions, deleted hardcoded columns, fixed comments in pr * #1704 code formatting, added check on loading * #1704 added again action for GetAllInstitutionsHierarchy * #1704 comments after review Co-authored-by: Nazarii Ivasyshyn <nivasy@softserveinc.com> Co-authored-by: Oleksandra Lytvynets <alitvinets7@gmail.com>
- Loading branch information
1 parent
ba5e2b0
commit 707fc3a
Showing
11 changed files
with
202 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...tions-institution-hierarchies-list/directions-institution-hierarchies-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="wrapper"> | ||
<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> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header> | ||
{{column}} | ||
</th> | ||
<td mat-cell *matCellDef="let element" class="tab"> | ||
<div class="tab-text"> {{ element[i] }} | ||
</div> | ||
</td> | ||
</ng-container> | ||
</ng-container> | ||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> | ||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr> | ||
</table> | ||
</div> | ||
</div> |
1 change: 1 addition & 0 deletions
1
...tions-institution-hierarchies-list/directions-institution-hierarchies-list.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "src/app/shared/styles/tables.scss"; |
30 changes: 30 additions & 0 deletions
30
...ns-institution-hierarchies-list/directions-institution-hierarchies-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MatTableModule } from '@angular/material/table'; | ||
import { NgxsModule } from '@ngxs/store'; | ||
import { DirectionsInstitutionHierarchiesListComponent } from './directions-institution-hierarchies-list.component'; | ||
|
||
describe('DirectionsInstitutionHierarchiesListComponent', () => { | ||
let component: DirectionsInstitutionHierarchiesListComponent; | ||
let fixture: ComponentFixture<DirectionsInstitutionHierarchiesListComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [NgxsModule.forRoot([]), MatTableModule], | ||
declarations: [DirectionsInstitutionHierarchiesListComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DirectionsInstitutionHierarchiesListComponent); | ||
component = fixture.componentInstance; | ||
component.institution = { | ||
id: "id", | ||
title: 'title', | ||
numberOfHierarchyLevels: 2 | ||
}; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
...ections-institution-hierarchies-list/directions-institution-hierarchies-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; | ||
import { MatTableDataSource } from '@angular/material/table'; | ||
import { Select, Store } from '@ngxs/store'; | ||
import { distinctUntilChanged, filter, map, Observable, Subject, takeUntil } from 'rxjs'; | ||
import { Institution, InstituitionHierarchy, InstitutionFieldDescription } from '../../../../../shared/models/institution.model'; | ||
import { GetFieldDescriptionByInstitutionId, GetAllInstitutionsHierarchy } from '../../../../../shared/store/meta-data.actions'; | ||
import { MetaDataState } from '../../../../../shared/store/meta-data.state'; | ||
|
||
|
||
@Component({ | ||
selector: 'app-directions-institution-hierarchies-list', | ||
templateUrl: './directions-institution-hierarchies-list.component.html', | ||
styleUrls: ['./directions-institution-hierarchies-list.component.scss'] | ||
}) | ||
export class DirectionsInstitutionHierarchiesListComponent implements OnInit, OnDestroy { | ||
@Input() institution: Institution; | ||
|
||
@Select(MetaDataState.instituitionsHierarchyAll) | ||
institutionsHierarchies$: Observable<InstituitionHierarchy[]>; | ||
@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.loadDirectionInstitutionHierarchiesData(); | ||
} | ||
|
||
private loadDirectionInstitutionHierarchiesData() { | ||
this.store.dispatch([new GetFieldDescriptionByInstitutionId(this.institution.id), | ||
new GetAllInstitutionsHierarchy()]); | ||
|
||
this.institutionFieldDesc$.pipe( | ||
filter((institutionFieldDesc: InstitutionFieldDescription[]) => !!institutionFieldDesc), | ||
distinctUntilChanged(), | ||
takeUntil(this.destroy$) | ||
).subscribe((institutionFieldDesc: InstitutionFieldDescription[]) => { | ||
this.displayedColumns = institutionFieldDesc.map((ins: InstitutionFieldDescription) => ins.title); | ||
}); | ||
this.institutionsHierarchies$.pipe( | ||
filter((institutiionHierarchies: InstituitionHierarchy[]) => !!institutiionHierarchies), | ||
distinctUntilChanged(), | ||
map((institutionHierarchies: InstituitionHierarchy[]) => | ||
this.createDirectionTableRecords(institutionHierarchies.filter(ins => ins.institution.title === this.institution.title)) | ||
), | ||
takeUntil(this.destroy$) | ||
).subscribe(() => { | ||
this.isLoaded = true; | ||
this.dataSource = new MatTableDataSource(this.records) | ||
}); | ||
} | ||
|
||
private createDirectionTableRecords(institutionalHierarchies: InstituitionHierarchy[]) { | ||
if (institutionalHierarchies) { | ||
this.institutionalHierarchies = institutionalHierarchies; | ||
this.records = []; | ||
const firstLevelInstitutions = this.institutionalHierarchies.filter((ins: InstituitionHierarchy) => ins.hierarchyLevel === 1); | ||
firstLevelInstitutions.forEach((ins: InstituitionHierarchy) => { | ||
let records: string[] = []; | ||
this.createDirectionTableRecord(ins, [...records]); | ||
}); | ||
} | ||
} | ||
|
||
private createDirectionTableRecord(parent: InstituitionHierarchy, records: string[]) { | ||
records.push(parent.title); | ||
let children = this.institutionalHierarchies.filter((ins: InstituitionHierarchy) => ins.parentId === parent.id); | ||
if (!children.length) { | ||
this.records.push(records); | ||
} | ||
else { | ||
children.forEach((child: InstituitionHierarchy) => { | ||
this.createDirectionTableRecord(child, [...records]); | ||
}) | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.destroy$.next(true); | ||
this.destroy$.unsubscribe(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
src/app/shell/admin-tools/data/directions-wrapper/directions-wrapper.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/app/shell/admin-tools/data/directions-wrapper/directions-wrapper.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters