[DEV] it works

This commit is contained in:
Edouard DUPIN 2022-07-15 21:37:30 +02:00
parent 14c10f4885
commit cf221ec2bb
10 changed files with 165 additions and 135 deletions

View File

@ -176,7 +176,7 @@ public class TrackResource {
System.out.println("Data already exist ... all good"); System.out.println("Data already exist ... all good");
System.out.flush(); System.out.flush();
} }
// Fist step: retive all the Id of each parents:... // Fist step: retrieve all the Id of each parents:...
System.out.println("Find typeNode"); System.out.println("Find typeNode");
Gender genderElem = null; Gender genderElem = null;
if (gender != null) { if (gender != null) {
@ -221,15 +221,14 @@ public class TrackResource {
Track trackElem = new Track(); Track trackElem = new Track();
trackElem.name = title; trackElem.name = title;
trackElem.track = trackId!=null?Long.parseLong(trackId):null;
trackElem.albumId = albumElem!=null?albumElem.id:null;
trackElem.genderId = genderElem!=null?genderElem.id:null; trackElem.genderId = genderElem!=null?genderElem.id:null;
trackElem.dataId = data.id; trackElem.dataId = data.id;
trackElem = SqlWrapper.insert(trackElem); trackElem = SqlWrapper.insert(trackElem);
if (artistElem != null) { if (artistElem != null) {
SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id); SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id);
} }
if (artistElem != null) {
SqlWrapper.addLink(Album.class, albumElem.id , "track", trackElem.id);
}
return Response.ok(trackElem).build(); return Response.ok(trackElem).build();
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Catch an unexpected error ... " + ex.getMessage()); System.out.println("Catch an unexpected error ... " + ex.getMessage());

View File

@ -12,8 +12,10 @@ CREATE TABLE `node` (
) AUTO_INCREMENT=10; ) AUTO_INCREMENT=10;
*/ */
import java.sql.Date; import java.sql.Date;
import java.util.List;
import org.kar.karusic.annotation.SQLIfNotExists; import org.kar.karusic.annotation.SQLIfNotExists;
import org.kar.karusic.annotation.SQLTableLinkGeneric;
import org.kar.karusic.annotation.SQLTableName; import org.kar.karusic.annotation.SQLTableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -22,6 +24,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@SQLTableName ("album") @SQLTableName ("album")
@SQLIfNotExists @SQLIfNotExists
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Album extends Playlist { public class Album extends NodeSmall {
public Date publication = null; public Date publication = null;
} }

View File

