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

Add institution type data #1290

Merged
merged 10 commits into from
Jun 14, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ <h5>Будинок</h5>
<mat-tab label="Опис">
<h5>Статус</h5>
<p class="description">{{ this.currentStatus }}</p>
<h5>Тип закладу</h5>
<p class="description">{{ institutionTypes[provider.institutionType] }}</p>
<h5>Про заклад</h5>
<p class="description">{{ provider?.description }}</p>
</mat-tab>
Expand Down
23 changes: 13 additions & 10 deletions src/app/shared/components/provider-info/provider-info.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused imports (output as I see)

import { Constants } from 'src/app/shared/constants/constants';
import { MatTabChangeEvent } from '@angular/material/tabs';
import {
CreateProviderSteps,
InstitutionTypes,
OwnershipType,
OwnershipTypeUkr,
ProviderType,
ProviderTypeUkr,
} from '../../enum/provider';
import { Provider } from '../../models/provider.model';
import { Select, Store } from '@ngxs/store';
import { GetInstitutionStatus } from '../../store/meta-data.actions';
import { MetaDataState } from '../../store/meta-data.state';
import { Observable, Subject } from 'rxjs';
import { InstitutionStatus } from '../../models/institutionStatus.model';
import { ActivateEditMode } from 'src/app/shared/store/app.actions';
import { GetInstitutionStatus } from '../../store/meta-data.actions';
import { filter, takeUntil } from 'rxjs/operators';
import { RegistrationState } from '../../store/registration.state';
import { ActivateEditMode } from 'src/app/shared/store/app.actions';

@Component({
selector: 'app-provider-info',
Expand All @@ -29,6 +30,8 @@ export class ProviderInfoComponent implements OnInit {
readonly ownershipType: typeof OwnershipType = OwnershipType;
readonly ownershipTypeUkr = OwnershipTypeUkr;
readonly providerTypeUkr = ProviderTypeUkr;
readonly institutionTypes = InstitutionTypes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty row after readonly fields


editLink: string = CreateProviderSteps[0];

@Input() provider: Provider;
Expand All @@ -50,13 +53,13 @@ export class ProviderInfoComponent implements OnInit {
.pipe(
filter((institutionStatuses) => !!institutionStatuses.length),
takeUntil(this.destroy$)
).subscribe((institutionStatuses) => {
const provider = this.store.selectSnapshot(RegistrationState.provider);
this.currentStatus =
institutionStatuses
.find((item) => +item.id === provider?.institutionStatusId)
?.name.toString() ?? 'Відсутній';
});
).subscribe((institutionStatuses) => {
const provider = this.store.selectSnapshot(RegistrationState.provider);
this.currentStatus =
institutionStatuses
.find((item) => +item.id === provider?.institutionStatusId)
?.name.toString() ?? 'Відсутній';
});
}

onTabChanged(tabChangeEvent: MatTabChangeEvent): void {
Expand Down
6 changes: 6 additions & 0 deletions src/app/shared/enum/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ export enum ProviderWorkshopSameValues {
website = 'website',
facebook = 'facebook',
instagram = 'instagram'
}

export enum InstitutionTypes {
Complex = 'Комплексний',
Profile = 'Профільний',
Specialized = 'Спеціалізований'
}
2 changes: 2 additions & 0 deletions src/app/shared/models/provider.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Provider {
image?: File[];
imageIds?: string[];
institutionStatusId?: number | null;
institutionType: string;

constructor(info, legalAddress: Address, actualAddress: Address, description, user: User, provider?: Provider) {
this.shortTitle = info.shortTitle;
Expand All @@ -45,6 +46,7 @@ export class Provider {
this.actualAddress = actualAddress;
this.description = description.description;
this.institutionStatusId = description.institutionStatusId || null;
this.institutionType = description.institutionType;
this.userId = user.id;
if (provider?.id) {
this.id = provider.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
</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="institutionType">
<mat-option *ngFor="let type of (institutionTypes | keyvalue)" [value]="type.key" class="dropdown-option">
{{type.value}}
</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 @@ -45,7 +45,8 @@ describe('CreatePhotoFormComponent', () => {
component.PhotoFormGroup = new FormGroup({
image: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
institutionStatusId: new FormControl('')
institutionStatusId: new FormControl(''),
institutionType: new FormControl('')
});
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Select, Store } from '@ngxs/store';
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 { 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';
Expand All @@ -16,25 +17,29 @@ import { MetaDataState } from 'src/app/shared/store/meta-data.state';
})
export class CreatePhotoFormComponent implements OnInit {
readonly validationConstants = ValidationConstants;
readonly institutionTypes = InstitutionTypes;

@Select(MetaDataState.institutionStatuses)
institutionStatuses$: Observable<InstitutionStatus[]>;
destroy$: Subject<boolean> = new Subject<boolean>();

@Input() provider: Provider;

@Output() passPhotoFormGroup = new EventEmitter();

PhotoFormGroup: FormGroup;
descriptionFormGroup: FormControl = new FormControl('', [
Validators.required,
Validators.minLength(ValidationConstants.INPUT_LENGTH_3),
Validators.maxLength(ValidationConstants.MAX_DESCRIPTION_LENGTH_2000)
]);
@Input() provider: Provider;

@Output() passPhotoFormGroup = new EventEmitter();

constructor(private formBuilder: FormBuilder, private store: Store ) {
this.PhotoFormGroup = this.formBuilder.group({
image: new FormControl(''),
description: this.descriptionFormGroup,
institutionStatusId: new FormControl(Constants.INSTITUTION_STATUS_ID_ABSENT_VALUE),
institutionStatusId: new FormControl(Constants.INSTITUTION_STATUS_ID_ABSENT_VALUE, Validators.required),
institutionType: new FormControl('', Validators.required),
});
}

Expand All @@ -45,9 +50,9 @@ export class CreatePhotoFormComponent implements OnInit {
}

private activateEditMode(): void {
this.PhotoFormGroup.patchValue(this.provider, { emitEvent: false });
this.provider.institutionStatusId = this.provider.institutionStatusId || Constants.SOCIAL_GROUP_ID_ABSENT_VALUE;
}
this.provider.institutionStatusId = this.provider.institutionStatusId || Constants.SOCIAL_GROUP_ID_ABSENT_VALUE;
this.PhotoFormGroup.patchValue(this.provider, { emitEvent: false });
}

ngOnDestroy(): void {
this.destroy$.next(true);
Expand Down