From 326ea73b864eb608caf453c6ec4491ce0a132e96 Mon Sep 17 00:00:00 2001 From: MiharyR Date: Mon, 13 Dec 2021 18:54:45 +0100 Subject: [PATCH] on ne peut pas ajouter plusieurs fois le memme 'centre d'interet'/'sujet' --- .../input-interests-admin.component.ts | 25 +++++++++++++------ .../input-interests-ad.component.ts | 9 +++---- .../input-interests-register.component.html | 2 +- .../input-interests-register.component.ts | 5 ++-- .../input-interests-profil.component.ts | 5 ++-- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/app/admin/userList/input-interests-admin/input-interests-admin.component.ts b/src/app/admin/userList/input-interests-admin/input-interests-admin.component.ts index 9ec0c25..d197e33 100644 --- a/src/app/admin/userList/input-interests-admin/input-interests-admin.component.ts +++ b/src/app/admin/userList/input-interests-admin/input-interests-admin.component.ts @@ -6,7 +6,6 @@ import {MessageService} from "../../../utils/services/message/message.service"; import {map, startWith} from "rxjs/operators"; import {MatChipInputEvent} from "@angular/material/chips"; import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete"; -import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service"; @@ -28,8 +27,7 @@ export class InputInterestsAdminComponent implements OnInit @ViewChild('tagInput') tagInput: ElementRef; - constructor( private fictitiousUtilsService: FictitiousUtilsService, - private messageService: MessageService ) {} + constructor( private messageService: MessageService ) {} ngOnInit(): void @@ -38,16 +36,26 @@ export class InputInterestsAdminComponent implements OnInit startWith(null), map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); - // --- FAUX CODE --- - this.allInterests = this.fictitiousUtilsService.getTags(); - this.allInterests.sort(); + this.messageService + .get("misc/getInterests") + .subscribe( retour => { + + if(retour.status !== "success") { + console.log(retour); + } + else { + this.allInterests = []; + for(let elt of retour.data) this.allInterests.push(elt.interest); + this.allInterests.sort(); + } + }); } add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1)) + if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); @@ -67,7 +75,8 @@ export class InputInterestsAdminComponent implements OnInit selected(event: MatAutocompleteSelectedEvent): void { - this.myInterests.push(event.option.viewValue); + const value = event.option.viewValue; + if(!this.myInterests.includes(value))this.myInterests.push(value); this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); diff --git a/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.ts b/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.ts index e5a83fe..be873b4 100644 --- a/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.ts +++ b/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.ts @@ -6,7 +6,6 @@ import {map, startWith} from "rxjs/operators"; import {MatChipInputEvent} from "@angular/material/chips"; import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete"; import {MessageService} from "../../../utils/services/message/message.service"; -import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service"; @@ -28,8 +27,7 @@ export class InputInterestsAdComponent implements OnInit @ViewChild('tagInput') tagInput: ElementRef; - constructor( private fictitiousUtilsService: FictitiousUtilsService, - private messageService: MessageService ) {} + constructor( private messageService: MessageService ) {} ngOnInit(): void @@ -56,7 +54,7 @@ export class InputInterestsAdComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allTags.indexOf(value) !== -1)) + if (value && (this.allTags.indexOf(value) !== -1) && (!this.myTags.includes(value))) { this.myTags.push(value); event.chipInput!.clear(); @@ -76,7 +74,8 @@ export class InputInterestsAdComponent implements OnInit selected(event: MatAutocompleteSelectedEvent): void { - this.myTags.push(event.option.viewValue); + const value = event.option.viewValue; + if(!this.myTags.includes(value))this.myTags.push(value); this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myTags); diff --git a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.html b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.html index c53b83d..2a7c484 100644 --- a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.html +++ b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.html @@ -2,7 +2,7 @@ - Tags + Centres d'intérêt diff --git a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts index 6f8301b..1a2395b 100644 --- a/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts +++ b/src/app/beforeConnexion/register/input-interests-register/input-interests-register.component.ts @@ -55,7 +55,7 @@ export class InputInterestsRegisterComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1)) + if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); @@ -75,7 +75,8 @@ export class InputInterestsRegisterComponent implements OnInit selected(event: MatAutocompleteSelectedEvent): void { - this.myInterests.push(event.option.viewValue); + const value = event.option.viewValue; + if(!this.myInterests.includes(value))this.myInterests.push(value); this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); diff --git a/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts b/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts index 70c60da..228b6fc 100644 --- a/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts +++ b/src/app/user/myProfil/input-interests-profil/input-interests-profil.component.ts @@ -55,7 +55,7 @@ export class InputInterestsProfilComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1)) + if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); @@ -75,7 +75,8 @@ export class InputInterestsProfilComponent implements OnInit selected(event: MatAutocompleteSelectedEvent): void { - this.myInterests.push(event.option.viewValue); + const value = event.option.viewValue; + if(!this.myInterests.includes(value))this.myInterests.push(value); this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests);