[api.core.AuthSystemDefault] added $_SESSION['VERSION'] [router.controller.js] added 'session.version' in javascript '_SERVER' variable [module.version] minmod [webpack.header] implemented VERSION: fetch|create|switch

This commit is contained in:
xdrm-brackets 2018-03-17 19:07:44 +01:00
parent 4280bbb5f6
commit 70ff0edeb9
6 changed files with 136 additions and 20 deletions

View File

@ -26,6 +26,7 @@
if( !isset($_SESSION['CAS']) || !is_array($_SESSION['CAS']) ) $_SESSION['CAS'] = [];
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) ) $_SESSION['AUTH'] = [];
if( !isset($_SESSION['AvailableDepartment']) || !is_array($_SESSION['AvailableDepartment']) ) $_SESSION['AvailableDepartment'] = [];
if( !isset($_SESSION['VERSION']) || !is_string($_SESSION['VERSION']) ) $_SESSION['VERSION'] = null;
/* (2) Check CAS

View File

@ -124,7 +124,7 @@ class versionController{
);
/* (3) Return versions */
return ['versions' => $versions];
return ['versions' => $versions ];
}
@ -218,7 +218,7 @@ class versionController{
/** @var department $dept_repo */
$dept_repo = Repo::getRepo('department');
/* (2) Check whether we have to [apply OR preview] */
/* (3) Check whether we have to [apply OR preview] */
$apply = ( $apply === '1' );
@ -230,6 +230,7 @@ class versionController{
/* (1) Reset database to 'prod' */
$_SESSION['CurrentDatabase'] = $this->origin_dbname;
$_SESSION['VERSION'] = null;
/* (2) Return success */
return [ 'updated' => true ];
@ -261,6 +262,7 @@ class versionController{
/* (1) Restore from this version */
$restored = $dept_repo->restore($this->origin_dbname, $snapshot);
$_SESSION['VERSION'] = null;
/* (2) Dispatch repo execution status */
return [ 'updated' => $restored ];
@ -286,6 +288,7 @@ class versionController{
/* (3) Store 'preview' database in session */
$_SESSION['CurrentDatabase'] = $preview_dbname;
$_SESSION['VERSION'] = $version;
/* (4) Return status */

View File

@ -33,12 +33,12 @@ class departmentController
$_SESSION['CurrentDatabase'] = $dep["dbName"];
$_SESSION['CurrentDepartementId'] = $dep["idDep"];
return ["success" => true];
return ['switched' => true];
}
}
}
return ["success" => false];
return ['switched' => false];
}

View File

@ -31,7 +31,8 @@
'name' => $_SESSION['CAS']['login'],
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartment']),
'department_id' => $_SESSION['CurrentDepartementId']
'department_id' => $_SESSION['CurrentDepartementId'],
'version' => $_SESSION['VERSION']
]
])."\n";

View File

