Skip to content

Commit

Permalink
Issue#2013 managed workshops lists (#2035)
Browse files Browse the repository at this point in the history
* Updated service: added a method to get a list of workshops for the admin provider
*  Added a new action and its processing
* Added a condition for choosing how to receive workshops depending on the user's role
* Now the role of the providerDeputy will receive the list of workshops and applications in the same way as the role of the provider
* Added the ability to mark select elements from the parent component. This is done by adding the ability to pass the FormControl via Input and manipulate the value via the parent component.
* Updated the data model of the providerAdmin for the changed model from the server
* Fixed a bug when sending null to OnUpdateProviderAdminSuccess, where they tried to access its properties. This happened because we expected the request to return the providerAdmin, however it does not return anything
* Added logic that is responsible for marking all workshops that are assigned to the providerAdmin
* Defined the type of variables that were declared without specifying a type
* Variable and method access modifiers defined
* Removed one unnecessary variable because it holds a duplicate value
  • Loading branch information
koliaBp authored Mar 16, 2023
1 parent 1d5d39b commit 8e5f0d7
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 258 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<mat-form-field class="dropdown-wrapper">
<mat-label class="label" [ngClass]="{ 'disabled-field': entities?.length < 1 }">{{ getLabelTitle(entities?.length) | translate}}</mat-label>
<mat-label class="label" [ngClass]="{ 'disabled-field': entities?.length < 1 }">{{
getLabelTitle(entities?.length) | translate
}}</mat-label>
<mat-select
[disabled]="entities?.length < 1"
[formControl]="entityControl"
Expand All @@ -10,7 +12,9 @@
>
<mat-select-trigger>
<div *ngIf="entityControl.value?.length">
<span *ngIf="entityControl.value?.length > 1"> {{ entityControl.value?.length | translateCases: Declination }} {{'SELECTED' | translate}} </span>
<span *ngIf="entityControl.value?.length > 1">
{{ entityControl.value?.length | translateCases: declination }} {{ 'SELECTED' | translate }}
</span>
<span *ngIf="entityControl.value?.length === 1"> {{ entityControl.value[0].title }} </span>
</div>
</mat-select-trigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { debounceTime, distinctUntilChanged, Subject, takeUntil } from 'rxjs';

import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Subject } from 'rxjs';
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators';

import { ChildDeclination, WorkshopDeclination } from '../../enum/enumUA/declinations/declination';
import { TruncatedItem } from '../../models/item.model';
import { TranslateCasesPipe } from '../../pipes/translate-cases.pipe';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'app-entity-checkbox-dropdown',
templateUrl: './entity-checkbox-dropdown.component.html',
styleUrls: ['./entity-checkbox-dropdown.component.scss'],
providers: [TranslateCasesPipe],
providers: [TranslateCasesPipe]
})
export class EntityCheckboxDropdownComponent implements OnInit, OnDestroy {
entityControl = new FormControl();
ids: string[];
destroy$: Subject<boolean> = new Subject<boolean>();
@Input() public entities: TruncatedItem[];
@Input() public declination: WorkshopDeclination | ChildDeclination;
@Input() public labelByDefault: string;
@Input() public entityControl: FormControl = new FormControl();
@Output() public entityCheck = new EventEmitter<string[]>();

@Input() entities: TruncatedItem[];
@Input() declination;
@Input() labelByDefault;
@Output() entityCheck = new EventEmitter<string[]>();
Declination;
private ids: string[];
private destroy$: Subject<boolean> = new Subject<boolean>();

constructor(private translateCases: TranslateCasesPipe) {}

ngOnInit(): void {
public ngOnInit(): void {
this.entityControl.valueChanges
.pipe(debounceTime(500), distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe(entities => {
this.ids = entities.map(entity => entity.id);
.subscribe((entities: TruncatedItem[]) => {
this.ids = entities.map((entity) => entity.id);
this.entityCheck.emit(this.ids);
});
this.Declination = this.declination;
}

getLabelTitle(quantity: number): string {
let allChildrenDeclination;
let allApplicationsDeclination;

if (this.Declination) {
allChildrenDeclination =
this.Declination[0] === 'ENUM.CHILD_DECLINATION.CHILD' ? 'ALL_CHILDREN' : '';
allApplicationsDeclination =
this.Declination[0] === 'ENUM.WORKSHOP_DECLINATION.WORKSHOP'
? 'ALL_WORKSHOPS'
: '';
public getLabelTitle(quantity: number): string {
let allChildrenDeclination: string;
let allApplicationsDeclination: string;

if (this.declination) {
allChildrenDeclination = this.declination[0] === 'ENUM.CHILD_DECLINATION.CHILD' ? 'ALL_CHILDREN' : '';
allApplicationsDeclination = this.declination[0] === 'ENUM.WORKSHOP_DECLINATION.WORKSHOP' ? 'ALL_WORKSHOPS' : '';
}

const allEntities = allChildrenDeclination || allApplicationsDeclination;
const selectedEntities = this.translateCases.transform(quantity, this.Declination);
const selectedEntities = this.translateCases.transform(quantity, this.declination);
return quantity < 1 ? selectedEntities : this.labelByDefault || allEntities;
}

ngOnDestroy(): void {
public ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/models/providerAdmin.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TruncatedItem } from './item.model';
import { PaginationParameters } from './queryParameters.model';
import { Person } from './user.model';

Expand Down Expand Up @@ -29,6 +30,7 @@ export class ProviderAdmin implements Person {
accountStatus?: string;
returnUrl?: string;
providerId?: string;
workshopTitles?: TruncatedItem[];

constructor(info, isDebuty: boolean, userId?: string, workshopIds?: string[], providerId?: string, accountStatus?: string) {
this.email = info.email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { ProviderWorkshopCard, WorkshopCard, WorkshopCardParameters } from './../../../models/workshop.model';
import { Observable } from 'rxjs';

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Workshop, WorkshopStatus } from '../../../models/workshop.model';

import { ProviderParameters } from '../../../../shared/models/provider.model';
import { PaginationParameters } from '../../../../shared/models/queryParameters.model';
import { FeaturesList } from '../../../models/featuresList.model';
import { MetaDataState } from '../../../store/meta-data.state';
import { TruncatedItem } from '../../../models/item.model';
import { SearchResponse } from '../../../models/search.model';
import { PaginationElement } from '../../../models/paginationElement.model';
import { ProviderParameters } from '../../../../shared/models/provider.model';
import { PaginationParameters } from '../../../../shared/models/queryParameters.model';
import { SearchResponse } from '../../../models/search.model';
import {
ProviderWorkshopCard, Workshop, WorkshopCard, WorkshopCardParameters, WorkshopStatus
} from '../../../models/workshop.model';
import { MetaDataState } from '../../../store/meta-data.state';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -68,6 +71,10 @@ export class UserWorkshopService {
return this.http.get<TruncatedItem[]>(`/api/v1/Workshop/GetWorkshopListByProviderId/${id}`);
}

getWorkshopListByProviderAdminId(id: string): Observable<TruncatedItem[]> {
return this.http.get<TruncatedItem[]>(`/api/v1/Workshop/GetWorkshopListByProviderAdminId/${id}`);
}

/**
* This method create workshop
* @param workshop: Workshop
Expand Down
18 changes: 14 additions & 4 deletions src/app/shared/store/provider.actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ProviderWorkshopCard, Workshop, WorkshopCardParameters, WorkshopStatus } from './../models/workshop.model';
import { HttpErrorResponse } from '@angular/common/http';

import { ApplicationEntityType } from '../enum/applications';
import { Achievement, AchievementParameters } from '../models/achievement.model';
import { LicenseStatusData, Provider, ProviderParameters, ProviderStatusUpdateData } from '../models/provider.model';
import { ProviderAdmin, ProviderAdminParameters } from '../models/providerAdmin.model';
import { BlockedParent, ProviderAdminBlockData } from '../models/block.model';
import { ApplicationEntityType } from '../enum/applications';
import {
LicenseStatusData, Provider, ProviderParameters, ProviderStatusUpdateData
} from '../models/provider.model';
import { ProviderAdmin, ProviderAdminParameters } from '../models/providerAdmin.model';
import { PaginationParameters } from '../models/queryParameters.model';
import {
ProviderWorkshopCard, Workshop, WorkshopCardParameters, WorkshopStatus
} from '../models/workshop.model';

export class GetAchievementById {
static readonly type = '[provider] get achievement By Id';
Expand Down Expand Up @@ -87,6 +92,11 @@ export class GetWorkshopListByProviderId {
constructor(public payload: string) {}
}

export class GetWorkshopListByProviderAdminId {
static readonly type = '[user] get Workshop List By Provider Admin Id';
constructor(public id: string) {}
}

export class CreateWorkshop {
static readonly type = '[provider] create Workshop';
constructor(public payload: Workshop) {}
Expand Down
122 changes: 45 additions & 77 deletions src/app/shared/store/provider.state.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,53 @@
import { GetApplicationsByPropertyId } from './shared-user.actions';
import { Observable, of } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';

import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { State, Action, StateContext, Selector } from '@ngxs/store';
import { Observable, of } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { Action, Selector, State, StateContext } from '@ngxs/store';

import { Constants, EMPTY_RESULT } from '../constants/constants';
import { SnackbarText } from '../enum/enumUA/messageBer';
import { ProviderStatuses } from '../enum/statuses';
import { Achievement } from '../models/achievement.model';
import { BlockedParent } from '../models/block.model';
import { Child } from '../models/child.model';
import { TruncatedItem } from '../models/item.model';
import { LicenseStatusData, Provider, ProviderStatusUpdateData } from '../models/provider.model';
import { ProviderAdmin } from '../models/providerAdmin.model';
import { SearchResponse } from '../models/search.model';
import { ProviderWorkshopCard, Workshop, WorkshopStatus } from '../models/workshop.model';
import { AchievementsService } from '../services/achievements/achievements.service';
import { BlockService } from '../services/block/block.service';
import { ProviderAdminService } from '../services/provider-admins/provider-admin.service';
import { ProviderService } from '../services/provider/provider.service';
import { UserWorkshopService } from '../services/workshops/user-workshop/user-workshop.service';
import { Util } from '../utils/utils';
import { GetFilteredProviders } from './admin.actions';
import { MarkFormDirty, ShowMessageBar } from './app.actions';
import {
BlockParent,
BlockParentFail,
BlockParentSuccess,
BlockProviderAdminById,
CreateAchievement,
CreateProvider,
CreateProviderAdmin,
CreateWorkshop,
DeleteAchievementById,
DeleteProviderAdminById,
DeleteProviderById,
DeleteWorkshopById,
GetAchievementById,
GetAchievementsByWorkshopId,
GetFilteredProviderAdmins,
GetBlockedParents,
GetChildrenByWorkshopId,
GetProviderAdminWorkshops,
GetProviderViewWorkshops,
GetWorkshopListByProviderId,
OnBlockProviderAdminFail,
OnBlockProviderAdminSuccess,
OnClearBlockedParents,
OnCreateAchievementFail,
OnCreateAchievementSuccess,
OnCreateProviderAdminFail,
OnCreateProviderAdminSuccess,
OnCreateProviderFail,
OnCreateProviderSuccess,
OnCreateWorkshopFail,
OnCreateWorkshopSuccess,
OnDeleteAchievementFail,
OnDeleteAchievementSuccess,
OnDeleteProviderAdminFail,
OnDeleteProviderAdminSuccess,
OnDeleteProviderByIdFail,
OnDeleteProviderByIdSuccess,
OnDeleteWorkshopFail,
OnDeleteWorkshopSuccess,
OnUpdateAchievementFail,
OnUpdateAchievementSuccess,
OnUpdateProviderAdminFail,
OnUpdateProviderAdminSuccess,
OnUpdateProviderFail,
OnUpdateProviderStatusFail,
OnUpdateProviderStatusSuccess,
OnUpdateProviderSuccess,
OnUpdateWorkshopFail,
OnUpdateWorkshopStatusFail,
OnUpdateWorkshopStatusSuccess,
OnUpdateWorkshopSuccess,
ResetAchievements,
UnBlockParent,
UnBlockParentFail,
UnBlockParentSuccess,
UpdateAchievement,
UpdateProvider,
UpdateProviderAdmin,
UpdateProviderStatus,
UpdateWorkshop,
UpdateWorkshopStatus,
GetProviderAdminById,
UpdateProviderLicenseStatuse,
ReinviteProviderAdmin
BlockParent, BlockParentFail, BlockParentSuccess, BlockProviderAdminById, CreateAchievement,
CreateProvider, CreateProviderAdmin, CreateWorkshop, DeleteAchievementById,
DeleteProviderAdminById, DeleteProviderById, DeleteWorkshopById, GetAchievementById,
GetAchievementsByWorkshopId, GetBlockedParents, GetChildrenByWorkshopId,
GetFilteredProviderAdmins, GetProviderAdminById, GetProviderAdminWorkshops,
GetProviderViewWorkshops, GetWorkshopListByProviderAdminId, GetWorkshopListByProviderId,
OnBlockProviderAdminFail, OnBlockProviderAdminSuccess, OnClearBlockedParents,
OnCreateAchievementFail, OnCreateAchievementSuccess, OnCreateProviderAdminFail,
OnCreateProviderAdminSuccess, OnCreateProviderFail, OnCreateProviderSuccess, OnCreateWorkshopFail,
OnCreateWorkshopSuccess, OnDeleteAchievementFail, OnDeleteAchievementSuccess,
OnDeleteProviderAdminFail, OnDeleteProviderAdminSuccess, OnDeleteProviderByIdFail,
OnDeleteProviderByIdSuccess, OnDeleteWorkshopFail, OnDeleteWorkshopSuccess,
OnUpdateAchievementFail, OnUpdateAchievementSuccess, OnUpdateProviderAdminFail,
OnUpdateProviderAdminSuccess, OnUpdateProviderFail, OnUpdateProviderStatusFail,
OnUpdateProviderStatusSuccess, OnUpdateProviderSuccess, OnUpdateWorkshopFail,
OnUpdateWorkshopStatusFail, OnUpdateWorkshopStatusSuccess, OnUpdateWorkshopSuccess,
ReinviteProviderAdmin, ResetAchievements, UnBlockParent, UnBlockParentFail, UnBlockParentSuccess,
UpdateAchievement, UpdateProvider, UpdateProviderAdmin, UpdateProviderLicenseStatuse,
UpdateProviderStatus, UpdateWorkshop, UpdateWorkshopStatus
} from './provider.actions';
import { GetProfile, CheckAuth } from './registration.actions';
import { BlockedParent } from '../models/block.model';
import { BlockService } from '../services/block/block.service';
import { TruncatedItem } from '../models/item.model';
import { SearchResponse } from '../models/search.model';
import { GetFilteredProviders } from './admin.actions';
import { ProviderStatuses } from './../enum/statuses';
import { SnackbarText } from '../enum/enumUA/messageBer';
import { CheckAuth, GetProfile } from './registration.actions';
import { GetApplicationsByPropertyId } from './shared-user.actions';

export interface ProviderStateModel {
isLoading: boolean;
Expand Down Expand Up @@ -219,6 +176,17 @@ export class ProviderState {
.pipe(tap((truncatedItems: TruncatedItem[]) => patchState({ truncatedItems, isLoading: false })));
}

@Action(GetWorkshopListByProviderAdminId)
getWorkshopListByProviderAdminId(
{ patchState }: StateContext<ProviderStateModel>,
{ id }: GetWorkshopListByProviderAdminId
): Observable<TruncatedItem[]> {
patchState({ isLoading: true });
return this.userWorkshopService
.getWorkshopListByProviderAdminId(id)
.pipe(tap((truncatedItems: TruncatedItem[]) => patchState({ truncatedItems, isLoading: false })));
}

@Action(CreateAchievement)
createAchievement({ dispatch }: StateContext<ProviderStateModel>, { payload }: CreateAchievement): Observable<void | Achievement> {
return this.achievementsService.createAchievement(payload).pipe(
Expand Down Expand Up @@ -618,7 +586,7 @@ export class ProviderState {
{ providerId, providerAdmin }: UpdateProviderAdmin
): Observable<void | ProviderAdmin> {
return this.providerAdminService.updateProviderAdmin(providerId, providerAdmin).pipe(
tap((res: ProviderAdmin) => dispatch(new OnUpdateProviderAdminSuccess(res))),
tap(() => dispatch(new OnUpdateProviderAdminSuccess(providerAdmin))),
catchError((error: HttpErrorResponse) => dispatch(new OnUpdateProviderAdminFail(error)))
);
}
Expand Down
Loading

0 comments on commit 8e5f0d7

Please sign in to comment.