diff --git a/build/api/core/AuthSystemDefault.php b/build/api/core/AuthSystemDefault.php index 764ba8f..cc538cb 100644 --- a/build/api/core/AuthSystemDefault.php +++ b/build/api/core/AuthSystemDefault.php @@ -26,7 +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['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; diff --git a/build/api/module/casController.php b/build/api/module/casController.php index 9da66c5..2258a68 100644 --- a/build/api/module/casController.php +++ b/build/api/module/casController.php @@ -148,12 +148,25 @@ class casController{ /* (4) Choose first department by default */ $_SESSION['CurrentDatabase'] = $departments[0]['versions'][0]['dbName']; $_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']); + /* (4) Fetch @cas_login professor data ---------------------------------------------------------*/ /* (1) Try to fetch professor */ diff --git a/build/api/module/department/version/switchController.php b/build/api/module/department/version/switchController.php index 29638b9..4f8a26a 100644 --- a/build/api/module/department/version/switchController.php +++ b/build/api/module/department/version/switchController.php @@ -20,7 +20,7 @@ class switchController $versionData = Repo::getRepo("meta")->getVersionById($version); $_SESSION['CurrentDatabase'] = $versionData["dbName"]; - $_SESSION['VERSION'] = $version; + $_SESSION['VERSION']['current'] = intval( $version ); return ["success" => true]; } diff --git a/webpack/scss/header.scss b/webpack/scss/header.scss index 7660192..b5b9a74 100644 --- a/webpack/scss/header.scss +++ b/webpack/scss/header.scss @@ -64,10 +64,6 @@ background-color: $form-invalid-color; } - &[data-id='-1']:before{ - background-color: $form-valid-color; - } - } @@ -124,11 +120,13 @@ border-radius: 50%; - background-color: $form-invalid-color; + background-color: $form-grey-color; } &[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; } } diff --git a/webpack/vue/header.vue b/webpack/vue/header.vue index 5c37315..0e09452 100644 --- a/webpack/vue/header.vue +++ b/webpack/vue/header.vue @@ -15,10 +15,10 @@
-
{{ get_vcurrent().date || 'version à jour' }}
-
- {{ v.date || 'version à jour' }} - Nouvelle version +
{{ get_vcurrent().name }}
+
+ {{ v.name }} + Créer
@@ -41,13 +41,11 @@ export default { dep_id: _SERVER.session.department_id, dpts: _SERVER.session.departments, - v_dialog: false, - ver_id: -1, - vers: [ - { id: -1, date: null }, - { id: 0, date: '01-02-2017' }, - { id: 1, date: '23-03-2017' } - ] + version: { + dialog: false, + current: -1, + list: [] + } }; }, methods: { @@ -68,19 +66,19 @@ export default { }, - /* (2) Get current versoin data + /* (2) Get current version data ---------------------------------------------------------*/ get_vcurrent(id){ - // use @dep_id, if invalid argument @id - ( isNaN(id) ) && ( id = this.ver_id ); + // use @version.current, if invalid argument @id + ( isNaN(id) ) && ( id = this.version.current ); - // search in @vers where id is @ver_id - for( var v in this.vers ) - if( this.vers[v].id == id ) - return this.vers[v]; + // search in @ist where id is @id + for( var v in this.version.list ) + if( this.version.list[v].id == id ) + return this.version.list[v]; - return { date: null }; + return { id: -2, name: '-' }; }, @@ -90,7 +88,7 @@ export default { // 1. De-activate dialogs this.d_dialog = false; - this.v_dialog = false; + this.version.dialog = false; // 2. Do nothing if no change if( this.dep_id == id ) @@ -119,27 +117,22 @@ export default { // 1. De-activate dialogs this.d_dialog = false; - this.v_dialog = false; + this.version.dialog = false; // 2. Do nothing if no change - if( this.ver_id == id ) + if( this.version.current == 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){ + // 3. Ask for department change + api.call(`GET department/version/switch/${id}`, {}, function(rs){ + console.log(rs); // 1. error -> do nothing - if( rs.error !== 0 || rs.updated !== true ) + if( rs.error !== 0 ) return; // 2. Update GUI - this.ver_id = id; + this.version.current = id; // 3. Reload page if needed setTimeout(() => { document.location = ''; }, 200); @@ -154,7 +147,7 @@ export default { // 1. De-activate dialogs this.d_dialog = false; - this.v_dialog = false; + this.version.dialog = false; // 2. Popup confirm (new Promise( (resolve, reject) => { @@ -170,7 +163,7 @@ export default { })).then( () => { // 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 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 - this.vers.push( { id: last_id+1, date: rs.created_id } ); + this.vers.push( { id: parseInt(rs.created_id), label: label } ); }.bind(this)); @@ -207,21 +197,22 @@ export default { return; // 2. Init version list - this.vers = [ { id: -1, date: null } ]; - var idv = 0; + this.version.list = []; // 3. Store versions for( var ver of rs.versions ){ - // if current version -> set @ver_id - if( _SERVER.session.version === ver ) - this.ver_id = idv + // if current version -> set @version.current + if( _SERVER.session.version.current === ver.iddatabase ) + this.version.current = ver.iddatabase // 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) ); @@ -235,7 +226,7 @@ export default { // only hide not [data-unblur-version] elements if( e.target.getAttribute('data-unblur-version') === null ) - this.v_dialog = false; + this.version.dialog = false; });