[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:
parent
4280bbb5f6
commit
70ff0edeb9
|
@ -26,6 +26,7 @@
|
||||||
if( !isset($_SESSION['CAS']) || !is_array($_SESSION['CAS']) ) $_SESSION['CAS'] = [];
|
if( !isset($_SESSION['CAS']) || !is_array($_SESSION['CAS']) ) $_SESSION['CAS'] = [];
|
||||||
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) ) $_SESSION['AUTH'] = [];
|
if( !isset($_SESSION['AUTH']) || !is_array($_SESSION['AUTH']) ) $_SESSION['AUTH'] = [];
|
||||||
if( !isset($_SESSION['AvailableDepartment']) || !is_array($_SESSION['AvailableDepartment']) ) $_SESSION['AvailableDepartment'] = [];
|
if( !isset($_SESSION['AvailableDepartment']) || !is_array($_SESSION['AvailableDepartment']) ) $_SESSION['AvailableDepartment'] = [];
|
||||||
|
if( !isset($_SESSION['VERSION']) || !is_string($_SESSION['VERSION']) ) $_SESSION['VERSION'] = null;
|
||||||
|
|
||||||
|
|
||||||
/* (2) Check CAS
|
/* (2) Check CAS
|
||||||
|
|
|
@ -124,7 +124,7 @@ class versionController{
|
||||||
);
|
);
|
||||||
|
|
||||||
/* (3) Return versions */
|
/* (3) Return versions */
|
||||||
return ['versions' => $versions];
|
return ['versions' => $versions ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ class versionController{
|
||||||
/** @var department $dept_repo */
|
/** @var department $dept_repo */
|
||||||
$dept_repo = Repo::getRepo('department');
|
$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' );
|
$apply = ( $apply === '1' );
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,6 +230,7 @@ class versionController{
|
||||||
|
|
||||||
/* (1) Reset database to 'prod' */
|
/* (1) Reset database to 'prod' */
|
||||||
$_SESSION['CurrentDatabase'] = $this->origin_dbname;
|
$_SESSION['CurrentDatabase'] = $this->origin_dbname;
|
||||||
|
$_SESSION['VERSION'] = null;
|
||||||
|
|
||||||
/* (2) Return success */
|
/* (2) Return success */
|
||||||
return [ 'updated' => true ];
|
return [ 'updated' => true ];
|
||||||
|
@ -261,6 +262,7 @@ class versionController{
|
||||||
|
|
||||||
/* (1) Restore from this version */
|
/* (1) Restore from this version */
|
||||||
$restored = $dept_repo->restore($this->origin_dbname, $snapshot);
|
$restored = $dept_repo->restore($this->origin_dbname, $snapshot);
|
||||||
|
$_SESSION['VERSION'] = null;
|
||||||
|
|
||||||
/* (2) Dispatch repo execution status */
|
/* (2) Dispatch repo execution status */
|
||||||
return [ 'updated' => $restored ];
|
return [ 'updated' => $restored ];
|
||||||
|
@ -286,6 +288,7 @@ class versionController{
|
||||||
|
|
||||||
/* (3) Store 'preview' database in session */
|
/* (3) Store 'preview' database in session */
|
||||||
$_SESSION['CurrentDatabase'] = $preview_dbname;
|
$_SESSION['CurrentDatabase'] = $preview_dbname;
|
||||||
|
$_SESSION['VERSION'] = $version;
|
||||||
|
|
||||||
|
|
||||||
/* (4) Return status */
|
/* (4) Return status */
|
||||||
|
|
|
@ -33,12 +33,12 @@ class departmentController
|
||||||
$_SESSION['CurrentDatabase'] = $dep["dbName"];
|
$_SESSION['CurrentDatabase'] = $dep["dbName"];
|
||||||
$_SESSION['CurrentDepartementId'] = $dep["idDep"];
|
$_SESSION['CurrentDepartementId'] = $dep["idDep"];
|
||||||
|
|
||||||
return ["success" => true];
|
return ['switched' => true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ["success" => false];
|
return ['switched' => false];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
'name' => $_SESSION['CAS']['login'],
|
'name' => $_SESSION['CAS']['login'],
|
||||||
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
|
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
|
||||||
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartment']),
|
'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";
|
])."\n";
|
||||||
|
|
|
@ -80,7 +80,11 @@
|
||||||
"per": [],
|
"per": [],
|
||||||
"par": {
|
"par": {
|
||||||
"URL0": {"des": "Department id", "typ": "id", "ren": "department" }
|
"URL0": {"des": "Department id", "typ": "id", "ren": "department" }
|
||||||
|
},
|
||||||
|
"output": {
|
||||||
|
"switched": { "des": "Whether the department has been switched", "typ": "bool" }
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"errors":{
|
"errors":{
|
||||||
"GET": {
|
"GET": {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<div class='current' @click='d_dialog=!d_dialog' data-unblur-department>{{ get_dcurrent().label || 'département à jour' }}</div>
|
<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>
|
<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>
|
||||||
|
|
||||||
</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='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>
|
<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 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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -53,11 +54,14 @@ export default {
|
||||||
|
|
||||||
/* (1) Get current department data
|
/* (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
|
// search in @dpts where id is @dep_id
|
||||||
for( var d in this.dpts )
|
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 this.dpts[d];
|
||||||
|
|
||||||
return { id: null, label: null };
|
return { id: null, label: null };
|
||||||
|
@ -66,11 +70,14 @@ export default {
|
||||||
|
|
||||||
/* (2) Get current versoin data
|
/* (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
|
// search in @vers where id is @ver_id
|
||||||
for( var v in this.vers )
|
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 this.vers[v];
|
||||||
|
|
||||||
return { date: null };
|
return { date: null };
|
||||||
|
@ -85,17 +92,21 @@ export default {
|
||||||
this.d_dialog = false;
|
this.d_dialog = false;
|
||||||
this.v_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){
|
api.call(`PUT department/${id}`, {}, function(rs){
|
||||||
|
|
||||||
// error -> do nothing
|
// 1. error -> do nothing
|
||||||
if( rs.error !== 0 || rs.success !== true )
|
if( rs.error !== 0 || rs.switched !== true )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 3. Update GUI
|
// 2. Update GUI
|
||||||
this.dep_id = id;
|
this.dep_id = id;
|
||||||
|
|
||||||
// 4. Reload page if needed
|
// 3. Reload page if needed
|
||||||
setTimeout(() => { document.location = ''; }, 200);
|
setTimeout(() => { document.location = ''; }, 200);
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -110,16 +121,112 @@ export default {
|
||||||
this.d_dialog = false;
|
this.d_dialog = false;
|
||||||
this.v_dialog = false;
|
this.v_dialog = false;
|
||||||
|
|
||||||
// 2. Ask for version change
|
// 2. Do nothing if no change
|
||||||
// TODO: api.call()
|
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(){
|
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) => {
|
window.onblur.link('header.department', (e) => {
|
||||||
|
|
||||||
// only hide not [data-unblur-department] elements
|
// only hide not [data-unblur-department] elements
|
||||||
|
|
Loading…
Reference in New Issue