[webpack.ue.manage] implemented 'upd_prof' to instant-update a professor for a Cours|TD|TP
This commit is contained in:
parent
045ced9002
commit
1b8f3eadee
|
@ -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>
|
||||||
|
|
|
@ -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( resource == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 5. Extract resource ID
|
||||||
|
var res_id = resource[`id${resM}`];
|
||||||
|
|
||||||
|
// 6. Extract <select> professor id
|
||||||
|
var new_prof_id = resource.new_prof;
|
||||||
|
|
||||||
|
// 7. Exit if not a number
|
||||||
|
if( isNaN(new_prof_id) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 8. Exit if same value
|
||||||
|
if( new_prof_id == resource.idProf )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 9. Request to add formation
|
||||||
|
api.call(`PUT ue/${res}/${res_id}`, { idProf: parseInt(new_prof_id) }, (rs) => {
|
||||||
|
|
||||||
|
// 9.1. On error -> reset <select> to default value
|
||||||
if( rs.error !== 0 || rs.updated !== true )
|
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)
|
// 9.2. Update the prof data
|
||||||
var local = gstore.get.manage[res];
|
resource.idProf = new_prof_id;
|
||||||
|
|
||||||
// 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.3. Update <select> VueJS if changed
|
||||||
|
resource.new_prof = new_prof_id;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue