update version model + casController/switch version format in session

This commit is contained in:
xdrm-brackets 2018-05-09 12:36:12 +02:00
parent 63fdcc012d
commit 73bc584036
5 changed files with 56 additions and 54 deletions

View File

@ -26,7 +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['AvailableDepartments']) || !is_array($_SESSION['AvailableDepartments']) ) $_SESSION['AvailableDepartments'] = []; if( !isset($_SESSION['AvailableDepartments']) || !is_array($_SESSION['AvailableDepartments']) ) $_SESSION['AvailableDepartments'] = [];
if( !isset($_SESSION['VERSION']) || !is_int($_SESSION['VERSION']) ) $_SESSION['VERSION'] = null; if( !isset($_SESSION['VERSION']) || !is_array($_SESSION['VERSION']) ) $_SESSION['VERSION'] = [];
if( !isset($_SESSION['CurrentDepartmentId']) || !is_int($_SESSION['CurrentDepartmentId']) ) $_SESSION['CurrentDepartmentId'] = null; if( !isset($_SESSION['CurrentDepartmentId']) || !is_int($_SESSION['CurrentDepartmentId']) ) $_SESSION['CurrentDepartmentId'] = null;

View File

@ -148,12 +148,25 @@ class casController{
/* (4) Choose first department by default */ /* (4) Choose first department by default */
$_SESSION['CurrentDatabase'] = $departments[0]['versions'][0]['dbName']; $_SESSION['CurrentDatabase'] = $departments[0]['versions'][0]['dbName'];
$_SESSION['CurrentDepartmentId'] = $departments[0]['idDep']; $_SESSION['CurrentDepartmentId'] = $departments[0]['idDep'];
$_SESSION['VERSION'] = [
'list' => $departments[0]['versions'],
'current' => null
];
/* (5) Use this department's database */ /* (5) Select actual version */
foreach($_SESSION['VERSION']['list'] as $v){
if( $v['dbName'] == $_SESSION['CurrentDatabase'] ){
$_SESSION['VERSION']['current'] = intval($v['iddatabase']);
break;
}
}
/* (6) Use this department's database */
Repo::switchDatabase($_SESSION['CurrentDatabase']); Repo::switchDatabase($_SESSION['CurrentDatabase']);
/* (4) Fetch @cas_login professor data /* (4) Fetch @cas_login professor data
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Try to fetch professor */ /* (1) Try to fetch professor */

View File

@ -20,7 +20,7 @@ class switchController
$versionData = Repo::getRepo("meta")->getVersionById($version); $versionData = Repo::getRepo("meta")->getVersionById($version);
$_SESSION['CurrentDatabase'] = $versionData["dbName"]; $_SESSION['CurrentDatabase'] = $versionData["dbName"];
$_SESSION['VERSION'] = $version; $_SESSION['VERSION']['current'] = intval( $version );
return ["success" => true]; return ["success" => true];
} }

View File

@ -64,10 +64,6 @@
background-color: $form-invalid-color; background-color: $form-invalid-color;
} }
&[data-id='-1']:before{
background-color: $form-valid-color;
}
} }
@ -124,11 +120,13 @@
border-radius: 50%; border-radius: 50%;
background-color: $form-invalid-color; background-color: $form-grey-color;
} }
&[data-id='-1']:before{ &[data-id='-1']:before{
background-color: $form-valid-color; border-radius: 0;
background: url('/asset/svg/plus.svg@#{$rd-form-valid-color}') center center no-repeat;
background-size: contain;
} }
} }

View File

