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

Commit 794e07c

Browse files
author
Michael Grauer
committed
BUG: Refs #212. Further work towards better default configuration of batchmake
1 parent b987208 commit 794e07c

File tree

7 files changed

+168
-51
lines changed

7 files changed

+168
-51
lines changed

modules/api/public/js/common/common.ajaxapi.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ ajaxWebApi._webApiCall = function(params)
6464
params.success(retVal);
6565
}
6666
},
67-
error: function() {
67+
error: function(retVal) {
6868
ajaxWebApi.logError('Ajax call to web API returned an error (' +
6969
json.global.webroot + '/api/json' + '?' + params.method + '&' + params.args + ')', params.log);
70+
if(params.error)
71+
{
72+
params.error(retVal);
73+
}
7074
if(params.complete)
7175
{
7276
params.complete();

modules/batchmake/Notification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getLeftLink()
5757
{
5858
$fc = Zend_Controller_Front::getInstance();
5959
$moduleWebroot = $fc->getBaseUrl() . MIDAS_BATCHMAKE_MODULE;
60-
return array(ucfirst(MIDAS_BATCHMAKE_MODULE) => array($moduleWebroot, $moduleWebRoot . '/public/images/cmake.png'));
60+
return array(ucfirst(MIDAS_BATCHMAKE_MODULE) => array($moduleWebroot, $moduleWebroot . '/public/images/cmake.png'));
6161
}
6262

6363
} //end class

modules/batchmake/controllers/ConfigController.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function createDefaultConfig($currentConfig)
6969
$returnedConfig = array();
7070
foreach($currentConfig as $configProp => $configDir)
7171
{
72-
if(!isset($configProp) || !isset($configDir) || $configDir == "")
72+
if((!isset($configProp) || !isset($configDir) || $configDir == "") && array_key_exists($configProp, $defaultConfigDirs))
7373
{
7474
$configDir = $defaultConfigDirs[$configProp];
7575
$returnedConfig[$configProp] = $configDir;
@@ -97,17 +97,16 @@ protected function createDefaultConfig($currentConfig)
9797
*/
9898
public function indexAction()
9999
{
100-
101-
$applicationConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties();
102-
$applicationConfig = $this->createDefaultConfig($applicationConfig);
100+
// get all the properties, not just the batchmake config
101+
$fullConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null,false);
102+
// now get just the batchmake ones
103+
$batchmakeConfig = $this->ModuleComponent->KWBatchmake->filterBatchmakeConfigProperties($fullConfig);
104+
105+
// $applicationConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties();
106+
$batchmakeConfig = $this->createDefaultConfig($batchmakeConfig);
103107
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
104-
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
105-
$formArray = $this->getFormAsArray($configForm);
106-
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
107-
{
108-
$formArray[$configProperty]->setValue($applicationConfig[$configProperty]);
109-
}
110-
$this->view->configForm = $formArray;
108+
109+
111110

112111
if($this->_request->isPost())
113112
{
@@ -119,16 +118,31 @@ public function indexAction()
119118
{
120119
$this->archiveOldModuleLocal();
121120
// save only those properties we are interested for local configuration
122-
$newsaver = array();
123121
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
124122
{
125-
$newsaver[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
123+
$fullConfig[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
126124
}
127-
$this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $newsaver);
125+
$this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $fullConfig);
126+
// $newsaver = array();
127+
// foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
128+
// {
129+
// $newsaver[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
130+
// }
131+
// $this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $newsaver);
128132
$msg = $this->t(MIDAS_BATCHMAKE_CHANGES_SAVED_STRING);
129133
echo JsonComponent::encode(array(true, $msg));
130134
}
131135
}
136+
else
137+
{
138+
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
139+
$formArray = $this->getFormAsArray($configForm);
140+
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
141+
{
142+
$formArray[$configProperty]->setValue($batchmakeConfig[$configProperty]);
143+
}
144+
$this->view->configForm = $formArray;
145+
}
132146

133147
}
134148

modules/batchmake/controllers/components/ApiComponent.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,30 @@ private function _checkKeys($keys, $values)
3838
* @param data_dir the path to the data export dir
3939
* @param condor_bin_dir the path to the location of the condor executables
4040
* @return an array, the first value is a 0 if the config is incorrect or 1
41-
* if the config is correct, the second value is a list of individual
42-
* config values and their status.
41+
* if the config is correct, the second value is a list of individual config values and their statuses.
4342
*/
44-
public function testConfig($value)
43+
public function testconfig($params)
4544
{
4645
// any values that aren't filled in, fill them in with a blank
4746
$expectedKeys = array("tmp_dir", "bin_dir", "script_dir", "app_dir", "data_dir", "condor_bin_dir");
48-
$replacements = array();
49-
foreach($value as $key=>$value)
47+
$configParams = array();
48+
foreach($expectedKeys as $propKey)
5049
{
51-
if(!isset($key))
50+
if(!isset($params[$propKey]))
5251
{
53-
$replacements[$key] = "";
52+
$configParams[$propKey] = "";
5453
}
55-
}
56-
foreach($replacements as $replacement=>$val)
57-
{
58-
$value[$replacement] = $val;
59-
}
60-
54+
else
55+
{
56+
$configParams[$propKey] = $params[$propKey];
57+
}
58+
}
6159

62-
$this->_checkKeys(array('item_id', 'metric_name'), $value);
60+
//$this->_checkKeys(array('item_id', 'metric_name'), $value);
6361

6462
$componentLoader = new MIDAS_ComponentLoader();
6563
$kwbatchmakeComponent = $componentLoader->loadComponent('KWBatchmake', 'batchmake');
66-
return array($kwbatchmakeComponent->testconfig($value));
64+
return array($kwbatchmakeComponent->testconfig($configParams));
6765
}
6866

6967

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public function __construct($alternateConfig = null, $executor = null)
8989
* helper function to load the correct config file
9090
* @return config array with config properties
9191
*/
92-
protected function loadConfig()
92+
protected function loadConfig($processSections = false)
9393
{
9494
$path = MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG;
9595
if(file_exists(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG))
9696
{
97-
$config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, false);
97+
$config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $processSections);
9898
}
9999
else
100100
{
@@ -103,44 +103,125 @@ protected function loadConfig()
103103
return $config;
104104
}
105105

106+
107+
108+
public function filterBatchmakeConfigProperties($fullConfig)
109+
{
110+
$batchmakeProps = array();
111+
$globalProps = $fullConfig['global'];
112+
$modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.';
113+
foreach($globalProps as $configProperty => $configPropertyVal)
114+
{
115+
$ind = strpos($configProperty, $modulePropertyNamespace);
116+
if($ind !== false && $ind == 0)
117+
{
118+
$reducedKey = substr($configProperty, strpos($configProperty, '.') + 1);
119+
$batchmakeProps[$reducedKey] = $configPropertyVal;
120+
}
121+
}
122+
return $batchmakeProps;
123+
}
124+
125+
106126
/**
107127
* @method loadConfigProperties
108128
* will load the configuration property values for this module, and filter
109129
* out only those properties that are in the 'batchmake.' config namespace,
110130
* removing the 'batchmake.' from the key name.
111131
* @param string $alternateConfig an array of alternate config props
132+
* @param boolean $batchmakeOnly whether to get all properties or only config
112133
* @return array of batchmake module specific config properties
113134
*/
114-
public function loadConfigProperties($alternateConfig = null)
135+
public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = true)
115136
{
116-
if(!isset($alternateConfig))
137+
// load the full config
138+
$rawConfig = $this->loadConfig(true);
139+
$globalProps = $rawConfig['global'];
140+
// now set all the batchmake properties, except if we have any alternatives
141+
$configPropertiesParamVals = array();
142+
if(isset($alternateConfig))
117143
{
118-
$configPropertiesParamVals = array();
119-
$rawConfig = $this->loadConfig();
120-
144+
$configPropertiesParamVals = $alternateConfig;
145+
// set these properties in the rawConfig
146+
foreach($alternateConfig as $propKey => $propVal)
147+
{
148+
$globalProps[MIDAS_BATCHMAKE_MODULE . '.' . $propKey] = $propVal;
149+
}
150+
$rawConfig['global'] = $globalProps;
151+
}
152+
// else
153+
// {
154+
$batchmakeProps = $this->filterBatchmakeConfigProperties($rawConfig);
155+
foreach($batchmakeProps as $configProperty => $configPropertyVal)
156+
{
157+
$configPropertiesParamVals[$configProperty] = $configPropertyVal;
158+
}
159+
160+
/* $configPropertiesParamVals = array();
121161
$modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.';
122-
foreach($rawConfig as $configProperty => $configPropertyVal)
162+
foreach($globalProps as $configProperty => $configPropertyVal)
123163
{
124164
$ind = strpos($configProperty, $modulePropertyNamespace);
125165
if($ind !== false && $ind == 0)
126166
{
127167
$reducedKey = substr($configProperty, strpos($configProperty, '.') + 1);
128168
$configPropertiesParamVals[$reducedKey] = $configPropertyVal;
129169
}
130-
}
131-
}
132-
else
133-
{
134-
$configPropertiesParamVals = $alternateConfig;
135-
}
170+
}*/
171+
// }
172+
// set the member fields for config variables
136173
$this->componentConfig = $configPropertiesParamVals;
137174
$this->configScriptDir = $this->componentConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
138175
$this->configAppDir = $this->componentConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
139176
$this->configTmpDir = $this->componentConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
140177
$this->configBinDir = $this->componentConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
141178
$this->configDataDir = $this->componentConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
142179
$this->configCondorBinDir = $this->componentConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
143-
return $this->componentConfig;
180+
// return only batchmake or full array
181+
if($batchmakeOnly)
182+
{
183+
return $this->componentConfig;
184+
}
185+
else
186+
{
187+
return $rawConfig;
188+
}
189+
190+
191+
/* if(!isset($alternateConfig))
192+
{
193+
$rawConfig = $this->loadConfig();
194+
195+
// batchmakeOnly option says to remove all other properties than those
196+
// prefixed with "batchmake."
197+
if($batchmakeOnly)
198+
{
199+
$modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.';
200+
foreach($rawConfig as $configProperty => $configPropertyVal)
201+
{
202+
$ind = strpos($configProperty, $modulePropertyNamespace);
203+
if($ind !== false && $ind == 0)
204+
{
205+
$reducedKey = substr($configProperty, strpos($configProperty, '.') + 1);
206+
$configPropertiesParamVals[$reducedKey] = $configPropertyVal;
207+
}
208+
}
209+
}
210+
}
211+
else
212+
{
213+
$configPropertiesParamVals = $alternateConfig;
214+
}
215+
216+
*/
217+
// $this->componentConfig = $configPropertiesParamVals;
218+
// $this->configScriptDir = $this->componentConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
219+
// $this->configAppDir = $this->componentConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
220+
// $this->configTmpDir = $this->componentConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
221+
// $this->configBinDir = $this->componentConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
222+
// $this->configDataDir = $this->componentConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
223+
// $this->configCondorBinDir = $this->componentConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
224+
// return $this->componentConfig;
144225
}
145226

