Skip to content

Commit

Permalink
#1704 added pulling of institution descriptions, deleted hardcoded c…
Browse files Browse the repository at this point in the history
…olumns, fixed comments in pr
  • Loading branch information
Nazarii Ivasyshyn committed Nov 7, 2022
1 parent af0e7f3 commit 26872a0
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="wrapper">
<div [hidden]="!dataSource" 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>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "src/app/shared/styles/tables.scss";
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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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[][];
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.institutionFieldDesc$.pipe(
filter((institutionFieldDesc: InstitutionFieldDescription[]) => !!institutionFieldDesc),
takeUntil(this.destroy$),
distinctUntilChanged()
).subscribe((institutionFieldDesc: InstitutionFieldDescription[]) => {
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);});
}

createDirectionTableRecords(institutionalHierarchies: InstituitionHierarchy[]) {
if (institutionalHierarchies) {
this.institutionalHierarchies = institutionalHierarchies;
this.records = [];
let 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[]) {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
<mat-tab label="Напрямки для користувача">
<app-directions></app-directions>
</mat-tab>
<mat-tab label="МОН"> </mat-tab>
<mat-tab label="МКІП"> </mat-tab>
<mat-tab label="Мінспорт"> </mat-tab>
<mat-tab label="Інші"> </mat-tab>
<ng-container *ngFor="let institution of (institutions$ | async)">
<mat-tab label="{{institution.title}}">
<ng-template matTabContent>
<app-directions-institution-hierarchies-list [institution]="institution">
</app-directions-institution-hierarchies-list>
</ng-template>
</mat-tab>
</ng-container>
</mat-tab-group>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatTabsModule } from '@angular/material/tabs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxsModule } from '@ngxs/store';
import { DirectionsWrapperComponent } from './directions-wrapper.component';
import { DirectionsComponent } from './directions/directions.component';

describe('DirectionsWrapperComponent', () => {
let component: DirectionsWrapperComponent;
let fixture: ComponentFixture<DirectionsWrapperComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NgxsModule.forRoot([])],
declarations: [DirectionsWrapperComponent]
imports: [NgxsModule.forRoot([]), MatTabsModule, MatDialogModule, BrowserAnimationsModule],
declarations: [DirectionsWrapperComponent, DirectionsComponent],
}).compileComponents();

fixture = TestBed.createComponent(DirectionsWrapperComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { NavBarName } from '../../../../shared/enum/navigation-bar';
import { PopNavPath, PushNavPath } from '../../../../shared/store/navigation.actions';
import { MetaDataState } from '../../../../shared/store/meta-data.state';
import { Institution } from '../../../../shared/models/institution.model';
import { GetAllInstitutions } from '../../../../shared/store/meta-data.actions';

@Component({
selector: 'app-directions-wrapper',
templateUrl: './directions-wrapper.component.html',
styleUrls: ['./directions-wrapper.component.scss']
})
export class DirectionsWrapperComponent implements OnInit, OnDestroy {
@Select(MetaDataState.institutions)
institutions$: Observable<Institution[]>;

constructor(private store: Store) {}

ngOnInit(): void {
this.store.dispatch(new GetAllInstitutions());
this.store.dispatch(
new PushNavPath({
name: NavBarName.Directions,
Expand Down

0 comments on commit 26872a0

Please sign in to comment.