[DEV] update upload

This commit is contained in:
Edouard DUPIN 2020-12-06 22:48:21 +01:00
parent 2b8d170383
commit f060c47a24
6 changed files with 122 additions and 71 deletions

View File

@ -38,27 +38,16 @@
<div *ngIf="mediaFile != null" class="fill-all">
<div class="request_raw">
<div class="label">
*Type:
Type:
</div>
<div class="input">
<div class="input" element.value>
<select [ngModel]="type_id"
(ngModelChange)="onChangeType($event)">
(ngModelChange)="onChangeType($event)"
[class.error]="type_id == null">
<option *ngFor="let element of listType" [ngValue]="element.value">{{element.label}}</option>
</select>
</div>
</div>
<div class="request_raw">
<div class="label">
*Title:
</div>
<div class="input">
<input type="text"
placeholder="Name of the Media"
[value]="parse_title"
(input)="onTitle($event.target.value)"
/>
</div>
</div>
<div class="request_raw">
<div class="label">
Universe:
@ -71,6 +60,7 @@
/>
</div>
</div>
<div class="request_raw">
<div class="label">
Series:
@ -84,10 +74,10 @@
</div>
</div>
<div class="request_raw">
<div class="label">
<div class="label label2">
==&gt;
</div>
<div class="input">
<div class="input input2">
<select [ngModel]="series_id"
(ngModelChange)="onChangeSeries($event)">
<option *ngFor="let element of listSeries" [ngValue]="element.value">{{element.label}}</option>
@ -125,8 +115,20 @@
/>
</div>
</div>
<div class="request_raw">
<div class="label">
Title:
</div>
<div class="input">
<input type="text"
placeholder="Name of the Media"
[value]="parse_title"
(input)="onTitle($event.target.value)"
[class.error]="parse_title == ''"
/>
</div>
</div>
<div class="clear"></div>
<div class="send_value">
<button class="button fill-x color-button-validate color-shadow-black"
[disabled]="!need_send"

View File

