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

Commit 5a7af21

Browse files
author
Jamie Snape
committed
Revise tracker module configuration form and add install script
1 parent 3ebfbca commit 5a7af21

File tree

10 files changed

+188
-113
lines changed

10 files changed

+188
-113
lines changed

modules/tracker/configs/module.ini

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[global]
2-
; version of the module
3-
version = 1.0.5
4-
; full name of the module (displayed on admin page)
5-
fullname = Tracker Dashboard
6-
; description (displayed on admin page)
7-
description = "Tracks scalar results over time"
8-
; category
9-
category = Visualization
10-
; dependencies (comma separated list of other module dependencies)
4+
fullname = "Tracker Dashboard"
5+
description = "Track scalar results over time"
6+
category = "Visualization"
117
dependencies = api,scheduler
8+
uuid = "3048a9fa-89ab-4e61-a55e-a49379fa6dc"
9+
version = "1.1.0"

modules/tracker/constant/module.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21+
define('MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY', 'tempScalarTtl');
22+
define('MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE', 24);
2123
define('MIDAS_TRACKER_EMAIL_USER', 'emailuser');
2224
define('MIDAS_TRACKER_EMAIL_GROUP', 'emailgroup');
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the tracker module. */
22+
class Tracker_AdminController extends Tracker_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'Tracker Module Configuration';
33+
$form = new Tracker_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
if ($value !== null) {
43+
$this->Setting->setConfig($key, $value, $this->moduleName);
44+
}
45+
}
46+
}
47+
48+
$form->populate($data);
49+
} else {
50+
$elements = $form->getElements();
51+
52+
foreach ($elements as $element) {
53+
$name = $element->getName();
54+
55+
if ($name !== 'csrf' && $name !== 'submit') {
56+
$value = $this->Setting->getValueByName($name, $this->moduleName);
57+
58+
if (!is_null($value)) {
59+
$form->setDefault($name, $value);
60+
}
61+
}
62+
}
63+
}
64+
65+
$this->view->form = $form;
66+
session_start();
67+
}
68+
}

modules/tracker/controllers/ConfigController.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

modules/tracker/controllers/components/ApiComponent.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/** Component for api methods */
2222
class Tracker_ApiComponent extends AppComponent
2323
{
24+
/** @var string */
25+
public $moduleName = 'tracker';
26+
2427
/**
2528
* Helper function for verifying keys in an input array
2629
*/
@@ -247,7 +250,7 @@ public function scalarAdd($args)
247250
if (!$official) {
248251
$jobModel = MidasLoader::loadModel('Job', 'scheduler');
249252
$settingModel = MidasLoader::loadModel('Setting');
250-
$nHours = $settingModel->getValueByName('tempScalarTtl', 'tracker');
253+
$nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName);
251254
if (!$nHours) {
252255
$nHours = 24; // default to 24 hours
253256
}
@@ -298,9 +301,9 @@ public function resultsUploadJson($args)
298301
if (!$official) {
299302
$jobModel = MidasLoader::loadModel('Job', 'scheduler');
300303
$settingModel = MidasLoader::loadModel('Setting');
301-
$nHours = $settingModel->getValueByName('tempScalarTtl', 'tracker');
304+
$nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName);
302305
if (!$nHours) {
303-
$nHours = 24; // default to 24 hours
306+
$nHours = MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE; // default to 24 hours
304307
}
305308
}
306309

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/tracker/constant/module.php';
22+
23+
/** Install the tracker module. */
24+
class Tracker_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'tracker';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE, $this->moduleName);
35+
}
36+
}

modules/tracker/database/upgrade/1.1.0.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@
2121
/** Upgrade the tracker module to version 1.1.0. */
2222
class Tracker_Upgrade_1_1_0 extends MIDASUpgrade
2323
{
24+
/** Pre database upgrade. */
25+
public function preUpgrade()
26+
{
27+
}
28+
29+
/** Post database upgrade. */
30+
public function postUpgrade()
31+
{
32+
}
2433
}

modules/tracker/forms/Admin.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin form for the tracker module. */
22+
class Tracker_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('tracker_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash('csrf');
31+
$csrf->setSalt('APSey8FJpXfDssQU5CqA9qe5');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$tempScalarTtl = new Zend_Form_Element_Text(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY);
35+
$tempScalarTtl->setLabel('Unofficial Scalar TTL');
36+
$tempScalarTtl->setRequired(true);
37+
$tempScalarTtl->addValidator('NotEmpty', true);
38+
$tempScalarTtl->addValidator('Digits', true);
39+
$tempScalarTtl->addValidator('GreaterThan', true, array('min' => 0));
40+
41+
$this->addDisplayGroup(array($tempScalarTtl), 'global');
42+
43+
$submit = new Zend_Form_Element_Submit('submit');
44+
$submit->setLabel('Save');
45+
46+
$this->addElements(array($csrf, $tempScalarTtl, $submit));
47+
}
48+
}

modules/tracker/public/js/config/config.index.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

modules/tracker/views/config/index.phtml renamed to modules/tracker/views/admin/index.phtml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.form.js');
22-
$this->headScript()->appendFile($this->moduleWebroot.'/public/js/config/config.index.js');
21+
$this->declareVars('form', 'pageTitle');
22+
$this->headTitle($this->escape($this->pageTitle));
2323
?>
2424

2525
<div class="viewMain">
26-
<form id="configForm" class="genericForm" method="POST"
27-
action="<?php echo $this->webroot; ?>/tracker/config/submit">
28-
<div class="explanation">
29-
<p>Set this field to the number of hours that unofficial submissions should be kept before being deleted
30-
automatically
31-
by the scheduler. The default value is 24 hours.</p>
32-
</div>
33-
<div>
34-
<label for="tempScalarTtl">Unofficial Scalar TTL</label>
35-
<input type="text" name="tempScalarTtl" value="<?php echo $this->tempScalarTtl; ?>"/>
36-
</div>
37-
<div>
38-
<input type="submit" value="Save"/>
39-
</div>
40-
</form>
26+
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
27+
<p>
28+
Set the unofficial scalar TTL to the number of hours that unofficial submissions should be kept before being
29+
deleted automatically by the scheduler.
30+
</p>
31+
<?php echo $this->form; ?>
32+
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
4133
</div>
34+
35+
36+

0 commit comments

Comments
 (0)