From 5a7af21c97b92386c71eeba01a03c08e8d9a2fa3 Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Mon, 17 Nov 2014 11:02:57 -0500 Subject: [PATCH] Revise tracker module configuration form and add install script --- modules/tracker/configs/module.ini | 16 ++--- modules/tracker/constant/module.php | 2 + .../tracker/controllers/AdminController.php | 68 +++++++++++++++++++ .../tracker/controllers/ConfigController.php | 63 ----------------- .../controllers/components/ApiComponent.php | 9 ++- modules/tracker/database/InstallScript.php | 36 ++++++++++ modules/tracker/database/upgrade/1.1.0.php | 9 +++ modules/tracker/forms/Admin.php | 48 +++++++++++++ .../tracker/public/js/config/config.index.js | 21 ------ .../views/{config => admin}/index.phtml | 29 ++++---- 10 files changed, 188 insertions(+), 113 deletions(-) create mode 100644 modules/tracker/controllers/AdminController.php delete mode 100644 modules/tracker/controllers/ConfigController.php create mode 100644 modules/tracker/database/InstallScript.php create mode 100644 modules/tracker/forms/Admin.php delete mode 100644 modules/tracker/public/js/config/config.index.js rename modules/tracker/views/{config => admin}/index.phtml (50%) diff --git a/modules/tracker/configs/module.ini b/modules/tracker/configs/module.ini index c85adddbd..fe2d10447 100644 --- a/modules/tracker/configs/module.ini +++ b/modules/tracker/configs/module.ini @@ -1,11 +1,9 @@ +; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0. + [global] -; version of the module -version = 1.0.5 -; full name of the module (displayed on admin page) -fullname = Tracker Dashboard -; description (displayed on admin page) -description = "Tracks scalar results over time" -; category -category = Visualization -; dependencies (comma separated list of other module dependencies) +fullname = "Tracker Dashboard" +description = "Track scalar results over time" +category = "Visualization" dependencies = api,scheduler +uuid = "3048a9fa-89ab-4e61-a55e-a49379fa6dc" +version = "1.1.0" diff --git a/modules/tracker/constant/module.php b/modules/tracker/constant/module.php index d78e8e03f..bffd52370 100644 --- a/modules/tracker/constant/module.php +++ b/modules/tracker/constant/module.php @@ -18,5 +18,7 @@ limitations under the License. =========================================================================*/ +define('MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY', 'tempScalarTtl'); +define('MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE', 24); define('MIDAS_TRACKER_EMAIL_USER', 'emailuser'); define('MIDAS_TRACKER_EMAIL_GROUP', 'emailgroup'); diff --git a/modules/tracker/controllers/AdminController.php b/modules/tracker/controllers/AdminController.php new file mode 100644 index 000000000..2deecf615 --- /dev/null +++ b/modules/tracker/controllers/AdminController.php @@ -0,0 +1,68 @@ +requireAdminPrivileges(); + + $this->view->pageTitle = 'Tracker Module Configuration'; + $form = new Tracker_Form_Admin(); + + if ($this->getRequest()->isPost()) { + $data = $this->getRequest()->getPost(); + + if ($form->isValid($data)) { + $values = $form->getValues(); + + foreach ($values as $key => $value) { + if ($value !== null) { + $this->Setting->setConfig($key, $value, $this->moduleName); + } + } + } + + $form->populate($data); + } else { + $elements = $form->getElements(); + + foreach ($elements as $element) { + $name = $element->getName(); + + if ($name !== 'csrf' && $name !== 'submit') { + $value = $this->Setting->getValueByName($name, $this->moduleName); + + if (!is_null($value)) { + $form->setDefault($name, $value); + } + } + } + } + + $this->view->form = $form; + session_start(); + } +} diff --git a/modules/tracker/controllers/ConfigController.php b/modules/tracker/controllers/ConfigController.php deleted file mode 100644 index d3f2cb0b6..000000000 --- a/modules/tracker/controllers/ConfigController.php +++ /dev/null @@ -1,63 +0,0 @@ -requireAdminPrivileges(); - $this->view->tempScalarTtl = $this->Setting->getValueByName('tempScalarTtl', $this->moduleName); - if (!$this->view->tempScalarTtl) { - $this->view->tempScalarTtl = 24; // default to 24 hours - } - - $breadcrumbs = array(); - $breadcrumbs[] = array('type' => 'moduleList'); - $breadcrumbs[] = array( - 'type' => 'custom', - 'text' => 'Tracker Dashboard Configuration', - 'icon' => $this->view->moduleWebroot.'/public/images/chart_line.png', - ); - $this->Component->Breadcrumb->setBreadcrumbHeader($breadcrumbs, $this->view); - } - - /** - * Submit configuration settings - */ - public function submitAction() - { - $this->requireAdminPrivileges(); - $this->disableLayout(); - $this->disableView(); - - $tempScalarTtl = $this->getParam('tempScalarTtl'); - - $this->Setting->setConfig('tempScalarTtl', $tempScalarTtl, $this->moduleName); - - echo JsonComponent::encode(array('message' => 'Changes saved', 'status' => 'ok')); - } -} diff --git a/modules/tracker/controllers/components/ApiComponent.php b/modules/tracker/controllers/components/ApiComponent.php index 130cc1052..4a98a94cb 100644 --- a/modules/tracker/controllers/components/ApiComponent.php +++ b/modules/tracker/controllers/components/ApiComponent.php @@ -21,6 +21,9 @@ /** Component for api methods */ class Tracker_ApiComponent extends AppComponent { + /** @var string */ + public $moduleName = 'tracker'; + /** * Helper function for verifying keys in an input array */ @@ -247,7 +250,7 @@ public function scalarAdd($args) if (!$official) { $jobModel = MidasLoader::loadModel('Job', 'scheduler'); $settingModel = MidasLoader::loadModel('Setting'); - $nHours = $settingModel->getValueByName('tempScalarTtl', 'tracker'); + $nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); if (!$nHours) { $nHours = 24; // default to 24 hours } @@ -298,9 +301,9 @@ public function resultsUploadJson($args) if (!$official) { $jobModel = MidasLoader::loadModel('Job', 'scheduler'); $settingModel = MidasLoader::loadModel('Setting'); - $nHours = $settingModel->getValueByName('tempScalarTtl', 'tracker'); + $nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); if (!$nHours) { - $nHours = 24; // default to 24 hours + $nHours = MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE; // default to 24 hours } } diff --git a/modules/tracker/database/InstallScript.php b/modules/tracker/database/InstallScript.php new file mode 100644 index 000000000..1e42219c0 --- /dev/null +++ b/modules/tracker/database/InstallScript.php @@ -0,0 +1,36 @@ +setConfig(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE, $this->moduleName); + } +} diff --git a/modules/tracker/database/upgrade/1.1.0.php b/modules/tracker/database/upgrade/1.1.0.php index ec7780487..38b9637ae 100644 --- a/modules/tracker/database/upgrade/1.1.0.php +++ b/modules/tracker/database/upgrade/1.1.0.php @@ -21,4 +21,13 @@ /** Upgrade the tracker module to version 1.1.0. */ class Tracker_Upgrade_1_1_0 extends MIDASUpgrade { + /** Pre database upgrade. */ + public function preUpgrade() + { + } + + /** Post database upgrade. */ + public function postUpgrade() + { + } } diff --git a/modules/tracker/forms/Admin.php b/modules/tracker/forms/Admin.php new file mode 100644 index 000000000..8afc6f46e --- /dev/null +++ b/modules/tracker/forms/Admin.php @@ -0,0 +1,48 @@ +setName('tracker_admin'); + $this->setMethod('POST'); + + $csrf = new Midas_Form_Element_Hash('csrf'); + $csrf->setSalt('APSey8FJpXfDssQU5CqA9qe5'); + $csrf->setDecorators(array('ViewHelper')); + + $tempScalarTtl = new Zend_Form_Element_Text(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY); + $tempScalarTtl->setLabel('Unofficial Scalar TTL'); + $tempScalarTtl->setRequired(true); + $tempScalarTtl->addValidator('NotEmpty', true); + $tempScalarTtl->addValidator('Digits', true); + $tempScalarTtl->addValidator('GreaterThan', true, array('min' => 0)); + + $this->addDisplayGroup(array($tempScalarTtl), 'global'); + + $submit = new Zend_Form_Element_Submit('submit'); + $submit->setLabel('Save'); + + $this->addElements(array($csrf, $tempScalarTtl, $submit)); + } +} diff --git a/modules/tracker/public/js/config/config.index.js b/modules/tracker/public/js/config/config.index.js deleted file mode 100644 index f1affd5b5..000000000 --- a/modules/tracker/public/js/config/config.index.js +++ /dev/null @@ -1,21 +0,0 @@ -// MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0. - -var midas = midas || {}; - -$(window).load(function () { - 'use strict'; - $('#configForm').ajaxForm({ - beforeSubmit: function () { - return true; - }, - success: function (text) { - var resp = $.parseJSON(text); - if (!resp) { - midas.createNotice('An error occurred, check the log', 3000, 'error'); - } - else { - midas.createNotice(resp.message, 3000, resp.status); - } - } - }); -}); diff --git a/modules/tracker/views/config/index.phtml b/modules/tracker/views/admin/index.phtml similarity index 50% rename from modules/tracker/views/config/index.phtml rename to modules/tracker/views/admin/index.phtml index 5dc50c1e5..209e5d577 100644 --- a/modules/tracker/views/config/index.phtml +++ b/modules/tracker/views/admin/index.phtml @@ -18,24 +18,19 @@ limitations under the License. =========================================================================*/ -$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.form.js'); -$this->headScript()->appendFile($this->moduleWebroot.'/public/js/config/config.index.js'); +$this->declareVars('form', 'pageTitle'); +$this->headTitle($this->escape($this->pageTitle)); ?>
-
-
-

Set this field to the number of hours that unofficial submissions should be kept before being deleted - automatically - by the scheduler. The default value is 24 hours.

-
-
- - -
-
- -
-
+

escape($this->pageTitle); ?>

+

+ Set the unofficial scalar TTL to the number of hours that unofficial submissions should be kept before being + deleted automatically by the scheduler. +

+ form; ?> +

« Back to Modules Administration

+ + +