From 13e545e5f93ac6be01c40d450da68296722f4411 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 9 May 2018 15:12:26 +0200 Subject: [PATCH] update version id + currentDatabase when switching department --- build/api/module/departmentController.php | 22 ++++++++++++++++++++-- webpack/vue/header.vue | 5 ++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/build/api/module/departmentController.php b/build/api/module/departmentController.php index d27b2d2..12f9d08 100644 --- a/build/api/module/departmentController.php +++ b/build/api/module/departmentController.php @@ -75,11 +75,29 @@ class departmentController foreach($deps as $dep){ - if( $dep['idDep'] == $department){ + if( $dep['idDep'] == $department ){ $_SESSION['AvailableDepartments'] = $deps; - $_SESSION['CurrentDatabase'] = $dep['dbName']; $_SESSION['CurrentDepartmentId'] = $dep['idDep']; + $_SESSION['VERSION'] = [ + 'list' => $dep['versions'], + 'current' => null + ]; + + // select version with default = 1 + foreach($_SESSION['VERSION']['list'] as $v){ + if( $v['default'] == 1 ){ + $_SESSION['VERSION']['current'] = intval($v['iddatabase']); + $_SESSION['CurrentDatabase'] = $v['dbName']; + break; + } + } + + // if no default -> select first + if( !is_int($_SESSION['VERSION']) ){ + $_SESSION['VERSION']['current'] = intval($_SESSION['VERSION']['list'][0]['iddatabase']); + $_SESSION['CurrentDatabase'] = $_SESSION['VERSION']['list'][0]['dbName']; + } return ['switched' => true]; diff --git a/webpack/vue/header.vue b/webpack/vue/header.vue index 18c8903..ebdcae7 100644 --- a/webpack/vue/header.vue +++ b/webpack/vue/header.vue @@ -125,7 +125,6 @@ export default { // 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 ) @@ -169,8 +168,8 @@ export default { if( rs.error !== 0 || !rs.hasOwnProperty('created_id') ){ return popup.ask({ - title: 'Error ('+err_code+')', - content: 'La création de sauvegarde à échoué.', + title: 'Erreur ('+err_code+')', + content: 'La création de version à échoué.', action: 'OK', type: 'neutral' }, () => {});