[add detection in upload of multiple files

This commit is contained in:
Edouard DUPIN 2022-03-11 22:27:43 +01:00
parent e98fe27a94
commit 6cc5195a19
6 changed files with 175 additions and 198 deletions

2
front/.gitignore vendored
View File

@ -1 +1,3 @@
/node_modules/
/.angular/
/.idea/

View File

@ -128,6 +128,7 @@
placeholder="e?"
[value]="data.episode"
(input)="onEpisode(data, $event.target.value)"
[class.error]="data.episodeDetected == true"
/>
</td>
<td class="right-colomn" >
@ -137,6 +138,9 @@
(input)="onTitle(data, $event.target.value)"
[class.error]="data.title == ''"
/>
<span *ngIf="data.nameDetected == true" class="error">
^^^This title already exist !!!
</span>
</td>
</tr>
</tbody>
@ -152,6 +156,27 @@
</button>
</div>
<div class="clear"></div>
<div class="request_raw_table" *ngIf="this.listFileInBdd != null">
<table>
<colgroup>
<col style="width:10%">
<col style="width:70%">
<col style="width:10%">
</colgroup>
<thead>
<tr>
<th>Episode ID:</th>
<th>Episode Title:</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of this.listFileInBdd">
<td class="left-colomn" [class.error]="data.episodeDetected == true">{{data.episode}}</td>
<td class="right-colomn" [class.error]="data.nameDetected == true">{{data.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div *ngIf="this.parsedElement.length != 0" class="fill-all">
<div class="request_raw_table">
@ -169,7 +194,7 @@
</td>
</tr>
-->
<tr *ngFor="let data of this.parsedFaledElement">
<tr *ngFor="let data of this.parsedFailedElement">
<td class="left-colomn">Rejected:</td>
<td class="right-colomn">
{{data.file.name}}<br/> ==&gt; {{data.reason}}

View File

@ -1,13 +1,3 @@
d.fill-all{
//width:100%;
max-width:80%;
height:100%;
margin: 20px auto;
padding: 20px;
border:0;
background-color: rgba(200, 200, 200, 0.5);
box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.6);
}
.title {
width: 90%;
@ -16,29 +6,6 @@ d.fill-all{
text-align: center;
}
.request_raw2 {
width: 90%;
margin: 0 auto;
height: 160px;
.label {
width: 15%;
margin-right: 10px;
text-align: right;
float: left;
display: block;
}
.input {
width: 75%;
float: left;
display: block;
textarea {
width: 100%;
font-size: 20px;
resize: none;
}
}
}
.request_raw_table {
display: block;
width: 90%;
@ -78,139 +45,9 @@ d.fill-all{
background-color: rgba(256,220,220,1.0);
}
}
.request_raw {
width: 90%;
margin: 0 auto;
height: 45px;
.label {
width: 15%;
margin-right: 10px;
text-align: right;
float: left;
display: block;
}
.input2 {
width: 75%;
float: left;
display: block;
.number-input {
clear: none;
width: 75px;
font-size: 20px;
border: 0px;
}
.title-input {
width: calc(100% - 75px);
font-size: 20px;
border: 0px;
}
.error {
border-color: rgba(200,0,0,1.0);
background-color: rgba(256,220,220,1.0);
}
}
.input {
width: 75%;
float: left;
display: block;
input {
width: 100%;
font-size: 20px;
}
select {
width: 100%;
font-size: 20px;
}
textarea {
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%;
float: right;
display: block;
}
.cover_div {
float: left;
display: block;
}
.cover_remove_div {
float: left;
display: block;
}
.cover {
max-width: 30%;
}
}
.send_value {
width: 300px;
margin: 0 auto;
padding: 10px;
display: block;
}
.item {
font-size: 20px;
height: 21%;
width: 23%;
margin: 1%;
padding: 0;
overflow: hidden;
//box-shadow: 0 1px 1.5px 0 rgba(0,0,0,.12),0 1px 1px 0 rgba(0,0,0,.24);
box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.6);
line-height: normal;
border: none;
font-family: "Roboto","Helvetica","Arial",sans-serif;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0;
will-change: box-shadow;
outline: none;
cursor: pointer;
text-decoration: none;
text-align: center;
vertical-align: middle;
transition-duration: 0.4s;
float:left;
display:block;
h1 {
font-size: 24px;
}
&:hover {
background-color: #F00;
}
.material-icons {
vertical-align: middle;
}
.material-icons {
position: absolute;
top: 50%;
left: 50%;
transform: ~"translate(-12px,-12px)";
line-height: 24px;
width: 24px;
}
}
.item-video {
&:hover {
background-color: #0F0;
}
}

View File

@ -5,11 +5,8 @@
*/
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { Location } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { fadeInAnimation } from '../../_animations/index';
import { HttpWrapperService } from '../../service/http-wrapper';
import { HttpEventType, HttpResponse } from '@angular/common/http';
import { PopInService } from '../../service/popin';
@ -17,9 +14,9 @@ import { TypeService } from '../../service/type';
import { UniverseService } from '../../service/universe';
import { SeriesService } from '../../service/series';
import { VideoService } from '../../service/video';
import { DataService } from '../../service/data';
import { ArianeService } from '../../service/ariane';
import { UploadProgress } from '../../popin/upload-progress/upload-progress';
import { SeasonService } from '../../service/season';
export class ElementList {
constructor(
@ -29,7 +26,9 @@ export class ElementList {
}
}
export class FileParsedElement {
public isSended: false;
public isSended: boolean = false;
public nameDetected: boolean = false;
public episodeDetected: boolean = false;
constructor(
public file: File,
public universe: string,
@ -57,21 +56,18 @@ export class FileFailParsedElement {
})
export class UploadScene implements OnInit {
id_video: number = -1;
error: string = "";
mediaFile: File[] = null;
parsedElement: FileParsedElement[] = [];
parsedFaledElement: FileFailParsedElement[] = [];
parsedFailedElement: FileFailParsedElement[] = [];
upload_file_value: string = ""
selectedFiles: FileList;
type_id: number = null
series_id: number = null
saison_id: number = null
need_send: boolean = false;
covers_display: Array<any> = [];
// list of all files already registered in the bdd to compare with the curent list of files.
listFileInBdd: any = null;
// section tha define the upload value to display in the pop-in of upload
public upload:UploadProgress = new UploadProgress();
@ -111,21 +107,18 @@ export class UploadScene implements OnInit {
global_series: string = "";
global_season: number = null;
constructor(private route: ActivatedRoute,
private router: Router,
private locate: Location,
private dataService: DataService,
private typeService: TypeService,
private universeService: UniverseService,
private seriesService: SeriesService,
private seasonService: SeasonService,
private videoService: VideoService,
private httpService: HttpWrapperService,
private arianeService: ArianeService,
private popInService: PopInService) {
// nothing to do.
}
updateNeedSend (): boolean {
if (this.mediaFile == null) {
if (this.parsedElement.length === 0) {
this.need_send = false;
return;
}
@ -143,7 +136,6 @@ export class UploadScene implements OnInit {
ngOnInit () {
this.arianeService.updateManual(this.route.snapshot.paramMap);
this.id_video = this.arianeService.getVideoId();
let self = this;
this.listType = [{ value: null, label: '---' }];
this.listUniverse = [{ value: null, label: '---' }];
@ -172,6 +164,7 @@ export class UploadScene implements OnInit {
this.series_id = null;
this.updateType (_value);
}
private updateType (_value: any): void {
console.log("Change requested of type ... " + _value);
if (this.type_id == _value) {
@ -209,11 +202,13 @@ export class UploadScene implements OnInit {
}
}
this.updateNeedSend();
this.updateListOfVideoToCheck();
}
onSeason (_value: any): void {
this.global_season = _value;
//console.log("change episode ID: " + _value + " ==> " + this.parse_season.toString());
this.updateNeedSend();
this.updateListOfVideoToCheck();
}
onTitle (data: FileParsedElement, _value: any): void {
@ -231,6 +226,7 @@ export class UploadScene implements OnInit {
//console.log("change episode ID: " + _value + " ==> " + this.parse_episode.toString());
this.updateNeedSend();
}
onSeries (_value: any): void {
this.global_series = _value;
let self = this;
@ -246,6 +242,7 @@ export class UploadScene implements OnInit {
} else if (response.length == 1) {
self.series_id = response[0].id;
}
this.updateListOfVideoToCheck();
}).catch(function(response) {
console.log("CAN NOT find element: " );
self.series_id = null;
@ -260,10 +257,12 @@ export class UploadScene implements OnInit {
this.global_series = "";
this.global_season = null;
this.parsedElement = [];
this.parsedFaledElement = [];
this.parsedFailedElement = [];
this.listFileInBdd = null;
this.type_id = null;
this.series_id = null;
this.saison_id = null;
this.listSeries = [{value: null, label: '---'}];
this.listSeason = [{value: null, label: '---'}];
}
@ -348,13 +347,6 @@ export class UploadScene implements OnInit {
// At the file input element
// (change)="selectFile($event)"
onChangeFile (_value: any): void {
this.mediaFile = [];
for (var i = 0; i < _value.files.length; i++) {
this.mediaFile.push(_value.files[i]);
}
//console.log("get files: " + JSON.stringify(tmpFileList));
//this.selectedFiles =_value.files;
//this.mediaFile = this.selectedFiles[0];
this.clearData();
for (let iii=0; iii<_value.files.length; iii++) {
@ -370,7 +362,7 @@ export class UploadScene implements OnInit {
for (let iii=1; iii<this.parsedElement.length; iii++) {
console.log("check universe [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[0].universe + " !== " + this.parsedElement[iii].universe + "'");
if (this.parsedElement[0].universe !== this.parsedElement[iii].universe) {
this.parsedFaledElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong universe value"));
this.parsedFailedElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong universe value"));
console.log("Remove from list (!= universe) : [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[iii].file.name + "'");
this.parsedElement.splice(iii,1);
iii--;
@ -380,7 +372,7 @@ export class UploadScene implements OnInit {
for (let iii=1; iii<this.parsedElement.length; iii++) {
console.log("check series [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[0].series + " !== " + this.parsedElement[iii].series + "'");
if (this.parsedElement[0].series !== this.parsedElement[iii].series) {
this.parsedFaledElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong series value"));
this.parsedFailedElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong series value"));
console.log("Remove from list (!= series) : [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[iii].file.name + "'");
this.parsedElement.splice(iii,1);
iii--;
@ -390,7 +382,7 @@ export class UploadScene implements OnInit {
for (let iii=1; iii<this.parsedElement.length; iii++) {
console.log("check season [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[0].season + " !== " + this.parsedElement[iii].season + "'");
if (this.parsedElement[0].season !== this.parsedElement[iii].season) {
this.parsedFaledElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong season value"));
this.parsedFailedElement.push(new FileFailParsedElement(this.parsedElement[iii].file, "Remove from list due to wrong season value"));
console.log("Remove from list (!= season) : [" + (iii+1) + "/" + this.parsedElement.length + "] '" + this.parsedElement[iii].file.name + "'");
this.parsedElement.splice(iii,1);
iii--;
@ -403,6 +395,7 @@ export class UploadScene implements OnInit {
this.updateNeedSend();
this.series_id = null;
this.saison_id = null;
let self = this;
if (this.global_series != "") {
this.seriesService.getLike(this.global_series)
@ -418,14 +411,17 @@ export class UploadScene implements OnInit {
self.series_id = serie_elem.id;
self.updateType(serie_elem.parent_id);
}
self.updateListOfVideoToCheck();
}).catch(function(response) {
console.log("CAN NOT find element: " );
});
}
}
sendFile(): void {
console.log("Send file requested ... " + this.mediaFile);
console.log("Send file requested ... " + this.parsedElement.length);
this.upload = new UploadProgress();
// display the upload pop-in
this.popInService.open("popin-upload-progress");
@ -504,6 +500,108 @@ export class UploadScene implements OnInit {
});
}
public checkSimilarString(valueA:string, valueB:string): boolean {
let valueAL = valueA.toLowerCase();
let valueBL = valueB.toLowerCase();
valueAL = valueAL.replace(/[ \t\n\r-_#~@]/g, "");
valueBL = valueBL.replace(/[ \t\n\r-_#~@]/g, "");
if (valueAL == valueBL) {
return true;
}
if (valueAL.startsWith(valueBL)) {
return true;
}
if (valueBL.startsWith(valueAL)) {
return true;
}
return false;
}
checkConcordence():void {
if (this.parsedElement === null) {
return;
}
// ckear checker
for (let iii = 0; iii < this.parsedElement.length; iii++) {
this.parsedElement[iii].nameDetected = false;
this.parsedElement[iii].episodeDetected = false;
}
if (this.listFileInBdd === null) {
return;
}
for (let iii = 0; iii < this.listFileInBdd.length; iii++) {
this.listFileInBdd[iii].nameDetected = false;
this.listFileInBdd[iii].episodeDetected = false;
}
for (let iii = 0; iii < this.parsedElement.length; iii++) {
for (let jjj = 0; jjj < this.listFileInBdd.length; jjj++) {
if (this.checkSimilarString(this.parsedElement[iii].title, this.listFileInBdd[jjj].name)) {
this.parsedElement[iii].nameDetected = true;
this.listFileInBdd[jjj].nameDetected = true;
}
if (this.parsedElement[iii].episode === this.listFileInBdd[jjj].episode) {
this.parsedElement[iii].episodeDetected = true;
this.listFileInBdd[jjj].episodeDetected = true;
}
}
}
}
updateListOfVideoToCheck(): void {
// No series ID set ==> nothing to do.
if (this.series_id === null) {
this.listFileInBdd = null;
return;
}
let self = this;
// no season check only the series files.
if (this.global_season === null) {
self.seriesService.getVideo(self.series_id)
.then(function(response: any[]) {
self.listFileInBdd = response;
//console.log("find video: " + response.length);
//for (let iii = 0; iii<response.length; iii++) {
// console.log(" - " + JSON.stringify(response[iii]));
//}
self.checkConcordence();
}).catch(function(response) {
self.listFileInBdd = null;
})
return;
}
self.saison_id = null;
// set 1 find the ID of the season:
this.seriesService.getSeason(this.series_id, [ "id" , "name" ])
.then(function(response: any[]) {
//console.log("find season: " + response.length);
for (let iii = 0; iii<response.length; iii++) {
//console.log(" - " + JSON.stringify(response[iii]) + 'compare with : ' + JSON.stringify(self.global_season));
if (response[iii].name == ""+self.global_season) {
self.saison_id = response[iii].id;
break;
}
}
if (self.saison_id === null) {
return;
}
self.seasonService.getVideo(self.saison_id)
.then(function(response: any[]) {
self.listFileInBdd = response;
//console.log("find video: " + response.length);
//for (let iii = 0; iii<response.length; iii++) {
// console.log(" - " + JSON.stringify(response[iii]));
//}
self.checkConcordence();
}).catch(function(response) {
self.listFileInBdd = null;
})
}).catch(function(response) {
self.listFileInBdd = null;
});
}
eventPopUpSeason (_event: string): void {
console.log("GET event: " + _event);
this.popInService.close("popin-new-season");

View File

@ -31,6 +31,11 @@ export class SeasonService {
});
});
}
/**
* Get all the video for a specific season
* @param _id - Id of the season.
* @returns a promise on the list of season elements
*/
getVideo(_id:number):any {
let self = this;
return new Promise((resolve, reject) => {
@ -44,6 +49,11 @@ export class SeasonService {
});
});
}
/**
* Get the number of video in this saison ID
* @param _id - Id of the season.
* @returns The number of element present in this saison
*/
countVideo(_id:number):any {
let self = this;
return new Promise((resolve, reject) => {

View File

@ -89,7 +89,12 @@ export class SeriesService {
});
});
}
/**
* Get all the season of a specific series
* @param _id - ID of the series
* @param _select - Selection filter
* @returns the required List.
*/
getSeason(_id:number, _select:Array<string> = []):any {
let self = this;
return new Promise((resolve, reject) => {