Skip to content

Commit

Permalink
Merge branch 'develop', remote-tracking branch 'origin' into dir
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinets committed Aug 7, 2022
3 parents e19aec5 + 61b6afd + d0fc8c3 commit e84d0fb
Show file tree
Hide file tree
Showing 26 changed files with 745 additions and 313 deletions.
3 changes: 2 additions & 1 deletion src/app/shared/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class Constants {
static readonly THERE_IS_SUCH_DATA = ': There is already a provider with such a data';

static readonly NO_CITY = 'Такого міста немає';
static readonly NO_SETTLEMENT = 'Такого населенного пункту немає';
static readonly KIEV: City = {
district: 'м.Київ',
id: 14446,
Expand Down Expand Up @@ -120,4 +121,4 @@ export class CropperConfigurationConstants {
static readonly croppedCoverImage = {
height: 250
};
}
}
15 changes: 15 additions & 0 deletions src/app/shared/enum/codeficator-categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum CodeficatorCategories {
Region = 'O', // Автономна Республіка Крим, області.
SpecialStatusCity = 'K', // Міста, що мають спеціальний статус.
Level1 = 'OK', // Автономна Республіка Крим, області та міста, що мають спеціальний статус.
District = 'P', // Райони в областях та Автономній Республіці Крим.
TerritorialCommunity = 'H', // Території територіальних громад (назви територіальних громад) в областях, територіальні громади Автономної Республіки Крим.
City = 'M', // Міста.
UrbanSettlement = 'T', // Селища міського типу.
Village = 'C', // Села.
Settlement = 'X', // Селища.
Level4 = 'MTCX', // Міста, селища міського типу, села та селища
CityDistrict = 'B', // Райони в містах.
Level2 = 'PB', // Райони в областях та Автономній Республіці Крим та райони в містах.
SearchableCategories = 'MTCXK', // Міста, що мають спеціальний статус, міста, селища міського типу, села та селища
}
7 changes: 7 additions & 0 deletions src/app/shared/models/address.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Codeficator } from './codeficator.model';

export class Address {
id?: number;
city: string;
Expand All @@ -7,6 +9,9 @@ export class Address {
district?: string;
latitude?: number;
longitude?: number;
// Codeficator
codeficatorId?: number;
codeficatorAddressDto?: Codeficator;

constructor(info, address?: Address) {
this.city = info.city;
Expand All @@ -17,6 +22,8 @@ export class Address {
this.buildingNumber = info.buildingNumber;
this.longitude = info.longitude;
this.latitude = info.latitude;
this.codeficatorId = info.codeficatorId ?? address.codeficatorId;
this.codeficatorAddressDto = info.codeficatorAddressDto ?? address.codeficatorAddressDto;
if (address) {
this.id = address.id;
}
Expand Down
22 changes: 22 additions & 0 deletions src/app/shared/models/codeficator.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CodeficatorCategories } from '../enum/codeficator-categories';

export interface Codeficator {
id: number;
category: CodeficatorCategories;
region: string;
district: string;
territorialCommunity: string;
settlement: string;
cityDistrict: string;
latitude: number;
longitude: number;
fullName: string;
fullAddress?: string;
}

export interface CodeficatorCityDistrict {
id: number;
parentId: number;
category: string;
name: string;
}
13 changes: 13 additions & 0 deletions src/app/shared/services/applications/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,17 @@ export class ApplicationService {
},
});
}

/**
* This method Check if exists an any rewiewed application in workshop for parent.
* @param id string
*/
getReviewedApplications(parentId: string, workshopId: string): Observable<boolean> {
return this.http.get<boolean>(`/api/v1/Rating/IsReviewed`, {
params: {
parentId,
workshopId
},
});
}
}
20 changes: 20 additions & 0 deletions src/app/shared/services/codeficator/codeficator.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { CodeficatorService } from './codeficator.service';

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

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

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

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

constructor(private http: HttpClient) {
}

/**
* This method to get all Codeficators from the database
* @param settlement string
*/
searchCodeficator(settlement: string): Observable<Codeficator[]> {
return this.http.get<Codeficator[]>(`/api/v1/Codeficator/search?Name=${settlement}`);
}

/**
* This method to get Codeficator by id
* @param id number
*/
getCodeficatorById(id: number): Observable<Codeficator> {
return this.http.get<Codeficator>(`/api/v1/Codeficator/${id}/parents`);
}

