From 1b8f3eadee503f036fb0b54fa7ebb0a827d49a5e Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 16 Mar 2018 15:39:03 +0100 Subject: [PATCH] [webpack.ue.manage] implemented 'upd_prof' to instant-update a professor for a Cours|TD|TP --- webpack/component/ue/manage.vue | 6 ++-- webpack/data/ue.js | 64 +++++++++++++++++---------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/webpack/component/ue/manage.vue b/webpack/component/ue/manage.vue index 3cc2671..c1786e6 100644 --- a/webpack/component/ue/manage.vue +++ b/webpack/component/ue/manage.vue @@ -21,7 +21,7 @@ v-for='(c,i) in gstore.manage.cours' :data-id='c.idCours'> - @@ -55,7 +55,7 @@ data-anim-incoming='1' :data-anim-bounce='gstore.nav_anim.out?1:0'> - @@ -89,7 +89,7 @@ data-anim-incoming='1' :data-anim-bounce='gstore.nav_anim.out?1:0'> - diff --git a/webpack/data/ue.js b/webpack/data/ue.js index 62c2e73..1453a7a 100644 --- a/webpack/data/ue.js +++ b/webpack/data/ue.js @@ -591,6 +591,7 @@ gstore.add('load_ue_groups', function(code, recur=0){ for( var group of rs.groups ){ group.add_form = '-'; ( group.idProf == null ) && ( group.idProf = -1 ); + group.new_prof = group.idProf; gstore.get.manage.cours.push( group ); } @@ -618,6 +619,7 @@ gstore.add('load_ue_groups', function(code, recur=0){ for( var group of rs.groups ){ group.add_form = '-'; ( group.idProf == null ) && ( group.idProf = -1 ); + group.new_prof = group.idProf; gstore.get.manage.td.push( group ); } @@ -647,6 +649,7 @@ gstore.add('load_ue_groups', function(code, recur=0){ for( var group of rs.groups ){ group.add_form = '-'; ( group.idProf == null ) && ( group.idProf = -1 ); + group.new_prof = group.idProf; gstore.get.manage.tp.push( group ); } @@ -865,10 +868,10 @@ gstore.add('add_form', function(type, res_i){ /* (12) Manage 'prof' for Cours|TD|T{} ---------------------------------------------------------*/ /* (1) Update a prof (or unset) */ -gstore.add('upd_prof', function(type, id_res, id_form){ +gstore.add('upd_prof', function(type, res_i){ // 1. Check params types - if( isNaN(type) || isNaN(id_res) || isNaN(id_form) ) + if( isNaN(type) || isNaN(res_i) ) return; // 2. Check @type param @@ -879,38 +882,39 @@ gstore.add('upd_prof', function(type, id_res, id_form){ var res = [ 'cours', 'td', 'tp' ][type]; var resM = [ 'Cours', 'TD', 'TP' ][type]; - // 4. Request to remove formation - api.call(`PUT ue/${res}/${id_res}`, { rem_form: [id_form] }, (rs) => { + // 4. Extract @resource from @res_i + var resource = gstore.get.manage[res][res_i]; - // 4.1. Manage error + // 4- Manage unreachable resource + if( resource == null ) + return; + + // 5. Extract resource ID + var res_id = resource[`id${resM}`]; + + // 6. Extract to default value if( rs.error !== 0 || rs.updated !== true ) - return; + return ( resource.new_prof = resource.idProf ); - // 4.2. Get reference of data in gstore (if Cours, TD, TP) - var local = gstore.get.manage[res]; - - // 4.3. Unset formation to remove from view - for( var c in local ){ - - // find ressource (cours|td|tp) - if( local[c][`id${resM}`] === id_res ){ - - // search for formation index - for( var f_index in local[c].formations ){ - - // if found -> remove by index - if( local[c].formations[f_index] === id_form ){ - local[c].formations.splice(f_index, 1); - break; - } - - } - - break; - } - - } + // 9.2. Update the prof data + resource.idProf = new_prof_id; + // 9.3. Update