Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Revise tracker module configuration form and add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 8, 2014
1 parent 3ebfbca commit 5a7af21
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 113 deletions.
16 changes: 7 additions & 9 deletions modules/tracker/configs/module.ini
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions modules/tracker/constant/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
68 changes: 68 additions & 0 deletions modules/tracker/controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Admin controller for the tracker module. */
class Tracker_AdminController extends Tracker_AppController
{
/** @var array */
public $_models = array('Setting');

/** Index action */
public function indexAction()
{
$this->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();
}
}
63 changes: 0 additions & 63 deletions modules/tracker/controllers/ConfigController.php

This file was deleted.

9 changes: 6 additions & 3 deletions modules/tracker/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}

Expand Down
36 changes: 36 additions & 0 deletions modules/tracker/database/InstallScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

require_once BASE_PATH.'/modules/tracker/constant/module.php';

/** Install the tracker module. */
class Tracker_InstallScript extends MIDASModuleInstallScript
{
/** @var string */
public $moduleName = 'tracker';

/** Post database install. */
public function postInstall()
{
/** @var SettingModel $settingModel */
$settingModel = MidasLoader::loadModel('Setting');
$settingModel->setConfig(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE, $this->moduleName);
}
}
9 changes: 9 additions & 0 deletions modules/tracker/database/upgrade/1.1.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
}
48 changes: 48 additions & 0 deletions modules/tracker/forms/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Admin form for the tracker module. */
class Tracker_Form_Admin extends Zend_Form
{
/** Initialize this form. */
public function init()
{
$this->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));
}
}
21 changes: 0 additions & 21 deletions modules/tracker/public/js/config/config.index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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));
?>

<div class="viewMain">
<form id="configForm" class="genericForm" method="POST"
action="<?php echo $this->webroot; ?>/tracker/config/submit">
<div class="explanation">
<p>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.</p>
</div>
<div>
<label for="tempScalarTtl">Unofficial Scalar TTL</label>
<input type="text" name="tempScalarTtl" value="<?php echo $this->tempScalarTtl; ?>"/>
</div>
<div>
<input type="submit" value="Save"/>
</div>
</form>
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
<p>
Set the unofficial scalar TTL to the number of hours that unofficial submissions should be kept before being
deleted automatically by the scheduler.
</p>
<?php echo $this->form; ?>
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
</div>



0 comments on commit 5a7af21

Please sign in to comment.