/**
* This method to get all Codeficator City Districts from the database
* @param id number
*/
searchCodeficatorCityDistrict(id: number): Observable<CodeficatorCityDistrict[]> {
return this.http.get<CodeficatorCityDistrict[]>(`/api/v1/Codeficator/children?id=${id}`);
}
}
4 changes: 4 additions & 0 deletions src/app/shared/store/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class GetStatusAllowedToReview {
static readonly type = '[user] get parent status By parent id';
constructor(public parentId: string, public workshopId: string) { }
}
export class GetReviewedApplications {
static readonly type = '[user] get reviewed applications By parent id';
constructor(public parentId: string, public workshopId: string) { }
}
export class GetApplicationsByProviderId {
static readonly type = '[user] get Applications By Provider Id';
constructor(public id: string, public parameters: ApplicationParameters) { }
Expand Down
29 changes: 26 additions & 3 deletions src/app/shared/store/user.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
GetStatusAllowedToReview,
GetProviderAdminWorkshops,
GetChildrenByWorkshopId,
GetReviewedApplications,
} from './user.actions';
import { ApplicationStatus } from '../enum/applications';
import { messageStatus } from '../enum/messageBar';
Expand Down Expand Up @@ -130,6 +131,7 @@ export interface UserStateModel {
blockedParent: BlockedParent;
isAllowChildToApply: boolean;
isAllowedToReview: boolean;
isReviewed: boolean;
approvedChildren: ChildCards;
}
@State<UserStateModel>({
Expand All @@ -150,7 +152,8 @@ export interface UserStateModel {
providerAdmins: null,
blockedParent: null,
isAllowChildToApply: true,
isAllowedToReview: false
isAllowedToReview: false,
isReviewed: false,
},
})
@Injectable()
Expand Down Expand Up @@ -225,6 +228,11 @@ export class UserState {
return state.isAllowedToReview;
}

@Selector()
static isReviewed(state: UserStateModel): boolean {
return state.isReviewed;
}

@Selector()
static blockedParent(state: UserStateModel): BlockedParent { return state.blockedParent; }

