From 0f57d5bd6e0ea4a26ee763043523a54bb6fd1d4b Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 15 Mar 2018 19:50:15 +0100 Subject: [PATCH] [webpack.ue.manage] can instant-remove formations (api+feedback) --- webpack/component/ue/manage.vue | 12 +++---- webpack/data/ue.js | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/webpack/component/ue/manage.vue b/webpack/component/ue/manage.vue index 8b4541f..38aeebf 100644 --- a/webpack/component/ue/manage.vue +++ b/webpack/component/ue/manage.vue @@ -27,7 +27,7 @@
{{ gstore.form_by_id(f).labelForm || '???' }} - +
@@ -38,7 +38,7 @@ v-show='c.formations.indexOf(f.idForm) < 0' :value='f.idForm'>{{ f.labelForm }} - +
@@ -58,7 +58,7 @@
{{ gstore.form_by_id(f).labelForm || '???' }} - +
@@ -69,7 +69,7 @@ v-show='td.formations.indexOf(f.idForm) < 0' :value='f.idForm'>{{ f.labelForm }} - +
@@ -89,7 +89,7 @@
{{ gstore.form_by_id(f).labelForm || '???' }} - +
@@ -100,7 +100,7 @@ v-show='tp.formations.indexOf(f.idForm) < 0' :value='f.idForm'>{{ f.labelForm }} - +
diff --git a/webpack/data/ue.js b/webpack/data/ue.js index 34bbfb2..b8ee2d5 100644 --- a/webpack/data/ue.js +++ b/webpack/data/ue.js @@ -720,3 +720,62 @@ gstore.add('manage_load', function(code, $router){ }); }) + + + + + +/* (12) Manage 'manage' formations add|rem +---------------------------------------------------------*/ +/* (1) Remove a formation */ +gstore.add('rem_form', function(type, id_res, id_form){ + + // 1. Check params types + if( isNaN(type) || isNaN(id_res) || isNaN(id_form) ) + return; + + // 2. Check @type param + if( [0,1,2].indexOf(type) == -1 ) + return; + + // 3. extract API resource from @type + 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.1. Manage error + if( rs.error !== 0 || rs.updated !== true ) + return; + + // 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; + } + + } + + + }); + + +}); \ No newline at end of file