146227
// above here is config setup

modules/batchmake/public/js/config/config.index.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ php_div = 'php_config_div';
3737

3838
$('#configForm input').keyup(function()
3939
{
40-
$(document).find('#submitConfig').attr('disabled','disabled');
40+
// $(document).find('#submitConfig').attr('disabled','disabled');
4141
// var obj=$(this);
4242
//checkAll(obj);
4343
});
4444

45-
$(document).find('#submitConfig').attr('disabled','disabled');
45+
// $(document).find('#submitConfig').attr('disabled','disabled');
4646

4747
checkConfig($(this));
4848
});
@@ -63,7 +63,22 @@ app_dir_val = $(document).find('#app_dir').val()
6363
data_dir_val = $(document).find('#data_dir').val()
6464
condor_bin_dir_val = $(document).find('#condor_bin_dir').val()
6565

66-
66+
/* ajaxWebApi.ajax({
67+
method: 'midas.batchmake.testconfig',
68+
args: 'tmp_dir=' + tmp_dir_val + '&bin_dir=' + bin_dir_val,
69+
log: $('#testError'),
70+
success: function(retVal) {
71+
handleValidationResponse(retVal);
72+
},
73+
error: function(retVal) {
74+
alert(retVal.responseText);
75+
},
76+
complete: function() {
77+
$('#testLoading').hide();
78+
}
79+
});*/
80+
81+
6782
$.ajax({
6883
type: "POST",
6984
url: json.global.webroot+'/batchmake/config/testconfig',
@@ -81,6 +96,9 @@ function handleValidationResponse(jsonContent)
8196
$(document).find('#testLoading').hide();
8297

8398
var testConfig=jQuery.parseJSON(jsonContent);
99+
// //some kinda error handling?
100+
//
101+
//
84102
// testConfig should be
85103
// [0] = 1 if the global config is correct, 0 otherwise
86104
// [1] = an array of individual config properties and statuses
@@ -93,13 +111,13 @@ function handleValidationResponse(jsonContent)
93111
{
94112
$(document).find('#testOk').show();
95113
$(document).find('#testError').html(global_config_correct_msg).removeClass().addClass(info_class);
96-
$(document).find('#submitConfig').removeAttr('disabled');
114+
// $(document).find('#submitConfig').removeAttr('disabled');
97115
}
98116
else
99117
{
100118
$(document).find('#testNok').show();
101119
$(document).find('#testError').html(global_config_error_msg).removeClass().addClass(error_class);
102-
$(document).find('#submitConfig').attr('disabled','disabled');
120+
// $(document).find('#submitConfig').attr('disabled','disabled');
103121
}
104122

105123
$(document).find('div #'+application_div).children().remove();

modules/batchmake/views/config/index.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

1313
$this->headScript()->appendFile($this->coreWebroot . '/public/js/jquery/jquery.form.js');
14+
$this->headScript()->appendFile($this->apiWebroot.'/public/js/common/common.ajaxapi.js');
1415
$this->headScript()->appendFile($this->moduleWebroot . '/public/js/config/config.index.js');
16+
1517
?>
1618
<link type="text/css" rel="stylesheet" href="<?php echo $this->moduleWebroot?>/public/css/config/config.index.css" />
1719
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.genericPage.css" />

0 commit comments

Comments
 (0)