Expand Down Expand Up @@ -286,8 +294,8 @@ export class UserState {
patchState({ isLoading: true });
return this.achievementsService.getChildrenByWorkshopId(payload).pipe(
tap((approvedChildren: ChildCards) => {
return patchState(approvedChildren
? { approvedChildren: approvedChildren, isLoading: false }
return patchState(approvedChildren
? { approvedChildren: approvedChildren, isLoading: false }
: { approvedChildren: {totalAmount: 0, entities: []}, isLoading: false });
})
);
Expand Down Expand Up @@ -917,6 +925,21 @@ export class UserState {
);
}

@Action(GetReviewedApplications)
getReviewedApplications(
{ patchState }: StateContext<UserStateModel>,
{ parentId, workshopId }: GetReviewedApplications
): Observable<boolean> {
patchState({ isLoading: true });
return this.applicationService
.getReviewedApplications(parentId, workshopId)
.pipe(
tap((status: boolean) => {
return patchState({ isReviewed: status, isLoading: false });
})
);
}

@Action(CreateRating)
createRating({ dispatch }: StateContext<UserStateModel>, { payload }: CreateRating): Observable<object> {
return this.ratingService.createRate(payload).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h4>{{portalItem.sectionName}}</h4>
</div>
</div>
</ng-container>

<ng-template #noInfoTmpl>
<div class="config" fxLayout="column" fxLayoutAlign="center center">
<a routerLink="edit" class="config_edit-icon" [routerLink]="['./update', type, '']">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AdminState } from 'src/app/shared/store/admin.state';
import { AdminTabsTitle } from 'src/app/shared/enum/enumUA/tech-admin/admin-tabs';
import { Select } from '@ngxs/store';
import { Component } from '@angular/core';
import { CompanyInformation } from 'src/app/shared/models/сompanyInformation.model';
import { AdminState } from 'src/app/shared/store/admin.state';
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { Select } from '@ngxs/store';

@Component({
selector: 'app-regulations-info',
template: '<app-info-card [type]="lawsAndRegulations" [platformInfo]="LawsAndRegulations$ | async"></app-info-card>',
Expand All @@ -13,6 +14,8 @@ export class RegulationsInfoComponent {

@Select(AdminState.LawsAndRegulations)
LawsAndRegulations$: Observable<CompanyInformation>;
@Select(AdminState.isLoading)
isLoading$: Observable<boolean>;

constructor() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<mat-icon class="star-icon">star</mat-icon> {{workshop.rating}} <p class="rate-amount">
({{ ((rating$|async)?.length ? (rating$|async)?.length : 0) | declination : ReviewDeclination }})</p>
</div>
<div [matTooltip]="!isApproved ? 'Ви повинні бути прийнятим до даного гуртка' : 'Ви вже оцінили цей гурток'"
[matTooltipDisabled]="!(this.isRated || !isAllowedToReview)">
<div [matTooltip]="!isReviewed ? 'Ви повинні бути прийнятим до даного гуртка' : 'Ви вже оцінили цей гурток'"
[matTooltipDisabled]="!(isReviewed || !isAllowedToReview)">
<button mat-raised-button class="button" (click)="onRate()" *ngIf="role !== Role.provider"
[disabled]="this.isRated || !isAllowedToReview">
[disabled]="isReviewed || !isAllowedToReview">
<mat-icon class="button-icon">edit</mat-icon> ЗАЛИШИТИ ОЦІНКУ
</button>
</div>
Expand All @@ -22,7 +22,7 @@
</p>
</div>
</ng-container>

<ng-template #isEmptyList>
<app-no-result-card [title]="noResultReviews"></app-no-result-card>
</ng-template>
Expand Down
30 changes: 16 additions & 14 deletions src/app/shell/details/details-tabs/reviews/reviews.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Workshop } from 'src/app/shared/models/workshop.model';
import { ClearRatings, GetRateByEntityId } from 'src/app/shared/store/meta-data.actions';
import { MetaDataState } from 'src/app/shared/store/meta-data.state';
import { RegistrationState } from 'src/app/shared/store/registration.state';
import { CreateRating, GetStatusAllowedToReview, OnCreateRatingSuccess } from 'src/app/shared/store/user.actions';
import { CreateRating, GetReviewedApplications, GetStatusAllowedToReview, OnCreateRatingSuccess } from 'src/app/shared/store/user.actions';
import { UserState } from 'src/app/shared/store/user.state';

@Component({
Expand All @@ -33,8 +33,10 @@ export class ReviewsComponent implements OnInit, OnDestroy {

@Select(RegistrationState.parent)
parent$: Observable<Parent>;
@Select(UserState.isAllowedToReview)
@Select(UserState.isAllowedToReview)
isAllowedToReview$: Observable<boolean>;
@Select(UserState.isReviewed)
isReviewed$: Observable<boolean>;

@Select(MetaDataState.rating)
rating$: Observable<Rate[]>;
Expand All @@ -43,8 +45,7 @@ export class ReviewsComponent implements OnInit, OnDestroy {

parent: Parent;
isAllowedToReview: boolean;
isRated = false;
isApproved = false;
isReviewed: boolean;

constructor(
private store: Store,
Expand All @@ -55,26 +56,32 @@ export class ReviewsComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.getParentData();
this.getWorkshopRatingList();
this.checkIfAllowedToReview(this.parent.id)


this.actions$.pipe(ofActionCompleted(OnCreateRatingSuccess))
.pipe(
takeUntil(this.destroy$),
distinctUntilChanged())
.subscribe(() => this.store.dispatch(new GetRateByEntityId('workshop', this.workshop.id)));
.subscribe(() => this.store.dispatch([new GetRateByEntityId('workshop', this.workshop.id), new GetReviewedApplications(this.parent.id, this.workshop.id)]));

this.isAllowedToReview$
.pipe(takeUntil(this.destroy$))
.subscribe((status: boolean) => (this.isAllowedToReview = status));

this.isReviewed$.pipe(
takeUntil(this.destroy$)
).subscribe((status: boolean) => (this.isReviewed = status));
}

private getParentData(): void {
this.parent$.pipe(
filter((parent: Parent) => parent !== undefined),
filter((parent: Parent) => !!parent),
takeUntil(this.destroy$)
).subscribe((parent: Parent) => {
this.parent = parent;
//this.store.dispatch(new GetApplicationsByParentId(parent.id)); // TODO: check if parent has applciation
this.store.dispatch([
new GetStatusAllowedToReview(this.parent.id, this.workshop.id),
new GetReviewedApplications(this.parent.id, this.workshop.id)
]);
});
}

Expand All @@ -85,14 +92,9 @@ export class ReviewsComponent implements OnInit, OnDestroy {
takeUntil(this.destroy$),
).subscribe((rating: Rate[]) => {
this.rating = rating;
this.isRated = rating?.some((rate: Rate) => rate.parentId === this.parent?.id);
});
}

private checkIfAllowedToReview(id: string): void {
this.store.dispatch(new GetStatusAllowedToReview(this.parent.id, this.workshop.id));
}

onRate(): void {
const dialogRef = this.matDialog.open(ConfirmationModalWindowComponent, {
width: Constants.MODAL_SMALL,
Expand Down
Loading

0 comments on commit e84d0fb

Please sign in to comment.