Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Yûki VACHOT 2021-12-15 01:26:14 +01:00
commit d94a22e87f
31 changed files with 397 additions and 239 deletions

View file

@ -25,6 +25,7 @@ export class InputInterestsAdminComponent implements OnInit
allInterests: string[] = [];
@Output() eventEmitter = new EventEmitter<string[]>();
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
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));
}
}

View file

@ -34,7 +34,7 @@ export class NavbarAdminComponent
onDeconnexionCallback(retour: any): void
{
console.log(retour);
if(retour.status !== "success") console.log(retour);
}
}

View file

@ -38,6 +38,7 @@ export class DragAndDropComponent
return;
}
this.files.splice(index, 1);
this.eventEmitter.emit(this.files);
}
/**

View file

@ -9,18 +9,18 @@
<mat-chip-list #chipList aria-label="Fruit selection">
<mat-chip
*ngFor="let tag of myTags"
*ngFor="let interest of myInterests"
[selectable]="selectable"
[removable]="removable"
(removed)="remove(tag)">
{{tag}}
(removed)="remove(interest)">
{{interest}}
<button matChipRemove *ngIf="removable">
<mat-icon>cancel</mat-icon>
</button>
</mat-chip>
<input
placeholder="Tapez un sujet et pressez 'Entré' pour l'inserer"
placeholder="Tapez un centre d'intérêt et pressez 'Entrer' pour l'inserer"
#tagInput
[formControl]="formControl"
[matAutocomplete]="auto"
@ -33,8 +33,8 @@
<!-- ------------------------------------------------------------------------------------ -->
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let tag of filteredTags | async" [value]="tag">
{{tag}}
<mat-option *ngFor="let interest of filteredInterests | async" [value]="interest">
{{interest}}
</mat-option>
</mat-autocomplete>

View file

@ -20,11 +20,12 @@ export class InputInterestsAdComponent implements OnInit
removable = true;
separatorKeysCodes: number[] = [ENTER, COMMA];
formControl = new FormControl();
filteredTags: Observable<string[]>;
@Input() myTags: string[] = [];
allTags: string[] = [];
filteredInterests: Observable<string[]>;
@Input() myInterests: string[] = [];
allInterests: string[] = [];
@Output() eventEmitter = new EventEmitter<string[]>();
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
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));
}
}

View file

@ -84,11 +84,14 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
console.log(retour);
}
else {
if(retour.data.length !== 0)
{
for(let advert of retour.data) this.tabAdvertWithCountViews.push(this.advertToAdvertWithCountViews(advert));
this.dataSource = new MatTableDataSource<AdvertWithCountViews>();
this.onFilter();
}
}
}
applyFilter(event: Event): void
@ -124,7 +127,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
{
const config = {
width: '75%',
height: '80%',
//height: '80%',
panelClass: 'custom-dialog-container',
data: {
action: "add",
@ -146,7 +149,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 +160,7 @@ export class PageAdListAdvertiserComponent implements AfterViewInit
{
const config = {
width: '75%',
height: '80%',
//height: '80%',
panelClass: 'custom-dialog-container',
data: {
action: "update",

View file

@ -15,24 +15,24 @@
<div class="col-6">
<!-- Title -->
<mat-form-field appearance="fill">
<mat-form-field class="titleContainer" appearance="fill">
<mat-label> Titre annonce </mat-label>
<input matInput type="text" [(ngModel)]="advert.title">
<input matInput type="text" [(ngModel)]="advert.title" required>
</mat-form-field>
<!-- Interests -->
<app-input-interests-ad [myTags]="advert.interests" (eventEmitter)="onEventInputTags($event)"></app-input-interests-ad>
<app-input-interests-ad [myInterests]="advert.interests" (eventEmitter)="onEventInputTags($event)"></app-input-interests-ad>
<!-- Comments -->
<mat-form-field class="commentContainer" appearance="fill">
<mat-label> Commentaire </mat-label>
<textarea matInput [(ngModel)]="advert.comment"></textarea>
<textarea matInput [(ngModel)]="advert.comment" rows="5" style="resize: none;"></textarea>
</mat-form-field><br>
<!-- url -->
<mat-form-field class="commentContainer" appearance="fill">
<mat-label> URL </mat-label>
<textarea matInput [(ngModel)]="advert.url"></textarea>
<input matInput [(ngModel)]="advert.url">
</mat-form-field><br>
<!-- IsVisible -->

View file

@ -31,6 +31,9 @@ h1 {
// -------------------------------------------------------------------------
.titleContainer {
width: 100%;
}
.commentContainer {
width: 100%;

View file

@ -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 {

View file

@ -27,7 +27,7 @@
<!-- chart -->
<div class="chartContainer">
<div *ngIf="isDisplayable" class="chartContainer">
<canvas baseChart
[datasets]="lineChartData"
[labels]="lineChartLabels"

View file

@ -25,7 +25,7 @@ interface CoupleNameViews {
})
export class PagesPopularityComponent implements OnInit
{
formControl: FormControl;
formControl: FormControl = new FormControl();
allCoupleNameViews: CoupleNameViews[] = [];
allInterests: string[] = [];
@ -48,6 +48,8 @@ export class PagesPopularityComponent implements OnInit
}
};
isDisplayable: boolean = false;
constructor( private router: Router,
public themeService: ThemeService,
@ -167,8 +169,8 @@ export class PagesPopularityComponent implements OnInit
this.lineChartLabels = [];
if(this.step <= 0) this.step = 0;
if(this.endDate === null) this.endDate = new Date();
if(this.startDate === null) this.startDate = new Date(this.endDate.getTime() - this.oneWeek); // date d'il y a une semaine
if((this.endDate === null) || (this.endDate === undefined)) this.endDate = new Date();
if((this.startDate === null) || (this.startDate === undefined)) this.startDate = new Date(this.endDate.getTime() - this.oneWeek); // date d'il y a une semaine
const startTime = this.startDate.getTime();
const endTime = this.endDate.getTime();
@ -211,6 +213,7 @@ export class PagesPopularityComponent implements OnInit
this.lineChartData.push({"data": data.slice(), "label": label});
}
this.isDisplayable = true;
}
@ -282,9 +285,9 @@ export class PagesPopularityComponent implements OnInit
{
let i = 0;
let n = tabDate.length;
let time0 = date0.getTime();
let time0 = (new Date(date0)).getTime();
while((i <n) && (time0 > tabDate[i].getTime())) i++;
while((i <n) && (time0 > (new Date(tabDate[i])).getTime())) i++;
if(i === n) tabDate.push(date0);
else tabDate.splice(i, 0, date0);

View file

@ -35,7 +35,7 @@ export class NavbarAdvertiserComponent
onDeconnexionCallback(retour: any): void
{
console.log(retour);
if(retour.status !== "success") console.log(retour);
}
}

View file

@ -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;
}

View file

@ -25,6 +25,7 @@ export class InputInterestsRegisterComponent implements OnInit
allInterests: string[] = [];
@Output() eventEmitter = new EventEmitter<string[]>();
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
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));
}
}

View file

@ -46,16 +46,22 @@ export class PageMyPlaylistsComponent implements OnInit
transmitPlaylistToVideoList(playlist): void
{
if ((playlist === null) || (playlist === undefined)) {
this.playlist = playlist;
}
else {
this.messageService
.get("playlist/findOne/" + playlist.id)
.subscribe(ret => this.afterReceivingPlaylistWithVideo(ret), err => this.afterReceivingPlaylistWithVideo(err));
.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;

View file

@ -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 ) { }
@ -45,14 +43,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));
}

View file

@ -25,6 +25,7 @@ export class InputInterestsProfilComponent implements OnInit
allInterests: string[] = [];
@Output() eventEmitter = new EventEmitter<string[]>();
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
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));
}
}

View file

@ -16,7 +16,7 @@
<!-- Search bar -->
<div class="input-group" style="width: 100%; margin: 0 auto;">
<div class="form-outline" style="width: 100%; margin: 0 auto;">
<input type="search" placeholder="Rechercher..." class="inputSearchBar" [(ngModel)]="search"/>
<input type="search" placeholder="Rechercher..." class="inputSearchBar" [(ngModel)]="search" (keydown)="onEnterOnSearchBar($event)"/>
<button mat-icon-button (click)="onSearch()">
<mat-icon>search</mat-icon>
</button>

View file

@ -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("adCallback retour:");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
}
else {
this.ad1 = retour.data[0];
@ -65,7 +68,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
@ -84,4 +86,10 @@ export class PageSearchComponent implements OnInit
}
}
onEnterOnSearchBar(event)
{
if(event.key === 'Enter') this.onSearch();
}
}

View file

@ -30,7 +30,8 @@
{{tronquage(tabVideo[indexPage+k].title)}}
<br>
<span style="color: gray">
{{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)}}.
</span>
</div>
</mat-grid-tile>

View file

@ -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 ) {}
@ -33,8 +31,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 +53,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" ;
}
}

View file

@ -1,23 +1,26 @@
<div *ngIf="from==='search' || from==='myPlaylists'" class="myContainer">
<div *ngIf="(from==='search' || from==='myPlaylists') && (imageExist)"
class="myContainer">
<span class="helper"></span>
<img [src]="'assets/pub/'+ad.images[idxImage].url"
[alt]="ad.title"
<img [src]="image.base64"
[alt]="image.description"
(click)="onClick()"
id="imgFromSearchOrMyPlaylists">
</div>
<!-- --------------------------------------------------------------------- -->
<img *ngIf="from === 'watchingLeft'"
[src]="'assets/pub/'+ad.images[idxImage].url"
[alt]="ad.title"
<img *ngIf="from === 'watchingLeft' && (imageExist)"
[src]="image.base64"
[alt]="image.description"
(click)="onClick()"
id="imgFromWatchingLeft">
<!-- --------------------------------------------------------------------- -->
<img *ngIf="from === 'watchingRight'"
[src]="'assets/pub/'+ad.images[idxImage].url"
[alt]="ad.title"
<img *ngIf="from === 'watchingRight' && (imageExist)"
[src]="image.base64"
[alt]="image.description"
(click)="onClick()"
id="imgFromWatchingRight">

View file

@ -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
{
if((this.ad !== null) && (this.ad !== undefined))
{
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 ---" ;
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;
}
}

View file

@ -35,7 +35,7 @@ export class NavbarUserComponent
onDeconnexionCallback(retour: any): void
{
console.log(retour);
if(retour.status !== "success") console.log(retour);
}
}

View file

@ -35,7 +35,8 @@
<mat-divider></mat-divider><!------------------------------------------------------------------------------------------------------------->
<span *ngIf="hasError" class="mat-error"> {{errorMessage}} </span>
<mat-dialog-actions style="justify-content: flex-end;">
<button mat-button mat-dialog-close (click)="onAnnuler()">Annuler</button>
<button mat-button mat-dialog-close="success" cdkFocusInitial (click)="onValider()">Valider</button>
<button mat-button (click)="onAnnuler()">Annuler</button>
<button mat-button cdkFocusInitial (click)="onValider()">Valider</button>
</mat-dialog-actions>

View file

@ -20,6 +20,9 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
goToCreatePlaylist = false;
newPlaylistName = "";
hasError: boolean = false;
tabNomPlaylist: string[] = [];
errorMessage: string = "" ;
constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>,
@ -34,37 +37,44 @@ 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
{
this.checkError();
if(!this.hasError)
{
// --- 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,36 +82,33 @@ 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));
}
}
// --- Finalement ---
this.dialogRef.close("success");
}
}
callbackForExistingPlaylists(retour: any): void
{
console.log("onValiderCallback");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
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);
@ -109,10 +116,26 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
}
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 = "" ;
}
}
}

View file

@ -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
{

View file

@ -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();
});
});

View file

@ -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 = [];
}
}

View file

@ -17,7 +17,7 @@
<!-- Search bar -->
<div class="input-group" style="width: 100%; margin: 0 auto;">
<div class="form-outline" style="width: 100%; margin: 0 auto;">
<input type="search" placeholder="Rechercher..." class="inputSearchBar"/>
<input type="search" placeholder="Rechercher..." class="inputSearchBar" (keydown)="onEnterOnSearchBar($event)"/>
<button mat-icon-button (click)="onSearch()">
<mat-icon>search</mat-icon>
</button>

View file

@ -34,11 +34,12 @@ export class PageWatchingVideoComponent implements OnInit
views: 0,
publishedAt: null,
description: "",
source: ""
source: "",
interest: ""
};
search: string = "";
ad1: any = { title: "", url: "", images: [] };
ad2: any = { title: "", url: "", images: [] };
ad1: any;
ad2: any;
from: string = "";
playlist: PlaylistDB;
@ -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);
}
@ -167,4 +169,10 @@ export class PageWatchingVideoComponent implements OnInit
else return "videoCell" ;
}
onEnterOnSearchBar(event)
{
if(event.key === 'Enter') this.onSearch();
}
}