-
Notifications
You must be signed in to change notification settings - Fork 1
/
structure-details.component.ts
290 lines (272 loc) · 10.2 KB
/
structure-details.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { animate, AUTO_STYLE, state, style, transition, trigger } from '@angular/animations';
import { Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core';
import { Location } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash';
import { Equipment } from '../../../map/models/enum/equipment.enum';
import { Structure } from '../../../map/models/structure.model';
import { Category } from '../../models/category.model';
import { AccessModality } from '../../models/enum/access-modality.enum';
import { PublicCategorie } from '../../models/enum/public.enum';
import { Module } from '../../models/module.model';
import { SearchRepository, SEARCH_TOKEN } from '../../repositories/search.repository';
import { StructureRepository, STRUCTURE_TOKEN } from '../../repositories/structure.repository';
import { PrintService } from '../../services/print.service';
@Component({
selector: 'app-structure-details',
templateUrl: './structure-details.component.html',
styleUrls: ['./structure-details.component.scss'],
animations: [
trigger('slideInOut', [
transition(':enter', [style({ left: '-600px' }), animate('200ms ease-in', style({ left: '0' }))]),
transition(':leave', [animate('200ms ease-in', style({ left: '-600px' }))])
]),
trigger('fadeInOut', [
transition(':enter', [
style({ backgroundColor: 'rgb(00, 00, 00, 0)' }),
animate('200ms ease-in', style({ backgroundColor: 'rgb(00, 00, 00, 0.6)' }))
]),
transition(':leave', [animate('200ms ease-in', style({ backgroundColor: 'rgb(00, 00, 00, 0)' }))])
]),
trigger('show', [
state('true', style({ height: AUTO_STYLE, visibility: AUTO_STYLE, margin: '8px 0' })),
state('false', style({ height: '0px', visibility: 'hidden', margin: '0' })),
transition('true => false', animate('300ms ease-out')),
transition('false => true', animate('300ms ease-out'))
])
],
providers: [PrintService]
})
export class StructureDetailsComponent implements OnInit {
@Input() public structure: Structure;
@Output() public closeDetails: EventEmitter<boolean> = new EventEmitter<boolean>();
public accessModality = AccessModality;
public baseSkillssReferentiel: Category;
public accessRightsReferentiel: Category;
public digitalCultureSecuritysReferentiel: Category;
public socialAndProfessionalsReferentiel: Category;
public parentingHelpsReferentiel: Category;
public baseSkills: Module[];
public accessRights: Module[];
public parentingHelp: Module[];
public socialAndProfessional: Module[];
public digitalCultureSecurity: Module[];
public showBaseSkills = false;
public showAccessRights = false;
public showParentingHelp = false;
public showSocialAndProfessional = false;
public showDigitalSecurity = false;
public printMode = false;
public isLoading = true;
public lockdownInfoDisplay = false;
public structureErrorModalOpenned = false;
public fullScreen = false;
constructor(
@Inject(SEARCH_TOKEN) readonly searchService: SearchRepository,
@Inject(STRUCTURE_TOKEN) readonly structureService: StructureRepository,
private readonly printService: PrintService,
private route: ActivatedRoute,
private router: Router,
private location: Location
) {
route.url.subscribe((url) => {
if (url[0]?.path === 'structure') {
this.structure = new Structure(this.printService.structure);
this.printMode = true;
// Display formations for printing
this.toggleAccessRights();
this.toggleBaseSkills();
this.toggleDigitalSecurity();
this.toggleParentingHelp();
this.toggleSocialAndProfessional();
this.initForm();
}
});
}
ngOnInit(): void {
this.isLoading = true;
this.route.queryParams.subscribe((queryParams) => {
if (queryParams.id) {
this.initForm();
} else if (!this.printMode) {
this.structure = null;
}
});
this.route.data.subscribe((data) => {
if (data.fullScreen) {
this.fullScreen = true;
}
});
}
private async initForm(): Promise<void> {
this.searchService.getCategoriesTraining().subscribe((referentiels) => {
referentiels.forEach((referentiel) => {
if (referentiel.isBaseSkills()) {
this.baseSkillssReferentiel = referentiel;
} else if (referentiel.isRigthtsAccess()) {
this.accessRightsReferentiel = referentiel;
} else if (referentiel.isDigitalCultureSecurity()) {
this.digitalCultureSecuritysReferentiel = referentiel;
} else if (referentiel.isParentingHelp()) {
this.parentingHelpsReferentiel = referentiel;
} else if (referentiel.isSocialAndProfessional()) {
this.socialAndProfessionalsReferentiel = referentiel;
}
});
this.setServiceCategories();
if (this.printMode) {
this.printService.onDataReady();
}
this.isLoading = false;
});
const index = this.structure.proceduresAccompaniment.indexOf('autres');
if (index > -1) {
this.structure.proceduresAccompaniment.splice(index, 1);
}
}
public getEquipmentsLabel(equipment: Equipment): string {
switch (equipment) {
case Equipment.wifi:
return 'Wifi en accès libre';
case Equipment.bornes:
return this.structure.nbNumericTerminal > 1 ? 'Bornes numériques' : 'Borne numérique';
case Equipment.printer:
return this.structure.nbPrinters > 1 ? 'Imprimantes' : 'Imprimante';
case Equipment.tablet:
return this.structure.nbTablets > 1 ? 'Tablettes' : 'Tablette';
case Equipment.computer:
return this.structure.nbComputers > 1 ? 'Ordinateurs' : 'Ordinateur';
case Equipment.scanner:
return this.structure.nbScanners > 1 ? 'Scanners' : 'Scanner';
default:
return null;
}
}
public close(): void {
this.route.url.subscribe((urls) => {
if (urls.length > 0 && urls[0].path !== 'orientation') {
this.router.navigate(['/acteurs'], {
relativeTo: this.route,
queryParams: {
id: null
},
queryParamsHandling: 'merge'
});
} else {
this.isLoading = true;
this.location.back();
}
});
}
public print(): void {
this.printService.printDocument('structure', this.structure);
}
public getAccessLabel(accessModality: AccessModality): string {
switch (accessModality) {
case AccessModality.free:
return 'Accès libre';
case AccessModality.meeting:
return 'Sur rendez-vous';
case AccessModality.meetingOnly:
return 'Uniquement sur RDV';
case AccessModality.numeric:
return 'Téléphone / Visio';
default:
return null;
}
}
public getPublicLabel(tagetPublic: PublicCategorie): string {
switch (tagetPublic) {
case PublicCategorie.young:
return 'Jeunes (16 - 25 ans)';
case PublicCategorie.adult:
return 'Adultes';
case PublicCategorie.elderly:
return 'Séniors (+ de 65 ans)';
case PublicCategorie.all:
return 'Tout public';
case PublicCategorie.under16Years:
return 'Moins de 16 ans';
case PublicCategorie.women:
return 'Uniquement femmes';
default:
return null;
}
}
public setServiceCategories(): void {
this.baseSkills = this.structure.baseSkills.map((skill) => _.find(this.baseSkillssReferentiel.modules, { id: skill }));
this.accessRights = this.structure.accessRight.map((rights) =>
_.find(this.accessRightsReferentiel.modules, { id: rights })
);
this.parentingHelp = this.structure.parentingHelp.map((help) =>
_.find(this.parentingHelpsReferentiel.modules, { id: help })
);
this.socialAndProfessional = this.structure.socialAndProfessional.map((skill) =>
_.find(this.socialAndProfessionalsReferentiel.modules, { id: skill })
);
this.digitalCultureSecurity = this.structure.digitalCultureSecurity.map((skill) =>
_.find(this.digitalCultureSecuritysReferentiel.modules, { id: skill })
);
}
public keepOriginalOrder = (a, b) => a.key;
public isBaseSkills(): boolean {
return this.baseSkills && this.baseSkills[0] !== undefined;
}
public isAccessRights(): boolean {
return this.accessRights && this.accessRights[0] !== undefined;
}
public isParentingHelp(): boolean {
return this.parentingHelp && this.parentingHelp[0] !== undefined;
}
public isSocialAndProfessional(): boolean {
return this.socialAndProfessional && this.socialAndProfessional[0] !== undefined;
}
public isDigitalSecurity(): boolean {
return this.digitalCultureSecurity && this.digitalCultureSecurity[0] !== undefined;
}
public filterOnlyEquipments(equipmentsAndServices: string[]): string[] {
return equipmentsAndServices.filter((eqpt) =>
['ordinateurs', 'tablettes', 'bornesNumeriques', 'imprimantes', 'scanners', 'wifiEnAccesLibre'].includes(eqpt)
);
}
public displayModalError(): void {
this.structureErrorModalOpenned = !this.structureErrorModalOpenned;
}
public sendErrorEmail(modalValue: any): void {
this.displayModalError();
if (modalValue.shouldSend) {
this.structureService.sendMailOnStructureError(this.structure._id, modalValue.content).subscribe(() => {});
}
}
public multipleWorkshop(): boolean {
if (
this.structure.baseSkills.length +
this.structure.accessRight.length +
this.structure.parentingHelp.length +
this.structure.socialAndProfessional.length +
this.structure.digitalCultureSecurity.length >
1
) {
return true;
}
return false;
}
public toggleBaseSkills(): void {
this.showBaseSkills = !this.showBaseSkills;
}
public toggleAccessRights(): void {
this.showAccessRights = !this.showAccessRights;
}
public toggleParentingHelp(): void {
this.showParentingHelp = !this.showParentingHelp;
}
public toggleSocialAndProfessional(): void {
this.showSocialAndProfessional = !this.showSocialAndProfessional;
}
public toggleDigitalSecurity(): void {
this.showDigitalSecurity = !this.showDigitalSecurity;
}
public goToWebsite(): void {
window.open(this.structure.website, '_blank');
}
}