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

Commit

Permalink
Revise batchmake module configuration form
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 8, 2014
1 parent e05da36 commit 074e1e6
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 480 deletions.
12 changes: 6 additions & 6 deletions modules/batchmake/configs/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ dependencies = api
uuid = "290da3c9-2e57-4866-b727-645a47419dc5"
version = "1.0.0"

batchmake.tmp_dir =
batchmake.bin_dir =
batchmake.script_dir =
batchmake.app_dir =
batchmake.data_dir =
batchmake.condor_bin_dir =
batchmake.app_dir = ""
batchmake.bin_dir = ""
batchmake.condor_bin_dir = ""
batchmake.data_dir = ""
batchmake.script_dir = ""
batchmake.tmp_dir = ""
10 changes: 10 additions & 0 deletions modules/batchmake/constant/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
define('MIDAS_BATCHMAKE_DATA_DIR_PROPERTY', 'data_dir');
define('MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY', 'condor_bin_dir');

// default subdirectories for the properties
define('MIDAS_BATCHMAKE_DEFAULT_TMP_DIR', 'batchmake/tmp');
define('MIDAS_BATCHMAKE_DEFAULT_BIN_DIR', 'batchmake/bin');
define('MIDAS_BATCHMAKE_DEFAULT_SCRIPT_DIR', 'batchmake/script');
define('MIDAS_BATCHMAKE_DEFAULT_APP_DIR', 'batchmake/bin');
define('MIDAS_BATCHMAKE_DEFAULT_DATA_DIR', 'batchmake/data');

// key for global config
define('MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME', 'global');

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

// name of csrf token
define('MIDAS_BATCHMAKE_CSRF_TOKEN', 'csrf');

// submit button name for config
define('MIDAS_BATCHMAKE_SUBMIT_CONFIG', 'submitConfig');

Expand Down
108 changes: 108 additions & 0 deletions modules/batchmake/controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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 batchmake module. */
class Batchmake_AdminController extends Batchmake_AppController
{
/** @var array */
public $_moduleComponents = array('KWBatchmake');

/** Index action */
public function indexAction()
{
$this->requireAdminPrivileges();

$this->view->pageTitle = 'BatchMake Module Configuration';
$config = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null, false);
$form = new Batchmake_Form_Admin();

if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();

if ($form->isValid($data)) {
$values = $form->getValues();

foreach ($values as $key => $value) {
if ($key !== MIDAS_BATCHMAKE_CSRF_TOKEN && !is_null($value)) {
$config[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$key] = $value;
}
}

UtilityComponent::createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $config);
}

$form->populate($data);
} else {
$elements = $form->getElements();

foreach ($elements as $element) {
$batchMakeConfig = $this->ModuleComponent->KWBatchmake->filterBatchmakeConfigProperties($config);
$defaultConfig = $this->createDefaultConfig($batchMakeConfig);
$name = $element->getName();

if ($name !== MIDAS_BATCHMAKE_CSRF_TOKEN && $name !== MIDAS_BATCHMAKE_SUBMIT_CONFIG) {
$value = $defaultConfig[$name];

if (!is_null($value)) {
$form->setDefault($name, $value);
}
}
}
}

$this->view->form = $form;
session_start();
}

/**
* will create default paths in the temporary directory
* for any properties not already set, except for the
* condor bin dir; imposing a firmer hand on the user
*
* @param array $currentConfig current configuration
* @return array
*/
protected function createDefaultConfig($currentConfig)
{
$defaultConfigDirs = array(
MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_TMP_DIR,
MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_BIN_DIR,
MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_SCRIPT_DIR,
MIDAS_BATCHMAKE_APP_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_APP_DIR,
MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => MIDAS_BATCHMAKE_DEFAULT_DATA_DIR,
);

$returnedConfig = array();

foreach ($currentConfig as $configProp => $configDir) {
if ((!isset($configProp) || !isset($configDir) || empty($configDir)) && array_key_exists(
$configProp,
$defaultConfigDirs
)
) {
$returnedConfig[$configProp] = UtilityComponent::getTempDirectory($defaultConfigDirs[$configProp]);
} else {
$returnedConfig[$configProp] = $configDir;
}
}

return $returnedConfig;
}
}
120 changes: 0 additions & 120 deletions modules/batchmake/controllers/ConfigController.php

This file was deleted.

50 changes: 0 additions & 50 deletions modules/batchmake/controllers/forms/ConfigForm.php

This file was deleted.

71 changes: 71 additions & 0 deletions modules/batchmake/form/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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 batchmake module. */
class Batchmake_Form_Admin extends Zend_Form
{
/** Initialize this form. */
public function init()
{
$this->setName('batchmake_admin');
$this->setMethod('POST');

$csrf = new Midas_Form_Element_Hash(MIDAS_BATCHMAKE_CSRF_TOKEN);
$csrf->setSalt('KZVfYdsDTzQh5T7eQDXmADfu');
$csrf->setDecorators(array('ViewHelper'));

$tmpDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY);
$tmpDirectory->setLabel('BatchMake Temporary Directory');
$tmpDirectory->setRequired(true);
$tmpDirectory->addValidator('NotEmpty', true);

$binDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_BIN_DIR_PROPERTY);
$binDirectory->setLabel('BatchMake Binary Directory');
$binDirectory->setRequired(true);
$binDirectory->addValidator('NotEmpty', true);

$scriptDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY);
$scriptDirectory->setLabel('BatchMake Script Directory');
$scriptDirectory->setRequired(true);
$scriptDirectory->addValidator('NotEmpty', true);

$appDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_APP_DIR_PROPERTY);
$appDirectory->setLabel('BatchMake Application Directory');
$appDirectory->setRequired(true);
$appDirectory->addValidator('NotEmpty', true);

$dataDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_DATA_DIR_PROPERTY);
$dataDirectory->setLabel('BatchMake Data Directory');
$dataDirectory->setRequired(true);
$dataDirectory->addValidator('NotEmpty', true);

$condorBinDirectory = new Zend_Form_Element_Text(MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY);
$condorBinDirectory->setLabel('Condor Binary Directory');
$condorBinDirectory->setRequired(true);
$condorBinDirectory->addValidator('NotEmpty', true);

$this->addDisplayGroup(array($tmpDirectory, $binDirectory, $scriptDirectory, $appDirectory, $dataDirectory, $condorBinDirectory), 'global');

$submit = new Zend_Form_Element_Submit(MIDAS_BATCHMAKE_SUBMIT_CONFIG);
$submit->setLabel('Save');

$this->addElements(array($csrf, $tmpDirectory, $binDirectory, $scriptDirectory, $appDirectory, $dataDirectory, $condorBinDirectory, $submit));
}
}
1 change: 0 additions & 1 deletion modules/batchmake/public/css/config/config.index.css

This file was deleted.

Loading

0 comments on commit 074e1e6

Please sign in to comment.