This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise batchmake module configuration form
- Loading branch information
Jamie Snape
committed
Dec 8, 2014
1 parent
e05da36
commit 074e1e6
Showing
14 changed files
with
239 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.