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

Commit 074e1e6

Browse files
author
Jamie Snape
committed
Revise batchmake module configuration form
1 parent e05da36 commit 074e1e6

File tree

14 files changed

+239
-480
lines changed

14 files changed

+239
-480
lines changed

modules/batchmake/configs/module.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ dependencies = api
88
uuid = "290da3c9-2e57-4866-b727-645a47419dc5"
99
version = "1.0.0"
1010

11-
batchmake.tmp_dir =
12-
batchmake.bin_dir =
13-
batchmake.script_dir =
14-
batchmake.app_dir =
15-
batchmake.data_dir =
16-
batchmake.condor_bin_dir =
11+
batchmake.app_dir = ""
12+
batchmake.bin_dir = ""
13+
batchmake.condor_bin_dir = ""
14+
batchmake.data_dir = ""
15+
batchmake.script_dir = ""
16+
batchmake.tmp_dir = ""

modules/batchmake/constant/module.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
define('MIDAS_BATCHMAKE_DATA_DIR_PROPERTY', 'data_dir');
5656
define('MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY', 'condor_bin_dir');
5757

58+
// default subdirectories for the properties
59+
define('MIDAS_BATCHMAKE_DEFAULT_TMP_DIR', 'batchmake/tmp');
60+
define('MIDAS_BATCHMAKE_DEFAULT_BIN_DIR', 'batchmake/bin');
61+
define('MIDAS_BATCHMAKE_DEFAULT_SCRIPT_DIR', 'batchmake/script');
62+
define('MIDAS_BATCHMAKE_DEFAULT_APP_DIR', 'batchmake/bin');
63+
define('MIDAS_BATCHMAKE_DEFAULT_DATA_DIR', 'batchmake/data');
64+
5865
// key for global config
5966
define('MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME', 'global');
6067

@@ -73,6 +80,9 @@
7380
define('MIDAS_BATCHMAKE_CONFIGS_PATH', LOCAL_CONFIGS_PATH.'/'.MIDAS_BATCHMAKE_MODULE);
7481
define('MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG', MIDAS_BATCHMAKE_CONFIGS_PATH.'.local.ini');
7582

83+
// name of csrf token
84+
define('MIDAS_BATCHMAKE_CSRF_TOKEN', 'csrf');
85+
7686
// submit button name for config
7787
define('MIDAS_BATCHMAKE_SUBMIT_CONFIG', 'submitConfig');
7888

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 batchmake module. */
22+
class Batchmake_AdminController extends Batchmake_AppController
23+
{
24+
/** @var array */
25+
public $_moduleComponents = array('KWBatchmake');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'BatchMake Module Configuration';
33+
$config = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null, false);
34+
$form = new Batchmake_Form_Admin();
35+
36+
if ($this->getRequest()->isPost()) {
37+
$data = $this->getRequest()->getPost();
38+
39+
if ($form->isValid($data)) {
40+
$values = $form->getValues();
41+
42+
foreach ($values as $key => $value) {
43+
if ($key !== MIDAS_BATCHMAKE_CSRF_TOKEN && !is_null($value)) {
44+
$config[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$key] = $value;
45+
}
46+
}
47+
48+
UtilityComponent::createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $config);
49+
}
50+
51+
$form->populate($data);
52+
} else {
53+
$elements = $form->getElements();
54+
55+
foreach ($elements as $element) {
56+
$batchMakeConfig = $this->ModuleComponent->KWBatchmake->filterBatchmakeConfigProperties($config);
57+
$defaultConfig = $this->createDefaultConfig($batchMakeConfig);
58+
$name = $element->getName();
59+
60+
if ($name !== MIDAS_BATCHMAKE_CSRF_TOKEN && $name !== MIDAS_BATCHMAKE_SUBMIT_CONFIG) {
61+
$value = $defaultConfig[$name];
62+
63+
if (!is_null($value)) {
64+
$form->setDefault($name, $value);
65+
}
66+
}
67+
}
68+
}
69+
70+
$this->view->form = $form;
71+
session_start();
72+
}
73+
74+
/**
75+
* will create default paths in the temporary directory
76+
* for any properties not already set, except for the
77+
* condor bin dir; imposing a firmer hand on the user
78+
*
79+
* @param array $currentConfig current configuration
80+
* @return array
81+
*/
82+
protected function createDefaultConfig($currentConfig)
83+
{
84+
$defaultConfigDirs = array(
85+
MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_TMP_DIR,
86+
MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_BIN_DIR,
87+
MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_SCRIPT_DIR,
88+
MIDAS_BATCHMAKE_APP_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_APP_DIR,
89+
MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_DATA_DIR,
90+
);
91+
92+
$returnedConfig = array();
93+
94+
foreach ($currentConfig as $configProp => $configDir) {
95+
if ((!isset($configProp) || !isset($configDir) || empty($configDir)) && array_key_exists(
96+
$configProp,
97+
$defaultConfigDirs
98+
)
99+
) {
100+
$returnedConfig[$configProp] = UtilityComponent::getTempDirectory($defaultConfigDirs[$configProp]);
101+
} else {
102+
$returnedConfig[$configProp] = $configDir;
103+
}
104+
}
105+
106+
return $returnedConfig;
107+
}
108+
}

modules/batchmake/controllers/ConfigController.php

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

modules/batchmake/controllers/forms/ConfigForm.php

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

modules/batchmake/form/Admin.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 batchmake module. */
22+
class Batchmake_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('batchmake_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash(MIDAS_BATCHMAKE_CSRF_TOKEN);
31+
$csrf->setSalt('KZVfYdsDTzQh5T7eQDXmADfu');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$tmpDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY);
35+
$tmpDirectory->setLabel('BatchMake Temporary Directory');
36+
$tmpDirectory->setRequired(true);
37+
$tmpDirectory->addValidator('NotEmpty', true);
38+
39+
$binDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_BIN_DIR_PROPERTY);
40+
$binDirectory->setLabel('BatchMake Binary Directory');
41+
$binDirectory->setRequired(true);
42+
$binDirectory->addValidator('NotEmpty', true);
43+
44+
$scriptDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY);
45+
$scriptDirectory->setLabel('BatchMake Script Directory');
46+
$scriptDirectory->setRequired(true);
47+
$scriptDirectory->addValidator('NotEmpty', true);
48+
49+
$appDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_APP_DIR_PROPERTY);
50+
$appDirectory->setLabel('BatchMake Application Directory');
51+
$appDirectory->setRequired(true);
52+
$appDirectory->addValidator('NotEmpty', true);
53+
54+
$dataDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_DATA_DIR_PROPERTY);
55+
$dataDirectory->setLabel('BatchMake Data Directory');
56+
$dataDirectory->setRequired(true);
57+
$dataDirectory->addValidator('NotEmpty', true);
58+
59+
$condorBinDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY);
60+
$condorBinDirectory->setLabel('Condor Binary Directory');
61+
$condorBinDirectory->setRequired(true);
62+
$condorBinDirectory->addValidator('NotEmpty', true);
63+
64+
$this->addDisplayGroup(array($tmpDirectory, $binDirectory, $scriptDirectory, $appDirectory, $dataDirectory, $condorBinDirectory), 'global');
65+
66+
$submit = new Zend_Form_Element_Submit(MIDAS_BATCHMAKE_SUBMIT_CONFIG);
67+
$submit->setLabel('Save');
68+
69+
$this->addElements(array($csrf, $tmpDirectory, $binDirectory, $scriptDirectory, $appDirectory, $dataDirectory, $condorBinDirectory, $submit));
70+
}
71+
}

modules/batchmake/public/css/config/config.index.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)