From 38c9b3846da16b7a713be6ff58be69b4471520d1 Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Wed, 26 Apr 2017 16:23:41 +0200 Subject: [PATCH] Dashboard: Partial replacement and autorefresh - Replaces the jqplot based 24h jobs status partial - Reorders current available partials on the dashboard - Adds autorefresh to all partials via ajax interval call --- .../Controller/DashboardController.php | 110 ++++---- .../view/dashboard/dashboard/index.phtml | 240 +++++++++--------- .../view/partial/JobsLastStatus.phtml | 4 +- .../Dashboard/view/partial/JobsPast24h.phtml | 79 ++++-- .../view/partial/LastDirectorMessages.phtml | 6 +- 5 files changed, 234 insertions(+), 205 deletions(-) diff --git a/module/Dashboard/src/Dashboard/Controller/DashboardController.php b/module/Dashboard/src/Dashboard/Controller/DashboardController.php index 45d076f281d..53684c8d2d9 100644 --- a/module/Dashboard/src/Dashboard/Controller/DashboardController.php +++ b/module/Dashboard/src/Dashboard/Controller/DashboardController.php @@ -5,7 +5,7 @@ * bareos-webui - Bareos Web-Frontend * * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/) + * @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) * * This program is free software: you can redistribute it and/or modify @@ -60,39 +60,45 @@ public function indexAction() ); } - try { - $this->bsock = $this->getServiceLocator()->get('director'); - $running = $this->getJobs("running", 1, null); - $waiting = $this->getJobs("waiting", 1, null); - $successful = $this->getJobs("successful", 1, null); - $unsuccessful = $this->getJobs("unsuccessful", 1, null); - $this->bsock->disconnect(); - } - catch(Exception $e) { - echo $e->getMessage(); - } - - return new ViewModel( - array( - 'runningJobs' => $running, - 'waitingJobs' => $waiting, - 'successfulJobs' => $successful, - 'unsuccessfulJobs' => $unsuccessful, - ) - ); + return new ViewModel(); } - private function getJobs($status=null, $days=1, $hours=null) + public function getDataAction() { - $num = null; + $this->RequestURIPlugin()->setRequestURI(); - if($status != null) { - if($status == "running") { - $jobs_R = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'R', $days, $hours); - $jobs_l = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'l', $days, $hours); - $num = count($jobs_R) + count($jobs_l); + if(!$this->SessionTimeoutPlugin()->isValid()) { + return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director']))); + } + + $result = null; + + $data = $this->params()->fromQuery('data'); + + if($data == "jobslaststatus") { + try { + $this->bsock = $this->getServiceLocator()->get('director'); + $result = $this->getJobModel()->getJobsLastStatus($this->bsock); + $this->bsock->disconnect(); + } + catch(Exception $e) { + echo $e->getMessage(); } - elseif($status == "waiting") { + } + elseif($data == "jobspast24h") { + + $days = 1; + $hours = null; + $waiting = null; + $running = null; + $successful = null; + $failed = null; + $result = null; + + try { + $this->bsock = $this->getServiceLocator()->get('director'); + + // waiting $jobs_F = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'F', $days, $hours); $jobs_S = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'S', $days, $hours); $jobs_s = $this->getJobModel()->getJobsByStatus($this->bsock, null, 's', $days, $hours); @@ -105,47 +111,35 @@ private function getJobs($status=null, $days=1, $hours=null) $jobs_t = $this->getJobModel()->getJobsByStatus($this->bsock, null, 't', $days, $hours); $jobs_p = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'p', $days, $hours); $jobs_q = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'q', $days, $hours); - $num = count($jobs_F) + count($jobs_S) + + $waiting = count($jobs_F) + count($jobs_S) + count($jobs_s) + count($jobs_m) + count($jobs_M) + count($jobs_j) + count($jobs_c) + count($jobs_C) + count($jobs_d) + count($jobs_t) + count($jobs_p) + count($jobs_q); - } - elseif($status == "successful") { + + // running + $jobs_R = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'R', $days, $hours); + $jobs_l = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'l', $days, $hours); + $running = count($jobs_R) + count($jobs_l); + + // successful $jobs_T = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'T', $days, $hours); $jobs_W = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'W', $days, $hours); - $num = count($jobs_T) + count($jobs_W); - } - elseif($status == "unsuccessful") { + $successful = count($jobs_T) + count($jobs_W); + + // failed $jobs_A = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'A', $days, $hours); $jobs_E = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'E', $days, $hours); $jobs_e = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'e', $days, $hours); $jobs_f = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'f', $days, $hours); - $num = count($jobs_A) + count($jobs_E) + count($jobs_e) + count($jobs_f); - } - } - - return $num; - } - - public function getDataAction() - { - $this->RequestURIPlugin()->setRequestURI(); - - if(!$this->SessionTimeoutPlugin()->isValid()) { - return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director']))); - } - - $result = null; + $failed = count($jobs_A) + count($jobs_E) + count($jobs_e) + count($jobs_f); - $data = $this->params()->fromQuery('data'); - - if($data == "jobslaststatus") { - try { - $this->bsock = $this->getServiceLocator()->get('director'); - $result = $this->getJobModel()->getJobsLastStatus($this->bsock); - $this->bsock->disconnect(); + // json result + $result['waiting'] = $waiting; + $result['running'] = $running; + $result['successful'] = $successful; + $result['failed'] = $failed; } catch(Exception $e) { echo $e->getMessage(); diff --git a/module/Dashboard/view/dashboard/dashboard/index.phtml b/module/Dashboard/view/dashboard/dashboard/index.phtml index 870a1b8e40a..647c20af2c7 100644 --- a/module/Dashboard/view/dashboard/dashboard/index.phtml +++ b/module/Dashboard/view/dashboard/dashboard/index.phtml @@ -5,7 +5,7 @@ * bareos-webui - Bareos Web-Frontend * * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/) + * @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) * * This program is free software: you can redistribute it and/or modify @@ -32,25 +32,18 @@ $this->headTitle($title);
-
+
partial('JobsPast24h'); ?> - partial('LastDirectorMessages'); ?> + partial('JobsLastStatus'); ?>
-
- partial('JobsLastStatus'); ?> +
+ partial('LastDirectorMessages'); ?>
headScript()->prependFile($this->basePath() . '/js/jqplot.pointLabels.min.js'); - echo $this->headScript()->prependFile($this->basePath() . '/js/jqplot.categoryAxisRenderer.min.js'); - echo $this->headScript()->prependFile($this->basePath() . '/js/jqplot.barRenderer.min.js'); - echo $this->headScript()->prependFile($this->basePath() . '/js/jqplot.pieRenderer.min.js'); - echo $this->headScript()->prependFile($this->basePath() . '/js/jquery.jqplot.min.js'); - echo $this->headLink()->prependStylesheet($this->basePath() . '/css/jquery.jqplot.min.css'); - echo $this->headScript()->prependFile($this->basePath() . '/js/datatables.plugins.js'); echo $this->headScript()->prependFile($this->basePath() . '/js/datatables.functions.js'); echo $this->headScript()->prependFile($this->basePath() . '/js/datatables.min.js'); @@ -59,45 +52,8 @@ $this->headTitle($title);