Removed a lot of unused models, services and enums

This commit is contained in:
Erik Tiekstra
2021-10-06 12:51:12 +02:00
parent 4d3d73b54a
commit 19a3b05e5f
24 changed files with 63 additions and 375 deletions

View File

@@ -1,11 +1,11 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
forwardRef,
Input,
AfterViewInit,
Output,
Renderer2,
ViewChild,
@@ -13,7 +13,7 @@ import {
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { DropdownTriggerForDirective } from '@msfa-shared/components/dropdown/dropdown-trigger-for.directive';
import { MultiselectFilterOption } from '@msfa-shared/components/multiselect/multiselect-filter-option';
import { uuid } from '@msfa-utils/uuid';
import { uuid } from '@msfa-utils/uuid.util';
interface PropagateChangeFn {
(_: unknown): void;

View File

@@ -11,7 +11,7 @@ import {
ViewChild,
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { uuid } from '@msfa-utils/uuid';
import { uuid } from '@msfa-utils/uuid.util';
import { TreeNode, TreeNodeModel, TreeNodesSelectorService } from '../../services/tree-nodes-selector.service';
import { TreeNodesSelectorPanelComponent } from '../tree-nodes-selector-panel/tree-nodes-selector-panel.component';

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { uuid } from '@msfa-utils/uuid';
import { uuid } from '@msfa-utils/uuid.util';
export interface TreeNode {
label: string;

View File

@@ -1,4 +0,0 @@
export enum Alternative {
FRANVARO = 'franvaro',
AVVIKELSE = 'avvikelse'
}

View File

@@ -1,6 +0,0 @@
export enum Authorization {
UserManagement = 'UserManagement',
Economy = 'Economy',
Reports = 'Reports',
ParticipantManagement = 'ParticipantManagement',
}

View File

@@ -1,4 +0,0 @@
export enum ParticipantStatus {
ACTIVE = 'active',
FOLLOW_UP = 'follow-up',
}

View File

@@ -0,0 +1,4 @@
export enum ReportType {
FRANVARO = 'franvaro',
AVVIKELSE = 'avvikelse',
}

View File

@@ -1,5 +0,0 @@
export enum ServiceEnum {
KVL,
KROM,
STOM
}

View File

@@ -1,11 +0,0 @@
import { Tjanst } from './tjanst.model';
export interface FormTagData {
tjanstekod: string;
name: string;
}
export function mapTjanstToFormTag(tjanstData: Tjanst): FormTagData {
const { name, code } = tjanstData;
return { tjanstekod: code, name };
}

View File

@@ -1,71 +0,0 @@
import { ParticipantStatus } from '@msfa-enums/participant-status.enum';
import { ServiceEnum } from '@msfa-enums/service.enum';
import { PaginationMeta } from './pagination-meta.model';
export interface Participant {
id: string;
firstName: string;
lastName: string;
fullName: string;
ssn: string;
status: ParticipantStatus;
nextStep: string;
service: ServiceEnum;
errandNumber: number;
startDate: Date;
endDate: Date;
handleBefore: Date;
}
export interface ParticipantsApiResponse {
data: ParticipantApiResponseData[];
meta?: PaginationMeta;
}
export interface ParticipantApiResponse {
data: ParticipantApiResponseData;
}
export interface ParticipantApiResponseData {
id: string;
firstName: string;
lastName: string;
ssn: string;
status: ParticipantStatus;
nextStep: string;
service: ServiceEnum;
errandNumber: number;
startDate: Date;
endDate: Date;
handleBefore: Date;
}
export function mapParticipantApiResponseToParticipant(data: ParticipantApiResponseData): Participant {
const {
id,
firstName,
lastName,
ssn,
status,
nextStep,
service,
errandNumber,
startDate,
endDate,
handleBefore,
} = data;
return {
id,
firstName,
lastName,
fullName: `${firstName} ${lastName}`,
ssn,
status,
nextStep,
service,
errandNumber,
startDate,
endDate,
handleBefore,
};
}

View File

@@ -1,45 +0,0 @@
import { ServiceEnum } from '@msfa-enums/service.enum';
export interface Service {
id: string;
name: string;
tjanstekod: string;
tjanstId: number;
type: ServiceEnum;
}
export interface ServiceApiResponse {
data: ServiceApiResponseData[];
}
export interface ServiceApiResponseData {
id: string;
name: string;
tjanstekod: string;
tjanstId: number;
type: ServiceEnum;
}
export function mapServiceApiResponseToService(data: ServiceApiResponseData): Service {
const { id, name, tjanstekod, tjanstId } = data;
return {
id,
name,
tjanstekod,
tjanstId,
type: getServiceEnumType(name),
};
}
export function getServiceEnumType(name: string):ServiceEnum {
switch (name) {
case 'Kundval Rusta och matcha':
return ServiceEnum.KROM;
case 'Karriärvägledning':
return ServiceEnum.KVL;
case 'Stöd och Matchning':
return ServiceEnum.STOM;
default:
break;
}
}

View File

@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Alternative } from '@msfa-enums/alternative.enum';
import { ReportType } from '@msfa-enums/report-type.enum';
import { ErrorType } from '@msfa-enums/error-type.enum';
import { environment } from '@msfa-environment';
import { FragorForAvvikelserResponse } from '@msfa-models/api/fragor-for-avvikelser.response';
@@ -72,10 +72,10 @@ export class AvvikelseApiService {
let endpoint = '';
switch (alternative) {
case Alternative.AVVIKELSE:
case ReportType.AVVIKELSE:
endpoint = 'avvikelse';
break;
case Alternative.FRANVARO:
case ReportType.FRANVARO:
endpoint = 'franvaro';
break;
default:

View File

@@ -1,107 +0,0 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ParticipantStatus } from '@msfa-enums/participant-status.enum';
import { SortOrder } from '@msfa-enums/sort-order.enum';
import { environment } from '@msfa-environment';
import {
mapParticipantApiResponseToParticipant,
Participant,
ParticipantApiResponse,
ParticipantsApiResponse,
} from '@msfa-models/participant.model';
import { Sort } from '@msfa-models/sort.model';
import { sort } from '@msfa-utils/sort.util';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
function filterParticipants(participants: Participant[], searchFilter: string): Participant[] {
return participants.filter(participant => {
const searchValueExistsInName = participant.fullName.toLowerCase().includes(searchFilter.toLowerCase());
const searchValueExistsInErrandNumber = participant.errandNumber.toString().includes(searchFilter);
return searchValueExistsInName || searchValueExistsInErrandNumber;
});
}
@Injectable({
providedIn: 'root',
})
export class ParticipantsService {
private _apiBaseUrl = `${environment.api.url}/participants`;
private _allParticipants$: Observable<Participant[]> = this.httpClient
.get<ParticipantsApiResponse>(this._apiBaseUrl)
.pipe(map(response => response.data.map(participant => mapParticipantApiResponseToParticipant(participant))));
private _activeParticipantsSortBy$ = new BehaviorSubject<Sort<keyof Participant> | null>({
key: 'handleBefore',
order: SortOrder.ASC,
});
public activeParticipantsSortBy$: Observable<
Sort<keyof Participant>
> = this._activeParticipantsSortBy$.asObservable();
private _followUpParticipantsSortBy$ = new BehaviorSubject<Sort<keyof Participant> | null>({
key: 'handleBefore',
order: SortOrder.ASC,
});
public followUpParticipantsSortBy$: Observable<
Sort<keyof Participant>
> = this._followUpParticipantsSortBy$.asObservable();
private _searchFilter$ = new BehaviorSubject<string>('');
public searchFilter$: Observable<string> = this._searchFilter$.asObservable();
public filteredParticipants$: Observable<Participant[]> = combineLatest([
this._allParticipants$,
this._searchFilter$,
]).pipe(map(([participants, searchFilter]) => filterParticipants(participants, searchFilter)));
public activeParticipants$: Observable<Participant[]> = combineLatest([
this.filteredParticipants$,
this._activeParticipantsSortBy$,
]).pipe(
map(([participants, sortBy]) => {
const activeParticipants = participants.filter(participant => participant.status === ParticipantStatus.ACTIVE);
return sortBy ? sort(activeParticipants, sortBy) : activeParticipants;
})
);
public followUpParticipants$: Observable<Participant[]> = combineLatest([
this.filteredParticipants$,
this._followUpParticipantsSortBy$,
]).pipe(
map(([participants, sortBy]) => {
const followUpParticipants = participants.filter(
participant => participant.status === ParticipantStatus.FOLLOW_UP
);
return sortBy ? sort(followUpParticipants, sortBy) : followUpParticipants;
})
);
public fetchDetailedParticipantData$(id: string): Observable<Participant> {
return this.httpClient
.get<ParticipantApiResponse>(`${this._apiBaseUrl}/${id}`)
.pipe(map(result => mapParticipantApiResponseToParticipant(result.data)));
}
public setSearchFilter(value: string): void {
this._searchFilter$.next(value);
}
public setActiveParticipantsSortKey(key: keyof Participant): void {
const currentSortBy = this._activeParticipantsSortBy$.getValue();
let order = currentSortBy.order;
if (currentSortBy?.key === key) {
order = order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
}
this._activeParticipantsSortBy$.next({ key, order });
}
public setFollowUpParticipantsSortKey(key: keyof Participant): void {
const currentSortBy = this._followUpParticipantsSortBy$.getValue();
let order = currentSortBy.order;
if (currentSortBy?.key === key) {
order = order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
}
this._followUpParticipantsSortBy$.next({ key, order });
}
constructor(private httpClient: HttpClient) {}
}

View File

@@ -1,18 +0,0 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '@msfa-environment';
import { mapServiceApiResponseToService, Service, ServiceApiResponse } from '@msfa-models/service.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class ServiceService {
private _apiBaseUrl = `${environment.api.url}/services`;
public services$: Observable<Service[]> = this.httpClient
.get<ServiceApiResponse>(this._apiBaseUrl)
.pipe(map(response => response.data.map(service => mapServiceApiResponseToService(service))));
constructor(private httpClient: HttpClient) {}
}

View File

@@ -1,12 +1,12 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { Alternative } from '@msfa-enums/alternative.enum';
import { ReportType } from '@msfa-enums/report-type.enum';
import { DayOrPartOfDay } from '@msfa-enums/day-or-part-of-day.enum';
import { FranvaroOrsaksKodEnum } from '@msfa-enums/franvaro-orsak-kod.enum';
import { KandaOrsakerEnum } from '@msfa-enums/kanda-orsaker-kod.enum';
import { ValidationError } from '@msfa-models/validation-error.model';
export interface Controls {
[key: string]: AbstractControl
[key: string]: AbstractControl;
}
export function requiredDescriptionValidator(): ValidatorFn {
@@ -19,12 +19,12 @@ export function requiredDescriptionValidator(): ValidatorFn {
const isRequired = !valueOfFormControl && +valueOfNestedFormControl === KandaOrsakerEnum.AnnanOrsak;
if (isRequired) {
return { type: 'required', message: 'Beskrivning är obligatoriskt' }
return { type: 'required', message: 'Beskrivning är obligatoriskt' };
}
return null;
}
}
};
}
export function requiredOrsakerValidator(): ValidatorFn {
@@ -41,7 +41,7 @@ export function requiredOrsakerValidator(): ValidatorFn {
return null;
}
}
};
}
export function requiredAnnanKandOrsakValidator(): ValidatorFn {
@@ -59,7 +59,7 @@ export function requiredAnnanKandOrsakValidator(): ValidatorFn {
return null;
}
}
};
}
export class RequiredDateValidator {
@@ -69,7 +69,7 @@ export class RequiredDateValidator {
const isRequired = !valueOfFormControl;
return isRequired ? { dateIsRequired: 'Datum är obligatoriskt' } : null;
}
};
}
}
@@ -78,7 +78,7 @@ export function requiredDayOrPartOfDayValidator(): ValidatorFn {
const ctrls = control?.parent?.controls as Controls;
if (ctrls) {
const isFranvaro = ctrls['alternative'].value === Alternative.FRANVARO;
const isFranvaro = ctrls['alternative'].value === ReportType.FRANVARO;
const valueOfFormControl = control.value as string;
const isRequired = isFranvaro && !valueOfFormControl;
@@ -88,7 +88,7 @@ export function requiredDayOrPartOfDayValidator(): ValidatorFn {
return null;
}
}
};
}
export function requiredStartTimeValidator(): ValidatorFn {
@@ -96,7 +96,7 @@ export function requiredStartTimeValidator(): ValidatorFn {
const ctrls = control?.parent?.parent?.controls as Controls;
if (ctrls) {
const isFranvaro = ctrls['alternative']?.value as string === Alternative.FRANVARO;
const isFranvaro = (ctrls['alternative']?.value as string) === ReportType.FRANVARO;
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
const valueOfFormControl = control?.value as string;
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
@@ -107,7 +107,7 @@ export function requiredStartTimeValidator(): ValidatorFn {
return null;
}
}
};
}
export function requiredEndTimeValidator(): ValidatorFn {
@@ -115,7 +115,7 @@ export function requiredEndTimeValidator(): ValidatorFn {
const ctrls = control?.parent?.parent?.controls as Controls;
if (ctrls) {
const isFranvaro = ctrls['alternative']?.value as string === Alternative.FRANVARO;
const isFranvaro = (ctrls['alternative']?.value as string) === ReportType.FRANVARO;
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
const valueOfFormControl = control?.value as string;
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
@@ -126,7 +126,7 @@ export function requiredEndTimeValidator(): ValidatorFn {
return null;
}
}
};
}
export function requiredFraga1Validator(): ValidatorFn {
@@ -144,7 +144,7 @@ export function requiredFraga1Validator(): ValidatorFn {
return null;
}
}
};
}
export function requiredfraga2Validator(): ValidatorFn {
@@ -155,11 +155,12 @@ export function requiredfraga2Validator(): ValidatorFn {
const isAvvikelse = ctrls['alternative']?.value === 'avvikelse';
const valueOfFormControl = control.value as string;
const orsaksKodToValidate = ctrls['orsakerFormGroup']?.get('orsaker')?.value as string;
const isRequired = isAvvikelse && !valueOfFormControl &&
(orsaksKodToValidate !== '19' &&
orsaksKodToValidate !== '20' &&
orsaksKodToValidate !== '28'
)
const isRequired =
isAvvikelse &&
!valueOfFormControl &&
orsaksKodToValidate !== '19' &&
orsaksKodToValidate !== '20' &&
orsaksKodToValidate !== '28';
if (isRequired) {
return { type: 'required', message: `Beskrivning är obligatoriskt` };
@@ -167,5 +168,5 @@ export function requiredfraga2Validator(): ValidatorFn {
return null;
}
}
};
}