@ -80,7 +80,11 @@
"per": [],
"par": {
"URL0": {"des": "Department id", "typ": "id", "ren": "department" }
},
"output": {
"switched": { "des": "Whether the department has been switched", "typ": "bool" }
}
},
"errors":{
"GET": {

View File

@ -7,7 +7,7 @@
<div class='current' @click='d_dialog=!d_dialog' data-unblur-department>{{ get_dcurrent().label || 'département à jour' }}</div>
<div class='department-dialog' v-show='d_dialog' data-unblur-department>
<span v-for='d in dpts' @click='d_switch(d.id)' data-unblur-department>{{ d.label }}</span>
<span v-for='d in dpts' v-show='d.id!=dep_id' @click='d_switch(d.id)' data-unblur-department>{{ d.label }}</span>
</div>
</div>
@ -18,6 +18,7 @@
<div class='current' @click='v_dialog=!v_dialog' :data-id='get_vcurrent().id' data-unblur-version>{{ get_vcurrent().date || 'version à jour' }}</div>
<div class='version-dialog' v-show='v_dialog' data-unblur-version>
<span v-for='v in vers' v-show='v.id!=ver_id' @click='v_switch(v.id)' :data-id='v.id' data-unblur-version>{{ v.date || 'version à jour' }}</span>
<span @click='v_create()' data-unblur-version data-id='-1'>Nouvelle version</span>
</div>
</div>
@ -53,11 +54,14 @@ export default {
/* (1) Get current department data
---------------------------------------------------------*/
get_dcurrent(){
get_dcurrent(id){
// use @dep_id, if invalid argument @id
( isNaN(id) ) && ( id = this.dep_id );
// search in @dpts where id is @dep_id
for( var d in this.dpts )
if( this.dpts[d].id == this.dep_id )
if( this.dpts[d].id == id )
return this.dpts[d];
return { id: null, label: null };
@ -66,11 +70,14 @@ export default {
/* (2) Get current versoin data
---------------------------------------------------------*/
get_vcurrent(){
get_vcurrent(id){
// use @dep_id, if invalid argument @id
( isNaN(id) ) && ( id = this.ver_id );
// search in @vers where id is @ver_id
for( var v in this.vers )
if( this.vers[v].id == this.ver_id )
if( this.vers[v].id == id )
return this.vers[v];
return { date: null };
@ -85,17 +92,21 @@ export default {
this.d_dialog = false;
this.v_dialog = false;
// 2. Ask for department change
// 2. Do nothing if no change
if( this.dep_id == id )
return;
// 3. Ask for department change
api.call(`PUT department/${id}`, {}, function(rs){
// error -> do nothing
if( rs.error !== 0 || rs.success !== true )
// 1. error -> do nothing
if( rs.error !== 0 || rs.switched !== true )
return;
// 3. Update GUI
// 2. Update GUI
this.dep_id = id;
// 4. Reload page if needed
// 3. Reload page if needed
setTimeout(() => { document.location = ''; }, 200);
}.bind(this));
@ -110,16 +121,112 @@ export default {
this.d_dialog = false;
this.v_dialog = false;
// 2. Ask for version change
// TODO: api.call()
// 2. Do nothing if no change
if( this.ver_id == id )
return;
// 3. Get version date
var verdate = this.get_vcurrent(id).date;
// 4. If null date -> go to current version
( verdate === null ) && ( verdate = '' );
// 5. Ask for department change
api.call(`PUT department/version/0/${verdate}`, {}, function(rs){
// 1. error -> do nothing
if( rs.error !== 0 || rs.updated !== true )
return;
// 2. Update GUI
this.ver_id = id;
// 3. Reload page if needed
setTimeout(() => { document.location = ''; }, 200);
}.bind(this));
},
/* (5) Create a new version from now
---------------------------------------------------------*/
v_create(){
// 1. De-activate dialogs
this.d_dialog = false;
this.v_dialog = false;
// 2. Popup confirm
(new Promise( (resolve, reject) => {
popup.ask({
title: 'Confirmation de création de version',
content: `Une sauvegarde (ou version) va être crée à partir de l'état actuel des données de tout le département<br><br>Voulez-vous créer cette sauvegarde ?`,
action: 'Créer',
type: 'valid'
}, (popup_rs) => { popup_rs && resolve() });
// 3. On popup confirm
})).then( () => {
// Call API to create a new version
api.call(`POST department/version/`, {}, function(rs){
// 1. error -> popup
if( rs.error !== 0 || !rs.hasOwnProperty('created_id') ){
return popup.ask({
title: 'Error ('+err_code+')',
content: 'La création de sauvegarde à échoué.',
action: 'OK',
type: 'neutral'
}, () => {});
}
// 2. Get last version id
var last_id = this.vers[ this.vers.length-1 ].id;
// 3. Update GUI
this.vers.push( { id: last_id+1, date: rs.created_id } );
}.bind(this));
})
// 3. Update GUI
this.ver_id = id;
}
},
beforeMount(){
// set onblur to hide department lists
/* (1) Try to fetch versions from API */
api.call('GET department/version', {}, function(rs){
// 1. Manage error
if( rs.error !== 0 || !rs.hasOwnProperty('versions') )
return;
// 2. Init version list
this.vers = [ { id: -1, date: null } ];
var idv = 0;
// 3. Store versions
for( var ver of rs.versions ){
// if current version -> set @ver_id
if( _SERVER.session.version === ver )
this.ver_id = idv
// add version to list
this.vers.push( { id: idv++, date: ver } );
}
}.bind(this) );
/* (2) Set onblur to hide department lists */
window.onblur.link('header.department', (e) => {
// only hide not [data-unblur-department] elements