@ -25,6 +25,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Track extends NodeSmall { public class Track extends NodeSmall {
public Long genderId = null; public Long genderId = null;
public Long albumId = null;
public Long track = null;
public Long dataId = null; public Long dataId = null;
@SQLTableLinkGeneric @SQLTableLinkGeneric
public List<Long> artists = null; public List<Long> artists = null;
@ -32,6 +34,6 @@ public class Track extends NodeSmall {
public String toString() { public String toString() {
return "Track [id=" + id + ", deleted=" + deleted + ", create_date=" + create_date + ", modify_date=" return "Track [id=" + id + ", deleted=" + deleted + ", create_date=" + create_date + ", modify_date="
+ modify_date + ", name=" + name + ", description=" + description + ", covers=" + covers + ", genderId=" + modify_date + ", name=" + name + ", description=" + description + ", covers=" + covers + ", genderId="
+ genderId + ", dataId=" + dataId + ", artists=" + artists + "]"; + genderId + ", albumId=" + albumId + ", track=" + track + ", dataId=" + dataId + ", artists=" + artists + "]";
} }
} }

View File

@ -6,6 +6,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Media } from 'app/model';
import { AlbumModel, isAlbumModel } from 'app/model/album'; import { AlbumModel, isAlbumModel } from 'app/model/album';
import { ArtistService, DataService, ArianeService, AlbumService, TrackService, PlayerService } from 'app/service'; import { ArtistService, DataService, ArianeService, AlbumService, TrackService, PlayerService } from 'app/service';
@ -27,7 +28,7 @@ export class ArtistAlbumScene implements OnInit {
public albumCovers: string[] = undefined; public albumCovers: string[] = undefined;
public tracksIds: number[] = undefined; public tracksIds: number[] = undefined;
public tracks: any[] = undefined; public tracks: Media[] = undefined;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -63,25 +64,22 @@ export class ArtistAlbumScene implements OnInit {
self.albumName = response.name; self.albumName = response.name;
self.albumDescription = response.description; self.albumDescription = response.description;
self.albumCovers = this.dataService.getCoverListUrl(response.covers); self.albumCovers = this.dataService.getCoverListUrl(response.covers);
if (isAlbumModel(response)) {
//console.log("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
self.tracksIds = (response as AlbumModel).tracks;
}
//console.log("all the tracks: " + self.tracksIds);
this.trackService.getAll(self.tracksIds)
.then((response2: NodeData[]) => {
self.tracks = response2;
//console.log(`>>>>BBB get tracks : ${JSON.stringify(response2, null, 2)}`);
}).catch((response) => {
//console.log(`>>>>BBB plop`);
self.tracks = undefined;
});
}).catch((response) => { }).catch((response) => {
self.albumDescription = undefined; self.albumDescription = undefined;
self.albumName = '???'; self.albumName = '???';
self.albumCovers = undefined; self.albumCovers = undefined;
// no check just ==> an error occured on album // no check just ==> an error occured on album
}); });
//console.log("all the tracks: " + self.tracksIds);
this.trackService.getWithAlbum(self.idAlbum)
.then((response2: Media[]) => {
self.tracks = response2;
console.log(`>>>>BBB get tracks : ${JSON.stringify(response2, null, 2)}`);
}).catch((response) => {
//console.log(`>>>>BBB plop`);
self.tracks = undefined;
});
} }
onSelectTrack(event: any, idSelected: number):void { onSelectTrack(event: any, idSelected: number):void {

View File

@ -185,7 +185,7 @@
</button> </button>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
<div class="request_raw_table" *ngIf="this.listFileInBdd !== undefined"> <div class="request_raw_table" *ngIf="this.listFileInBdd">
<table> <table>
<colgroup> <colgroup>
<col style="width:10%"> <col style="width:10%">

View File

@ -11,6 +11,7 @@ import { GenderService, PlaylistService, ArtistService, TrackService, ArianeServ
import { NodeData } from 'common/model'; import { NodeData } from 'common/model';
import { UploadProgress } from 'common/popin/upload-progress/upload-progress'; import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
import { PopInService } from 'common/service'; import { PopInService } from 'common/service';
import { isNullOrUndefined } from 'common/utils';
export class ElementList { export class ElementList {
constructor( constructor(
@ -51,13 +52,13 @@ export class UploadScene implements OnInit {
parsedFailedElement: FileFailParsedElement[] = []; parsedFailedElement: FileFailParsedElement[] = [];
uploadFileValue: string = ''; uploadFileValue: string = '';
selectedFiles: FileList; selectedFiles: FileList;
genderId: number = null; genderId: number = undefined;
artistId: number = null; artistId: number = undefined;
saisonId: number = null; albumId: number = undefined;
needSend: boolean = false; needSend: boolean = false;
// list of all files already registered in the bdd to compare with the curent list of files. // list of all files already registered in the bdd to compare with the curent list of files.
listFileInBdd: any = null; listFileInBdd: any[] = undefined;
// section tha define the upload value to display in the pop-in of upload // section tha define the upload value to display in the pop-in of upload
public upload:UploadProgress = new UploadProgress(); public upload:UploadProgress = new UploadProgress();
@ -65,13 +66,12 @@ export class UploadScene implements OnInit {
listGender: ElementList[] = [ listGender: ElementList[] = [
{ value: null, label: '---' }, { value: null, label: '---' },
]; ];
listPlaylist: ElementList[] = [
{ value: null, label: '---' },
];
listArtist: ElementList[] = [ listArtist: ElementList[] = [
{ value: null, label: '---' }, { value: null, label: '---' },
]; ];
listArtist2 = [ { id: null, description: '---' } ]; listAlbum: ElementList[] = [
{ value: null, label: '---' },
];
/* /*
config = { config = {
@ -92,15 +92,11 @@ export class UploadScene implements OnInit {
searchPlaceholder: 'Search', // label thats displayed in search input, searchPlaceholder: 'Search', // label thats displayed in search input,
searchOnKey: 'description', // key on which search should be performed this will be selective search. if undefined this will be extensive search on all keys searchOnKey: 'description', // key on which search should be performed this will be selective search. if undefined this will be extensive search on all keys
}; };
listAlbum: ElementList[] = [ globalGender: string = null;
{ value: null, label: '---' }, globalArtist: string = null;
];
globalGender: string = '';
globalArtist: string = '';
globalAlbum: string = null; globalAlbum: string = null;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private genderService: GenderService, private genderService: GenderService,
private playlistService: PlaylistService,
private artistService: ArtistService, private artistService: ArtistService,
private albumService: AlbumService, private albumService: AlbumService,
private trackService: TrackService, private trackService: TrackService,
@ -116,12 +112,12 @@ export class UploadScene implements OnInit {
} }
this.needSend = true; this.needSend = true;
for(let iii = 0; iii < this.parsedElement.length; iii++) { for(let iii = 0; iii < this.parsedElement.length; iii++) {
if(this.parsedElement[iii].title === undefined || this.parsedElement[iii].title === null || this.parsedElement[iii].title === '') { if(isNullOrUndefined(this.parsedElement[iii].title) || this.parsedElement[iii].title === '') {
this.needSend = false; this.needSend = false;
} }
} }
/* /*
if(this.genderId === undefined || this.genderId === null) { if(isNullOrUndefined(this.genderId)) {
this.needSend = false; this.needSend = false;
} }
*/ */
@ -132,13 +128,12 @@ export class UploadScene implements OnInit {
this.arianeService.updateManual(this.route.snapshot.paramMap); this.arianeService.updateManual(this.route.snapshot.paramMap);
let self = this; let self = this;
this.listGender = [ { value: null, label: '---' } ]; this.listGender = [ { value: null, label: '---' } ];
this.listPlaylist = [ { value: null, label: '---' } ];
this.listArtist = [ { value: null, label: '---' } ]; this.listArtist = [ { value: null, label: '---' } ];
this.listAlbum = [ { value: null, label: '---' } ]; this.listAlbum = [ { value: null, label: '---' } ];
this.playlistService.getData() this.artistService.getOrder()
.then((response2) => { .then((response2) => {
for(let iii = 0; iii < response2.length; iii++) { for(let iii = 0; iii < response2.length; iii++) {
self.listPlaylist.push({ value: response2[iii].id, label: response2[iii].name }); self.listArtist.push({ value: response2[iii].id, label: response2[iii].name });
} }
}).catch((response2) => { }).catch((response2) => {
console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`); console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`);
@ -155,36 +150,6 @@ export class UploadScene implements OnInit {
console.log(' END INIT '); console.log(' END INIT ');
} }
onChangeType(value: any): void {
this.artistId = null;
this.updateType(value);
}
private updateType(value: any): void {
console.log(`Change requested of type ... ${ value}`);
if(this.genderId === value) {
return;
}
this.genderId = value;
// this.data.artist_id = null;
// this.data.album_id = null;
this.listArtist = [ { value: null, label: '---' } ];
this.listAlbum = [ { value: null, label: '---' } ];
let self = this;
this.updateNeedSend();
if(this.genderId !== null) {
self.genderService.getSubArtist(this.genderId)
.then((response2) => {
for(let iii = 0; iii < response2.length; iii++) {
self.listArtist.push({ value: response2[iii].id, label: response2[iii].name });
}
}).catch((response2) => {
console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`);
});
}
}
onGender(value: any): void { onGender(value: any): void {
this.globalGender = value; this.globalGender = value;
let self = this; let self = this;
@ -196,13 +161,13 @@ export class UploadScene implements OnInit {
console.log(` - ${ JSON.stringify(response[iii])}`); console.log(` - ${ JSON.stringify(response[iii])}`);
} }
if(response.length === 0) { if(response.length === 0) {
self.genderId = null; self.genderId = undefined;
} else if(response.length === 1) { } else if(response.length === 1) {
self.genderId = response[0].id; self.genderId = response[0].id;
} }
}).catch((response) => { }).catch((response) => {
console.log('CAN NOT find element: '); console.log('CAN NOT find element: ');
self.genderId = null; self.genderId = undefined;
}); });
} }
this.updateNeedSend(); this.updateNeedSend();
@ -211,7 +176,7 @@ export class UploadScene implements OnInit {
onChangeGender(value: any): void { onChangeGender(value: any): void {
this.globalGender = value; this.globalGender = value;
if(!(value === undefined || value === null)) { if(!isNullOrUndefined(value)) {
for(let iii = 0; iii < this.listGender.length; iii++) { for(let iii = 0; iii < this.listGender.length; iii++) {
if(this.listGender[iii].value === value) { if(this.listGender[iii].value === value) {
this.globalGender = this.listGender[iii].label; this.globalGender = this.listGender[iii].label;
@ -222,32 +187,50 @@ export class UploadScene implements OnInit {
this.updateNeedSend(); this.updateNeedSend();
} }
private updateTheListOfAlbum() {
this.listAlbum = [ { value: null, label: '---' } ];
if (isNullOrUndefined(this.artistId)) {
return;
}
let self = this;
this.artistService.getAlbum(this.artistId)
.then((response2) => {
for(let iii = 0; iii < response2.length; iii++) {
self.listAlbum.push({ value: response2[iii].id, label: response2[iii].name });
}
}).catch((response2) => {
console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`);
});
}
onArtist(value: any): void { onArtist(value: any): void {
this.globalArtist = value; this.globalArtist = value;
let self = this; let self = this;
if(this.globalArtist !== '') { if(this.globalArtist !== '') {
console.log(`update artist List Element: ${this.globalArtist}`);
this.artistService.getLike(this.globalArtist) this.artistService.getLike(this.globalArtist)
.then((response: any[]) => { .then((response: any[]) => {
console.log(`find element: ${ response.length}`); console.log(` ==> find artist like ${this.globalArtist} : ${ JSON.stringify(response, null, 2)}`);
for(let iii = 0; iii < response.length; iii++) {
console.log(` - ${ JSON.stringify(response[iii])}`);
}
if(response.length === 0) { if(response.length === 0) {
self.artistId = null; self.artistId = undefined;
} else if(response.length === 1) { } else if(response.length === 1) {
self.artistId = response[0].id; self.artistId = response[0].id;
self.updateTheListOfAlbum();
}
if (!isNullOrUndefined(this.globalAlbum)) {
this.onAlbum(this.globalAlbum)
} else {
self.updateListOfTrackToCheck();
} }
self.updateListOfTrackToCheck();
}).catch((response) => { }).catch((response) => {
console.log('CAN NOT find element: '); console.log(` ==> CAN NOT find artist like ${this.globalArtist} : ${ response.length}`);
self.artistId = null; self.artistId = undefined;
}); });
} }
this.updateNeedSend(); this.updateNeedSend();
} }
onChangeArtist(value: any): void { onChangeArtist(value: any): void {
this.artistId = value; this.artistId = value;
if(!(value === undefined || value === null)) { if(!isNullOrUndefined(value)) {
for(let iii = 0; iii < this.listArtist.length; iii++) { for(let iii = 0; iii < this.listArtist.length; iii++) {
if(this.listArtist[iii].value === value) { if(this.listArtist[iii].value === value) {
this.globalArtist = this.listArtist[iii].label; this.globalArtist = this.listArtist[iii].label;
@ -290,25 +273,24 @@ export class UploadScene implements OnInit {
clearData() { clearData() {
this.globalGender = null; this.globalGender = null;
this.globalArtist = ''; this.globalArtist = null;
this.globalAlbum = null; this.globalAlbum = null;
this.parsedElement = []; this.parsedElement = [];
this.parsedFailedElement = []; this.parsedFailedElement = [];
this.listFileInBdd = null; this.listFileInBdd = undefined;
this.genderId = null; this.genderId = undefined;
this.artistId = null; this.artistId = undefined;
this.saisonId = null; this.albumId = undefined;
//this.listGender = [ { value: null, label: '---' } ]; //this.listGender = [ { value: null, label: '---' } ];
this.listArtist = [ { value: null, label: '---' } ];
this.listAlbum = [ { value: null, label: '---' } ]; this.listAlbum = [ { value: null, label: '---' } ];
} }
addFileWithMetaData(file: File) { addFileWithMetaData(file: File) {
// parsedElement: FileParsedElement[] = []; // parsedElement: FileParsedElement[] = [];
let artist: string = null; let artist: string = undefined;
let album: string | null = null; let album: string | null = undefined;
let trackIdNumber: number | null = null; let trackIdNumber: number | null = undefined;
let title: string = ''; let title: string = '';
console.log(`select file ${ file.name}`); console.log(`select file ${ file.name}`);
@ -337,10 +319,10 @@ export class UploadScene implements OnInit {
title = tmpName; title = tmpName;
if(isNaN(trackIdNumber)) { if(isNaN(trackIdNumber)) {
trackIdNumber = null; trackIdNumber = undefined;
} }
// remove extention // remove extention
title = title.replace(new RegExp('\\.(mkv|MKV|Mkv|webm|WEBM|Webm|mp4)'), ''); title = title.replace(new RegExp('\\.(webm|WEBM|Webm)'), '');
let tmp = new FileParsedElement(file, artist, album, trackIdNumber, title); let tmp = new FileParsedElement(file, artist, album, trackIdNumber, title);
console.log(`==>${ JSON.stringify(tmp)}`); console.log(`==>${ JSON.stringify(tmp)}`);
// add it in the list. // add it in the list.
@ -395,16 +377,14 @@ export class UploadScene implements OnInit {
} }
console.log(`check : ${JSON.stringify(this.parsedElement[0])}`) console.log(`check : ${JSON.stringify(this.parsedElement[0])}`)
this.globalArtist = this.parsedElement[0].artist ?? ''; this.globalArtist = this.parsedElement[0].artist ?? '';
this.globalAlbum = this.parsedElement[0].album ?? null; this.globalAlbum = this.parsedElement[0].album ?? '';
this.updateNeedSend(); this.updateNeedSend();
this.artistId = null; this.artistId = undefined;
this.saisonId = null; this.albumId = undefined;
let self = this;
this.onArtist(this.globalArtist); this.onArtist(this.globalArtist);
} }
sendFile(): void { sendFile(): void {
console.log(`Send file requested ... ${ this.parsedElement.length}`); console.log(`Send file requested ... ${ this.parsedElement.length}`);
this.upload = new UploadProgress(); this.upload = new UploadProgress();
@ -437,21 +417,21 @@ export class UploadScene implements OnInit {
} }
*/ */
// add artist // add artist
if(self.globalArtist !== null) { if(!isNullOrUndefined(self.globalArtist)) {
if(self.upload.labelMediaTitle.length !== 0) { if(self.upload.labelMediaTitle.length !== 0) {
self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }:`; self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }:`;
} }
self.upload.labelMediaTitle = self.upload.labelMediaTitle + self.globalArtist; self.upload.labelMediaTitle = self.upload.labelMediaTitle + self.globalArtist;
} }
// add album // add album
if(self.globalAlbum !== null && self.globalAlbum !== undefined && self.globalAlbum.toString().length !== 0) { if(!isNullOrUndefined(self.globalAlbum) && self.globalAlbum.toString().length !== 0) {
if(self.upload.labelMediaTitle.length !== 0) { if(self.upload.labelMediaTitle.length !== 0) {
self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }-`; self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }-`;
} }
self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }s${ self.globalAlbum.toString()}`; self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }s${ self.globalAlbum.toString()}`;
} }
// add episode ID // add episode ID
if(elemnent.trackId !== null && elemnent.trackId !== undefined && elemnent.trackId.toString().length !== 0) { if(!isNullOrUndefined(elemnent.trackId) && elemnent.trackId.toString().length !== 0) {
if(self.upload.labelMediaTitle.length !== 0) { if(self.upload.labelMediaTitle.length !== 0) {
self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }-`; self.upload.labelMediaTitle = `${self.upload.labelMediaTitle }-`;
} }
@ -502,7 +482,7 @@ export class UploadScene implements OnInit {
} }
checkConcordence():void { checkConcordence():void {
if(this.parsedElement === null) { if(isNullOrUndefined(this.parsedElement)) {
return; return;
} }
// ckear checker // ckear checker
@ -510,7 +490,7 @@ export class UploadScene implements OnInit {
this.parsedElement[iii].nameDetected = false; this.parsedElement[iii].nameDetected = false;
this.parsedElement[iii].episodeDetected = false; this.parsedElement[iii].episodeDetected = false;
} }
if(this.listFileInBdd === null) { if(isNullOrUndefined(this.listFileInBdd)) {
return; return;
} }
for(let iii = 0; iii < this.listFileInBdd.length; iii++) { for(let iii = 0; iii < this.listFileInBdd.length; iii++) {
@ -533,55 +513,58 @@ export class UploadScene implements OnInit {
updateListOfTrackToCheck(): void { updateListOfTrackToCheck(): void {
// No artist ID set ==> nothing to do. // No artist ID set ==> nothing to do.
if(this.artistId === null) { if(isNullOrUndefined(this.artistId)) {
this.listFileInBdd = null; this.listFileInBdd = undefined;
return; return;
} }
let self = this; let self = this;
// no album check only the artist files. // no album check only the artist files.
if(this.globalAlbum === null) { if(isNullOrUndefined(this.globalAlbum)) {
console.error(`NO ALBUM ==> check artist ID...`);
self.artistService.getTrack(self.artistId) self.artistService.getTrack(self.artistId)
.then((response: any[]) => { .then((response: any[]) => {
self.listFileInBdd = response; self.listFileInBdd = response;
// console.log("find track: " + response.length); console.error(`find track: ${JSON.stringify(response, null, 2)}`);
// for (let iii = 0; iii<response.length; iii++) { // for (let iii = 0; iii<response.length; iii++) {
// console.log(" - " + JSON.stringify(response[iii])); // console.log(" - " + JSON.stringify(response[iii]));
// } // }
self.checkConcordence(); self.checkConcordence();
}).catch((response) => { }).catch((response) => {
self.listFileInBdd = null; self.listFileInBdd = undefined;
}); });
return; return;
} }
self.saisonId = null; self.albumId = undefined;
console.error(`ALBUM ==> check album values...`);
// set 1 find the ID of the album: // set 1 find the ID of the album:
this.artistService.getAlbum(this.artistId) this.artistService.getAlbum(this.artistId)
.then((response: any[]) => { .then((response: any[]) => {
// console.log("find album: " + response.length); console.log(`find album: ${JSON.stringify(response, null, 2)}`);
for(let iii = 0; iii < response.length; iii++) { for(let iii = 0; iii < response.length; iii++) {
// console.log(" - " + JSON.stringify(response[iii]) + 'compare with : ' + JSON.stringify(self.globalAlbum)); // console.log(" - " + JSON.stringify(response[iii]) + 'compare with : ' + JSON.stringify(self.globalAlbum));
if(response[iii].name === `${self.globalAlbum}`) { if(response[iii].name === `${self.globalAlbum}`) {
self.saisonId = response[iii].id; self.albumId = response[iii].id;
break; break;
} }
} }
if(self.saisonId === null) { if(isNullOrUndefined(self.albumId)) {
return; return;
} }
self.albumService.getTrack(self.saisonId) self.albumService.getTrack(self.albumId)
.then((response2: any[]) => { .then((response2: any[]) => {
self.listFileInBdd = response2; self.listFileInBdd = response2;
console.log(`find album: ${JSON.stringify(response, null, 2)}`);
// console.log("find track: " + response2.length); // console.log("find track: " + response2.length);
// for (let iii = 0; iii<response2.length; iii++) { // for (let iii = 0; iii<response2.length; iii++) {
// console.log(" - " + JSON.stringify(response2[iii])); // console.log(" - " + JSON.stringify(response2[iii]));
// } // }
self.checkConcordence(); self.checkConcordence();
}).catch((response3) => { }).catch((response3) => {
self.listFileInBdd = null; self.listFileInBdd = undefined;
}); });
}).catch((response4) => { }).catch((response4) => {
self.listFileInBdd = null; self.listFileInBdd = undefined;
}); });
} }

View File

@ -22,10 +22,10 @@ export class AlbumService extends GenericInterfaceModelDB {
/** /**
* Get all the track for a specific album * Get all the track for a specific album
* @param id - Id of the album. * @param idAlbum - Id of the album.
* @returns a promise on the list of track elements * @returns a promise on the list of track elements
*/ */
getTrack(id:number): Promise<NodeData[]> { getTrack(idAlbum:number): Promise<NodeData[]> {
let self = this; let self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
self.bdd.get('track') self.bdd.get('track')
@ -34,10 +34,10 @@ export class AlbumService extends GenericInterfaceModelDB {
{ {
check: TypeCheck.EQUAL, check: TypeCheck.EQUAL,
key: 'albumId', key: 'albumId',
value: id, value: idAlbum,
}, },
], ],
[ 'episode', 'name' ]); [ 'name' ]); // tODO : set the Id in the track ...
resolve(data); resolve(data);
}).catch((response) => { }).catch((response) => {
reject(response); reject(response);

View File

@ -24,10 +24,10 @@ export class ArtistService extends GenericInterfaceModelDB {
/** /**
* Get all the track for a specific artist * Get all the track for a specific artist
* @param id - Id of the artist. * @param idArtist - Id of the artist.
* @returns a promise on the list of track elements * @returns a promise on the list of track elements
*/ */
getTrack(id:number): Promise<NodeData[]> { getTrack(idArtist:number): Promise<NodeData[]> {
let self = this; let self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
self.bdd.get('track') self.bdd.get('track')
@ -36,7 +36,7 @@ export class ArtistService extends GenericInterfaceModelDB {
{ {
check: TypeCheck.EQUAL, check: TypeCheck.EQUAL,
key: 'artistId', key: 'artistId',
value: id, value: idArtist,
}, { }, {
check: TypeCheck.EQUAL, check: TypeCheck.EQUAL,
key: 'albumId', key: 'albumId',
@ -77,37 +77,37 @@ export class ArtistService extends GenericInterfaceModelDB {
/** /**
* Get all the album of a specific artist * Get all the album of a specific artist
* @param id - ID of the artist * @param idArtist - ID of the artist
* @returns the required List. * @returns the required List.
*/ */
getAlbum(id:number): Promise<NodeData[]> { getAlbum(idArtist:number): Promise<NodeData[]> {
let self = this; let self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
self.bdd.get('track') self.bdd.get('track')
.then((response:DataInterface) => { .then((response:DataInterface) => {
//console.log(" <<<========================================>>> " + id); console.log(" <<<========================================>>> " + idArtist);
let data = response.getsWhere([ let data = response.getsWhere([
{ {
check: TypeCheck.CONTAINS, //< this is for array containing check: TypeCheck.CONTAINS, //< this is for array containing
key: 'artists', key: 'artists',
value: id, value: idArtist,
}, },
], [ 'id' ]); ], [ 'id' ]);
//console.log("==> get all tracks of the artist: " + JSON.stringify(data, null, 2)); console.log("==> get all tracks of the artist: " + JSON.stringify(data, null, 2));
// extract a single time all value "id" in an array // extract a single time all value "id" in an array
const listTrack = DataInterface.extractLimitOne(data, "id"); const listAlbumId = DataInterface.extractLimitOne(data, "albumId");
//console.log("==> List Of ids: " + JSON.stringify(listTrack, null, 2)); console.log("==> List Of ids: " + JSON.stringify(listAlbumId, null, 2));
self.bdd.get('album') self.bdd.get('album')
.then((response:DataInterface) => { .then((response:DataInterface) => {
let dataAlbum = response.getsWhere([ let dataAlbum = response.getsWhere([
{ {
check: TypeCheck.CONTAINS, check: TypeCheck.EQUAL,
key: 'tracks', key: 'id',
value: listTrack, value: listAlbumId,
}, },
], [ 'name', 'id' ]); ], [ 'publication', 'name', 'id' ]);
resolve(dataAlbum); resolve(dataAlbum);
//console.log("==> get all albums: " + JSON.stringify(dataAlbum, null, 2)); console.log("==> get all albums: " + JSON.stringify(dataAlbum, null, 2));
return; return;
}).catch((response) => { }).catch((response) => {
reject(response); reject(response);

View File

@ -5,8 +5,10 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { NodeData } from 'common/model';
import { HttpWrapperService, BddService } from 'common/service'; import { HttpWrapperService, BddService } from 'common/service';
import { DataInterface, TypeCheck } from 'common/utils';
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB'; import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
@Injectable() @Injectable()
@ -25,5 +27,25 @@ export class PlaylistService extends GenericInterfaceModelDB {
// this.checkLocalBdd(); // this.checkLocalBdd();
} }
getAll(ids: number[]): Promise<NodeData[]> {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.get(self.serviceName)
.then((response: DataInterface) => {
let data = response.getsWhere([
{
check: TypeCheck.EQUAL,
key: 'id',
value: ids,
},
],
[ 'name', 'id' ]);
resolve(data);
return;
}).catch((response) => {
reject(response);
});
});
}
} }

View File

@ -9,7 +9,7 @@ import { isMedia, Media } from 'app/model';
import { NodeData } from 'common/model'; import { NodeData } from 'common/model';
import { HttpWrapperService, BddService } from 'common/service'; import { HttpWrapperService, BddService } from 'common/service';
import { isArrayOf } from 'common/utils'; import { DataInterface, isArrayOf, TypeCheck } from 'common/utils';
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB'; import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
@Injectable() @Injectable()
@ -33,6 +33,30 @@ export class TrackService extends GenericInterfaceModelDB {
}); });
}); });
} }
getWithAlbum(idAlbum: number): Promise<Media[]> {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.get(self.serviceName)
.then((response: DataInterface) => {
let data = response.getsWhere([
{
check: TypeCheck.EQUAL,
key: 'albumId',
value: idAlbum,
},
],
[ 'track', 'name', 'id' ]);
if (isArrayOf(data, isMedia)) {
resolve(data);
return;
}
reject("model is wrong !!!");
return;
}).catch((response) => {
reject(response);
});
});
}
getData(): Promise<Media[]> { getData(): Promise<Media[]> {