@ -15,10 +15,10 @@
<!-- Version management --> <!-- Version management -->
<div class='versions' data-unblur-version> <div class='versions' data-unblur-version>
<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='version.dialog=!version.dialog' :data-id='get_vcurrent().id' data-unblur-version>{{ get_vcurrent().name }}</div>
<div class='version-dialog' v-show='v_dialog' data-unblur-version> <div class='version-dialog' v-show='version.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 version.list' v-show='v.id!=version.current' @click='v_switch(v.id)' :data-id='v.id' data-unblur-version>{{ v.name }}</span>
<span @click='v_create()' data-unblur-version data-id='-1'>Nouvelle version</span> <span @click='v_create()' data-unblur-version data-id='-1'>Créer</span>
</div> </div>
</div> </div>
@ -41,13 +41,11 @@ export default {
dep_id: _SERVER.session.department_id, dep_id: _SERVER.session.department_id,
dpts: _SERVER.session.departments, dpts: _SERVER.session.departments,
v_dialog: false, version: {
ver_id: -1, dialog: false,
vers: [ current: -1,
{ id: -1, date: null }, list: []
{ id: 0, date: '01-02-2017' }, }
{ id: 1, date: '23-03-2017' }
]
}; };
}, },
methods: { methods: {
@ -68,19 +66,19 @@ export default {
}, },
/* (2) Get current versoin data /* (2) Get current version data
---------------------------------------------------------*/ ---------------------------------------------------------*/
get_vcurrent(id){ get_vcurrent(id){
// use @dep_id, if invalid argument @id // use @version.current, if invalid argument @id
( isNaN(id) ) && ( id = this.ver_id ); ( isNaN(id) ) && ( id = this.version.current );
// search in @vers where id is @ver_id // search in @ist where id is @id
for( var v in this.vers ) for( var v in this.version.list )
if( this.vers[v].id == id ) if( this.version.list[v].id == id )
return this.vers[v]; return this.version.list[v];
return { date: null }; return { id: -2, name: '-' };
}, },
@ -90,7 +88,7 @@ export default {
// 1. De-activate dialogs // 1. De-activate dialogs
this.d_dialog = false; this.d_dialog = false;
this.v_dialog = false; this.version.dialog = false;
// 2. Do nothing if no change // 2. Do nothing if no change
if( this.dep_id == id ) if( this.dep_id == id )
@ -119,27 +117,22 @@ export default {
// 1. De-activate dialogs // 1. De-activate dialogs
this.d_dialog = false; this.d_dialog = false;
this.v_dialog = false; this.version.dialog = false;
// 2. Do nothing if no change // 2. Do nothing if no change
if( this.ver_id == id ) if( this.version.current == id )
return; return;
// 3. Get version date // 3. Ask for department change
var verdate = this.get_vcurrent(id).date; api.call(`GET department/version/switch/${id}`, {}, function(rs){
console.log(rs);
// 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 // 1. error -> do nothing
if( rs.error !== 0 || rs.updated !== true ) if( rs.error !== 0 )
return; return;
// 2. Update GUI // 2. Update GUI
this.ver_id = id; this.version.current = id;
// 3. Reload page if needed // 3. Reload page if needed
setTimeout(() => { document.location = ''; }, 200); setTimeout(() => { document.location = ''; }, 200);
@ -154,7 +147,7 @@ export default {
// 1. De-activate dialogs // 1. De-activate dialogs
this.d_dialog = false; this.d_dialog = false;
this.v_dialog = false; this.version.dialog = false;
// 2. Popup confirm // 2. Popup confirm
(new Promise( (resolve, reject) => { (new Promise( (resolve, reject) => {
@ -170,7 +163,7 @@ export default {
})).then( () => { })).then( () => {
// Call API to create a new version // Call API to create a new version
api.call(`POST department/version/`, {}, function(rs){ api.call(`POST department/version/`, {label:'test'}, function(rs){
// 1. error -> popup // 1. error -> popup
if( rs.error !== 0 || !rs.hasOwnProperty('created_id') ){ if( rs.error !== 0 || !rs.hasOwnProperty('created_id') ){
@ -184,11 +177,8 @@ export default {
} }
// 2. Get last version id
var last_id = this.vers[ this.vers.length-1 ].id;
// 3. Update GUI // 3. Update GUI
this.vers.push( { id: last_id+1, date: rs.created_id } ); this.vers.push( { id: parseInt(rs.created_id), label: label } );
}.bind(this)); }.bind(this));
@ -207,21 +197,22 @@ export default {
return; return;
// 2. Init version list // 2. Init version list
this.vers = [ { id: -1, date: null } ]; this.version.list = [];
var idv = 0;
// 3. Store versions // 3. Store versions
for( var ver of rs.versions ){ for( var ver of rs.versions ){
// if current version -> set @ver_id // if current version -> set @version.current
if( _SERVER.session.version === ver ) if( _SERVER.session.version.current === ver.iddatabase )
this.ver_id = idv this.version.current = ver.iddatabase
// add version to list // add version to list
this.vers.push( { id: idv++, date: ver } ); this.version.list.push( { id: ver.iddatabase, name: ver.label } );
} }
this.version
}.bind(this) ); }.bind(this) );
@ -235,7 +226,7 @@ export default {
// only hide not [data-unblur-version] elements // only hide not [data-unblur-version] elements
if( e.target.getAttribute('data-unblur-version') === null ) if( e.target.getAttribute('data-unblur-version') === null )
this.v_dialog = false; this.version.dialog = false;
}); });