[DEV] add delete for video
This commit is contained in:
parent
2e9fc87fb5
commit
ac5707b781
@ -380,6 +380,14 @@ export class VideoEditComponent implements OnInit {
|
||||
}
|
||||
removeMedia() {
|
||||
console.log("Request remove Media...");
|
||||
this.videoService.delete(this.id_video)
|
||||
.then(function(response3) {
|
||||
//self.data_ori = tmpp;
|
||||
//self.updateNeedSend();
|
||||
}).catch(function(response3) {
|
||||
|
||||
//self.updateNeedSend();
|
||||
});
|
||||
}
|
||||
|
||||
eventPopUpSaison(_event: string): void {
|
||||
|
@ -43,6 +43,23 @@ export class BddService {
|
||||
});
|
||||
}
|
||||
|
||||
delete(_name: string, _id: number, ret: any) {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
self.get(_name)
|
||||
.then(function(response) {
|
||||
ret.then(function(response2) {
|
||||
response.delete(_id);
|
||||
resolve(response2);
|
||||
}).catch(function(response2) {
|
||||
reject(response2);
|
||||
});
|
||||
}).catch(function(response) {
|
||||
reject(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get(_name: string): any {
|
||||
let self = this;
|
||||
if (this.bdd[_name] === undefined) {
|
||||
|
@ -68,7 +68,7 @@ export class DataInterface {
|
||||
console.log("[I] delete " + this.name + " " + _id)
|
||||
for (let iii=0; iii<this.bdd.length; iii++) {
|
||||
if (this.bdd[iii]['id'] == _id) {
|
||||
this.bdd[iii] = undefined
|
||||
this.bdd.splice(iii, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,6 +138,40 @@ export class HttpWrapperService {
|
||||
});
|
||||
});
|
||||
}
|
||||
delete(_uriRest:string, _headerOption:any) {
|
||||
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);
|
||||
@ -259,12 +293,12 @@ export class HttpWrapperService {
|
||||
}
|
||||
url += "?" + select;
|
||||
}
|
||||
console.log("call GET " + url);
|
||||
//console.log("call GET " + url);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.get(url, httpOption, {})
|
||||
.then(function(response: any) {
|
||||
console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
//console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
if (response.status == 200) {
|
||||
resolve(response.data);
|
||||
return;
|
||||
@ -281,8 +315,8 @@ export class HttpWrapperService {
|
||||
};
|
||||
|
||||
// Complex wrapper to simplify interaction:
|
||||
put_specific(_base:string, _id:number, _data:any, _subElement:string = ""):any {
|
||||
console.log("put data to " + _base);
|
||||
delete_specific(_base:string, _id:number, _subElement:string = ""):any {
|
||||
//console.log("delete data to " + _base);
|
||||
const httpOption = { 'Content-Type': 'application/json' };
|
||||
let url = _base;
|
||||
if (_id != null) {
|
||||
@ -291,13 +325,49 @@ export class HttpWrapperService {
|
||||
if (_subElement != "") {
|
||||
url += "/" + _subElement;
|
||||
}
|
||||
console.log("call PUT: " + url);
|
||||
console.log(" data: " + JSON.stringify(_data, null, 2));
|
||||
//console.log("call DELETE: " + url);
|
||||
//console.log(" data: " + JSON.stringify(_data, null, 2));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.delete(url, httpOption)
|
||||
.then(function(response: any) {
|
||||
//console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
if (response.status == 200) {
|
||||
resolve(response.data);
|
||||
return;
|
||||
}
|
||||
if (response.status == 201) {
|
||||
resolve(response.data);
|
||||
return;
|
||||
}
|
||||
reject("An error occured");
|
||||
}, function(response: any) {
|
||||
if (typeof response.data === 'undefined') {
|
||||
reject("return ERROR undefined");
|
||||
} else {
|
||||
reject("return ERROR " + JSON.stringify(response.data, null, 2));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
// Complex wrapper to simplify interaction:
|
||||
put_specific(_base:string, _id:number, _data:any, _subElement:string = ""):any {
|
||||
//console.log("put data to " + _base);
|
||||
const httpOption = { 'Content-Type': 'application/json' };
|
||||
let url = _base;
|
||||
if (_id != null) {
|
||||
url += "/" + _id;
|
||||
}
|
||||
if (_subElement != "") {
|
||||
url += "/" + _subElement;
|
||||
}
|
||||
//console.log("call PUT: " + url);
|
||||
//console.log(" data: " + JSON.stringify(_data, null, 2));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.put(url, httpOption, _data)
|
||||
.then(function(response: any) {
|
||||
console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
//console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
if (response.status == 200) {
|
||||
resolve(response.data);
|
||||
return;
|
||||
@ -318,7 +388,7 @@ export class HttpWrapperService {
|
||||
};
|
||||
// Complex wrapper to simplify interaction:
|
||||
post_specific(_base:string, _id:number, _data:any, _subElement:string = ""):any {
|
||||
console.log("put data to " + _base);
|
||||
//console.log("put data to " + _base);
|
||||
const httpOption = { 'Content-Type': 'application/json' };
|
||||
let url = _base;
|
||||
if (_id != null) {
|
||||
@ -327,13 +397,13 @@ export class HttpWrapperService {
|
||||
if (_subElement != "") {
|
||||
url += "/" + _subElement;
|
||||
}
|
||||
console.log("call PUT: " + url);
|
||||
console.log(" data: " + JSON.stringify(_data, null, 2));
|
||||
//console.log("call PUT: " + url);
|
||||
//console.log(" data: " + JSON.stringify(_data, null, 2));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.post(url, httpOption, _data)
|
||||
.then(function(response: any) {
|
||||
console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
//console.log("URL: " + url + "\nRespond(" + response.status + "): " + JSON.stringify(response.data, null, 2));
|
||||
if (response.status == 200) {
|
||||
resolve(response.data);
|
||||
return;
|
||||
|
@ -39,11 +39,12 @@ export class VideoService {
|
||||
|
||||
put(_id:number, _data:any):any {
|
||||
let ret = this.http.put_specific(this.serviceName, _id, _data);
|
||||
if (environment.localBdd != true) {
|
||||
return ret;
|
||||
}
|
||||
return this.bdd.setAfterPut(this.serviceName, _id, ret);
|
||||
};
|
||||
delete(_id:number):any {
|
||||
let ret = this.http.delete_specific(this.serviceName, _id);
|
||||
return this.bdd.delete(this.serviceName, _id, ret);
|
||||
};
|
||||
addCover(_id:number, _coverId:number):any {
|
||||
return this.http.post_specific(this.serviceName, _id, {"data_id":_coverId}, "add_cover");
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user