@ -65,6 +65,16 @@ d.fill-all{
width: 100%;
font-size: 20px;
}
.error {
border-color: rgba(200,0,0,1.0);
background-color: rgba(256,220,220,1.0);
}
}
.label2 {
width: 20%;
}
.input2 {
width: 70%;
}
.input_add {
width: 5%;

View File

@ -47,8 +47,8 @@ export class UploadScene implements OnInit {
mediaFile: File = null;
upload_file_value: string = ""
selectedFiles: FileList;
type_id: number = undefined
series_id: number = undefined
type_id: number = null
series_id: number = null
need_send: boolean = false;
covers_display: Array<any> = [];
@ -59,16 +59,15 @@ export class UploadScene implements OnInit {
listType: ElementList[] = [
{ value: undefined, label: '---' },
{ value: null, label: '---' },
];
listUniverse: ElementList[] = [
{ value: undefined, label: '---' },
{ value: null, label: '---' },
];
listSeries: ElementList[] = [
{ value: undefined, label: '---' },
{ value: null, label: '---' },
];
listSeries2 = [{ id: undefined, description: '---' }];
listSeries2 = [{ id: null, description: '---' }];
/*
config = {
displayKey: "label", // if objects array passed which key to be displayed defaults to description
@ -89,7 +88,7 @@ export class UploadScene implements OnInit {
searchOnKey: 'description', // key on which search should be performed this will be selective search. if undefined this will be extensive search on all keys
}
listSeason: ElementList[] = [
{ value: undefined, label: '---' },
{ value: null, label: '---' },
];
parse_universe: string = "";
parse_series: string = "";
@ -119,7 +118,7 @@ export class UploadScene implements OnInit {
if (this.parse_title === undefined || this.parse_title === null || this.parse_title === "") {
this.need_send = false;
}
if (this.type_id === undefined) {
if (this.type_id === undefined || this.type_id === null) {
this.need_send = false;
}
return this.need_send;
@ -129,10 +128,10 @@ export class UploadScene implements OnInit {
this.arianeService.updateManual(this.route.snapshot.paramMap);
this.id_video = this.arianeService.getVideoId();
let self = this;
this.listType = [{ value: undefined, label: '---' }];
this.listUniverse = [{ value: undefined, label: '---' }];
this.listSeries = [{ value: undefined, label: '---' }];
this.listSeason = [{ value: undefined, label: '---' }];
this.listType = [{ value: null, label: '---' }];
this.listUniverse = [{ value: null, label: '---' }];
this.listSeries = [{ value: null, label: '---' }];
this.listSeason = [{ value: null, label: '---' }];
this.universeService.getData()
.then(function (response2) {
for (let iii = 0; iii < response2.length; iii++) {
@ -150,6 +149,7 @@ export class UploadScene implements OnInit {
console.log("get response22 : " + JSON.stringify(response2, null, 2));
});
//this.seriesService.getOrder()
/*
this.seriesService.getData()
.then(function (response3) {
for (let iii = 0; iii < response3.length; iii++) {
@ -159,6 +159,7 @@ export class UploadScene implements OnInit {
}).catch(function (response3) {
console.log("get response3 : " + JSON.stringify(response3, null, 2));
});
*/
/*
this.videoService.get(this.id_video)
.then(function (response) {
@ -199,16 +200,22 @@ export class UploadScene implements OnInit {
}
onChangeType (_value: any): void {
this.series_id = null;
this.updateType (_value);
}
private updateType (_value: any): void {
console.log("Change requested of type ... " + _value);
if (this.type_id == _value) {
return;
}
this.type_id = _value;
//this.data.series_id = null;
//this.data.season_id = null;
//this.listSeries = [{value: undefined, label: '---'}];
//this.listSeason = [{value: undefined, label: '---'}];
this.listSeries = [{value: null, label: '---'}];
this.listSeason = [{value: null, label: '---'}];
let self = this;
this.updateNeedSend();
/*
if (this.type_id != undefined) {
if (this.type_id != null) {
self.typeService.getSubSeries(this.type_id, ["id", "name"])
.then(function(response2) {
for(let iii= 0; iii < response2.length; iii++) {
@ -218,7 +225,6 @@ export class UploadScene implements OnInit {
console.log("get response22 : " + JSON.stringify(response2, null, 2));
});
}
*/
}
onChangeSeries (_value: any): void {
@ -237,6 +243,7 @@ export class UploadScene implements OnInit {
}
onSeason (_value: any): void {
this.parse_season = _value;
//console.log("change episode ID: " + _value + " ==> " + this.parse_season.toString());
this.updateNeedSend();
}
@ -251,7 +258,8 @@ export class UploadScene implements OnInit {
}
onEpisode (_value: any): void {
this.parse_episode = parseInt(_value.value, 10);
this.parse_episode = _value;
//console.log("change episode ID: " + _value + " ==> " + this.parse_episode.toString());
this.updateNeedSend();
}
onSeries (_value: any): void {
@ -259,9 +267,16 @@ export class UploadScene implements OnInit {
let self = this;
if (this.parse_series != "") {
this.seriesService.getLike(this.parse_series)
.then(function(response) {
console.log("find elemet: " + response.name + " " + response.id);
self.series_id = response.id;
.then(function(response: any[]) {
console.log("find element: " + response.length);
for (let iii = 0; iii<response.length; iii++) {
console.log(" - " + JSON.stringify(response[iii]));
}
if (response.length == 0) {
self.series_id = null;
} else if (response.length == 1) {
self.series_id = response[0].id;
}
}).catch(function(response) {
console.log("CAN NOT find element: " );
self.series_id = null;
@ -289,16 +304,26 @@ export class UploadScene implements OnInit {
_event.preventDefault();
}
// At the file input element
// (change)="selectFile($event)"
onChangeFile (_value: any): void {
clearData() {
this.parse_universe = "";
this.parse_series = "";
this.parse_season = null;
this.parse_episode = null;
this.parse_title = "";
this.selectedFiles = _value.files
this.type_id = null;
this.series_id = null;
this.listSeries = [{value: null, label: '---'}];
this.listSeason = [{value: null, label: '---'}];
}
// At the file input element
// (change)="selectFile($event)"
onChangeFile (_value: any): void {
this.selectedFiles = _value.files;
this.mediaFile = this.selectedFiles[0];
this.clearData();
console.log("select file " + this.mediaFile.name);
const splitElement = this.mediaFile.name.split('-');
if (splitElement.length == 1) {
@ -348,24 +373,31 @@ export class UploadScene implements OnInit {
}
}
// remove extention
this.parse_title = this.parse_title.replace(new RegExp("\.(mkv|MKV|Mkv|webm|WEBM|Webm)"),"");
//this.uploadFile(this.coverFile);
this.parse_title = this.parse_title.replace(new RegExp("\.(mkv|MKV|Mkv|webm|WEBM|Webm|mp4)"),"");
this.updateNeedSend();
this.series_id = null;
let self = this;
if (this.parse_series != "") {
this.seriesService.getLike(this.parse_series)
.then(function(response) {
console.log("find elemet: " + response.name + " " + response.id);
self.series_id = response.id;
.then(function(response: any[]) {
console.log("find element: " + response.length);
for (let iii = 0; iii<response.length; iii++) {
console.log(" - " + JSON.stringify(response[iii]));
}
if (response.length == 0) {
self.series_id = null;
} else if (response.length == 1) {
let serie_elem = response[0];
self.series_id = serie_elem.id;
self.updateType(serie_elem.parent_id);
}
}).catch(function(response) {
console.log("CAN NOT find element: " );
});
}
}
uploadFile (_file: File) {
if (_file == undefined) {
console.log("No file selected!");
@ -381,25 +413,25 @@ export class UploadScene implements OnInit {
*/
this.upload = new UploadProgress();
// add universe
if (this.parse_universe != null) {
if (this.parse_universe !== null) {
this.upload.labelMediaTitle += this.parse_universe;
}
// add series
if (this.parse_series != null) {
if (this.parse_series !== null) {
if (this.upload.labelMediaTitle.length != 0) {
this.upload.labelMediaTitle += "/";
}
this.upload.labelMediaTitle += this.parse_series;
}
// add season
if (this.parse_season != null) {
if (this.parse_season !== null && this.parse_season !== undefined && this.parse_season.toString().length != 0) {
if (this.upload.labelMediaTitle.length != 0) {
this.upload.labelMediaTitle += "-";
}
this.upload.labelMediaTitle += "s" + this.parse_season.toString();
}
// add episode ID
if (this.parse_episode != null) {
if (this.parse_episode !== null && this.parse_episode !== undefined && this.parse_episode.toString().length != 0) {
if (this.upload.labelMediaTitle.length != 0) {
this.upload.labelMediaTitle += "-";
}
@ -412,9 +444,11 @@ export class UploadScene implements OnInit {
this.upload.labelMediaTitle += this.parse_title;
// display the upload pop-in
this.popInService.open("popin-upload-progress");
this.videoService.uploadFile(_file,
this.parse_universe,
this.parse_series,
this.series_id,
this.parse_season,
this.parse_episode,
this.parse_title,

View File

@ -13,7 +13,7 @@ export class DataInterface {
private name: string;
private bdd: any;
constructor(_name, _data) {
constructor(_name:string, _data:any) {
this.name = _name;
this.bdd = _data;
}
@ -66,15 +66,13 @@ export class DataInterface {
}
return out;
}
getNameLike(_name: string){
let out = undefined;
getNameLike(_name: string): any[] {
let out = [];
let nameLower = _name.toLowerCase();
for (let iii=0; iii<this.bdd.length; iii++) {
//console.log("compare '" + _name + "' ??? '" + this.bdd[iii]['name'] + "'");
if (this.bdd[iii]['name'] == _name) {
return this.bdd[iii];
} else if (this.bdd[iii]['name'].toLowerCase() == nameLower) {
out = this.bdd[iii];
if (this.bdd[iii]['name'].toLowerCase() == nameLower) {
out.push(this.bdd[iii]);
}
}
return out;

View File

@ -19,7 +19,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getSeries()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.get(_id);
if (data === null || data === undefined) {
reject("Data does not exist in the local BDD");
@ -37,7 +37,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getSeries()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.gets();
resolve(data);
}).catch(function(response) {
@ -51,7 +51,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getSeries()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.gets_where([["!=", "id", null]], ["id", "name"], ["name","id"])
resolve(data);
}).catch(function(response) {
@ -69,7 +69,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getVideo()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.gets_where([["==", "series_id", _id], ["==", "season_id", null]], undefined, ["episode", "name"])
resolve(data);
}).catch(function(response) {
@ -81,7 +81,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getVideo()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.gets_where([["==", "series_id", _id]], undefined, undefined)
resolve(data.length);
}).catch(function(response) {
@ -94,7 +94,7 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getSeason()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.gets_where([["==", "parent_id", _id]], ["id"], ["number"])
if (_select.length == 0) {
resolve(data);
@ -131,9 +131,9 @@ export class SeriesService {
let self = this;
return new Promise((resolve, reject) => {
self.bdd.getSeries()
.then(function(response) {
.then(function(response:DataInterface) {
let data = response.getNameLike(_nameSeries);
if (data === null || data === undefined) {
if (data === null || data === undefined || data.length === 0 ) {
reject("Data does not exist in the local BDD");
return;
}

View File

@ -52,6 +52,7 @@ export class VideoService {
uploadFile(_file:File,
_universe:string,
_series:string,
_series_id:number,
_season:number,
_episode:number,
_title:string,
@ -59,7 +60,14 @@ export class VideoService {
_progress:any = null) {
const formData = new FormData();
formData.append('file_name', _file.name);
// set the file at hte begining it will permit to abort the transmission
formData.append('file', _file);
formData.append('universe', _universe);
if (_series_id != null) {
formData.append('series_id', _series_id.toString());
} else {
formData.append('series_id', null);
}
formData.append('series', _series);
if (_season != null) {
formData.append('season', _season.toString());
@ -79,7 +87,6 @@ export class VideoService {
} else {
formData.append('type_id', null);
}
formData.append('file', _file);
return this.http.uploadMultipart(this.serviceName + "/upload/", formData, _progress);
}