From 95e88f93ab6fef6e3ac0e73e86854bbb392f5b07 Mon Sep 17 00:00:00 2001 From: MiharyR Date: Tue, 14 Dec 2021 17:43:54 +0100 Subject: [PATCH 1/5] ajout d'une video dans une playlist: fonctionnel --- .../video-list/video-list.component.ts | 14 +++++----- .../popup-add-video-to-playlists.component.ts | 27 ++++++++++++------- .../page-watching-video.component.ts | 8 +++--- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/app/user/myPlaylists/video-list/video-list.component.ts b/src/app/user/myPlaylists/video-list/video-list.component.ts index 3a6c049..e2a5eac 100644 --- a/src/app/user/myPlaylists/video-list/video-list.component.ts +++ b/src/app/user/myPlaylists/video-list/video-list.component.ts @@ -45,14 +45,14 @@ export class VideoListComponent implements OnChanges onDelete(video0: any, indexVideo: number): void { - let _idsVideo = this.videosInPlaylist.filter( x => (x._id !== video0._id) ); - _idsVideo = _idsVideo.map( x => x._id ); - - console.log("_idsVideo:"); - console.log(_idsVideo); - + const data = { + videoId: { + id: video0._id, + action: "delete" + } + } this.messageService - .put("playlist/update/"+this.playlist._id, {videoIds: _idsVideo}) + .put("playlist/update/"+this.playlist._id, data) .subscribe( ret => this.onDeleteCallback(ret, indexVideo), err => this.onDeleteCallback(err, indexVideo)); } diff --git a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts index 8318e32..3b158cd 100644 --- a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts +++ b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts @@ -52,19 +52,28 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit onValider(): void { // --- Existing playlists --- - let listeDesPlaylists = "" ; + let listeDesPlaylistsSelected = "" ; + let listeDesPlaylistsNotSelected = "" ; for(let playlist of this.tabPlaylistAndBool) { - if(playlist.isSelected) listeDesPlaylists += playlist.id + "," ; + if(playlist.isSelected) listeDesPlaylistsSelected += playlist.id + "," ; + else listeDesPlaylistsNotSelected += playlist.id + "," ; } - if(listeDesPlaylists.endsWith(",")) listeDesPlaylists = listeDesPlaylists.slice(0, listeDesPlaylists.length-1); + if(listeDesPlaylistsSelected.endsWith(",")) listeDesPlaylistsSelected = listeDesPlaylistsSelected.slice(0, listeDesPlaylistsSelected.length-1); + if(listeDesPlaylistsNotSelected.endsWith(",")) listeDesPlaylistsNotSelected = listeDesPlaylistsNotSelected.slice(0, listeDesPlaylistsNotSelected.length-1); - console.log(listeDesPlaylists); - if(listeDesPlaylists !== "") + if(listeDesPlaylistsSelected !== "") { - const data1 = { videoId: this._idVideo }; + const data1 = { videoId: { id: this._idVideo, action: "add" } }; this.messageService - .put( "playlist/update/"+listeDesPlaylists, data1) + .put( "playlist/update/"+listeDesPlaylistsSelected, data1) + .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); + } + if(listeDesPlaylistsNotSelected !== "") + { + const data2 = { videoId: { id: this._idVideo, action: "delete" } }; + this.messageService + .put( "playlist/update/"+listeDesPlaylistsNotSelected, data2) .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); } @@ -72,12 +81,12 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit // --- New playlists --- if(this.goToCreatePlaylist) { - const data2 = { + const data3 = { name: this.newPlaylistName, video: {videoId: this.videoId, interest: this.interest, source: this.source} }; this.messageService - .post("playlist/create", data2) + .post("playlist/create", data3) .subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err)); } } diff --git a/src/app/user/watching/page-watching-video/page-watching-video.component.ts b/src/app/user/watching/page-watching-video/page-watching-video.component.ts index 10ce73a..2f88464 100644 --- a/src/app/user/watching/page-watching-video/page-watching-video.component.ts +++ b/src/app/user/watching/page-watching-video/page-watching-video.component.ts @@ -34,7 +34,8 @@ export class PageWatchingVideoComponent implements OnInit views: 0, publishedAt: null, description: "", - source: "" + source: "", + interest: "" }; search: string = ""; ad1: any = { title: "", url: "", images: [] }; @@ -55,7 +56,8 @@ export class PageWatchingVideoComponent implements OnInit public themeService: ThemeService, private activatedRoute: ActivatedRoute, private router: Router, - private _sanitizer: DomSanitizer ) { } + private _sanitizer: DomSanitizer, + private addVideoToPlaylistsService: AddVideoToPlaylistsService ) { } ngOnInit(): void @@ -139,7 +141,7 @@ export class PageWatchingVideoComponent implements OnInit onAddToPlaylist(): void { - //this.addVideoToPlaylistsService.run(this.video); + this.addVideoToPlaylistsService.run(this.video.videoId, this.video.source, this.video.interest); } From c1ecb3cb5e12fae3e3304d9e475ee7b2f028127a Mon Sep 17 00:00:00 2001 From: MiharyR Date: Tue, 14 Dec 2021 18:44:05 +0100 Subject: [PATCH 2/5] gestion des erreurs dans quand on ajoute une video dans une playlist --- .../login/page-login/page-login.component.ts | 2 +- .../page-my-playlists.component.ts | 14 +- .../page-search/page-search.component.ts | 1 - ...opup-add-video-to-playlists.component.html | 5 +- .../popup-add-video-to-playlists.component.ts | 126 ++++++++++-------- .../add-video-to-playlists.service.ts | 11 +- 6 files changed, 86 insertions(+), 73 deletions(-) diff --git a/src/app/beforeConnexion/login/page-login/page-login.component.ts b/src/app/beforeConnexion/login/page-login/page-login.component.ts index 86005af..f80cfe3 100644 --- a/src/app/beforeConnexion/login/page-login/page-login.component.ts +++ b/src/app/beforeConnexion/login/page-login/page-login.component.ts @@ -52,8 +52,8 @@ export class PageLoginComponent implements OnInit onSeConnecterCallback(retour): void { - console.log(retour); if(retour.status !== "success") { + console.log(retour); this.errorMessage = retour.error.reason; this.hasError = true; } diff --git a/src/app/user/myPlaylists/page-my-playlists/page-my-playlists.component.ts b/src/app/user/myPlaylists/page-my-playlists/page-my-playlists.component.ts index 0fe8f36..6f76196 100644 --- a/src/app/user/myPlaylists/page-my-playlists/page-my-playlists.component.ts +++ b/src/app/user/myPlaylists/page-my-playlists/page-my-playlists.component.ts @@ -46,16 +46,22 @@ export class PageMyPlaylistsComponent implements OnInit transmitPlaylistToVideoList(playlist): void { - this.messageService - .get("playlist/findOne/"+playlist.id) - .subscribe(ret => this.afterReceivingPlaylistWithVideo(ret), err => this.afterReceivingPlaylistWithVideo(err)); + if ((playlist === null) || (playlist === undefined)) { + this.playlist = playlist; + } + else { + this.messageService + .get("playlist/findOne/" + playlist.id) + .subscribe(ret => this.afterReceivingPlaylistWithVideo(ret, playlist), err => this.afterReceivingPlaylistWithVideo(err, playlist)); + } } - afterReceivingPlaylistWithVideo(retour: any): void + afterReceivingPlaylistWithVideo(retour: any, playlist): void { if(retour.status !== "success") { console.log(retour); + this.playlist = playlist; } else { this.playlist = retour.data; diff --git a/src/app/user/search/page-search/page-search.component.ts b/src/app/user/search/page-search/page-search.component.ts index 0005371..3e0ba18 100644 --- a/src/app/user/search/page-search/page-search.component.ts +++ b/src/app/user/search/page-search/page-search.component.ts @@ -65,7 +65,6 @@ export class PageSearchComponent implements OnInit else if((!this.tabPlateform[0].isSelected) && this.tabPlateform[1].isSelected) sources += "dm" ; else if(this.tabPlateform[0].isSelected && (!this.tabPlateform[1].isSelected)) sources += "yt" ; else sources += "" ; - console.log(sources); params = params.append('sources', sources); this.messageService diff --git a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.html b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.html index f103ce9..115b281 100644 --- a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.html +++ b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.html @@ -35,7 +35,8 @@ + {{errorMessage}} - - + + diff --git a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts index 3b158cd..6a2d58d 100644 --- a/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts +++ b/src/app/user/utils/components/popup-add-video-to-playlists/popup-add-video-to-playlists.component.ts @@ -20,6 +20,9 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit goToCreatePlaylist = false; newPlaylistName = ""; + hasError: boolean = false; + tabNomPlaylist: string[] = []; + errorMessage: string = "" ; constructor( public dialogRef: MatDialogRef, @@ -34,83 +37,69 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit this.source = this.data.source; this.interest = this.data.interest; - console.log("_id: " + this._idVideo); - console.log("videoId: " + this.videoId); - console.log("source: " + this.source); - console.log("interest: " + this.interest); - for(let playlist of this.data.playlists) { if(playlist.videoIds.includes(this._idVideo)) playlist["isSelected"] = true; else playlist["isSelected"] = false; this.tabPlaylistAndBool.push(playlist); + this.tabNomPlaylist.push(playlist.name); } } - onValider(): void { - // --- Existing playlists --- - let listeDesPlaylistsSelected = "" ; - let listeDesPlaylistsNotSelected = "" ; - for(let playlist of this.tabPlaylistAndBool) + this.checkError(); + if(!this.hasError) { - if(playlist.isSelected) listeDesPlaylistsSelected += playlist.id + "," ; - else listeDesPlaylistsNotSelected += playlist.id + "," ; - } - if(listeDesPlaylistsSelected.endsWith(",")) listeDesPlaylistsSelected = listeDesPlaylistsSelected.slice(0, listeDesPlaylistsSelected.length-1); - if(listeDesPlaylistsNotSelected.endsWith(",")) listeDesPlaylistsNotSelected = listeDesPlaylistsNotSelected.slice(0, listeDesPlaylistsNotSelected.length-1); + // --- Existing playlists --- + let listeDesPlaylistsSelected = "" ; + let listeDesPlaylistsNotSelected = "" ; + for(let playlist of this.tabPlaylistAndBool) + { + if(playlist.isSelected) listeDesPlaylistsSelected += playlist.id + "," ; + else listeDesPlaylistsNotSelected += playlist.id + "," ; + } + if(listeDesPlaylistsSelected.endsWith(",")) listeDesPlaylistsSelected = listeDesPlaylistsSelected.slice(0, listeDesPlaylistsSelected.length-1); + if(listeDesPlaylistsNotSelected.endsWith(",")) listeDesPlaylistsNotSelected = listeDesPlaylistsNotSelected.slice(0, listeDesPlaylistsNotSelected.length-1); - if(listeDesPlaylistsSelected !== "") - { - const data1 = { videoId: { id: this._idVideo, action: "add" } }; - this.messageService - .put( "playlist/update/"+listeDesPlaylistsSelected, data1) - .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); - } - if(listeDesPlaylistsNotSelected !== "") - { - const data2 = { videoId: { id: this._idVideo, action: "delete" } }; - this.messageService - .put( "playlist/update/"+listeDesPlaylistsNotSelected, data2) - .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); - } + if(listeDesPlaylistsSelected !== "") + { + const data1 = { videoId: { id: this._idVideo, action: "add" } }; + this.messageService + .put( "playlist/update/"+listeDesPlaylistsSelected, data1) + .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); + } + if(listeDesPlaylistsNotSelected !== "") + { + const data2 = { videoId: { id: this._idVideo, action: "delete" } }; + this.messageService + .put( "playlist/update/"+listeDesPlaylistsNotSelected, data2) + .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); + } - // --- New playlists --- - if(this.goToCreatePlaylist) - { - const data3 = { - name: this.newPlaylistName, - video: {videoId: this.videoId, interest: this.interest, source: this.source} - }; - this.messageService - .post("playlist/create", data3) - .subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err)); + // --- New playlists --- + if(this.goToCreatePlaylist) + { + const data3 = { + name: this.newPlaylistName, + video: {videoId: this.videoId, interest: this.interest, source: this.source} + }; + this.messageService + .post("playlist/create", data3) + .subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err)); + } + + + // --- Finalement --- + this.dialogRef.close("success"); } } - callbackForExistingPlaylists(retour: any): void { - console.log("onValiderCallback"); - console.log(retour); - - if(retour.status !== "success") { - //console.log(retour); - this.dialogRef.close(null); - } - } - - - - callbackForNewPlaylist(retour: any): void - { - console.log("callbackForNewPlaylist"); - console.log(retour); - if(retour.status !== "success") { console.log(retour); this.dialogRef.close(null); @@ -118,10 +107,35 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit } + callbackForNewPlaylist(retour: any): void + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + } + onAnnuler(): void { this.dialogRef.close("annulation"); } + + checkError(): void + { + if(this.goToCreatePlaylist && (this.newPlaylistName === "")) { + this.errorMessage = "Le nom ne peut pas être vide" ; + this.hasError = true; + } + else if(this.goToCreatePlaylist && this.tabNomPlaylist.includes(this.newPlaylistName)){ + this.errorMessage = "Ce nom est déjà utilisé" ; + this.hasError = true; + } + else { + this.hasError = false; + this.errorMessage = "" ; + } + } + } diff --git a/src/app/user/utils/services/addVideoToPlaylists/add-video-to-playlists.service.ts b/src/app/user/utils/services/addVideoToPlaylists/add-video-to-playlists.service.ts index 33b8aa6..50a5606 100644 --- a/src/app/user/utils/services/addVideoToPlaylists/add-video-to-playlists.service.ts +++ b/src/app/user/utils/services/addVideoToPlaylists/add-video-to-playlists.service.ts @@ -4,7 +4,6 @@ import {MatDialog} from "@angular/material/dialog"; import {PopupAddVideoToPlaylistsComponent} from "../../components/popup-add-video-to-playlists/popup-add-video-to-playlists.component"; import {MatSnackBar} from "@angular/material/snack-bar"; import {FictitiousVideosService} from "../../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service"; -import {HttpParams} from "@angular/common/http"; @@ -40,11 +39,8 @@ export class AddVideoToPlaylistsService private afterCreatingVideo(retour: any): void { - console.log("afterCreatingVideo"); - console.log(retour); - if(retour.status !== "success") { - //console.log(retour); + console.log(retour); } else { this._idVideo = retour.data.id; @@ -58,11 +54,8 @@ export class AddVideoToPlaylistsService private afterReceivingPlaylists(retour: any): void { - console.log("afterReceivingPlaylists"); - console.log(retour); - if(retour.status !== "success") { - //console.log(retour); + console.log(retour); } else { From f1614c44aa7b639f1226dd756f875665cdd2a967 Mon Sep 17 00:00:00 2001 From: MiharyR Date: Tue, 14 Dec 2021 20:55:45 +0100 Subject: [PATCH 3/5] =?UTF-8?q?les=20'interests'/'themes'=20ne=20s'affiche?= =?UTF-8?q?nt=20plus=20dans=20l'input=20s'ils=20ont=20d=C3=A9j=C3=A0=20?= =?UTF-8?q?=C3=A9t=C3=A9=20s=C3=A9lectionn=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../input-interests-admin.component.ts | 45 ++++++++++--- .../drag-and-drop/drag-and-drop.component.ts | 1 + .../input-interests-ad.component.html | 12 ++-- .../input-interests-ad.component.ts | 64 ++++++++++++++----- .../page-ad-list-advertiser.component.ts | 6 +- .../popup-add-or-update-ad.component.html | 10 +-- .../popup-add-or-update-ad.component.scss | 3 + .../popup-add-or-update-ad.component.ts | 12 ++-- .../input-interests-register.component.ts | 45 ++++++++++--- .../input-interests-profil.component.ts | 45 ++++++++++--- 10 files changed, 184 insertions(+), 59 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 d197e33..72ead85 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 @@ -25,6 +25,7 @@ export class InputInterestsAdminComponent implements OnInit allInterests: string[] = []; @Output() eventEmitter = new EventEmitter(); @ViewChild('tagInput') tagInput: ElementRef; + interestsNotSelected: string[] = []; constructor( private messageService: MessageService ) {} @@ -34,7 +35,7 @@ export class InputInterestsAdminComponent implements OnInit { this.filteredInterests = this.formControl.valueChanges.pipe( startWith(null), - map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); + map((fruit: string | null) => fruit ? this._filter(fruit) : this.interestsNotSelected.slice())); this.messageService .get("misc/getInterests") @@ -45,8 +46,11 @@ export class InputInterestsAdminComponent implements OnInit } else { this.allInterests = []; - for(let elt of retour.data) this.allInterests.push(elt.interest); - this.allInterests.sort(); + for(let elt of retour.data) + { + this.allInterests.push(elt.interest); + this.interestsNotSelected.push(elt.interest); + } } }); } @@ -55,28 +59,53 @@ export class InputInterestsAdminComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) + const index = this.interestsNotSelected.indexOf(value); + if (value && (index !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); + this.interestsNotSelected.splice(index, 1); } } - remove(tag: string): void + remove(interest: string): void { - const index = this.myInterests.indexOf(tag); + // supprimer 'interest' de 'myInterest' + const index = this.myInterests.indexOf(interest); if (index >= 0) this.myInterests.splice(index, 1); this.eventEmitter.emit(this.myInterests); + + // remmettre 'interest' dans 'interestsNotSelected' + if(!this.interestsNotSelected.includes(interest)) + { + const indexOfAutres = this.interestsNotSelected.indexOf("Autres"); + if(indexOfAutres !== -1) + { + this.interestsNotSelected.splice(indexOfAutres, 1); + if(interest !== "Autres") this.interestsNotSelected.push(interest); + this.interestsNotSelected.sort(); + this.interestsNotSelected.push("Autres"); + } + else { + this.interestsNotSelected.push(interest); + if(interest !== "Autres") this.interestsNotSelected.sort(); + } + } } selected(event: MatAutocompleteSelectedEvent): void { const value = event.option.viewValue; - if(!this.myInterests.includes(value))this.myInterests.push(value); + if(!this.myInterests.includes(value)) + { + this.myInterests.push(value); + const index = this.interestsNotSelected.indexOf(value); + this.interestsNotSelected.splice(index, 1); + } this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); @@ -86,7 +115,7 @@ export class InputInterestsAdminComponent implements OnInit private _filter(value: string): string[] { const filterValue = value.toLowerCase(); - return this.allInterests.filter(fruit => fruit.toLowerCase().includes(filterValue)); + return this.interestsNotSelected.filter(fruit => fruit.toLowerCase().includes(filterValue)); } } diff --git a/src/app/advertiser/adList/drag-and-drop/drag-and-drop.component.ts b/src/app/advertiser/adList/drag-and-drop/drag-and-drop.component.ts index 8c4de43..e626bef 100644 --- a/src/app/advertiser/adList/drag-and-drop/drag-and-drop.component.ts +++ b/src/app/advertiser/adList/drag-and-drop/drag-and-drop.component.ts @@ -38,6 +38,7 @@ export class DragAndDropComponent return; } this.files.splice(index, 1); + this.eventEmitter.emit(this.files); } /** diff --git a/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.html b/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.html index 8df4522..6def6c2 100644 --- a/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.html +++ b/src/app/advertiser/adList/input-interests-ad/input-interests-ad.component.html @@ -9,18 +9,18 @@ - {{tag}} + (removed)="remove(interest)"> + {{interest}} - - {{tag}} + + {{interest}} 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 be873b4..617cc43 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 @@ -20,11 +20,12 @@ export class InputInterestsAdComponent implements OnInit removable = true; separatorKeysCodes: number[] = [ENTER, COMMA]; formControl = new FormControl(); - filteredTags: Observable; - @Input() myTags: string[] = []; - allTags: string[] = []; + filteredInterests: Observable; + @Input() myInterests: string[] = []; + allInterests: string[] = []; @Output() eventEmitter = new EventEmitter(); @ViewChild('tagInput') tagInput: ElementRef; + interestsNotSelected: string[] = []; constructor( private messageService: MessageService ) {} @@ -32,9 +33,9 @@ export class InputInterestsAdComponent implements OnInit ngOnInit(): void { - this.filteredTags = this.formControl.valueChanges.pipe( + this.filteredInterests = this.formControl.valueChanges.pipe( startWith(null), - map((fruit: string | null) => fruit ? this._filter(fruit) : this.allTags.slice())); + map((fruit: string | null) => fruit ? this._filter(fruit) : this.interestsNotSelected.slice())); this.messageService .get("misc/getInterests") @@ -44,8 +45,12 @@ export class InputInterestsAdComponent implements OnInit console.log(retour); } else { - this.allTags = retour.data.map(x => x.interest) - this.allTags.sort(); + this.allInterests = []; + for(let elt of retour.data) + { + this.allInterests.push(elt.interest); + this.interestsNotSelected.push(elt.interest); + } } }); } @@ -54,38 +59,63 @@ export class InputInterestsAdComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allTags.indexOf(value) !== -1) && (!this.myTags.includes(value))) + const index = this.interestsNotSelected.indexOf(value); + if (value && (index !== -1) && (!this.myInterests.includes(value))) { - this.myTags.push(value); + this.myInterests.push(value); event.chipInput!.clear(); this.formControl.setValue(null); - this.eventEmitter.emit(this.myTags); + this.eventEmitter.emit(this.myInterests); + this.interestsNotSelected.splice(index, 1); } } - remove(tag: string): void + remove(interest: string): void { - const index = this.myTags.indexOf(tag); - if (index >= 0) this.myTags.splice(index, 1); - this.eventEmitter.emit(this.myTags); + // supprimer 'interest' de 'myInterest' + const index = this.myInterests.indexOf(interest); + if (index >= 0) this.myInterests.splice(index, 1); + this.eventEmitter.emit(this.myInterests); + + // remmettre 'interest' dans 'interestsNotSelected' + if(!this.interestsNotSelected.includes(interest)) + { + const indexOfAutres = this.interestsNotSelected.indexOf("Autres"); + if(indexOfAutres !== -1) + { + this.interestsNotSelected.splice(indexOfAutres, 1); + if(interest !== "Autres") this.interestsNotSelected.push(interest); + this.interestsNotSelected.sort(); + this.interestsNotSelected.push("Autres"); + } + else { + this.interestsNotSelected.push(interest); + if(interest !== "Autres") this.interestsNotSelected.sort(); + } + } } selected(event: MatAutocompleteSelectedEvent): void { const value = event.option.viewValue; - if(!this.myTags.includes(value))this.myTags.push(value); + if(!this.myInterests.includes(value)) + { + this.myInterests.push(value); + const index = this.interestsNotSelected.indexOf(value); + this.interestsNotSelected.splice(index, 1); + } this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); - this.eventEmitter.emit(this.myTags); + this.eventEmitter.emit(this.myInterests); } private _filter(value: string): string[] { const filterValue = value.toLowerCase(); - return this.allTags.filter(fruit => fruit.toLowerCase().includes(filterValue)); + return this.interestsNotSelected.filter(fruit => fruit.toLowerCase().includes(filterValue)); } } diff --git a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts index 7810130..ca072a5 100644 --- a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts +++ b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts @@ -124,7 +124,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit { const config = { width: '75%', - height: '80%', + //height: '80%', panelClass: 'custom-dialog-container', data: { action: "add", @@ -146,7 +146,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit else { this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advertAdded)); this.onFilter(); - message = "L'annoonce a bien été ajoutée ✔" ; + message = "L'annonce a bien été ajoutée ✔" ; } this.snackBar.open( message, "", config); }); @@ -157,7 +157,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit { const config = { width: '75%', - height: '80%', + //height: '80%', panelClass: 'custom-dialog-container', data: { action: "update", diff --git a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.html b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.html index f461435..e3b7986 100644 --- a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.html +++ b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.html @@ -15,24 +15,24 @@
- + Titre annonce - + - + Commentaire - +
URL - +
diff --git a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.scss b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.scss index 2221b39..3bb2eed 100644 --- a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.scss +++ b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.scss @@ -31,6 +31,9 @@ h1 { // ------------------------------------------------------------------------- +.titleContainer { + width: 100%; +} .commentContainer { width: 100%; diff --git a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.ts b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.ts index 8601e49..32831f9 100644 --- a/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.ts +++ b/src/app/advertiser/adList/popup-add-or-update-ad/popup-add-or-update-ad.component.ts @@ -56,6 +56,7 @@ export class PopupAddOrUpdateAdComponent implements OnInit if(this.data.action === "add") { this.advert = Object.assign({}, ADVERT_VIDE); + this.advert.images = []; this.advert.interests = []; this.title = "Ajouter annonce" ; } @@ -103,12 +104,15 @@ export class PopupAddOrUpdateAdComponent implements OnInit checkField() { if(this.advert.title.length === 0) { - this.errorMessage = "Veuillez remplir le champ 'titre'" ; + this.errorMessage = "Veuillez remplir le champ 'titre'." ; this.hasError = true; } - else if(this.allTitle.includes(this.advert.title)) - { - this.errorMessage = "Ce titre est déjà pris" ; + else if(this.allTitle.includes(this.advert.title)) { + this.errorMessage = "Ce titre est déjà pris." ; + this.hasError = true; + } + else if((this.advert.images.length === 0) && (this.tabOfNewImagesName.length === 0)) { + this.errorMessage = "Veuillez uploader au moins une image." ; this.hasError = true; } else { 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 1a2395b..537cf45 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 @@ -25,6 +25,7 @@ export class InputInterestsRegisterComponent implements OnInit allInterests: string[] = []; @Output() eventEmitter = new EventEmitter(); @ViewChild('tagInput') tagInput: ElementRef; + interestsNotSelected: string[] = []; constructor( private messageService: MessageService ) {} @@ -34,7 +35,7 @@ export class InputInterestsRegisterComponent implements OnInit { this.filteredInterests = this.formControl.valueChanges.pipe( startWith(null), - map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); + map((fruit: string | null) => fruit ? this._filter(fruit) : this.interestsNotSelected.slice())); this.messageService .get("misc/getInterests") @@ -45,8 +46,11 @@ export class InputInterestsRegisterComponent implements OnInit } else { this.allInterests = []; - for(let elt of retour.data) this.allInterests.push(elt.interest); - this.allInterests.sort(); + for(let elt of retour.data) + { + this.allInterests.push(elt.interest); + this.interestsNotSelected.push(elt.interest); + } } }); } @@ -55,28 +59,53 @@ export class InputInterestsRegisterComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) + const index = this.interestsNotSelected.indexOf(value); + if (value && (index !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); + this.interestsNotSelected.splice(index, 1); } } - remove(tag: string): void + remove(interest: string): void { - const index = this.myInterests.indexOf(tag); + // supprimer 'interest' de 'myInterest' + const index = this.myInterests.indexOf(interest); if (index >= 0) this.myInterests.splice(index, 1); this.eventEmitter.emit(this.myInterests); + + // remmettre 'interest' dans 'interestsNotSelected' + if(!this.interestsNotSelected.includes(interest)) + { + const indexOfAutres = this.interestsNotSelected.indexOf("Autres"); + if(indexOfAutres !== -1) + { + this.interestsNotSelected.splice(indexOfAutres, 1); + if(interest !== "Autres") this.interestsNotSelected.push(interest); + this.interestsNotSelected.sort(); + this.interestsNotSelected.push("Autres"); + } + else { + this.interestsNotSelected.push(interest); + if(interest !== "Autres") this.interestsNotSelected.sort(); + } + } } selected(event: MatAutocompleteSelectedEvent): void { const value = event.option.viewValue; - if(!this.myInterests.includes(value))this.myInterests.push(value); + if(!this.myInterests.includes(value)) + { + this.myInterests.push(value); + const index = this.interestsNotSelected.indexOf(value); + this.interestsNotSelected.splice(index, 1); + } this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); @@ -86,7 +115,7 @@ export class InputInterestsRegisterComponent implements OnInit private _filter(value: string): string[] { const filterValue = value.toLowerCase(); - return this.allInterests.filter(fruit => fruit.toLowerCase().includes(filterValue)); + return this.interestsNotSelected.filter(fruit => fruit.toLowerCase().includes(filterValue)); } } 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 228b6fc..8ceb7c1 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 @@ -25,6 +25,7 @@ export class InputInterestsProfilComponent implements OnInit allInterests: string[] = []; @Output() eventEmitter = new EventEmitter(); @ViewChild('tagInput') tagInput: ElementRef; + interestsNotSelected: string[] = []; constructor( private messageService: MessageService ) {} @@ -34,7 +35,7 @@ export class InputInterestsProfilComponent implements OnInit { this.filteredInterests = this.formControl.valueChanges.pipe( startWith(null), - map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice())); + map((fruit: string | null) => fruit ? this._filter(fruit) : this.interestsNotSelected.slice())); this.messageService .get("misc/getInterests") @@ -45,8 +46,11 @@ export class InputInterestsProfilComponent implements OnInit } else { this.allInterests = []; - for(let elt of retour.data) this.allInterests.push(elt.interest); - this.allInterests.sort(); + for(let elt of retour.data) + { + this.allInterests.push(elt.interest); + this.interestsNotSelected.push(elt.interest); + } } }); } @@ -55,28 +59,53 @@ export class InputInterestsProfilComponent implements OnInit add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); - if (value && (this.allInterests.indexOf(value) !== -1) && (!this.myInterests.includes(value))) + const index = this.interestsNotSelected.indexOf(value); + if (value && (index !== -1) && (!this.myInterests.includes(value))) { this.myInterests.push(value); event.chipInput!.clear(); this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); + this.interestsNotSelected.splice(index, 1); } } - remove(tag: string): void + remove(interest: string): void { - const index = this.myInterests.indexOf(tag); + // supprimer 'interest' de 'myInterest' + const index = this.myInterests.indexOf(interest); if (index >= 0) this.myInterests.splice(index, 1); this.eventEmitter.emit(this.myInterests); + + // remmettre 'interest' dans 'interestsNotSelected' + if(!this.interestsNotSelected.includes(interest)) + { + const indexOfAutres = this.interestsNotSelected.indexOf("Autres"); + if(indexOfAutres !== -1) + { + this.interestsNotSelected.splice(indexOfAutres, 1); + if(interest !== "Autres") this.interestsNotSelected.push(interest); + this.interestsNotSelected.sort(); + this.interestsNotSelected.push("Autres"); + } + else { + this.interestsNotSelected.push(interest); + if(interest !== "Autres") this.interestsNotSelected.sort(); + } + } } selected(event: MatAutocompleteSelectedEvent): void { const value = event.option.viewValue; - if(!this.myInterests.includes(value))this.myInterests.push(value); + if(!this.myInterests.includes(value)) + { + this.myInterests.push(value); + const index = this.interestsNotSelected.indexOf(value); + this.interestsNotSelected.splice(index, 1); + } this.tagInput.nativeElement.value = ''; this.formControl.setValue(null); this.eventEmitter.emit(this.myInterests); @@ -86,7 +115,7 @@ export class InputInterestsProfilComponent implements OnInit private _filter(value: string): string[] { const filterValue = value.toLowerCase(); - return this.allInterests.filter(fruit => fruit.toLowerCase().includes(filterValue)); + return this.interestsNotSelected.filter(fruit => fruit.toLowerCase().includes(filterValue)); } } From 7ea0a5eb97f84096a77285aed7cde536647967ef Mon Sep 17 00:00:00 2001 From: MiharyR Date: Tue, 14 Dec 2021 22:05:58 +0100 Subject: [PATCH 4/5] rectification de 'publishedAt' sur la page 'user/search' --- .../page-search/page-search.component.html | 2 +- .../page-search/page-search.component.ts | 6 +++ .../video-grid/video-grid.component.html | 3 +- .../search/video-grid/video-grid.component.ts | 44 ++++++++++++++++++- .../page-watching-video.component.html | 2 +- .../page-watching-video.component.ts | 6 +++ 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/app/user/search/page-search/page-search.component.html b/src/app/user/search/page-search/page-search.component.html index 3142d35..1f6f645 100644 --- a/src/app/user/search/page-search/page-search.component.html +++ b/src/app/user/search/page-search/page-search.component.html @@ -16,7 +16,7 @@
- + diff --git a/src/app/user/search/page-search/page-search.component.ts b/src/app/user/search/page-search/page-search.component.ts index 3e0ba18..362e69f 100644 --- a/src/app/user/search/page-search/page-search.component.ts +++ b/src/app/user/search/page-search/page-search.component.ts @@ -83,4 +83,10 @@ export class PageSearchComponent implements OnInit } } + + onEnterOnSearchBar(event) + { + if(event.key === 'Enter') this.onSearch(); + } + } diff --git a/src/app/user/search/video-grid/video-grid.component.html b/src/app/user/search/video-grid/video-grid.component.html index ff39326..f0227d8 100644 --- a/src/app/user/search/video-grid/video-grid.component.html +++ b/src/app/user/search/video-grid/video-grid.component.html @@ -30,7 +30,8 @@ {{tronquage(tabVideo[indexPage+k].title)}}
- {{tabVideo[indexPage+k].views | number: '1.0-0'}} vues. Il y a 2h. + {{tabVideo[indexPage+k].views | number: '1.0-0'}} vues. + Il y a {{dateToElapsedTime(tabVideo[indexPage+k].publishedAt)}}.
diff --git a/src/app/user/search/video-grid/video-grid.component.ts b/src/app/user/search/video-grid/video-grid.component.ts index abec899..00af085 100644 --- a/src/app/user/search/video-grid/video-grid.component.ts +++ b/src/app/user/search/video-grid/video-grid.component.ts @@ -33,8 +33,8 @@ export class VideoGridComponent tronquage(str: string) { - if(str.length < 33) return str; - else return str.substring(0, 30) + "..." ; + if(str.length < 30) return str; + else return str.substring(0, 27) + "..." ; } @@ -55,4 +55,44 @@ export class VideoGridComponent if(retour.status !== "success") console.log(retour); } + + dateToElapsedTime(date0): string + { + const ellapsedTimeInMilliSeconds = (new Date()).getTime() - (new Date(date0)).getTime(); + + // seconde + const ellapsedTimeInSeconds = Math.trunc(ellapsedTimeInMilliSeconds / 1000); + if(ellapsedTimeInSeconds < 60) { + if(ellapsedTimeInSeconds <= 1)return ellapsedTimeInSeconds + " seconde" ; + else return ellapsedTimeInSeconds + " secondes" ; + } + // minute + const ellapsedTimeInMinutes = Math.trunc(ellapsedTimeInSeconds / 60); + if(ellapsedTimeInMinutes < 60) { + if(ellapsedTimeInMinutes <= 1) return ellapsedTimeInMinutes + " minute" ; + else return ellapsedTimeInMinutes + " minutes" ; + } + // heure + const ellapsedTimeInHours = Math.trunc(ellapsedTimeInMinutes / 60); + if(ellapsedTimeInHours < 24) { + if(ellapsedTimeInHours <= 1) return ellapsedTimeInHours + " heure" ; + else return ellapsedTimeInHours + " heures" ; + } + // jour + const ellapsedTimeInDays = Math.trunc(ellapsedTimeInHours / 24); + if(ellapsedTimeInDays < 31) { + if(ellapsedTimeInDays <= 1) return ellapsedTimeInDays + " jour" ; + else return ellapsedTimeInDays + " jours" ; + } + // mois + const ellapsedTimeInMonths = Math.trunc(ellapsedTimeInDays / 31); + if(ellapsedTimeInMonths < 12) { + return ellapsedTimeInMonths + " mois" ; + } + // an + const ellapsedTimeInYears = Math.trunc(ellapsedTimeInMonths / 12); + if(ellapsedTimeInYears <= 1) return ellapsedTimeInYears + " an" ; + else return ellapsedTimeInYears + " ans" ; + } + } diff --git a/src/app/user/watching/page-watching-video/page-watching-video.component.html b/src/app/user/watching/page-watching-video/page-watching-video.component.html index b7e4332..fdee7e7 100644 --- a/src/app/user/watching/page-watching-video/page-watching-video.component.html +++ b/src/app/user/watching/page-watching-video/page-watching-video.component.html @@ -17,7 +17,7 @@
- + diff --git a/src/app/user/watching/page-watching-video/page-watching-video.component.ts b/src/app/user/watching/page-watching-video/page-watching-video.component.ts index 2f88464..fd1e2f7 100644 --- a/src/app/user/watching/page-watching-video/page-watching-video.component.ts +++ b/src/app/user/watching/page-watching-video/page-watching-video.component.ts @@ -169,4 +169,10 @@ export class PageWatchingVideoComponent implements OnInit else return "videoCell" ; } + + onEnterOnSearchBar(event) + { + if(event.key === 'Enter') this.onSearch(); + } + } From b0b17c062d3513727ece756de628ad4e29292fa9 Mon Sep 17 00:00:00 2001 From: MiharyR Date: Wed, 15 Dec 2021 00:49:33 +0100 Subject: [PATCH 5/5] gestion de l'affichage des annonces dans la partie user --- .../navbar-admin/navbar-admin.component.ts | 2 +- .../page-ad-list-advertiser.component.ts | 9 +++-- .../pages-popularity.component.html | 2 +- .../pages-popularity.component.ts | 13 +++--- .../navbar-advertiser.component.ts | 2 +- .../video-list/video-list.component.ts | 2 - .../page-search/page-search.component.ts | 11 +++-- .../search/video-grid/video-grid.component.ts | 4 +- .../components/advert/advert.component.html | 21 +++++----- .../components/advert/advert.component.ts | 30 ++++++++------ .../navbar-user/navbar-user.component.ts | 2 +- .../userHistory/userHistory.service.spec.ts | 16 -------- .../userHistory/userHistory.service.ts | 40 ------------------- .../page-watching-video.component.ts | 4 +- 14 files changed, 57 insertions(+), 101 deletions(-) delete mode 100644 src/app/user/utils/services/userHistory/userHistory.service.spec.ts delete mode 100644 src/app/user/utils/services/userHistory/userHistory.service.ts diff --git a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts index dd4f436..5df617a 100644 --- a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts +++ b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts @@ -34,7 +34,7 @@ export class NavbarAdminComponent onDeconnexionCallback(retour: any): void { - console.log(retour); + if(retour.status !== "success") console.log(retour); } } diff --git a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts index ca072a5..6adf0ed 100644 --- a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts +++ b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts @@ -84,9 +84,12 @@ export class PageAdListAdvertiserComponent implements AfterViewInit console.log(retour); } else { - for(let advert of retour.data) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advert)); - this.dataSource = new MatTableDataSource(); - this.onFilter(); + if(retour.data.length !== 0) + { + for(let advert of retour.data) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advert)); + this.dataSource = new MatTableDataSource(); + this.onFilter(); + } } } diff --git a/src/app/advertiser/pages-popularity/pages-popularity.component.html b/src/app/advertiser/pages-popularity/pages-popularity.component.html index 1f59267..30fbd44 100644 --- a/src/app/advertiser/pages-popularity/pages-popularity.component.html +++ b/src/app/advertiser/pages-popularity/pages-popularity.component.html @@ -27,7 +27,7 @@ -
+
tabDate[i].getTime())) i++; + while((i (new Date(tabDate[i])).getTime())) i++; if(i === n) tabDate.push(date0); else tabDate.splice(i, 0, date0); diff --git a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts index 9bd8e1e..7f403db 100644 --- a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts +++ b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts @@ -35,7 +35,7 @@ export class NavbarAdvertiserComponent onDeconnexionCallback(retour: any): void { - console.log(retour); + if(retour.status !== "success") console.log(retour); } } diff --git a/src/app/user/myPlaylists/video-list/video-list.component.ts b/src/app/user/myPlaylists/video-list/video-list.component.ts index e2a5eac..504884e 100644 --- a/src/app/user/myPlaylists/video-list/video-list.component.ts +++ b/src/app/user/myPlaylists/video-list/video-list.component.ts @@ -3,7 +3,6 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {AddVideoToPlaylistsService} from "../../utils/services/addVideoToPlaylists/add-video-to-playlists.service"; import {MessageService} from "../../../utils/services/message/message.service"; import {MatSnackBar} from "@angular/material/snack-bar"; -import {UserHistoryService} from "../../utils/services/userHistory/userHistory.service"; import {Router} from "@angular/router"; import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -24,7 +23,6 @@ export class VideoListComponent implements OnChanges public themeService: ThemeService, private addVideoToPlaylistsService: AddVideoToPlaylistsService, private snackBar: MatSnackBar, - private historiqueService: UserHistoryService, private profilService: ProfilService, private router: Router ) { } diff --git a/src/app/user/search/page-search/page-search.component.ts b/src/app/user/search/page-search/page-search.component.ts index 362e69f..7d48734 100644 --- a/src/app/user/search/page-search/page-search.component.ts +++ b/src/app/user/search/page-search/page-search.component.ts @@ -23,8 +23,8 @@ export class PageSearchComponent implements OnInit tabPlateform = TAB_PLATEFORM; tabVideo: VideoAll[] = []; search: string = ""; - ad1: any = { title: "", url: "", images: [] }; - ad2: any = { title: "", url: "", images: [] }; + ad1: any; + ad2: any; constructor( private messageService: MessageService, @@ -45,8 +45,11 @@ export class PageSearchComponent implements OnInit adCallback(retour: any): void { - if(retour !== "success") { - console.log(retour); + console.log("adCallback retour:"); + console.log(retour); + + if(retour.status !== "success") { + //console.log(retour); } else { this.ad1 = retour.data[0]; diff --git a/src/app/user/search/video-grid/video-grid.component.ts b/src/app/user/search/video-grid/video-grid.component.ts index 00af085..ce2dfde 100644 --- a/src/app/user/search/video-grid/video-grid.component.ts +++ b/src/app/user/search/video-grid/video-grid.component.ts @@ -1,6 +1,5 @@ import {Component, Input } from '@angular/core'; import {VideoAll} from "../../../utils/interfaces/video"; -import {UserHistoryService} from "../../utils/services/userHistory/userHistory.service"; import {AddVideoToPlaylistsService} from "../../utils/services/addVideoToPlaylists/add-video-to-playlists.service"; import {Router} from "@angular/router"; import {MessageService} from "../../../utils/services/message/message.service"; @@ -19,8 +18,7 @@ export class VideoGridComponent indexPage: number = 0; - constructor( private historiqueService: UserHistoryService, - private addVideoToPlaylistsService: AddVideoToPlaylistsService, + constructor( private addVideoToPlaylistsService: AddVideoToPlaylistsService, private router: Router, private messageService: MessageService ) {} diff --git a/src/app/user/utils/components/advert/advert.component.html b/src/app/user/utils/components/advert/advert.component.html index 39d1334..b1c034a 100644 --- a/src/app/user/utils/components/advert/advert.component.html +++ b/src/app/user/utils/components/advert/advert.component.html @@ -1,23 +1,26 @@ -
+
+ - +
- - diff --git a/src/app/user/utils/components/advert/advert.component.ts b/src/app/user/utils/components/advert/advert.component.ts index d8c62d9..8008745 100644 --- a/src/app/user/utils/components/advert/advert.component.ts +++ b/src/app/user/utils/components/advert/advert.component.ts @@ -1,6 +1,4 @@ -import {Component, Input, OnInit} from '@angular/core'; -import {Advert} from "../../../../utils/interfaces/advert"; -import {Router} from "@angular/router"; +import {Component, Input, OnChanges, SimpleChanges} from '@angular/core'; @@ -9,26 +7,32 @@ import {Router} from "@angular/router"; templateUrl: './advert.component.html', styleUrls: ['./advert.component.scss'] }) -export class AdvertComponent implements OnInit +export class AdvertComponent implements OnChanges { @Input() ad: any; @Input() from: string = "search"; - idxImage: number = 0; + image: any; + imageExist: boolean = false; - constructor(private router: Router) { } - ngOnInit(): void + constructor() { } + + + ngOnChanges(changes: SimpleChanges): void { - const nbImages = this.ad.images.length; - if(nbImages === 0) this.ad.images.push({url: "img pub"}); - this.idxImage = Math.floor(Math.random() * nbImages); - - if(this.ad.title === "") this.ad.title = "--- pub ---" ; + if((this.ad !== null) && (this.ad !== undefined)) + { + const nbImages = this.ad.images.length; + const indexImage = Math.floor(Math.random() * nbImages); + this.image = this.ad.images[indexImage]; + this.imageExist = true; + } } + onClick(): void { - document.location.href = this.ad.url; + if(this.ad.url !== "") document.location.href = this.ad.url; } } diff --git a/src/app/user/utils/components/navbar-user/navbar-user.component.ts b/src/app/user/utils/components/navbar-user/navbar-user.component.ts index bb2e345..5947c0b 100644 --- a/src/app/user/utils/components/navbar-user/navbar-user.component.ts +++ b/src/app/user/utils/components/navbar-user/navbar-user.component.ts @@ -35,7 +35,7 @@ export class NavbarUserComponent onDeconnexionCallback(retour: any): void { - console.log(retour); + if(retour.status !== "success") console.log(retour); } } diff --git a/src/app/user/utils/services/userHistory/userHistory.service.spec.ts b/src/app/user/utils/services/userHistory/userHistory.service.spec.ts deleted file mode 100644 index b7cba8c..0000000 --- a/src/app/user/utils/services/userHistory/userHistory.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { UserHistoryService } from './userHistory.service'; - -describe('HistoriqueService', () => { - let service: UserHistoryService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(UserHistoryService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/user/utils/services/userHistory/userHistory.service.ts b/src/app/user/utils/services/userHistory/userHistory.service.ts deleted file mode 100644 index 66b0999..0000000 --- a/src/app/user/utils/services/userHistory/userHistory.service.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Injectable } from '@angular/core'; -import {VideoDB} from "../../../../utils/interfaces/video"; -import {MessageService} from "../../../../utils/services/message/message.service"; - - - -@Injectable({ - providedIn: 'root' -}) -export class UserHistoryService -{ - private tabVideoUrlClicked: string[] = []; - - - constructor(private messageService: MessageService) { } - - - public addVideoToHistoque(video: VideoDB): void - { - if (!this.tabVideoUrlClicked.includes(video.videoId)) - { - this.tabVideoUrlClicked.push(video.videoId); - video.watchedDates.push(new Date()); - - // --- VRAI CODE --- - /* - this.messageService - .sendMessage("user/add/watchedVideo", {watchedVideo: watchedVideo0}) - .subscribe(retour => {}); - */ - } - } - - - public clearTabVideoUrlClicked() - { - this.tabVideoUrlClicked = []; - } - -} diff --git a/src/app/user/watching/page-watching-video/page-watching-video.component.ts b/src/app/user/watching/page-watching-video/page-watching-video.component.ts index fd1e2f7..f501d95 100644 --- a/src/app/user/watching/page-watching-video/page-watching-video.component.ts +++ b/src/app/user/watching/page-watching-video/page-watching-video.component.ts @@ -38,8 +38,8 @@ export class PageWatchingVideoComponent implements OnInit interest: "" }; search: string = ""; - ad1: any = { title: "", url: "", images: [] }; - ad2: any = { title: "", url: "", images: [] }; + ad1: any; + ad2: any; from: string = ""; playlist: PlaylistDB;