diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 7804991513a421522737bf4bd7d55fa91dc6c0a5..494f7d0199025917e57d0a4743c8a9021c873e89 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -38,8 +38,9 @@ </label> </div> </div> - <p>Description</p> + <p>Description*</p> <textarea rows="4" style="width: 100%" maxlength="500" formControlName="description"></textarea> + <app-validator-form [control]="getStructureControl('description')"></app-validator-form> <p> Afin de rendre visible l'offre de formation numérique proposée lors de ce nouveau confinement, merci d'indiquer ici, les activités que vous avez pu maintenir diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 442669834e68f943c128b6d26068ff780ecf9700..3e931bedada2803a234a7ab0b89ca453f05fdc6f 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -20,7 +20,7 @@ import { User } from '../models/user.model'; styleUrls: ['./form.component.scss'], }) export class FormComponent implements OnInit { - @Input() public idStructure?: number; + @Input() public idStructure?: string; @Input() public isEditMode: boolean; @Input() public profile?: User; @Output() closeEvent = new EventEmitter<Structure>(); @@ -39,7 +39,7 @@ export class FormComponent implements OnInit { public publicsAccompaniment: Category; public equipmentsAndServices: Category; public proceduresAccompaniment: Category; - public structureId: number; + public structureId: string; constructor( private structureService: StructureService, private searchService: SearchService, @@ -50,7 +50,7 @@ export class FormComponent implements OnInit { if (this.idStructure) { this.structureService.getStructure(this.idStructure).subscribe((structure) => { this.initForm(structure); - this.structureId = structure.id; + this.structureId = structure._id; }); } else { this.initForm(new Structure()); @@ -93,7 +93,7 @@ export class FormComponent implements OnInit { private initForm(structure: Structure): void { // Init form this.structureForm = new FormGroup({ - id: new FormControl(structure.id), + _id: new FormControl(structure._id), coord: new FormControl(structure.coord), structureType: this.loadArrayForCheckbox(structure.structureType, true), structureName: new FormControl(structure.structureName, Validators.required), diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 8633018fcb07ad730973ed82b72aa72a90f6563a..ec5984d94a4d526181f57b476148dbb0bbb45cc7 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -15,8 +15,8 @@ import { GeojsonService } from '../services/geojson.service'; }) export class HomeComponent implements OnInit { public structures: Structure[] = []; - public displayMarkerId: number; - public selectedMarkerId: number; + public displayMarkerId: string; + public selectedMarkerId: string; public geolocation = false; public currentLocation: GeoJson; public currentStructure: Structure; @@ -67,7 +67,7 @@ export class HomeComponent implements OnInit { public updateStructures(s: Structure): void { this.structures = this.structures.map((structure) => { - return structure.id === s.id ? s : structure; + return structure._id === s._id ? s : structure; }); } @@ -156,11 +156,11 @@ export class HomeComponent implements OnInit { ); } - public setMapMarkerId(event: Array<number>): void { - this.displayMarkerId = event[0]; + public setMapMarkerId(event: string): void { + this.displayMarkerId = event; } - public setSelectedMarkerId(id: number): void { + public setSelectedMarkerId(id: string): void { this.selectedMarkerId = id; } diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index 8191c2b7eb37c769e5c3a9eacf07a88fa5bc1bde..e22a7c4129b56d2953b568816632a3afce43eef5 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -38,8 +38,8 @@ import brignais from '../../../assets/geojson/brignais.json'; }) export class MapComponent implements OnChanges { @Input() public structures: Structure[] = []; - @Input() public toogleToolTipId: number; - @Input() public selectedMarkerId: number; + @Input() public toogleToolTipId: string; + @Input() public selectedMarkerId: string; @Input() public isMapPhone: boolean; @ViewChild(NgxLeafletLocateComponent, { static: false }) locateComponent: NgxLeafletLocateComponent; @Output() selectedStructure: EventEmitter<Structure> = new EventEmitter<Structure>(); @@ -125,7 +125,7 @@ export class MapComponent implements OnChanges { structure.getLat(), structure.getLon(), MarkerType.structure, - structure.id, + structure._id, this.buildToolTip(structure) ) .addTo(this.map) @@ -154,7 +154,7 @@ export class MapComponent implements OnChanges { structure.structureName + '</h1>' + '<p>' + - this.getLabelTypeStructure(structure.structureType) + + structure.getLabelTypeStructure() + '</p><div>' + '<span class="ico-dot-' + cssAvailabilityClass + @@ -164,17 +164,6 @@ export class MapComponent implements OnChanges { ); } - private getLabelTypeStructure(typeStructure: string[]): string { - let label = ''; - typeStructure.forEach((type) => { - if (label) { - label += ', '; - } - label += typeStructureEnum[type]; - }); - return label; - } - private buildMdmPopUp(mdmProperties: GeoJsonProperties): string { return `<h1>${mdmProperties.nom}</h1><p>${mdmProperties.adresse}</p>`; } @@ -230,7 +219,7 @@ export class MapComponent implements OnChanges { }); } - private centerLeafletMapOnMarker(markerId: number): void { + private centerLeafletMapOnMarker(markerId: string): void { const marker = this.mapService.getMarker(markerId); const latLngs = [marker.getLatLng()]; const markerBounds = latLngBounds(latLngs); diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts index eb7143fdc1b7666a997db978e9f0a210d0646b5f..52d5ba0b7e3a8f70c0c8d4aaf4d3dcfd1b0b911f 100644 --- a/src/app/map/services/map.service.ts +++ b/src/app/map/services/map.service.ts @@ -45,7 +45,7 @@ export class MapService { }); constructor() {} - public createMarker(lat: number, lon: number, markerType: MarkerType, id?: number, tooltip?: string): Marker { + public createMarker(lat: number, lon: number, markerType: MarkerType, id?: string, tooltip?: string): Marker { const marker = new Marker([lat, lon], { icon: this.getMarkerIcon(markerType), attribution: this.getLayerAttributton(markerType), @@ -106,11 +106,11 @@ export class MapService { /** * @param id marker id */ - public setActiveMarker(id: number): void { + public setActiveMarker(id: string): void { this.getMarker(id).setIcon(this.getMarkerIconHover(MarkerType.structure)); } - public setUnactiveMarker(id: number): void { + public setUnactiveMarker(id: string): void { // To skip mouseleave when user emit click on structure list if (!this.isMarkerActive) { this.getMarker(id).setIcon(this.getMarkerIcon(MarkerType.structure)); @@ -123,7 +123,7 @@ export class MapService { * @param id markerId * @param html html to display */ - public setToolTip(id: number, html: string): void { + public setToolTip(id: string, html: string): void { this.getMarker(id).bindTooltip(html); } @@ -132,7 +132,7 @@ export class MapService { * @param id markerId * @param html html to display */ - public setSelectedMarker(id: number): void { + public setSelectedMarker(id: string): void { if (id) { this.getMarker(id).setIcon(this.markerIconActive); this.isMarkerActive = true; @@ -144,7 +144,7 @@ export class MapService { * @param id markerId * @param html html to display */ - public setDefaultMarker(id: number): void { + public setDefaultMarker(id: string): void { if (id) { const markerIcon = divIcon({ className: null, @@ -160,7 +160,7 @@ export class MapService { /** * Get marker by id */ - public getMarker(id: number): Marker { + public getMarker(id: string): Marker { return MapService.markersList[id] ? MapService.markersList[id] : null; } diff --git a/src/app/models/structure.model.ts b/src/app/models/structure.model.ts index 060157da0e8a2c3fd81015334e74747cc7d12943..b8125ec9fa6d26f3a6cdc13b188fa59d2bf07203 100644 --- a/src/app/models/structure.model.ts +++ b/src/app/models/structure.model.ts @@ -1,11 +1,11 @@ -import { WebElement } from 'protractor'; +import { typeStructureEnum } from '../shared/enum/typeStructure.enum'; import { Weekday } from '../structure-list/enum/weekday.enum'; import { Address } from './address.model'; import { Day } from './day.model'; import { OpeningDay } from './openingDay.model'; import { Week } from './week.model'; export class Structure { - public id: number = null; + public _id: string = null; public numero: string = null; public createdAt: string = null; public updatedAt: string = null; @@ -90,6 +90,17 @@ export class Structure { } } + public getLabelTypeStructure(): string { + let label = ''; + this.structureType.forEach((type) => { + if (label) { + label += ', '; + } + label += typeStructureEnum[type]; + }); + return label; + } + /** * Check if a structure has equipments */ diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index 0a438e858617c30593de154ac86f44a28df507c7..d4c4b9a58ec6a5d41bea93d69302150fc6aba921 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -8,8 +8,8 @@ export class User { emailVerified: boolean; role: number; validationToken: string; - structuresLink: number[]; - pendingStructuresLink: number[] = []; + structuresLink: string[]; + pendingStructuresLink: string[] = []; constructor(obj?: any) { Object.assign(this, obj); diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index eba09ef410d3d3cd66b25c806d4f73f921f71eee..87c91ca9f988eaec479661528e1a70c3e0d5e96b 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -28,7 +28,7 @@ export class ProfileService { this.currentProfile = profile; } - public isLinkedToStructure(idStructure: number): boolean { + public isLinkedToStructure(idStructure: string): boolean { if (!this.currentProfile) { return false; } @@ -39,7 +39,7 @@ export class ProfileService { this.currentProfile = null; } - public createUserandLinkStructure(id: number, body: User): Observable<User> { + public createUserandLinkStructure(id: string, body: User): Observable<User> { body.pendingStructuresLink = [id]; return this.http.post<any>(`${this.baseUrl}`, body); } diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index 40118194df608cb916f0ab6b25eea29db1bf1298..e28d78f8f4bacf463e01f4bfdd1ee32a232110fe 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -25,20 +25,21 @@ export class StructureService { return this.http.post(`${this.baseUrl}`, { structure, idUser }).pipe(map((item: Structure) => new Structure(item))); } - public editStructure(id: number, structure: Structure): Observable<Structure> { + public editStructure(id: string, structure: Structure): Observable<Structure> { structure.updatedAt = new Date().toString(); + delete structure._id; // id should not be provided for update return this.http.put(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); } - public isClaimed(id: number): Observable<any> { + public isClaimed(id: string): Observable<any> { return this.http.get(`${this.baseUrl}/${id}/isClaimed`); } - public claimStructureWithAccount(id: number, email: string): Observable<number[]> { + public claimStructureWithAccount(id: string, email: string): Observable<string[]> { return this.http.post<any>(`${this.baseUrl}/${id}/claim`, { email }); } - public getStructure(id: number): Observable<Structure> { + public getStructure(id: string): Observable<Structure> { return this.http.get(`${this.baseUrl}/${id}`).pipe(map((item: any) => new Structure(item))); } public getStructures(filters: Filter[]): Observable<Structure[]> { diff --git a/src/app/structure-list/components/card/card.component.html b/src/app/structure-list/components/card/card.component.html index 2e4a7f611a02f04fc305904356e922df691cd355..72c5cb144d0424cedeb73bf463ce77cecdd1e091 100644 --- a/src/app/structure-list/components/card/card.component.html +++ b/src/app/structure-list/components/card/card.component.html @@ -16,6 +16,6 @@ </div> </div> </div> - <span class="typeStructure">{{ getLabelTypeStructure(structure.structureType) }}</span> + <span class="typeStructure">{{ structure.getLabelTypeStructure() }}</span> <br /> </div> diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index e9778837277fa60e9a2ad27a4ff598d13c29fb7c..dc6e8ce1e96bbe61fcd7ce6a3efe835188c7cf25 100644 --- a/src/app/structure-list/components/card/card.component.ts +++ b/src/app/structure-list/components/card/card.component.ts @@ -31,16 +31,6 @@ export class CardComponent implements OnInit { this.showDetails.emit(this.structure); } - public getLabelTypeStructure(typeStructure: string[]): string { - let label = ''; - for (let i = 0; i < typeStructure.length; i++) { - if (label) { - label += ', '; - } - label += typeStructureEnum[typeStructure[i]]; - } - return label; - } public cardHover(): void { this.hover.emit(this.structure); } diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 4c5061cec87ad01514731f2cd7b5273807df39f3..8fb67057cbedcd79421bf777f3e6ac50ba7b3c86 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -1,6 +1,6 @@ <app-structureForm *ngIf="showForm" - [idStructure]="structure.id" + [idStructure]="structure._id" [isEditMode]="isEditMode" [profile]="currentProfile" (closeEvent)="updateStructure($event)" @@ -12,7 +12,7 @@ <button (click)="claimStructure()">Revendiquer</button> </div> <div fxLayout="row" fxLayoutAlign="center center"> - <button *ngIf="profileService.isLinkedToStructure(structure.id)" (click)="editStructure()"> + <button *ngIf="profileService.isLinkedToStructure(structure._id)" (click)="editStructure()"> Modifier ma structure </button> </div> @@ -24,7 +24,7 @@ <div fxLayout="row" fxLayoutAlign="space-between start"> <div fxLayout="column"> <h2 class="bold">{{ structure.structureName }}</h2> - <h3>{{ getLabelTypeStructure(structure.structureType) }}</h3> + <h3>{{ structure.getLabelTypeStructure() }}</h3> </div> <div class="printButton" fxLayout="column" fxLayoutAlign="end"> <app-button @@ -126,7 +126,13 @@ </div> </div> <!-- Accueil --> - <div fxLayout="column" class="structure-details-block" fxLayoutAlign="baseline baseline" fxLayoutGap="20px"> + <div + *ngIf="structure.accessModality.length > 0 || structure.hours.hasData()" + fxLayout="column" + class="structure-details-block" + fxLayoutAlign="baseline baseline" + fxLayoutGap="20px" + > <div fxLayout="row" fxLayoutAlign="none flex-end" fxLayoutGap="8px"> <app-svg-icon [type]="'ico'" [icon]="'accueil'" [iconClass]="'icon-32'"></app-svg-icon> <h2>Accueil</h2> @@ -152,7 +158,7 @@ </div> </div> <!-- accessModality --> - <div fxFlex="50%"> + <div *ngIf="structure.accessModality.length > 0" fxFlex="50%"> <h3 class="subtitle">Accès</h3> <div *ngFor="let acces of structure.accessModality" diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index ef9efeb2ddac4d9310e1ee81fd27dd5fb7f66c80..59c5011ba4fb647b4d5bce1a89aae023920ddc22 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -65,7 +65,7 @@ export class StructureDetailsComponent implements OnInit { } // GetTclStopPoints this.getTclStopPoints(); - this.structureService.isClaimed(this.structure.id).subscribe((boolean) => { + this.structureService.isClaimed(this.structure._id).subscribe((boolean) => { this.isClaimed = boolean; this.searchService.getCategoriesTraining().subscribe((referentiels) => { referentiels.forEach((referentiel) => { @@ -88,16 +88,6 @@ export class StructureDetailsComponent implements OnInit { } }); } - public getLabelTypeStructure(typeStructure: string[]): string { - let label = ''; - typeStructure.forEach((type) => { - if (label) { - label += ', '; - } - label += typeStructureEnum[type]; - }); - return label; - } public getEquipmentsIcon(equipment: Equipment): string { switch (equipment) { diff --git a/src/app/structure-list/structure-list.component.ts b/src/app/structure-list/structure-list.component.ts index 68b0db213920b4720f9d922553ed91e1e83bf327..b1a5c31b10387e6abc704db14d0f703a2fc77b52 100644 --- a/src/app/structure-list/structure-list.component.ts +++ b/src/app/structure-list/structure-list.component.ts @@ -14,9 +14,8 @@ export class StructureListComponent implements OnChanges { @Output() searchEvent = new EventEmitter(); @Input() public location: GeoJson; @Input() public selectedStructure: Structure = new Structure(); - @Output() public displayMapMarkerId: EventEmitter<Array<number>> = new EventEmitter<Array<number>>(); - @Output() public hoverOut: EventEmitter<Array<number>> = new EventEmitter<Array<number>>(); - @Output() public selectedMarkerId: EventEmitter<number> = new EventEmitter<number>(); + @Output() public displayMapMarkerId: EventEmitter<string> = new EventEmitter<string>(); + @Output() public selectedMarkerId: EventEmitter<string> = new EventEmitter<string>(); @Output() public updatedStructure: EventEmitter<Structure> = new EventEmitter<Structure>(); public showStructureDetails = false; @@ -43,7 +42,7 @@ export class StructureListComponent implements OnChanges { public showDetails(event: Structure): void { this.showStructureDetails = true; this.structure = event; - this.selectedMarkerId.emit(this.structure.id); + this.selectedMarkerId.emit(this.structure._id); } public closeDetails(): void { @@ -51,12 +50,12 @@ export class StructureListComponent implements OnChanges { this.showStructureDetails = false; } - public handleCardHover(event: Structure): void { - this.displayMapMarkerId.emit([event.id]); + public handleCardHover(structure: Structure): void { + this.displayMapMarkerId.emit(structure._id); } public mouseLeave(): void { - this.displayMapMarkerId.emit([undefined]); + this.displayMapMarkerId.emit(undefined); } public emitUpdatedStructure(s: Structure): void {