From 766db280f937108f45995907a9771acbe5603c6e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 15 Jan 2020 00:00:40 +0100 Subject: [PATCH] [DEV] integrate update of video properties --- back/src/api/group.py | 17 ++- back/src/api/saison.py | 2 +- back/src/api/type.py | 18 ++- back/src/api/univers.py | 8 +- back/src/api/video.py | 4 +- back/src/data_interface.py | 15 +- .../src/app/scene/video-edit/video-edit.html | 30 ++-- front/src/app/scene/video-edit/video-edit.ts | 131 ++++++++++++------ front/src/app/service/group.service.ts | 37 +---- front/src/app/service/http-wrapper.service.ts | 113 +++++++++++++++ front/src/app/service/saison.service.ts | 32 +---- front/src/app/service/type.service.ts | 129 ++--------------- front/src/app/service/univers.service.ts | 99 +------------ front/src/app/service/video.service.ts | 32 +---- 14 files changed, 302 insertions(+), 365 deletions(-) diff --git a/back/src/api/group.py b/back/src/api/group.py index 8859784..e8de7ed 100644 --- a/back/src/api/group.py +++ b/back/src/api/group.py @@ -104,17 +104,24 @@ def add(_app, _name_api): @doc.description("List all the videos availlable for this group tht does not depend on saison.") @doc.produces(content_type='application/json') async def retrive_saison(request, id): - value = data_global_elements.get_interface(data_global_elements.API_SAISON).gets_where(select=[["==", "group_id", id]], filter=["id"]) - if value != None: - return response.json(value) - raise ServerError("No data found", status_code=404) + list_values = data_global_elements.get_interface(data_global_elements.API_SAISON).gets_where(select=[["==", "group_id", id]], filter=["id"]) + if list_values == None: + raise ServerError("No data found", status_code=404) + if len(list_values) == 0: + return response.json(list_values) + if "select" in request.args: + if request.args["select"] == "*": + list_values = data_global_elements.get_interface(data_global_elements.API_SAISON).gets_where(select=[["==", "id", list_values]]) + else: + list_values = data_global_elements.get_interface(data_global_elements.API_SAISON).gets_where(select=[["==", "id", list_values]], filter=request.args["select"]) + return response.json(list_values) @elem_blueprint.put('/' + _name_api + '/', strict_slashes=True) @doc.summary("Update resource") @doc.description("Update the specified resource in storage.") @doc.response_success(status=201, description='If successful updated') async def update(request, id): - ret = data_global_elements.get_interface(_name_api).put(id) + ret = data_global_elements.get_interface(_name_api).put(id, request.json) return response.json({}) @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) diff --git a/back/src/api/saison.py b/back/src/api/saison.py index 37bcc4c..620e41c 100644 --- a/back/src/api/saison.py +++ b/back/src/api/saison.py @@ -97,7 +97,7 @@ def add(_app, _name_api): @doc.description("Update the specified resource in storage.") @doc.response_success(status=201, description='If successful updated') async def update(request, id): - ret = data_global_elements.get_interface(_name_api).put(id) + ret = data_global_elements.get_interface(_name_api).put(id, request.json) return response.json({}) @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) diff --git a/back/src/api/type.py b/back/src/api/type.py index e59e930..25c74f1 100644 --- a/back/src/api/type.py +++ b/back/src/api/type.py @@ -73,7 +73,7 @@ def add(_app, _name_api): @doc.description("Update the specified resource in storage.") @doc.response_success(status=201, description='If successful updated') async def update(request, id): - ret = data_global_elements.get_interface(_name_api).put(id) + ret = data_global_elements.get_interface(_name_api).put(id, request.json) return response.json({}) @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) @@ -111,6 +111,8 @@ def add(_app, _name_api): list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["==", "group_id", None], ["==", "univers_id", None]], filter=["id"]) return response.json(list_values) + ## ---------------------------------------------------------------------------------------- + ## sub list of Groups ... @elem_blueprint.get('/' + _name_api + '//group', strict_slashes=True) @doc.summary("List all group availlable.") @doc.description("List all groups availlable in this type (not depending of an univers).") @@ -119,9 +121,15 @@ def add(_app, _name_api): list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["!=", "group_id", None], ["==", "univers_id", None]], filter=["group_id"]) if len(list_values) == 0: return response.json(list_values) - list_values = data_global_elements.get_interface(data_global_elements.API_GROUP).gets_where(select=[["==", "id", list_values]], filter=["id", "name"]) + if "select" in request.args: + if request.args["select"] == "*": + list_values = data_global_elements.get_interface(data_global_elements.API_GROUP).gets_where(select=[["==", "id", list_values]]) + else: + list_values = data_global_elements.get_interface(data_global_elements.API_GROUP).gets_where(select=[["==", "id", list_values]], filter=request.args["select"]) return response.json(list_values) + ## ---------------------------------------------------------------------------------------- + ## Sub list of univers ... @elem_blueprint.get('/' + _name_api + '//univers', strict_slashes=True) @doc.summary("List all univers availlable.") @doc.description("List all univers availlable.") @@ -130,7 +138,11 @@ def add(_app, _name_api): list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["!=", "univers_id", None]], filter=["univers_id"]) if len(list_values) == 0: return response.json(list_values) - list_values = data_global_elements.get_interface(data_global_elements.API_UNIVERS).gets_where(select=[["==", "id", list_values]], filter=["id", "name"]) + if "select" in request.args: + if request.args["select"] == "*": + list_values = data_global_elements.get_interface(data_global_elements.API_UNIVERS).gets_where(select=[["==", "id", list_values]]) + else: + list_values = data_global_elements.get_interface(data_global_elements.API_UNIVERS).gets_where(select=[["==", "id", list_values]], filter=request.args["select"]) return response.json(list_values) _app.blueprint(elem_blueprint) \ No newline at end of file diff --git a/back/src/api/univers.py b/back/src/api/univers.py index c1fefc1..2ca1eba 100644 --- a/back/src/api/univers.py +++ b/back/src/api/univers.py @@ -74,7 +74,7 @@ def add(_app, _name_api): @doc.description("Update the specified resource in storage.") @doc.response_success(status=201, description='If successful updated') async def update(request, id): - ret = data_global_elements.get_interface(_name_api).put(id) + ret = data_global_elements.get_interface(_name_api).put(id, request.json) return response.json({}) @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) @@ -112,12 +112,18 @@ def add(_app, _name_api): list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id], ["==", "group_id", None], ["==", "univers_id", None]], filter=["id"]) return response.json(list_values) + ## ---------------------------------------------------------------------------------------- @elem_blueprint.get('/' + _name_api + '//group', strict_slashes=True) @doc.summary("List all group availlable.") @doc.description("List all groups availlable in this univers (not depending of an univers).") @doc.produces(content_type='application/json') async def retrive_group(request, id): list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id], ["!=", "group_id", None], ["==", "univers_id", None]], filter=["group_id"]) + if "select" in request.args: + if request.args["select"] == "*": + list_values = data_global_elements.get_interface(data_global_elements.API_GROUP).gets_where(select=[["==", "id", list_values]]) + else: + list_values = data_global_elements.get_interface(data_global_elements.API_GROUP).gets_where(select=[["==", "id", list_values]], filter=request.args["select"].split('|')) return response.json(list_values) @elem_blueprint.post('/' + _name_api + "//add_cover", strict_slashes=True) diff --git a/back/src/api/video.py b/back/src/api/video.py index 22d9562..46b45a7 100644 --- a/back/src/api/video.py +++ b/back/src/api/video.py @@ -152,8 +152,8 @@ def add(_app, _name_api): @doc.description("Update the specified resource in storage.") @doc.response_success(status=201, description='If successful updated') async def update(request, id): - ret = data_global_elements.get_interface(_name_api).put(id) - return response.json({}) + ret = data_global_elements.get_interface(_name_api).put(id, request.json) + return response.json({"update":"done"}); @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) @doc.summary("Remove resource") diff --git a/back/src/data_interface.py b/back/src/data_interface.py index 6c99a0f..6a0cac5 100644 --- a/back/src/data_interface.py +++ b/back/src/data_interface.py @@ -12,6 +12,7 @@ import tools import json from realog import debug import random +import copy from sanic.exceptions import ServerError ## ## @breif Generic interface to access to the BDD (no BDD, direct file IO) @@ -167,8 +168,16 @@ class DataInterface(): id_in_bdd = self.get_table_index(_id) if id_in_bdd == None: return False - _value["id"] = _id - self.bdd[id_in_bdd] = _value + # todo: check the model before update ... + debug.warning("update element: " + str(_id)) + value_bdd = copy.deepcopy(self.bdd[id_in_bdd]); + for elem in _value.keys(): + debug.warning(" [" + elem + "] " + str(value_bdd[elem]) + " ==> " + str(_value[elem])) + value_bdd[elem] = _value[elem] + if self.check_with_model(value_bdd) == False: + raise ServerError("FORBIDDEN Corelation with BDD error", status_code=403) + self.bdd[id_in_bdd] = value_bdd + debug.warning(" ==> " + str(self.bdd[id_in_bdd])) self.mark_to_store() return True @@ -265,6 +274,8 @@ class DataInterface(): def filter_object_values(self, _values, _filter): out = [] + if _filter == None: + return _values if len(_filter) == 1: token = _filter[0] for elem in _values: diff --git a/front/src/app/scene/video-edit/video-edit.html b/front/src/app/scene/video-edit/video-edit.html index 2338063..a7afbd7 100644 --- a/front/src/app/scene/video-edit/video-edit.html +++ b/front/src/app/scene/video-edit/video-edit.html @@ -6,8 +6,9 @@
@@ -16,7 +17,10 @@ Description:
- +
@@ -24,7 +28,9 @@ Date:
- +
@@ -32,7 +38,8 @@ Type:
-
@@ -42,7 +49,8 @@ Univers:
-
@@ -52,7 +60,8 @@ Group:
-
@@ -62,7 +71,8 @@ Saison:
-
@@ -72,7 +82,9 @@ Episode:
- +
diff --git a/front/src/app/scene/video-edit/video-edit.ts b/front/src/app/scene/video-edit/video-edit.ts index 15b6b0c..d44145f 100644 --- a/front/src/app/scene/video-edit/video-edit.ts +++ b/front/src/app/scene/video-edit/video-edit.ts @@ -15,6 +15,7 @@ import { HttpWrapperService } from '../../service/http-wrapper.service'; import { TypeService } from '../../service/type.service'; import { UniversService } from '../../service/univers.service'; +import { GroupService } from '../../service/group.service'; import { VideoService } from '../../service/video.service'; export class ElementList { @@ -49,7 +50,6 @@ export class VideoEditComponent implements OnInit { time:number = undefined type_id:number = undefined generated_name:string = "" - video_source:string = "" listType: ElementList[] = [ {value: undefined, label: '---'}, ]; @@ -68,66 +68,48 @@ export class VideoEditComponent implements OnInit { private locate: Location, private typeService: TypeService, private universService: UniversService, + private groupService: GroupService, private videoService: VideoService, private httpService: HttpWrapperService) { } - sendValues():void { - console.log("send new values...."); - } - ngOnInit() { this.id_video = parseInt(this.route.snapshot.paramMap.get('video_id')); let self = this; + this.listType = [{value: undefined, label: '---'}]; + this.listUnivers = [{value: undefined, label: '---'}]; + this.listGroup = [{value: undefined, label: '---'}]; + this.listSaison = [{value: undefined, label: '---'}]; this.universService.getData() .then(function(response2) { - self.listUnivers = [{value: undefined, label: '---'}]; for(let iii= 0; iii < response2.length; iii++) { self.listUnivers.push({value: response2[iii].id, label: response2[iii].name}); } }).catch(function(response2) { console.log("get response22 : " + JSON.stringify(response2, null, 2)); }); + this.typeService.getData() + .then(function(response2) { + for(let iii= 0; iii < response2.length; iii++) { + self.listType.push({value: response2[iii].id, label: response2[iii].name}); + } + }).catch(function(response2) { + console.log("get response22 : " + JSON.stringify(response2, null, 2)); + }); this.videoService.get(this.id_video) .then(function(response) { console.log("get response of video : " + JSON.stringify(response, null, 2)); self.name = response.name; self.description = response.description; self.episode = response.episode; - self.type_id = response.type_id; - self.typeService.getData() - .then(function(response2) { - self.listType = [{value: undefined, label: '---'}]; - for(let iii= 0; iii < response2.length; iii++) { - self.listType.push({value: response2[iii].id, label: response2[iii].name}); - } - }).catch(function(response2) { - console.log("get response22 : " + JSON.stringify(response2, null, 2)); - }); - self.saison_id = response.saison_id; - self.group_id = response.group_id; - self.listGroup = [{value: undefined, label: '---'}]; - if (response.type_id != undefined) { - self.typeService.getSubGroup(response.type_id) - .then(function(response2) { - for(let iii= 0; iii < response2.length; iii++) { - self.listGroup.push({value: response2[iii].id, label: response2[iii].name}); - } - }).catch(function(response2) { - console.log("get response22 : " + JSON.stringify(response2, null, 2)); - }); - } self.univers_id = response.univers_id; self.data_id = response.data_id; self.time = response.time; self.generated_name = response.generated_name; - if (self.data_id != -1) { - self.video_source = self.httpService.createRESTCall("data/" + self.data_id); - } else { - self.video_source = ""; - } - console.log("display source " + self.video_source); + self.onChangeType(response.type_id); + self.onChangeGroup(response.group_id); + self.saison_id = response.saison_id; //console.log("set transformed : " + JSON.stringify(self, null, 2)); }).catch(function(response) { self.error = "Can not get the data"; @@ -140,12 +122,83 @@ export class VideoEditComponent implements OnInit { self.data_id = -1; self.time = undefined; self.generated_name = ""; - self.video_source = ""; }); } - submitChange(videoForm:NgForm):void { - console.log("videoForm form display" + videoForm); - + + onChangeType(_value:any):void { + console.log("Change requested of type ... " + _value); + this.type_id = _value; + this.group_id = null; + this.saison_id = null; + this.listGroup = [{value: undefined, label: '---'}]; + this.listSaison = [{value: undefined, label: '---'}]; + let self = this; + if (this.type_id != undefined) { + self.typeService.getSubGroup(this.type_id, ["id", "name"]) + .then(function(response2) { + for(let iii= 0; iii < response2.length; iii++) { + self.listGroup.push({value: response2[iii].id, label: response2[iii].name}); + } + }).catch(function(response2) { + console.log("get response22 : " + JSON.stringify(response2, null, 2)); + }); + } + } + + onChangeUnivers(_value:any):void { + this.univers_id = _value; + } + + onChangeGroup(_value:any):void { + this.group_id = _value; + this.saison_id = null; + this.listSaison = [{value: undefined, label: '---'}]; + let self = this; + if (this.group_id != undefined) { + self.groupService.getSaison(this.group_id, ["id", "number"]) + .then(function(response3) { + for(let iii= 0; iii < response3.length; iii++) { + self.listSaison.push({value: response3[iii].id, label: "saison " + response3[iii].number}); + } + }).catch(function(response3) { + console.log("get response22 : " + JSON.stringify(response3, null, 2)); + }); + } + } + onChangeSaison(_value:any):void { + this.saison_id = _value; + } + + onName(_value:any):void { + this.name = _value; + } + + onDescription(_value:any):void { + this.description = _value; + } + + onDate(_value:any):void { + this.time = _value; + } + + onEpisode(_value:any):void { + this.episode = _value; + } + + + sendValues():void { + console.log("send new values...."); + let data = { + "name": this.name, + "description": this.description, + "episode": this.episode, + "time": this.time, + "type_id": this.type_id, + "univers_id": this.univers_id, + "group_id": this.group_id, + "saison_id": this.saison_id + }; + this.videoService.put(this.id_video, data); } } diff --git a/front/src/app/service/group.service.ts b/front/src/app/service/group.service.ts index 55ed82f..ab0171f 100644 --- a/front/src/app/service/group.service.ts +++ b/front/src/app/service/group.service.ts @@ -10,47 +10,20 @@ export class GroupService { console.log("Start GroupService"); } - get_specific(_id:number, _subElement:string = ""):any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "group/" + _id; - if (_subElement != "") { - url += "/" + _subElement; - } - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - //console.log("get data from type : " + 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)); - } - }); - }); - }; get(_id:number):any { - return this.get_specific(_id); + return this.http.get_specific("group", _id); }; getVideoAll(_id:number):any { - return this.get_specific(_id, "video_all"); + return this.http.get_specific("group", _id, "video_all"); }; getVideo(_id:number):any { - return this.get_specific(_id, "video"); + return this.http.get_specific("group", _id, "video"); }; - getSaison(_id:number):any { - return this.get_specific(_id, "saison"); + getSaison(_id:number, _select:Array = []):any { + return this.http.get_specific("group", _id, "saison", _select); }; } diff --git a/front/src/app/service/http-wrapper.service.ts b/front/src/app/service/http-wrapper.service.ts index 8c85cd6..7294404 100644 --- a/front/src/app/service/http-wrapper.service.ts +++ b/front/src/app/service/http-wrapper.service.ts @@ -103,4 +103,117 @@ export class HttpWrapperService { }); }); } + put(_uriRest:string, _headerOption:any, _data: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 + " data=" + JSON.stringify(_data, null, 2)); + } + let request = this.http.put(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}); + }); + }); + } + + // Complex wrapper to simplify interaction: + get_specific(_base:string, _id:number = null, _subElement:string = "", _select:Array = []):any { + console.log("Get All data from " + _base); + const httpOption = { 'Content-Type': 'application/json' }; + let url = _base; + if (_id != null) { + url += "/" + _id; + } + if (_subElement != "") { + url += "/" + _subElement; + } + if (_select.length != 0) { + let select = "" + for (let iii=0; iii<_select.length; iii++) { + if (select.length != 0) { + select += "&"; + } + select += "select=" + _select[iii]; + } + url += "?" + select; + } + 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)); + if (response.status == 200) { + 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)); + 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)); + } + }); + }); + }; } diff --git a/front/src/app/service/saison.service.ts b/front/src/app/service/saison.service.ts index f848515..70a6fa3 100644 --- a/front/src/app/service/saison.service.ts +++ b/front/src/app/service/saison.service.ts @@ -10,40 +10,12 @@ export class SaisonService { console.log("Start SaisonService"); } - get_specific(_id:number, _subElement:string = ""):any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "saison/" + _id; - if (_subElement != "") { - url += "/" + _subElement; - } - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - //console.log("get data from type : " + 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)); - } - }); - }); - }; - get(_id:number):any { - return this.get_specific(_id); + return this.http.get_specific("saison", _id); }; getVideo(_id:number):any { - return this.get_specific(_id, "video"); + return this.http.get_specific("saison", _id, "video"); }; } diff --git a/front/src/app/service/type.service.ts b/front/src/app/service/type.service.ts index 0e1651f..05c61f2 100644 --- a/front/src/app/service/type.service.ts +++ b/front/src/app/service/type.service.ts @@ -20,136 +20,25 @@ export class TypeService { console.log("Start TypeService"); } + getData():any { - console.log("Get All data from types"); - let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms'); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "type"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - //console.log("get data from type : " + 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)); - } - }); - }); + return this.http.get_specific("type"); }; get(_id:number):any { - console.log("Get All data from types"); - let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms'); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "type/" + _id; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); - + return this.http.get_specific("type", _id); }; - getSubGroup(_id: number):any { - console.log("Get All data from types"); - let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms'); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "type/" + _id + "/group"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); - + getSubGroup(_id:number, _select:Array = []):any { + return this.http.get_specific("type", _id, "group", _select); }; - getSubVideo(_id: number):any { - console.log("Get All data from types"); - let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms'); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "type/" + _id + "/video"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); + getSubVideo(_id:number, _select:Array = []):any { + return this.http.get_specific("type", _id, "video", _select); }; - getSubUnivers(_id: number):any { - console.log("Get All data from types"); - let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms'); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "type/" + _id + "/univers"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); + getSubUnivers(_id:number, _select:Array = []):any { + return this.http.get_specific("type", _id, "univers", _select); }; } diff --git a/front/src/app/service/univers.service.ts b/front/src/app/service/univers.service.ts index 7b645c0..1b9a7d0 100644 --- a/front/src/app/service/univers.service.ts +++ b/front/src/app/service/univers.service.ts @@ -11,106 +11,19 @@ export class UniversService { } getData():any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "univers"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - //console.log("get data from univers : " + 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)); - } - }); - }); + return this.http.get_specific("univers"); }; get(_id:number):any { - console.log("Get All data from univers"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "univers/" + _id; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); - + return this.http.get_specific("univers", _id); }; - getSubGroup(_id: number):any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "univers/" + _id + "/group"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); - + getSubGroup(_id:number, _select:Array = []):any { + return this.http.get_specific("univers", _id, "group", _select); }; - getSubVideo(_id: number):any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "univers/" + _id + "/video_no_group"; - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - console.log("get data from type : " + 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)); - } - }); - }); - + getSubVideo(_id:number, _select:Array = []):any { + return this.http.get_specific("univers", _id, "video", _select); }; } diff --git a/front/src/app/service/video.service.ts b/front/src/app/service/video.service.ts index 3e61d16..6298e23 100644 --- a/front/src/app/service/video.service.ts +++ b/front/src/app/service/video.service.ts @@ -10,35 +10,11 @@ export class VideoService { console.log("Start VideoService"); } - get_specific(_id:number, _subElement:string = ""):any { - console.log("Get All data from types"); - const httpOption = { 'Content-Type': 'application/json' }; - let url = "video/" + _id; - if (_subElement != "") { - url += "/" + _subElement; - } - console.log("call GET " + url); - - return new Promise((resolve, reject) => { - this.http.get(url, httpOption, {}) - .then(function(response: any) { - if (response.status == 200) { - resolve(response.data); - //console.log("get data from response : " + JSON.stringify(response.data, null, 2)); - 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)); - } - }); - }); - }; get(_id:number):any { - return this.get_specific(_id); + return this.http.get_specific("video", _id); + }; + put(_id:number, _data:any):any { + return this.http.put_specific("video", _id, _data); }; }