[DEV] generize code for model access
This commit is contained in:
parent
0eb9163fd8
commit
887763286c
@ -28,9 +28,8 @@ import { AppComponent } from './app.component';
|
|||||||
import { ErrorComponent } from '../common/error/error';
|
import { ErrorComponent } from '../common/error/error';
|
||||||
import { HomeScene, HelpScene, TypeScene, UniverseScene, SeriesScene, SeasonScene, VideoScene, SettingsScene,
|
import { HomeScene, HelpScene, TypeScene, UniverseScene, SeriesScene, SeasonScene, VideoScene, SettingsScene,
|
||||||
VideoEditScene, SeasonEditScene, SeriesEditScene } from './scene';
|
VideoEditScene, SeasonEditScene, SeriesEditScene } from './scene';
|
||||||
import { BddService, TypeService,
|
import { TypeService, DataService, UniverseService, SeriesService, SeasonService, VideoService, ArianeService } from './service';
|
||||||
DataService, UniverseService, SeriesService, SeasonService, VideoService, ArianeService } from './service';
|
import { BddService, CookiesService, HttpWrapperService, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
||||||
import { CookiesService, HttpWrapperService, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
|
||||||
import { ErrorViewerScene, SsoScene } from 'common/scene';
|
import { ErrorViewerScene, SsoScene } from 'common/scene';
|
||||||
import { UploadScene } from './scene/upload/upload';
|
import { UploadScene } from './scene/upload/upload';
|
||||||
|
|
||||||
|
@ -8,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
import { SeasonService , ArianeService, DataService} from 'app/service';
|
import { SeasonService , ArianeService, DataService} from 'app/service';
|
||||||
|
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 { isNumberFinite } from 'common/utils';
|
||||||
|
|
||||||
export interface ElementList {
|
export interface ElementList {
|
||||||
value: number;
|
value: number;
|
||||||
@ -79,9 +81,11 @@ export class SeasonEditScene implements OnInit {
|
|||||||
this.idSeason = this.arianeService.getSeasonId();
|
this.idSeason = this.arianeService.getSeasonId();
|
||||||
let self = this;
|
let self = this;
|
||||||
this.seasonService.get(this.idSeason)
|
this.seasonService.get(this.idSeason)
|
||||||
.then((response) => {
|
.then((response: NodeData) => {
|
||||||
console.log(`get response of season : ${ JSON.stringify(response, null, 2)}`);
|
console.log(`get response of season : ${ JSON.stringify(response, null, 2)}`);
|
||||||
self.numberVal = response.name;
|
if (isNumberFinite(response.name)) {
|
||||||
|
self.numberVal = response.name;
|
||||||
|
}
|
||||||
self.description = response.description;
|
self.description = response.description;
|
||||||
self.updateCoverList(response.covers);
|
self.updateCoverList(response.covers);
|
||||||
self.itemIsLoading = false;
|
self.itemIsLoading = false;
|
||||||
|
@ -12,6 +12,7 @@ import { DataService, TypeService, UniverseService, SeriesService, VideoService,
|
|||||||
import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
|
import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
|
||||||
import { NodeData } from 'common/model';
|
import { NodeData } from 'common/model';
|
||||||
import { PopInService } from 'common/service';
|
import { PopInService } from 'common/service';
|
||||||
|
import { Media } from 'app/model';
|
||||||
|
|
||||||
export interface ElementList {
|
export interface ElementList {
|
||||||
value?: number;
|
value?: number;
|
||||||
@ -200,18 +201,18 @@ export class VideoEditScene implements OnInit {
|
|||||||
console.log(`get response3 : ${ JSON.stringify(response3, null, 2)}`);
|
console.log(`get response3 : ${ JSON.stringify(response3, null, 2)}`);
|
||||||
});
|
});
|
||||||
this.videoService.get(this.idVideo)
|
this.videoService.get(this.idVideo)
|
||||||
.then((response) => {
|
.then((response: Media) => {
|
||||||
console.log(`get response of video : ${ JSON.stringify(response, null, 2)}`);
|
console.log(`get response of video : ${ JSON.stringify(response, null, 2)}`);
|
||||||
self.data.name = response.name;
|
self.data.name = response.name;
|
||||||
self.data.description = response.description;
|
self.data.description = response.description;
|
||||||
self.data.episode = response.episode;
|
self.data.episode = response.episode;
|
||||||
self.data.universeId = response.universId;
|
self.data.universeId = response.universeId;
|
||||||
if(self.data.universeId === undefined) {
|
if(self.data.universeId === undefined) {
|
||||||
self.data.universeId = null;
|
self.data.universeId = null;
|
||||||
}
|
}
|
||||||
self.data.dataId = response.dataId;
|
self.data.dataId = response.dataId;
|
||||||
self.data.time = response.time;
|
self.data.time = response.time;
|
||||||
self.data.generatedName = response.generatedName;
|
self.data.generatedName = "????????? TODO ????????? "; // response.generatedName;
|
||||||
self.onChangeType(response.typeId);
|
self.onChangeType(response.typeId);
|
||||||
self.onChangeSeries(response.seriesId);
|
self.onChangeSeries(response.seriesId);
|
||||||
self.data.seasonId = response.seasonId;
|
self.data.seasonId = response.seasonId;
|
||||||
|
@ -206,7 +206,7 @@ export class VideoScene implements OnInit {
|
|||||||
self.seasonId = response.seasonId;
|
self.seasonId = response.seasonId;
|
||||||
self.dataId = response.dataId;
|
self.dataId = response.dataId;
|
||||||
self.time = response.time;
|
self.time = response.time;
|
||||||
self.generatedName = response.generatedName;
|
self.generatedName = "????????? TODO: ???????" //response.generatedName;
|
||||||
if(self.dataId !== -1) {
|
if(self.dataId !== -1) {
|
||||||
self.videoSource = self.httpService.createRESTCall2({
|
self.videoSource = self.httpService.createRESTCall2({
|
||||||
api: `data/${ self.dataId}/${self.generatedName}`,
|
api: `data/${ self.dataId}/${self.generatedName}`,
|
||||||
|
96
front/src/app/service/GenericInterfaceModelDB.ts
Normal file
96
front/src/app/service/GenericInterfaceModelDB.ts
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import { NodeData } from "common/model";
|
||||||
|
import { HttpWrapperService, BddService } from "common/service";
|
||||||
|
import { DataInterface, isNullOrUndefined } from "common/utils";
|
||||||
|
|
||||||
|
export class GenericInterfaceModelDB {
|
||||||
|
constructor(
|
||||||
|
protected serviceName:string,
|
||||||
|
protected http: HttpWrapperService,
|
||||||
|
protected bdd: BddService) {
|
||||||
|
// nothing to do ...
|
||||||
|
}
|
||||||
|
|
||||||
|
get(id:number): Promise<NodeData> {
|
||||||
|
let self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
self.bdd.get(self.serviceName)
|
||||||
|
.then((response: DataInterface) => {
|
||||||
|
let data = response.get(id);
|
||||||
|
if(isNullOrUndefined(data)) {
|
||||||
|
reject('Data does not exist in the local BDD');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(data);
|
||||||
|
return;
|
||||||
|
}).catch((response) => {
|
||||||
|
reject(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getData(): Promise<NodeData[]> {
|
||||||
|
let self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
self.bdd.get(self.serviceName)
|
||||||
|
.then((response:DataInterface) => {
|
||||||
|
let data = response.gets();
|
||||||
|
resolve(data);
|
||||||
|
}).catch((response) => {
|
||||||
|
console.log(`[E] ${ self.constructor.name }: can not retrive BDD values`);
|
||||||
|
reject(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
put(id:number, data:any):any {
|
||||||
|
let ret = this.http.putSpecific([this.serviceName, id], data);
|
||||||
|
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(id:number):any {
|
||||||
|
let ret = this.http.deleteSpecific([this.serviceName, id]);
|
||||||
|
return this.bdd.delete(this.serviceName, id, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteCover(nodeId:number, coverId:number) {
|
||||||
|
let self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
self.http.getSpecific([this.serviceName, nodeId, 'rm_cover', coverId])
|
||||||
|
.then((response) => {
|
||||||
|
let data = response;
|
||||||
|
if(data === null || data === undefined) {
|
||||||
|
reject('error retrive data from server');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
||||||
|
resolve(data);
|
||||||
|
}).catch((response) => {
|
||||||
|
reject(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
uploadCover(file:File,
|
||||||
|
nodeId:number,
|
||||||
|
progress:any = null) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('fileName', file.name);
|
||||||
|
formData.append('id', nodeId.toString());
|
||||||
|
formData.append('file', file);
|
||||||
|
let self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
self.http.uploadMultipart(`${this.serviceName }/${nodeId}/add_cover/`, formData, progress)
|
||||||
|
.then((response) => {
|
||||||
|
let data = response;
|
||||||
|
if(data === null || data === undefined) {
|
||||||
|
reject('error retrive data from server');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
||||||
|
resolve(data);
|
||||||
|
}).catch((response) => {
|
||||||
|
reject(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@ import { SeriesService } from './series';
|
|||||||
import { SeasonService } from './season';
|
import { SeasonService } from './season';
|
||||||
import { VideoService } from './video';
|
import { VideoService } from './video';
|
||||||
import { environment } from 'environments/environment';
|
import { environment } from 'environments/environment';
|
||||||
|
import { NodeData } from 'common/model';
|
||||||
|
|
||||||
export class InputOrders {
|
export class InputOrders {
|
||||||
public typeId: number = null;
|
public typeId: number = null;
|
||||||
@ -51,7 +52,7 @@ export class ArianeService {
|
|||||||
private seriesService: SeriesService,
|
private seriesService: SeriesService,
|
||||||
private seasonService: SeasonService,
|
private seasonService: SeasonService,
|
||||||
private videoService: VideoService) {
|
private videoService: VideoService) {
|
||||||
console.log('Start ArianeService');
|
//console.log('Start ArianeService');
|
||||||
}
|
}
|
||||||
updateParams(params) {
|
updateParams(params) {
|
||||||
console.log(`sparams ${ params}`);
|
console.log(`sparams ${ params}`);
|
||||||
@ -205,8 +206,8 @@ export class ArianeService {
|
|||||||
}
|
}
|
||||||
let self = this;
|
let self = this;
|
||||||
this.universeService.get(id)
|
this.universeService.get(id)
|
||||||
.then((response) => {
|
.then((response: NodeData) => {
|
||||||
self.universeName = response.number;
|
self.universeName = response.name;
|
||||||
self.universeChange.emit(self.universeId);
|
self.universeChange.emit(self.universeId);
|
||||||
}).catch((response) => {
|
}).catch((response) => {
|
||||||
self.universeChange.emit(self.universeId);
|
self.universeChange.emit(self.universeId);
|
||||||
@ -234,7 +235,7 @@ export class ArianeService {
|
|||||||
}
|
}
|
||||||
let self = this;
|
let self = this;
|
||||||
this.seriesService.get(id)
|
this.seriesService.get(id)
|
||||||
.then((response) => {
|
.then((response: NodeData) => {
|
||||||
self.seriesName = response.name;
|
self.seriesName = response.name;
|
||||||
self.seriesChange.emit(self.seriesId);
|
self.seriesChange.emit(self.seriesId);
|
||||||
}).catch((response) => {
|
}).catch((response) => {
|
||||||
@ -263,7 +264,7 @@ export class ArianeService {
|
|||||||
}
|
}
|
||||||
let self = this;
|
let self = this;
|
||||||
this.seasonService.get(id)
|
this.seasonService.get(id)
|
||||||
.then((response) => {
|
.then((response: NodeData) => {
|
||||||
// self.setSeries(response.seriesId);
|
// self.setSeries(response.seriesId);
|
||||||
self.seasonName = response.name;
|
self.seasonName = response.name;
|
||||||
self.seasonChange.emit(self.seasonId);
|
self.seasonChange.emit(self.seasonId);
|
||||||
|
@ -26,11 +26,6 @@ export class DataService {
|
|||||||
return this.http.getSpecific([this.serviceName, _id]);
|
return this.http.getSpecific([this.serviceName, _id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendFile(_file:File) {
|
|
||||||
// return this.http.uploadFileMultipart(this.serviceName, null, _file);
|
|
||||||
return this.http.uploadFileBase64(this.serviceName, null, _file);
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadFile(_form:FormData, _progress:any = null) {
|
uploadFile(_form:FormData, _progress:any = null) {
|
||||||
// return this.http.uploadFileMultipart(this.serviceName, null, _file);
|
// return this.http.uploadFileMultipart(this.serviceName, null, _file);
|
||||||
return this.http.uploadMultipart(`${this.serviceName }/upload/`, _form, _progress);
|
return this.http.uploadMultipart(`${this.serviceName }/upload/`, _form, _progress);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ArianeService } from "./ariane";
|
import { ArianeService } from "./ariane";
|
||||||
import { BddService } from "./bdd";
|
|
||||||
import { DataService } from "./data";
|
import { DataService } from "./data";
|
||||||
import { SeasonService } from "./season";
|
import { SeasonService } from "./season";
|
||||||
import { SeriesService } from "./series";
|
import { SeriesService } from "./series";
|
||||||
@ -11,7 +10,6 @@ import { VideoService } from "./video";
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
ArianeService,
|
ArianeService,
|
||||||
BddService,
|
|
||||||
DataService,
|
DataService,
|
||||||
SeasonService,
|
SeasonService,
|
||||||
SeriesService,
|
SeriesService,
|
||||||
|
@ -5,50 +5,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { NodeData } from 'common/model';
|
||||||
|
|
||||||
import { HttpWrapperService } from '../../common/service/http-wrapper';
|
import { HttpWrapperService, BddService } from 'common/service';
|
||||||
import { DataInterface } from 'common/utils';
|
import { DataInterface, TypeCheck } from 'common/utils';
|
||||||
import { BddService } from './bdd';
|
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||||
import { TypeCheck } from 'common/utils/dataInterface';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SeasonService {
|
export class SeasonService extends GenericInterfaceModelDB {
|
||||||
private serviceName:string = 'season';
|
|
||||||
|
constructor(http: HttpWrapperService,
|
||||||
constructor(private http: HttpWrapperService,
|
bdd: BddService) {
|
||||||
private bdd: BddService) {
|
super('season', http, bdd);
|
||||||
console.log('Start SeasonService');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
get(id:number):any {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getSeason()
|
|
||||||
.then((response: DataInterface) => {
|
|
||||||
let data = response.get(id);
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('Data does not exist in the local BDD');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the video for a specific season
|
* Get all the video for a specific season
|
||||||
* @param id - Id of the season.
|
* @param id - Id of the season.
|
||||||
* @returns a promise on the list of season elements
|
* @returns a promise on the list of video elements
|
||||||
*/
|
*/
|
||||||
getVideo(id:number):any {
|
getVideo(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
// let data = response.getsWhere([["==", "seasonId", id]], ["id", "name", "episode"], ["episode", "name"])
|
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
check: TypeCheck.EQUAL,
|
check: TypeCheck.EQUAL,
|
||||||
@ -69,73 +49,23 @@ export class SeasonService {
|
|||||||
* @param id - Id of the season.
|
* @param id - Id of the season.
|
||||||
* @returns The number of element present in this saison
|
* @returns The number of element present in this saison
|
||||||
*/
|
*/
|
||||||
countVideo(id:number):any {
|
countVideo(id:number): Promise<number> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
// let data = response.getsWhere([["==", "seasonId", _id]], ["id", "name", "episode"], ["episode", "name"])
|
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
check: TypeCheck.EQUAL,
|
check: TypeCheck.EQUAL,
|
||||||
key: 'seasonId',
|
key: 'seasonId',
|
||||||
value: id,
|
value: id,
|
||||||
} ] );
|
},
|
||||||
|
]);
|
||||||
resolve(data.length);
|
resolve(data.length);
|
||||||
}).catch((response) => {
|
}).catch((response) => {
|
||||||
reject(response);
|
reject(response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
put(id:number, data:any):any {
|
|
||||||
let ret = this.http.putSpecific([this.serviceName, id], data);
|
|
||||||
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id:number):any {
|
|
||||||
let ret = this.http.deleteSpecific([this.serviceName, id]);
|
|
||||||
return this.bdd.delete(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
deleteCover(nodeId:number,
|
|
||||||
coverId:number) {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.getSpecific([this.serviceName, nodeId, 'rm_cover', coverId])
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadCover(file:File,
|
|
||||||
nodeId:number,
|
|
||||||
progress:any = null) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('fileName', file.name);
|
|
||||||
formData.append('nodeId', nodeId.toString());
|
|
||||||
formData.append('file', file);
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.uploadMultipart(`${this.serviceName }/${ nodeId }/add_cover/`, formData, progress)
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,58 +6,25 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { HttpWrapperService } from '../../common/service/http-wrapper';
|
import { HttpWrapperService, BddService } from 'common/service';
|
||||||
import { DataInterface, TypeCheck } from 'common/utils/dataInterface';
|
import { DataInterface, TypeCheck, isArrayOf } from 'common/utils';
|
||||||
import { BddService } from './bdd';
|
|
||||||
import { isNodeData, NodeData } from 'common/model';
|
import { isNodeData, NodeData } from 'common/model';
|
||||||
import { isArrayOf, isNullOrUndefined } from 'common/utils';
|
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SeriesService {
|
export class SeriesService extends GenericInterfaceModelDB {
|
||||||
private serviceName:string = 'series';
|
|
||||||
|
|
||||||
constructor(private http: HttpWrapperService,
|
constructor(http: HttpWrapperService,
|
||||||
private bdd: BddService) {
|
bdd: BddService) {
|
||||||
console.log('Start SeriesService');
|
super('series', http, bdd);
|
||||||
}
|
|
||||||
|
|
||||||
get(id:number): Promise<NodeData> {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getSeries()
|
|
||||||
.then((response:DataInterface) => {
|
|
||||||
let data = response.get(id);
|
|
||||||
if(isNullOrUndefined(data)) {
|
|
||||||
reject('Data does not exist in the local BDD');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(data);
|
|
||||||
return;
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getData(): Promise<NodeData[]> {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getSeries()
|
|
||||||
.then((response:DataInterface) => {
|
|
||||||
let data = response.gets();
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
console.log(`[E] ${ self.constructor.name }: can not retrive BDD values`);
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrder(): Promise<NodeData[]> {
|
getOrder(): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getSeries()
|
self.bdd.get(self.serviceName)
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -78,11 +45,16 @@ export class SeriesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getVideo(id:number):Promise<NodeData[]> {
|
/**
|
||||||
|
* Get all the video for a specific series
|
||||||
|
* @param id - Id of the series.
|
||||||
|
* @returns a promise on the list of video elements
|
||||||
|
*/
|
||||||
|
getVideo(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response:DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
check: TypeCheck.EQUAL,
|
check: TypeCheck.EQUAL,
|
||||||
@ -101,10 +73,16 @@ export class SeriesService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of video in this series ID
|
||||||
|
* @param id - Id of the series.
|
||||||
|
* @returns The number of video present in this series
|
||||||
|
*/
|
||||||
countVideo(id:number): Promise<number> {
|
countVideo(id:number): Promise<number> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response:DataInterface) => {
|
.then((response:DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -128,7 +106,7 @@ export class SeriesService {
|
|||||||
getSeason(id:number): Promise<NodeData[]> {
|
getSeason(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getSeason()
|
self.bdd.get('season')
|
||||||
.then((response:DataInterface) => {
|
.then((response:DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -145,20 +123,10 @@ export class SeriesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
put(id:number, data:any):any {
|
|
||||||
let ret = this.http.putSpecific([this.serviceName, id], data);
|
|
||||||
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id:number):any {
|
|
||||||
let ret = this.http.deleteSpecific([this.serviceName, id]);
|
|
||||||
return this.bdd.delete(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
getLike(nameSeries:string):any {
|
getLike(nameSeries:string):any {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getSeries()
|
self.bdd.get('series')
|
||||||
.then((response:DataInterface) => {
|
.then((response:DataInterface) => {
|
||||||
let data = response.getNameLike(nameSeries);
|
let data = response.getNameLike(nameSeries);
|
||||||
if(data === null || data === undefined || data.length === 0) {
|
if(data === null || data === undefined || data.length === 0) {
|
||||||
@ -172,46 +140,5 @@ export class SeriesService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
deleteCover(nodeId:number,
|
|
||||||
coverId:number) {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.getSpecific([this.serviceName, nodeId, 'rm_cover', coverId])
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadCover(file:File,
|
|
||||||
nodeId:number,
|
|
||||||
progress:any = null) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('fileName', file.name);
|
|
||||||
formData.append('nodeId', nodeId.toString());
|
|
||||||
formData.append('file', file);
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.uploadMultipart(`${this.serviceName }/${nodeId}/add_cover/`, formData, progress)
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,10 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { HttpWrapperService } from '../../common/service/http-wrapper';
|
import { HttpWrapperService, BddService } from 'common/service';
|
||||||
import { BddService } from './bdd';
|
import { DataInterface, isNullOrUndefined, TypeCheck } from 'common/utils';
|
||||||
import { DataInterface, isNullOrUndefined } from 'common/utils';
|
|
||||||
import { NodeData } from 'common/model';
|
import { NodeData } from 'common/model';
|
||||||
import { TypeCheck } from 'common/utils/dataInterface';
|
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||||
|
|
||||||
export interface MessageLogIn {
|
export interface MessageLogIn {
|
||||||
id: number;
|
id: number;
|
||||||
@ -19,34 +18,20 @@ export interface MessageLogIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TypeService {
|
export class TypeService extends GenericInterfaceModelDB {
|
||||||
|
|
||||||
constructor(private http: HttpWrapperService,
|
constructor(http: HttpWrapperService,
|
||||||
private bdd: BddService) {
|
bdd: BddService) {
|
||||||
console.log('Start TypeService');
|
super('type', http, bdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getData(): Promise<NodeData[]> {
|
get(id:number): Promise<NodeData> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getType()
|
self.bdd.get(self.serviceName)
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.gets();
|
let data = response.get(id);
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
console.log(`[E] ${ self.constructor.name }: can not retrive BDD values`);
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get(_id:number): Promise<NodeData> {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getType()
|
|
||||||
.then((response: DataInterface) => {
|
|
||||||
let data = response.get(_id);
|
|
||||||
if(isNullOrUndefined(data)) {
|
if(isNullOrUndefined(data)) {
|
||||||
reject('Data does not exist in the local BDD');
|
reject('Data does not exist in the local BDD');
|
||||||
return;
|
return;
|
||||||
@ -58,10 +43,29 @@ export class TypeService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getData(): Promise<NodeData[]> {
|
||||||
|
let self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
self.bdd.get(self.serviceName)
|
||||||
|
.then((response: DataInterface) => {
|
||||||
|
let data = response.gets();
|
||||||
|
resolve(data);
|
||||||
|
}).catch((response) => {
|
||||||
|
console.log(`[E] ${ self.constructor.name }: can not retrive BDD values`);
|
||||||
|
reject(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
countVideo(id:number): Promise<number> {
|
countVideo(id:number): Promise<number> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -79,7 +83,7 @@ export class TypeService {
|
|||||||
getSubVideo(id:number): Promise<NodeData[]> {
|
getSubVideo(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -106,7 +110,7 @@ export class TypeService {
|
|||||||
getSubSeries(id:number): Promise<NodeData[]> {
|
getSubSeries(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getSeries()
|
self.bdd.get('series')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
@ -125,7 +129,7 @@ export class TypeService {
|
|||||||
getSubUniverse(id:number): Promise<NodeData[]> {
|
getSubUniverse(id:number): Promise<NodeData[]> {
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.getVideo()
|
self.bdd.get('video')
|
||||||
.then((response: DataInterface) => {
|
.then((response: DataInterface) => {
|
||||||
let data = response.getsWhere([
|
let data = response.getsWhere([
|
||||||
{
|
{
|
||||||
|
@ -6,48 +6,15 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { HttpWrapperService } from '../../common/service/http-wrapper';
|
import { HttpWrapperService, BddService } from 'common/service';
|
||||||
import { BddService } from './bdd';
|
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UniverseService {
|
export class UniverseService extends GenericInterfaceModelDB {
|
||||||
// 0: Not hide password; 1 hide password;
|
|
||||||
private identificationVersion: number = 1;
|
|
||||||
private serviceName:string = 'universe';
|
|
||||||
|
|
||||||
constructor(private http: HttpWrapperService,
|
constructor(http: HttpWrapperService,
|
||||||
private bdd: BddService) {
|
bdd: BddService) {
|
||||||
console.log('Start universeService');
|
super('universe', http, bdd);
|
||||||
}
|
|
||||||
|
|
||||||
getData():any {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getUniverse()
|
|
||||||
.then((response) => {
|
|
||||||
let data = response.gets();
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get(id:number):any {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.bdd.getUniverse()
|
|
||||||
.then((response) => {
|
|
||||||
let data = response.get(id);
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('Data does not exist in the local BDD');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSubSeries(id:number, select:Array<string> = []):any {
|
getSubSeries(id:number, select:Array<string> = []):any {
|
||||||
@ -58,50 +25,5 @@ export class UniverseService {
|
|||||||
// this.checkLocalBdd();
|
// this.checkLocalBdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
put(id:number, data:any):any {
|
|
||||||
let ret = this.http.putSpecific([this.serviceName, id], data);
|
|
||||||
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
deleteCover(nodeId:number,
|
|
||||||
coverId:number) {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.getSpecific([this.serviceName, nodeId, 'rm_cover', coverId])
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadCover(file:File,
|
|
||||||
nodeId:number,
|
|
||||||
progress:any = null) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('fileName', file.name);
|
|
||||||
formData.append('nodeId', nodeId.toString());
|
|
||||||
formData.append('file', file);
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.uploadMultipart(`${this.serviceName }/${ nodeId }/add_cover/`, formData, progress)
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, nodeId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,46 +5,50 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { isMedia, Media } from 'app/model';
|
||||||
|
import { NodeData } from 'common/model';
|
||||||
|
|
||||||
import { HttpWrapperService } from '../../common/service/http-wrapper';
|
import { HttpWrapperService, BddService } from 'common/service';
|
||||||
import { BddService } from './bdd';
|
import { isArrayOf } from 'common/utils';
|
||||||
import { DataInterface } from 'common/utils/dataInterface';
|
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VideoService {
|
export class VideoService extends GenericInterfaceModelDB {
|
||||||
private serviceName:string = 'video';
|
|
||||||
|
|
||||||
constructor(private http: HttpWrapperService,
|
constructor(http: HttpWrapperService,
|
||||||
private bdd: BddService) {
|
bdd: BddService) {
|
||||||
console.log('Start VideoService');
|
super('video', http, bdd);
|
||||||
}
|
}
|
||||||
|
get(id:number): Promise<Media> {
|
||||||
get(id:number):any {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
self.bdd.get(this.serviceName)
|
super.get(id).then((data: NodeData) => {
|
||||||
.then((response: DataInterface) => {
|
if (isMedia(data)) {
|
||||||
let data = response.get(id);
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('Data does not exist in the local BDD');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}).catch((response) => {
|
return;
|
||||||
reject(response);
|
}
|
||||||
});
|
reject("model is wrong !!!")
|
||||||
|
return
|
||||||
|
}).catch((reason:any) => {
|
||||||
|
reject(reason);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
put(id:number, data:any):any {
|
getData(): Promise<Media[]> {
|
||||||
let ret = this.http.putSpecific([this.serviceName, id], data);
|
return new Promise((resolve, reject) => {
|
||||||
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
super.getData().then((data: NodeData[]) => {
|
||||||
|
if (isArrayOf(data, isMedia)) {
|
||||||
|
resolve(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reject("model is wrong !!!")
|
||||||
|
return
|
||||||
|
}).catch((reason:any) => {
|
||||||
|
reject(reason);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
delete(id:number):any {
|
|
||||||
let ret = this.http.deleteSpecific([this.serviceName, id]);
|
|
||||||
return this.bdd.delete(this.serviceName, id, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadFile(file:File,
|
uploadFile(file:File,
|
||||||
universe?:string,
|
universe?:string,
|
||||||
series?:string,
|
series?:string,
|
||||||
@ -86,47 +90,6 @@ export class VideoService {
|
|||||||
return this.http.uploadMultipart(`${this.serviceName }/upload/`, formData, progress);
|
return this.http.uploadMultipart(`${this.serviceName }/upload/`, formData, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCover(mediaId:number,
|
|
||||||
coverId:number) {
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.getSpecific([this.serviceName, mediaId, 'rm_cover', coverId])
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, mediaId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadCover(file:File,
|
|
||||||
mediaId:number,
|
|
||||||
progress:any = null) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('fileName', file.name);
|
|
||||||
formData.append('id', mediaId.toString());
|
|
||||||
formData.append('file', file);
|
|
||||||
let self = this;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
self.http.uploadMultipart(`${this.serviceName }/${ mediaId }/add_cover/`, formData, progress)
|
|
||||||
.then((response) => {
|
|
||||||
let data = response;
|
|
||||||
if(data === null || data === undefined) {
|
|
||||||
reject('error retrive data from server');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.bdd.asyncSetInDB(self.serviceName, mediaId, data);
|
|
||||||
resolve(data);
|
|
||||||
}).catch((response) => {
|
|
||||||
reject(response);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadCoverBlob(blob:Blob,
|
uploadCoverBlob(blob:Blob,
|
||||||
mediaId:number,
|
mediaId:number,
|
||||||
progress:any = null) {
|
progress:any = null) {
|
||||||
|
@ -6,26 +6,15 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpWrapperService } from 'common/service/http-wrapper';
|
import { HttpWrapperService } from 'common/service/http-wrapper';
|
||||||
|
import { isNullOrUndefined } from 'common/utils';
|
||||||
import { DataInterface } from 'common/utils/dataInterface';
|
import { DataInterface } from 'common/utils/dataInterface';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BddService {
|
export class BddService {
|
||||||
private bdd = {
|
private bdd = {};
|
||||||
type: null,
|
private bddPomise = {};
|
||||||
series: null,
|
private baseLocalStorageName = 'bdd_';
|
||||||
season: null,
|
|
||||||
universe: null,
|
|
||||||
video: null
|
|
||||||
};
|
|
||||||
private bddPomise = {
|
|
||||||
type: null,
|
|
||||||
series: null,
|
|
||||||
season: null,
|
|
||||||
universe: null,
|
|
||||||
video: null
|
|
||||||
};
|
|
||||||
private baseLocalStorageName = 'yota_karideo_bdd_';
|
|
||||||
private useLocalStorage = false; // we exceed the limit of 5MB
|
private useLocalStorage = false; // we exceed the limit of 5MB
|
||||||
|
|
||||||
constructor(private http: HttpWrapperService) {
|
constructor(private http: HttpWrapperService) {
|
||||||
@ -80,17 +69,13 @@ export class BddService {
|
|||||||
get(name: string): Promise<DataInterface> {
|
get(name: string): Promise<DataInterface> {
|
||||||
let self = this;
|
let self = this;
|
||||||
console.log(`Try to get DB '${ name }'`);
|
console.log(`Try to get DB '${ name }'`);
|
||||||
if(this.bdd[name] === undefined) {
|
if( !isNullOrUndefined(this.bdd[name]) ) {
|
||||||
console.log(`Try to get a non existant DB ... '${ name }'`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.bdd[name] !== null) {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve(self.bdd[name]);
|
resolve(self.bdd[name]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(`get DB: ?? ${ name } ??`);
|
console.log(`get DB: ?? ${ name } ??`);
|
||||||
if(this.bddPomise[name] === null) {
|
if(isNullOrUndefined(this.bddPomise[name])) {
|
||||||
this.bddPomise[name] = [];
|
this.bddPomise[name] = [];
|
||||||
// Try to load Local Data (storage)
|
// Try to load Local Data (storage)
|
||||||
let retriveBDDString = null;
|
let retriveBDDString = null;
|
||||||
@ -142,32 +127,12 @@ export class BddService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(self.bdd[name] !== null) {
|
if(!isNullOrUndefined(self.bdd[name])) {
|
||||||
resolve(self.bdd[name]);
|
resolve(self.bdd[name]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.bddPomise[name].push({ resolve: resolve, reject: reject });
|
self.bddPomise[name].push({ resolve: resolve, reject: reject });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getType(): Promise<DataInterface> {
|
|
||||||
return this.get('type');
|
|
||||||
}
|
|
||||||
|
|
||||||
getSeries(): Promise<DataInterface> {
|
|
||||||
return this.get('series');
|
|
||||||
}
|
|
||||||
|
|
||||||
getSeason(): Promise<DataInterface> {
|
|
||||||
return this.get('season');
|
|
||||||
}
|
|
||||||
|
|
||||||
getUniverse(): Promise<DataInterface> {
|
|
||||||
return this.get('universe');
|
|
||||||
}
|
|
||||||
|
|
||||||
getVideo(): Promise<DataInterface> {
|
|
||||||
return this.get('video');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
|
|||||||
import { environment } from 'environments/environment';
|
import { environment } from 'environments/environment';
|
||||||
|
|
||||||
import { SessionService } from './session';
|
import { SessionService } from './session';
|
||||||
import { isArrayOf, isArrayOfs, isBoolean, isNullOrUndefined, isNumber, isString } from 'common/utils';
|
import { isArrayOfs, isBoolean, isNullOrUndefined, isNumber, isString } from 'common/utils';
|
||||||
|
|
||||||
export enum HTTPRequestModel {
|
export enum HTTPRequestModel {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
@ -230,7 +230,7 @@ export class HttpWrapperService {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
// Deprecated ... old model stream
|
||||||
post(uriRest:string, headerOption:any, data:any, progress:ProgressCallback = null) {
|
post(uriRest:string, headerOption:any, data:any, progress:ProgressCallback = null) {
|
||||||
console.log(`-------------------------------------------------------\nHTTP-wrapper POST '${ uriRest }'\n\t\theaderOption=${ JSON.stringify(headerOption, null, 2)}\n\t\tdata=${ JSON.stringify(data, null, 2)}`);
|
console.log(`-------------------------------------------------------\nHTTP-wrapper POST '${ uriRest }'\n\t\theaderOption=${ JSON.stringify(headerOption, null, 2)}\n\t\tdata=${ JSON.stringify(data, null, 2)}`);
|
||||||
this.addTokenIfNeeded(headerOption);
|
this.addTokenIfNeeded(headerOption);
|
||||||
@ -286,265 +286,9 @@ export class HttpWrapperService {
|
|||||||
}
|
}
|
||||||
reject({ status:error.status, data:error.error });
|
reject({ status:error.status, data:error.error });
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
switch (event.type) {
|
|
||||||
|
|
||||||
case HttpEventType.UploadProgress:
|
|
||||||
const progress = Math.round(100 * event.loaded / event.total);
|
|
||||||
return { status: 'progress', message: progress };
|
|
||||||
|
|
||||||
case HttpEventType.Response:
|
|
||||||
return event.body;
|
|
||||||
default:
|
|
||||||
return `Unhandled event: ${event.type}`;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
putwwww(uriRest:string, headerOption:any, data:any) {
|
|
||||||
console.log(`-------------------------------------------------------\nHTTP-wrapper PUT '${ uriRest }'\n\t\theaderOption=${ JSON.stringify(headerOption, null, 2)}\n\t\tdata=${ JSON.stringify(data, null, 2)}`);
|
|
||||||
this.addTokenIfNeeded(headerOption);
|
|
||||||
let connectionAdresse = this.createRESTCall(uriRest, {});
|
|
||||||
const httpOption = {
|
|
||||||
headers: new HttpHeaders(headerOption)
|
|
||||||
};
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if(this.displayReturn === true) {
|
|
||||||
console.log(`call POST ${ connectionAdresse } data=${ JSON.stringify(data, null, 2)}`);
|
|
||||||
}
|
|
||||||
let request = this.http.put<any>(connectionAdresse, data, httpOption);
|
|
||||||
let self = this;
|
|
||||||
request.subscribe((res: any) => {
|
|
||||||
if(self.displayReturn === true) {
|
|
||||||
console.log(`!! data ${ JSON.stringify(res, null, 2)}`);
|
|
||||||
}
|
|
||||||
if(res) {
|
|
||||||
if(res.httpCode) {
|
|
||||||
resolve({ status:res.httpCode, data:res });
|
|
||||||
} else {
|
|
||||||
resolve({ status:200, data:res });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolve({ status:200, data:'' });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
if(self.displayReturn === true) {
|
|
||||||
console.log(`an error occured status: ${ error.status}`);
|
|
||||||
console.log(`answer: ${ JSON.stringify(error, null, 2)}`);
|
|
||||||
}
|
|
||||||
reject({ status:error.status, data:error.error });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(uriRest:string, headerOption:any) {
|
|
||||||
this.addTokenIfNeeded(headerOption);
|
|
||||||
let connectionAdresse = this.createRESTCall(uriRest, {});
|
|
||||||
const httpOption = {
|
|
||||||
headers: new HttpHeaders(headerOption)
|
|
||||||
};
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if(this.displayReturn === true) {
|
|
||||||
console.log(`call POST ${ connectionAdresse}`);
|
|
||||||
}
|
|
||||||
let request = this.http.delete<any>(connectionAdresse, httpOption);
|
|
||||||
let self = this;
|
|
||||||
request.subscribe((res: any) => {
|
|
||||||
if(self.displayReturn === true) {
|
|
||||||
console.log(`!! data ${ JSON.stringify(res, null, 2)}`);
|
|
||||||
}
|
|
||||||
if(res) {
|
|
||||||
if(res.httpCode) {
|
|
||||||
resolve({ status:res.httpCode, data:res });
|
|
||||||
} else {
|
|
||||||
resolve({ status:200, data:res });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolve({ status:200, data:'' });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
if(self.displayReturn === true) {
|
|
||||||
console.log(`an error occured status: ${ error.status}`);
|
|
||||||
console.log(`answer: ${ JSON.stringify(error, null, 2)}`);
|
|
||||||
}
|
|
||||||
reject({ status:error.status, data:error.error });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadFileMultipart(base:string, id:number, file:File): any {
|
|
||||||
console.log(`Upload file to ${ base}`);
|
|
||||||
|
|
||||||
let url = base;
|
|
||||||
if(id !== null) {
|
|
||||||
url = `${url }/${ id}`;
|
|
||||||
}
|
|
||||||
let formData = new FormData();
|
|
||||||
formData.append('upload', file);
|
|
||||||
let headers = new Headers();
|
|
||||||
console.log(`upload filename : ${ file.name}`);
|
|
||||||
let extention = file.name.split('.').pop();
|
|
||||||
if(extention === 'jpg') {
|
|
||||||
headers.append('Content-Type', 'image/jpeg');
|
|
||||||
} else if(extention === 'png') {
|
|
||||||
headers.append('Content-Type', 'image/png');
|
|
||||||
} else if(extention === 'mkv') {
|
|
||||||
headers.append('Content-Type', 'video/x-matroska');
|
|
||||||
} else if(extention === 'webm') {
|
|
||||||
headers.append('Content-Type', 'video/webm');
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
headers.append('filename', file.name);
|
|
||||||
|
|
||||||
const httpOption = {
|
|
||||||
headers: headers,
|
|
||||||
reportProgress: true,
|
|
||||||
};
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.post(url, httpOption, formData)
|
|
||||||
.then((response: any) => {
|
|
||||||
console.log(`URL: ${ url }\nRespond(${ response.status }): ${ JSON.stringify(response.data, null, 2)}`);
|
|
||||||
if(response.status === 200) {
|
|
||||||
resolve(response.data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
reject('An error occured');
|
|
||||||
}, (response: any) => {
|
|
||||||
if(typeof response.data === 'undefined') {
|
|
||||||
reject('return ERROR undefined');
|
|
||||||
} else {
|
|
||||||
reject(`return ERROR ${ JSON.stringify(response.data, null, 2)}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadFileBase64(base:string, id:number, file:File): any {
|
|
||||||
console.log(`Upload file to ${ base}`);
|
|
||||||
|
|
||||||
let url = base;
|
|
||||||
if(id !== null) {
|
|
||||||
url = `${url }/${ id}`;
|
|
||||||
}
|
|
||||||
let self = this;
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.readAsArrayBuffer(file);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
reader.onload = () => {
|
|
||||||
let headers:any = {};// new Headers();
|
|
||||||
console.log(`upload filename : ${ file.name}`);
|
|
||||||
let extention = file.name.split('.').pop();
|
|
||||||
if(extention === 'jpg') {
|
|
||||||
// headers.append('Content-Type', "image/jpeg");
|
|
||||||
headers['Content-Type'] = 'image/jpeg';
|
|
||||||
headers['mime-type'] = 'image/jpeg';
|
|
||||||
} else if(extention === 'jpeg') {
|
|
||||||
// headers.append('Content-Type', "image/jpeg");
|
|
||||||
headers['Content-Type'] = 'image/jpeg';
|
|
||||||
headers['mime-type'] = 'image/jpeg';
|
|
||||||
} else if(extention === 'webp') {
|
|
||||||
// headers.append('Content-Type', "image/webp");
|
|
||||||
headers['Content-Type'] = 'image/webp';
|
|
||||||
headers['mime-type'] = 'image/webp';
|
|
||||||
} else if(extention === 'png') {
|
|
||||||
// headers.append('Content-Type', "image/png");
|
|
||||||
headers['Content-Type'] = 'image/png';
|
|
||||||
headers['mime-type'] = 'image/png';
|
|
||||||
} else if(extention === 'mkv') {
|
|
||||||
headers['Content-Type'] = 'video/x-matroska';
|
|
||||||
headers['mime-type'] = 'video/x-matroska';
|
|
||||||
} else if(extention === 'webm') {
|
|
||||||
headers['Content-Type'] = 'video/webm';
|
|
||||||
headers['mime-type'] = 'video/webm';
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// headers.append('filename', file.name);
|
|
||||||
headers.filename = file.name;
|
|
||||||
|
|
||||||
self.post(url, headers, reader.result)
|
|
||||||
.then((response: any) => {
|
|
||||||
console.log(`URL: ${ url }\nRespond(${ response.status }): ${ JSON.stringify(response.data, null, 2)}`);
|
|
||||||
if(response.status === 200) {
|
|
||||||
resolve(response.data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
reject('An error occured');
|
|
||||||
}, (response: any) => {
|
|
||||||
if(typeof response.data === 'undefined') {
|
|
||||||
reject('return ERROR undefined');
|
|
||||||
} else {
|
|
||||||
reject('return ERROR ...');// + JSON.stringify(response, null, 2));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
uploadFile(base:string, file:File): any {
|
|
||||||
console.log(`Upload file to ${ base}`);
|
|
||||||
|
|
||||||
let url = base;
|
|
||||||
let self = this;
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.readAsArrayBuffer(file);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
reader.onload = () => {
|
|
||||||
let headers: any = {};// new Headers();
|
|
||||||
console.log(`upload filename : ${ file.name}`);
|
|
||||||
let extention = file.name.split('.').pop();
|
|
||||||
if(extention === 'jpg') {
|
|
||||||
// headers.append('Content-Type', "image/jpeg");
|
|
||||||
headers['Content-Type'] = 'image/jpeg';
|
|
||||||
headers['mime-type'] = 'image/jpeg';
|
|
||||||
} else if(extention === 'jpeg') {
|
|
||||||
// headers.append('Content-Type', "image/jpeg");
|
|
||||||
headers['Content-Type'] = 'image/jpeg';
|
|
||||||
headers['mime-type'] = 'image/jpeg';
|
|
||||||
} else if(extention === 'webp') {
|
|
||||||
// headers.append('Content-Type', "image/webp");
|
|
||||||
headers['Content-Type'] = 'image/webp';
|
|
||||||
headers['mime-type'] = 'image/webp';
|
|
||||||
} else if(extention === 'png') {
|
|
||||||
// headers.append('Content-Type', "image/png");
|
|
||||||
headers['Content-Type'] = 'image/png';
|
|
||||||
headers['mime-type'] = 'image/png';
|
|
||||||
} else if(extention === 'mkv') {
|
|
||||||
headers['Content-Type'] = 'video/x-matroska';
|
|
||||||
headers['mime-type'] = 'video/x-matroska';
|
|
||||||
} else if(extention === 'webm') {
|
|
||||||
headers['Content-Type'] = 'video/webm';
|
|
||||||
headers['mime-type'] = 'video/webm';
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// headers.append('filename', file.name);
|
|
||||||
headers.filename = file.name;
|
|
||||||
|
|
||||||
self.post(url, headers, reader.result)
|
|
||||||
.then((response: any) => {
|
|
||||||
console.log(`URL: ${ url }\nRespond(${ response.status }): ${ JSON.stringify(response.data, null, 2)}`);
|
|
||||||
if(response.status === 200) {
|
|
||||||
resolve(response.data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
reject('An error occured');
|
|
||||||
}, (response: any) => {
|
|
||||||
if(typeof response.data === 'undefined') {
|
|
||||||
reject('return ERROR undefined');
|
|
||||||
} else {
|
|
||||||
reject('return ERROR ...');// + JSON.stringify(response, null, 2));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Deprecated ... old model stream
|
||||||
uploadMultipart(base:string, multipart:FormData, progress: ProgressCallback): any {
|
uploadMultipart(base:string, multipart:FormData, progress: ProgressCallback): any {
|
||||||
console.log(`Upload multipart to ${ base}`);
|
console.log(`Upload multipart to ${ base}`);
|
||||||
|
|
||||||
@ -599,8 +343,7 @@ export class HttpWrapperService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complex wrapper to simplify interaction:
|
// Complex wrapper to simplify interaction:s
|
||||||
//// TODO change thje base and ID to manage a single [] ...
|
|
||||||
putSpecific(urlPath: UrlPath, data: object):Promise<ModelResponseHttp> {
|
putSpecific(urlPath: UrlPath, data: object):Promise<ModelResponseHttp> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.request({
|
this.request({
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { BddService } from "./bdd";
|
||||||
import { CookiesService } from "./cookies";
|
import { CookiesService } from "./cookies";
|
||||||
import { HttpWrapperService, ModelResponseHttp, HTTPRequest, HTTPMimeType, HTTPRequestModel } from "./http-wrapper";
|
import { HttpWrapperService, ModelResponseHttp, HTTPRequest, HTTPMimeType, HTTPRequestModel } from "./http-wrapper";
|
||||||
import { StorageService } from "./local-storage";
|
import { StorageService } from "./local-storage";
|
||||||
@ -7,6 +8,7 @@ import { SSOService } from "./sso";
|
|||||||
import { UserService } from "./user";
|
import { UserService } from "./user";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
BddService,
|
||||||
CookiesService,
|
CookiesService,
|
||||||
StorageService,
|
StorageService,
|
||||||
HttpWrapperService,
|
HttpWrapperService,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import { DataInterface } from "./dataInterface";
|
import { DataInterface, TypeCheck } from "./dataInterface";
|
||||||
import { isArray, isArrayOf, isBoolean, isNull, isNullOrUndefined, isNumber, isNumberFinite, isObject, isOptionalOf, isOptionalArrayOf, isString, isUndefined, isArrayOfs } from "./validator";
|
import { isArray, isArrayOf, isBoolean, isNull, isNullOrUndefined, isNumber, isNumberFinite, isObject, isOptionalOf, isOptionalArrayOf, isString, isUndefined, isArrayOfs } from "./validator";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -18,5 +18,6 @@ export {
|
|||||||
isOptionalOf,
|
isOptionalOf,
|
||||||
isOptionalArrayOf,
|
isOptionalArrayOf,
|
||||||
DataInterface,
|
DataInterface,
|
||||||
|
TypeCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user