Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Create provider] - INSTITUTIONS - Important! #1316

Merged
merged 8 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ <h5>Статус</h5>
<p class="description">{{ this.currentStatus }}</p>
<h5>Тип закладу</h5>
<p class="description">{{ institutionTypes[provider.institutionType] }}</p>
<h5>Підпорядкування</h5>
<p class="description">{{ provider.institution.title }}</p>
<h5>Про заклад</h5>
<p class="description">{{ provider?.description }}</p>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Institution } from './../../models/institution.model';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatFormFieldModule } from '@angular/material/form-field';
Expand Down Expand Up @@ -41,6 +42,8 @@ describe('ProviderInfoComponent', () => {
component.provider = {} as Provider;
component.provider.actualAddress = {} as Address;
component.provider.legalAddress = {} as Address;
component.provider.institution = {} as Institution;

fixture.detectChanges();
});

Expand Down
5 changes: 5 additions & 0 deletions src/app/shared/models/institution.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Institution {
id: string;
title: string;
numberOfHierarchyLevels: number;
}
3 changes: 3 additions & 0 deletions src/app/shared/models/provider.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Institution } from './institution.model';
import { Address } from './address.model';
import { User } from './user.model';
import { Workshop } from './workshop.model';
Expand Down Expand Up @@ -27,6 +28,7 @@ export class Provider {
imageIds?: string[];
institutionStatusId?: number | null;
institutionType: string;
institution: Institution;

constructor(info, legalAddress: Address, actualAddress: Address, description, user: User, provider?: Provider) {
this.shortTitle = info.shortTitle;
Expand All @@ -48,6 +50,7 @@ export class Provider {
this.institutionStatusId = description.institutionStatusId || null;
this.institutionType = description.institutionType;
this.userId = user.id;
this.institution = description.institution;
if (provider?.id) {
this.id = provider.id;
}
Expand Down
19 changes: 19 additions & 0 deletions src/app/shared/services/institutions/institutions.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';

import { InstitutionsService } from './institutions.service';

describe('InstitutionsService', () => {
let service: InstitutionsService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
service = TestBed.inject(InstitutionsService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
16 changes: 16 additions & 0 deletions src/app/shared/services/institutions/institutions.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Institution } from '../../models/institution.model';

@Injectable({
providedIn: 'root'
})
export class InstitutionsService {

constructor(private http: HttpClient) {}

getAllInstitutions(): Observable<Institution[]> {
return this.http.get<Institution[]>('/api/v1/Institution/GetAll');
}
}
4 changes: 4 additions & 0 deletions src/app/shared/store/meta-data.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ export class GetFeaturesList {
static readonly type = '[meta-data] Get features list';
constructor() { }
}
export class GetAllInstitutions {
static readonly type = '[meta-data] Get All Institutions';
constructor() { }
}
21 changes: 20 additions & 1 deletion src/app/shared/store/meta-data.state.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InstitutionsService } from './../services/institutions/institutions.service';
import { Institution } from './../models/institution.model';
import { Constants } from './../constants/constants';
import { Injectable } from '@angular/core';
import { State, Action, StateContext, Selector } from '@ngxs/store';
Expand Down Expand Up @@ -29,6 +31,7 @@ import {
GetInstitutionStatus,
ClearRatings,
GetFeaturesList,
GetAllInstitutions,
} from './meta-data.actions';
import { Observable } from 'rxjs';
import { InstitutionStatus } from '../models/institutionStatus.model';
Expand All @@ -48,6 +51,7 @@ export interface MetaDataStateModel {
rating: Rate[];
isLoading: boolean;
featuresList: FeaturesList;
institutions: Institution[];
}
@State<MetaDataStateModel>({
name: 'metaDataState',
Expand All @@ -65,6 +69,7 @@ export interface MetaDataStateModel {
rating: [],
isLoading: false,
featuresList: null,
institutions: null,
}

})
Expand Down Expand Up @@ -110,13 +115,18 @@ export class MetaDataState {
@Selector()
static featuresList(state: MetaDataStateModel): FeaturesList { return state.featuresList; }

@Selector()
static institutions(state: MetaDataStateModel): Institution[] { return state.institutions; }

constructor(
private categoriesService: CategoriesService,
private childrenService: ChildrenService,
private providerService: ProviderService,
private cityService: CityService,
private ratingService: RatingService,
private featureManagementService: FeatureManagementService) { }
private featureManagementService: FeatureManagementService,
private institutionsService: InstitutionsService,
) { }

@Action(GetDirections)
getDirections({ patchState }: StateContext<MetaDataStateModel>, { }: GetDirections): Observable<Direction[]> {
Expand Down Expand Up @@ -243,4 +253,13 @@ export class MetaDataState {
))
}

@Action(GetAllInstitutions)
getAllInstitutions({ patchState }: StateContext<MetaDataStateModel>, { }: GetAllInstitutions): Observable<Institution[]> {
return this.institutionsService
.getAllInstitutions()
.pipe(
tap((institutions: Institution[]) => patchState({ institutions: institutions })
))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export class CreateInfoFormComponent implements OnInit {
readonly ownershipTypeUkr = OwnershipTypeUkr;
readonly providerTypeUkr = ProviderTypeUkr;

InfoFormGroup: FormGroup;

@Input() provider: Provider;
@Output() passInfoFormGroup = new EventEmitter();

InfoFormGroup: FormGroup;
dateFilter: RegExp = DATE_REGEX;
maxDate: Date = Util.getMaxBirthDate();
minDate: Date = Util.getMinBirthDate(ValidationConstants.BIRTH_AGE_MAX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
<label class="step-label">Тип закладу</label>
<mat-form-field floatLabel="never" appearance="none">
<mat-select disableOptionCentering panelClass="dropdown-panel" class="step-input"
formControlName="institutionType">
formControlName="institutionType" placeholder="Оберіть підпорядкування">
<mat-option *ngFor="let type of (institutionTypes | keyvalue)" [value]="type.key" class="dropdown-option">
{{type.value}}
</mat-option>
</mat-select>
</mat-form-field>

<label class="step-label">Підпорядкування</label>
<mat-form-field floatLabel="never" appearance="none">
<mat-select disableOptionCentering panelClass="dropdown-panel" class="step-input"
formControlName="institution" placeholder="Оберіть підпорядкування">
<mat-option *ngFor="let institution of (institutions$ | async)" [value]="institution" class="dropdown-option">
{{institution.title}}
</mat-option>
</mat-select>
</mat-form-field>

<div class="step-label-combined">
<label class="step-label"> Опис<span class="step-required">*</span></label>
<label class="step-characters-count">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('CreatePhotoFormComponent', () => {
image: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
institutionStatusId: new FormControl(''),
institutionType: new FormControl('')
institutionType: new FormControl(''),
institution: new FormControl(''),
});
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Observable, Subject } from 'rxjs';
import { Constants } from 'src/app/shared/constants/constants';
import { ValidationConstants } from 'src/app/shared/constants/validation';
import { InstitutionTypes } from 'src/app/shared/enum/provider';
import { Institution } from 'src/app/shared/models/institution.model';
import { InstitutionStatus } from 'src/app/shared/models/institutionStatus.model';
import { Provider } from 'src/app/shared/models/provider.model';
import { GetInstitutionStatus } from 'src/app/shared/store/meta-data.actions';
import { GetAllInstitutions, GetInstitutionStatus } from 'src/app/shared/store/meta-data.actions';
import { MetaDataState } from 'src/app/shared/store/meta-data.state';

@Component({
Expand All @@ -22,6 +23,8 @@ export class CreatePhotoFormComponent implements OnInit {
@Select(MetaDataState.institutionStatuses)
institutionStatuses$: Observable<InstitutionStatus[]>;
destroy$: Subject<boolean> = new Subject<boolean>();
@Select(MetaDataState.institutions)
institutions$: Observable<Institution[]>;

@Input() provider: Provider;

Expand All @@ -40,11 +43,12 @@ export class CreatePhotoFormComponent implements OnInit {
description: this.descriptionFormGroup,
institutionStatusId: new FormControl(Constants.INSTITUTION_STATUS_ID_ABSENT_VALUE, Validators.required),
institutionType: new FormControl('', Validators.required),
institution: new FormControl('', Validators.required),
});
}

ngOnInit(): void {
this.store.dispatch(new GetInstitutionStatus());
this.store.dispatch([new GetInstitutionStatus(), new GetAllInstitutions()]);
this.provider && this.activateEditMode();
this.passPhotoFormGroup.emit(this.PhotoFormGroup);
}
Expand Down