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 educational institution status#363/zubkov #635

Merged
merged 19 commits into from
Nov 15, 2021
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
1 change: 1 addition & 0 deletions src/app/shared/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Constants {
static WorkingDaysValues: any;

static readonly SOCIAL_GROUP_ID_ABSENT_VALUE = 0;
static readonly INSTITUTION_STATUS_ID_ABSENT_VALUE = 0;

}

Expand Down
5 changes: 5 additions & 0 deletions src/app/shared/models/institutionStatus.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface InstitutionStatus {
id: string;
name: number;
}

6 changes: 4 additions & 2 deletions src/app/shared/models/provider.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export class Provider {
actualAddress?: Address;
workshop?: Workshop;
image?: File[];
institutionStatusId?: number | null;

constructor(info, legalAddress: Address, actualAddress: Address, photo, user: User, provider?: Provider) {
constructor(info, legalAddress: Address, actualAddress: Address, description, user: User, provider?: Provider) {
this.shortTitle = info.shortTitle;
this.ownership = info.ownership;
this.type = info.type;
Expand All @@ -41,7 +42,8 @@ export class Provider {
this.founder = info.founder;
this.legalAddress = legalAddress;
this.actualAddress = actualAddress;
this.description = photo.description;
this.description = description.description;
this.institutionStatusId = description.institutionStatusId || null;
this.userId = user.id;
if (provider?.id) {
this.id = provider.id;
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/services/provider/provider.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { InstitutionStatus } from '../../models/institutionStatus.model';
import { Provider } from '../../models/provider.model';

@Injectable({
Expand Down Expand Up @@ -40,4 +41,11 @@ export class ProviderService {
updateProvider(provider: Provider): Observable<object> {
return this.http.put('/api/v1/Provider/Update', provider);
}

/**
* This method get all institution statuses
*/
getInstitutionStatus(): Observable<InstitutionStatus[]> {
return this.http.get<InstitutionStatus[]>('/api/v1/InstitutionStatus/Get');
Copy link
Collaborator

Choose a reason for hiding this comment

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

indentations

}
}
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 @@ -22,6 +22,10 @@ export class GetSocialGroup {
static readonly type = '[meta-data] Get GetSocialGroup';
constructor() { }
}
export class GetInstitutionStatus{
static readonly type = '[meta-data] Get GetInstitutionStatus';
constructor() { }
}
export class ClearClasses {
static readonly type = '[meta-data] clear classes state';
}
Expand Down
21 changes: 20 additions & 1 deletion src/app/shared/store/meta-data.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import {
GetTopDirections,
ClearDepartments,
ClearClasses,
GetInstitutionStatus,
ClearRatings
} from './meta-data.actions';
import { Observable } from 'rxjs';
import { InstitutionStatus } from '../models/institutionStatus.model';
import { ProviderService } from '../services/provider/provider.service';

export interface MetaDataStateModel {
directions: Direction[];
Expand All @@ -35,6 +38,7 @@ export interface MetaDataStateModel {
classes: IClass[];
cities: City[];
socialGroups: SocialGroup[];
institutionStatuses: InstitutionStatus[];
isCity: boolean;
filteredDirections: Direction[];
filteredDepartments: Department[];
Expand All @@ -51,6 +55,7 @@ export interface MetaDataStateModel {
classes: [],
cities: null,
socialGroups: [],
institutionStatuses: [],
isCity: false,
filteredDirections: [],
filteredDepartments: [],
Expand Down Expand Up @@ -78,6 +83,9 @@ export class MetaDataState {
@Selector()
static socialGroups(state: MetaDataStateModel): SocialGroup[] { return state.socialGroups; }

@Selector()
static institutionStatuses(state: MetaDataStateModel): InstitutionStatus[] { return state.institutionStatuses; }

@Selector()
static cities(state: MetaDataStateModel): City[] { return state.cities; }

Expand All @@ -102,9 +110,10 @@ export class MetaDataState {
constructor(
private categoriesService: CategoriesService,
private childrenService: ChildrenService,
private providerService: ProviderService,
private cityService: CityService,
private ratingService: RatingService) { }

@Action(GetDirections)
getDirections({ patchState }: StateContext<MetaDataStateModel>, { }: GetDirections): Observable<Direction[]> {
patchState({ isLoading: true })
Expand Down Expand Up @@ -151,6 +160,16 @@ export class MetaDataState {
tap((socialGroups: SocialGroup[]) => patchState({ socialGroups: socialGroups })
))
}

@Action(GetInstitutionStatus)
getInstitutionStatus({ patchState }: StateContext<MetaDataStateModel>, { }: GetInstitutionStatus): Observable<InstitutionStatus[]> {
return this.providerService
.getInstitutionStatus()
.pipe(
tap((institutionStatuses: InstitutionStatus[]) => patchState({ institutionStatuses: institutionStatuses })
))
}

@Action(ClearClasses)
clearClasses({ patchState }: StateContext<MetaDataStateModel>, { }: ClearClasses): void {
patchState({ classes: undefined });
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/store/user.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export class UserState {
onUpdateProviderSuccess({ dispatch }: StateContext<UserStateModel>, { payload }: OnUpdateProviderSuccess): void {
dispatch(new MarkFormDirty(false));
console.log('Provider is updated', payload);
dispatch(new ShowMessageBar({ message: 'Організація успішно відредагована', type: 'success' }));
dispatch([new ShowMessageBar({ message: 'Організація успішно відредагована', type: 'success' }), new GetProfile()]);
dispatch(new GetProfile()).subscribe(() => this.router.navigate(['/personal-cabinet/provider/info']));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<form [formGroup]="PhotoFormGroup" fxLayout='column' fxLayoutAlign='center space-between' class="step">
<!-- <app-image-form-control [imgMaxAmount]="4" [label]="'Фото'" formControlName="image">
</app-image-form-control> TODO: Second release -->

<label class="step-label">Статус</label>
<mat-form-field floatLabel="never" appearance="none">
<mat-select disableOptionCentering panelClass="dropdown-panel" class="step-input" formControlName="institutionStatusId">
<mat-option [value]="0" class="dropdown-option"> Відсутній </mat-option>
<mat-option *ngFor="let status of (institutionStatuses$ | async)" [value]="status.id" class="dropdown-option">
{{status.name}}
</mat-option>
</mat-select>
</mat-form-field>

<label class="step-label"> Опис <span class="step-required">*</span></label>
<mat-form-field appPlaceholderStyling floatLabel="never" appearance="none">
<textarea matInput class="step-textarea" placeholder="Максимум {{constants.MAX_DESCRIPTION_LENGTH}} символів"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { MatInputModule } from '@angular/material/input';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatGridListModule } from '@angular/material/grid-list';
import { Component, Input } from '@angular/core';
import { MatOptionModule } from '@angular/material/core';
import { MatSelectModule } from '@angular/material/select';

describe('CreatePhotoFormComponent', () => {
let component: CreatePhotoFormComponent;
Expand All @@ -24,6 +26,8 @@ describe('CreatePhotoFormComponent', () => {
BrowserAnimationsModule,
NgxsModule.forRoot([]),
MatIconModule,
MatOptionModule,
MatSelectModule,
MatGridListModule
],
declarations: [
Expand All @@ -41,6 +45,7 @@ describe('CreatePhotoFormComponent', () => {
component.PhotoFormGroup = new FormGroup({
image: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
institutionStatusId: new FormControl('')
});
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Select, Store } from '@ngxs/store';
import { Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Constants } from 'src/app/shared/constants/constants';
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 { MetaDataState } from 'src/app/shared/store/meta-data.state';

@Component({
selector: 'app-create-photo-form',
Expand All @@ -12,20 +18,47 @@ export class CreatePhotoFormComponent implements OnInit {

readonly constants: typeof Constants = Constants;


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

PhotoFormGroup: FormGroup;

@Input() provider: Provider;
@Input() editMode: boolean;

@Output() passPhotoFormGroup = new EventEmitter();

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

ngOnInit(): void {
this.store.dispatch(new GetInstitutionStatus());
if (this.provider?.institutionStatusId === null) {
this.provider.institutionStatusId = 0
}
this.provider && this.PhotoFormGroup.patchValue(this.provider, { emitEvent: false });
this.passPhotoFormGroup.emit(this.PhotoFormGroup);

this.institutionStatuses$
.pipe(
takeUntil(this.destroy$),
).subscribe(() => {
if (this.editMode) {
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);
this.destroy$.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ <h5>Будинок</h5>
<mat-tab label="Опис">
<h5>Опис</h5>
<p class="description">{{provider.description}}</p>
<h5>Статус</h5>
<p class="description">{{this.currentStatus}}</p>

</mat-tab>

</mat-tab-group>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { MatTabChangeEvent } from '@angular/material/tabs';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Actions, ofAction, ofActionSuccessful, Select, Store } from '@ngxs/store';
import { Observable, Subject } from 'rxjs';
import { distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
import { createProviderSteps, OwnershipType, OwnershipTypeUkr, ProviderType, ProviderTypeUkr } 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 { ActivateEditMode } from 'src/app/shared/store/app.actions';
import { ActivateEditMode, ShowMessageBar } from 'src/app/shared/store/app.actions';
import { GetInstitutionStatus } from 'src/app/shared/store/meta-data.actions';
import { MetaDataState } from 'src/app/shared/store/meta-data.state';
import { GetProfile } from 'src/app/shared/store/registration.actions';
import { RegistrationState } from 'src/app/shared/store/registration.state';
import { OnUpdateProviderSuccess } from 'src/app/shared/store/user.actions';

@Component({
selector: 'app-provider-org-info',
Expand All @@ -22,11 +28,30 @@ export class ProviderOrgInfoComponent implements OnInit {

editLink: string = createProviderSteps[0];

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

currentStatus: string;
constructor(private store: Store) { }

ngOnInit(): void { }
ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}

ngOnInit(): void {
this.store.dispatch(new GetInstitutionStatus());
this.institutionStatuses$.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() ?? 'Відсутній'
});
}

ActivateEditMode(): void {
this.store.dispatch(new ActivateEditMode(true));
Expand Down