[webpack.ue.manage] implemented 'upd_prof' to instant-update a professor for a Cours|TD|TP

This commit is contained in:
xdrm-brackets 2018-03-16 15:39:03 +01:00
parent 045ced9002
commit 1b8f3eadee
2 changed files with 37 additions and 33 deletions

View File

@ -21,7 +21,7 @@
v-for='(c,i) in gstore.manage.cours' v-for='(c,i) in gstore.manage.cours'
:data-id='c.idCours'> :data-id='c.idCours'>
<select v-model='c.idProf' @change='upd_prof(i)'> <select v-model='c.new_prof' @change='gstore.upd_prof(0, i)'>
<option value='-1' v-show='c.idProf!=-1'>Aucun enseignant affecté</option> <option value='-1' v-show='c.idProf!=-1'>Aucun enseignant affecté</option>
<option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=c.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option> <option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=c.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option>
</select> </select>
@ -55,7 +55,7 @@
data-anim-incoming='1' data-anim-incoming='1'
:data-anim-bounce='gstore.nav_anim.out?1:0'> :data-anim-bounce='gstore.nav_anim.out?1:0'>
<select v-model='td.idProf' @change='upd_prof(i)'> <select v-model='td.new_prof' @change='gstore.upd_prof(1, i)'>
<option value='-1' v-show='td.idProf!=-1'>Aucun enseignant affecté</option> <option value='-1' v-show='td.idProf!=-1'>Aucun enseignant affecté</option>
<option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=td.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option> <option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=td.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option>
</select> </select>
@ -89,7 +89,7 @@
data-anim-incoming='1' data-anim-incoming='1'
:data-anim-bounce='gstore.nav_anim.out?1:0'> :data-anim-bounce='gstore.nav_anim.out?1:0'>
<select v-model='tp.idProf' @change='upd_prof(i)'> <select v-model='tp.new_prof' @change='gstore.upd_prof(2, i)'>
<option value='-1' v-show='tp.idProf!=-1'>Aucun enseignant affecté</option> <option value='-1' v-show='tp.idProf!=-1'>Aucun enseignant affecté</option>
<option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=tp.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option> <option v-for='p in gstore.manage.prof' :value='p.idProfesseur' v-show='p.idProfesseur!=tp.idProf'>{{ `${p.firstName} ${p.lastName}` }}</option>
</select> </select>

View File

@ -591,6 +591,7 @@ gstore.add('load_ue_groups', function(code, recur=0){
for( var group of rs.groups ){ for( var group of rs.groups ){
group.add_form = '-'; group.add_form = '-';
( group.idProf == null ) && ( group.idProf = -1 ); ( group.idProf == null ) && ( group.idProf = -1 );
group.new_prof = group.idProf;
gstore.get.manage.cours.push( group ); 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 ){ for( var group of rs.groups ){
group.add_form = '-'; group.add_form = '-';
( group.idProf == null ) && ( group.idProf = -1 ); ( group.idProf == null ) && ( group.idProf = -1 );
group.new_prof = group.idProf;
gstore.get.manage.td.push( group ); 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 ){ for( var group of rs.groups ){
group.add_form = '-'; group.add_form = '-';
( group.idProf == null ) && ( group.idProf = -1 ); ( group.idProf == null ) && ( group.idProf = -1 );
group.new_prof = group.idProf;
gstore.get.manage.tp.push( group ); 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{} /* (12) Manage 'prof' for Cours|TD|T{}
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Update a prof (or unset) */ /* (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 // 1. Check params types
if( isNaN(type) || isNaN(id_res) || isNaN(id_form) ) if( isNaN(type) || isNaN(res_i) )
return; return;
// 2. Check @type param // 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 res = [ 'cours', 'td', 'tp' ][type];
var resM = [ 'Cours', 'TD', 'TP' ][type]; var resM = [ 'Cours', 'TD', 'TP' ][type];
// 4. Request to remove formation // 4. Extract @resource from @res_i
api.call(`PUT ue/${res}/${id_res}`, { rem_form: [id_form] }, (rs) => { var resource = gstore.get.manage[res][res_i];
// 4.1. Manage error // 4- Manage unreachable resource
if( rs.error !== 0 || rs.updated !== true ) if( resource == null )
return; return;
// 4.2. Get reference of data in gstore (if Cours, TD, TP) // 5. Extract resource ID
var local = gstore.get.manage[res]; var res_id = resource[`id${resM}`];
// 4.3. Unset formation to remove from view // 6. Extract <select> professor id
for( var c in local ){ var new_prof_id = resource.new_prof;
// find ressource (cours|td|tp) // 7. Exit if not a number
if( local[c][`id${resM}`] === id_res ){ if( isNaN(new_prof_id) )
return;
// search for formation index // 8. Exit if same value
for( var f_index in local[c].formations ){ if( new_prof_id == resource.idProf )
return;
// if found -> remove by index // 9. Request to add formation
if( local[c].formations[f_index] === id_form ){ api.call(`PUT ue/${res}/${res_id}`, { idProf: parseInt(new_prof_id) }, (rs) => {
local[c].formations.splice(f_index, 1);
break;
}
} // 9.1. On error -> reset <select> to default value
if( rs.error !== 0 || rs.updated !== true )
return ( resource.new_prof = resource.idProf );
break; // 9.2. Update the prof data
} resource.idProf = new_prof_id;
}
// 9.3. Update <select> VueJS if changed
resource.new_prof = new_prof_id;
}); });