[webpack.data.ue] manage page 'manage' load on nav from page 'view' + standalone with redirection if invalid 'code' in URL
This commit is contained in:
parent
d8d5c74654
commit
30940dda48
|
@ -4,17 +4,26 @@
|
|||
|
||||
<div class='list container'>
|
||||
|
||||
<!-- COURS -->
|
||||
<section
|
||||
v-for='c in gstore.manage.cours'
|
||||
data-anim-incoming='1'
|
||||
:data-anim-bounce='gstore.nav_anim.out?1:0'>
|
||||
<h1 >{{ $route.params.code }}</h1>
|
||||
|
||||
<div :data-prof='c.idProf'>{{ `${c.firstName} ${c.lastName}` || 'blabla' }}</div>
|
||||
<div>{{ c.volume }}</div>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<!-- TD -->
|
||||
|
||||
|
||||
<!-- TP -->
|
||||
|
||||
<div class='footer'>
|
||||
<button class='neutral' @click='gstore.nav_out($router)'>Retour</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -31,6 +40,9 @@
|
|||
name: 'CONTAINER_VIEW',
|
||||
data(){
|
||||
return { gstore: gstore.get }
|
||||
},
|
||||
beforeMount(){
|
||||
gstore.get.manage_load(this.$route.params.code, this.$router);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ gstore.add('ir_handler', function(ue_id){
|
|||
var gi = gstore.get.ues.map( (data, i) => { return ( data.code && data.code == ue_id ) ? i : ''; }).join('');
|
||||
|
||||
/* (2.2) Exit if not found */
|
||||
if( isNaN(gi) ) return;
|
||||
if( gi.length === 0 ) return;
|
||||
var local = gstore.get.ues[gi];
|
||||
|
||||
/* (3) Show popup */
|
||||
|
@ -536,10 +536,112 @@ gstore.add('ia_handler', function(ue_i){
|
|||
});
|
||||
|
||||
|
||||
/* (9) Manage 'manage' sub-page
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Initialize current opened UE data */
|
||||
gstore.add('manage', {
|
||||
cours: [],
|
||||
td: [],
|
||||
tp: [],
|
||||
});
|
||||
|
||||
|
||||
/* (2) Function to load UE data */
|
||||
gstore.add('load_ue_groups', function(code, recur=0){
|
||||
|
||||
/* (1) If UE not already loaded -> wait for 200ms */
|
||||
if( gstore.get.ues.length === 0 && recur > 0 ){
|
||||
|
||||
return new Promise( (rs, rj) => setTimeout( () => {
|
||||
|
||||
return gstore.get.load_ue_groups(code, --recur).catch( (rj2) => rj(rj2) );
|
||||
|
||||
}, 200) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (2.1) Check that code is a valid existing UE code */
|
||||
if( code == null )
|
||||
return new Promise( (rs, rj) => rj({label: 'interne', code: -1}) );
|
||||
|
||||
/* (2.2) Find index in gstore */
|
||||
var ue_i = gstore.get.ues.map( (data, i) => { return ( data.code && data.code == code ) ? i : ''; }).join('');
|
||||
|
||||
/* (2.3) Exit if not found */
|
||||
if( ue_i.length === 0 )
|
||||
return new Promise( (rs, rj) => rj({label: 'interne', code: -1}) );
|
||||
|
||||
|
||||
/* (3) Ask for UE Cours data */
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
api.call(`GET ue/cours/${code}`, {}, function(rs){
|
||||
|
||||
// reject on error
|
||||
if( rs.error !== 0 || !(rs['groups'] instanceof Array) ){
|
||||
gstore.get.manage.cours.splice();
|
||||
reject({ label: 'Cours', code: rs.error});
|
||||
}
|
||||
|
||||
// resolve data on success
|
||||
gstore.get.manage.cours = rs.groups;
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
/* (4) Ask for UE TD data */
|
||||
}).then( () => {
|
||||
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
api.call(`GET ue/td/${code}`, {}, function(rs){
|
||||
|
||||
// reject on error
|
||||
if( rs.error !== 0 || !(rs['groups'] instanceof Array) ){
|
||||
gstore.get.manage.td.splice();
|
||||
reject({ label: 'TD', code: rs.error});
|
||||
}
|
||||
|
||||
// resolve data on success
|
||||
gstore.get.manage.td = rs.groups;
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (5) Ask for UE TP data */
|
||||
}).then( () => {
|
||||
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
api.call(`GET ue/tp/${code}`, {}, function(rs){
|
||||
|
||||
// reject on error
|
||||
if( rs.error !== 0 || !(rs['groups'] instanceof Array) ){
|
||||
gstore.get.manage.tp.splice();
|
||||
reject({ label: 'TP', code: rs.error});
|
||||
}
|
||||
|
||||
// resolve data on success
|
||||
gstore.get.manage.tp = rs.groups;
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
/* (9) Manage navigation
|
||||
|
||||
|
||||
|
||||
/* (10) Manage navigation
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Initialize current opened UE */
|
||||
gstore.add('nav_anim', {
|
||||
|
@ -554,37 +656,67 @@ gstore.add('nav_in', function($router, ue_i){
|
|||
if( ue_i == null || isNaN(ue_i) || gstore.get.ues[ue_i] == null)
|
||||
return;
|
||||
|
||||
/* (2) Set animation class */
|
||||
/* (2) Try to get data (Promise) */
|
||||
gstore.get.load_ue_groups(gstore.get.ues[ue_i].code).then( () => {
|
||||
|
||||
/* 1. Start animation */
|
||||
gstore.get.nav_anim.in = true;
|
||||
|
||||
setTimeout( () => {
|
||||
|
||||
/* (3) Load page */
|
||||
/* 2. Load page */
|
||||
$router.push(`/ue/manage/${gstore.get.ues[ue_i].code}`);
|
||||
|
||||
/* (4) Remove animation class */
|
||||
/* 3. Stop animation */
|
||||
gstore.get.nav_anim.in = false;
|
||||
|
||||
}, 500 );
|
||||
|
||||
}).catch( (err) => console.log(`[label] ${err.label} [error] ${err.code}`) );
|
||||
|
||||
|
||||
});
|
||||
|
||||
/* (3) Manage nav out */
|
||||
gstore.add('nav_out', function($router){
|
||||
|
||||
/* (1) Set animation class */
|
||||
/* 1. Start animation */
|
||||
gstore.get.nav_anim.out = true;
|
||||
|
||||
setTimeout( () => {
|
||||
|
||||
/* (2) Load page */
|
||||
/* 2. Load page */
|
||||
$router.push(`/ue/view/`);
|
||||
|
||||
/* (3) Remove animation class */
|
||||
/* 3. Stop animation */
|
||||
gstore.get.nav_anim.out = false;
|
||||
|
||||
/* 4. Remove 'manage' data */
|
||||
gstore.get.manage.cours = [];
|
||||
gstore.get.manage.td = [];
|
||||
gstore.get.manage.tp = [];
|
||||
|
||||
}, 500 );
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (11) Load 'manage' page data if loaded from URL
|
||||
---------------------------------------------------------*/
|
||||
gstore.add('manage_load', function(code, $router){
|
||||
|
||||
/* (1) Try to load data */
|
||||
gstore.get.load_ue_groups(code, 3).catch( (err) => { // try at max 3 times (200ms each) for UE to be loaded
|
||||
|
||||
/* (2) On error -> go to 'view' page */
|
||||
$router.push('/ue/view/');
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue