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

Commit 3974ef3

Browse files
author
Charles Ma
committed
ENH: refs #301 Added autogenerated name
Fixed wizard style Added my jobs page Added jobs name
1 parent c668b0c commit 3974ef3

File tree

23 files changed

+310
-121
lines changed

23 files changed

+310
-121
lines changed

core/public/css/jquery/jquery.smartWizard-2.0.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
border: 0px solid #CCC;
2727
overflow:hidden;
2828
clear:right;
29-
height:400px;
29+
height:500px;
3030
}
3131

3232
.swMain .stepContainer div.content {
@@ -39,7 +39,7 @@
3939
font: normal 12px Verdana, Arial, Helvetica, sans-serif;
4040
color:#5A5655;
4141
background-color:#F8F8F8;
42-
height:450px;
42+
height:500px;
4343
text-align:left;
4444
overflow:auto;
4545
z-index:88;

core/views/item/view.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ if($this->preview) // module visualize
203203
</li>
204204
<li>
205205
<a href='javascript:;' type='item' element='{$this->itemDao->getKey()}' class='sharingLink' ><img alt='' src='{$this->coreWebroot}/public/images/icons/share.png'/> {$this->t('Permissions')}</a>
206-
</li>
206+
</li>
207207
<li>
208208
<a href='javascript:;' type='item' element='{$this->itemDao->getKey()}' class='uploadRevisionLink' ><img alt='' src='{$this->coreWebroot}/public/images/icons/upload.png'/> {$this->t('Upload new revision')}</a>
209209
</li>

modules/remoteprocessing/Notification.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getActionMenu($params)
6666
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/executable/define/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/xml.png'/> ".$this->t('Define Executable')."</a>
6767
</li>
6868
<li>
69-
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/job/manage/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/job.png'/> ".$this->t('Manage Processing Jobs')."</a>
69+
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/job/init/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/job.png'/> ".$this->t('Create a Job')."</a>
7070
</li> ";
7171
return $html;
7272
}
@@ -143,8 +143,13 @@ public function getItemInfo($params)
143143
$i = 0;
144144
foreach($jobs as $job)
145145
{
146+
$name = $job->getName();
147+
if(empty($name))
148+
{
149+
$name = $job->getCreationDate();
150+
}
146151
$html .= "<li>";
147-
$html .= "<a element='".$job->getKey()."' href='".Zend_Registry::get('webroot')."/remoteprocessing/job/view/?jobId=".$job->getKey()."'>".$job->getCreationDate()."</a>";
152+
$html .= "<a element='".$job->getKey()."' href='".Zend_Registry::get('webroot')."/remoteprocessing/job/view/?jobId=".$job->getKey()."'>".$name."</a>";
148153
$html .= "</li>";
149154
if($i > 3)
150155
{
@@ -187,9 +192,11 @@ public function processProcessingResults($params)
187192
if(file_exists($filepath))
188193
{
189194
$tmpArray = array_reverse(explode('.', basename($filepath)));
195+
$oldfilepath = $filepath;
196+
$filepath = str_replace(".".$tmpArray[1].".", ".", $filepath);
197+
rename($oldfilepath, $filepath);
190198
$item = $uploadComponent->createUploadedItem($userDao, basename($filepath), $filepath, $folder);
191199
$jobModel->addItemRelation($job, $item, MIDAS_REMOTEPROCESSING_RELATION_TYPE_OUPUT);
192-
193200
// add parameter metadata
194201
if(is_numeric($tmpArray[1]) && isset($params['parametersList']) && isset($params['optionMatrix']))
195202
{
@@ -269,6 +276,10 @@ public function addJob($params)
269276
{
270277
$job->setCreatorId($params['params']['creator_id']);
271278
}
279+
if(isset($params['params']['job_name']))
280+
{
281+
$job->setName($params['params']['job_name']);
282+
}
272283

273284
$job->setParams(JsonComponent::encode($params['params']));
274285
$this->Remoteprocessing_Job->save($job);

modules/remoteprocessing/controllers/JobController.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,17 @@ class Remoteprocessing_JobController extends Remoteprocessing_AppController
2020
/** manage jobs */
2121
function manageAction()
2222
{
23-
$itemId = $this->_getParam("itemId");
24-
if(!isset($itemId) || !is_numeric($itemId))
25-
{
26-
throw new Zend_Exception("itemId should be a number");
27-
}
28-
29-
$itemDao = $this->Item->load($itemId);
30-
if($itemDao === false)
31-
{
32-
throw new Zend_Exception("This item doesn't exist.");
33-
}
34-
if(!$this->Item->policyCheck($itemDao, $this->userSession->Dao, MIDAS_POLICY_WRITE))
23+
if(!$this->logged)
3524
{
36-
throw new Zend_Exception("Problem policies.");
25+
$this->haveToBeLogged();
26+
return false;
3727
}
38-
$this->view->header = $this->t("Manage Jobs: ".$itemDao->getName());
39-
$metaFile = $this->ModuleComponent->Executable->getMetaIoFile($itemDao);
40-
$this->view->metaFile = $metaFile;
41-
$this->view->itemDao = $itemDao;
42-
43-
$this->view->relatedJobs = $this->Remoteprocessing_Job->getRelatedJob($itemDao);
28+
$this->view->header = $this->t("Manage Your Jobs");
4429

45-
if(isset($_GET['inprogress']))
46-
{
47-
$this->showNotificationMessage('The Job will appear in a next few minutes.');
48-
}
30+
$modelLoad = new MIDAS_ModelLoader();
31+
$schedulerJobModel = $modelLoad->loadModel('Job', 'scheduler');
32+
$this->view->scheduledJobs = $schedulerJobModel->getJobsByTaskAndCreator('TASK_REMOTEPROCESSING_ADD_JOB', $this->userSession->Dao);
33+
$this->view->relatedJobs = $this->Remoteprocessing_Job->getByUser($this->userSession->Dao, 10);
4934
}
5035

5136
/** init a job*/
@@ -128,7 +113,7 @@ function initAction()
128113
}
129114
else if($option->field->external == 1)
130115
{
131-
$parametersList[$i] = $option->name;
116+
$parametersList[$i] = (string)$option->name;
132117
if(strpos($result, 'folder') !== false)
133118
{
134119
$folder = $this->Folder->load(str_replace('folder', '', $result));
@@ -151,7 +136,7 @@ function initAction()
151136
}
152137
else
153138
{
154-
$parametersList[$i] = $option->name;
139+
$parametersList[$i] = (string)$option->name;
155140
$cmdOptions[$i] = array('type' => 'param', 'values' => array());
156141
if(strpos($result, ';') !== false)
157142
{
@@ -184,7 +169,7 @@ function initAction()
184169

185170
if(!empty($option->tag))
186171
{
187-
$cmdOptions[$i]['tag'] = $option->tag;
172+
$cmdOptions[$i]['tag'] = (string)$option->tag;
188173
}
189174
}
190175
$i++;
@@ -204,7 +189,7 @@ function initAction()
204189
}
205190
}
206191

207-
$this->ModuleComponent->Executable->initAndSchedule($this->userSession->Dao, $itemDao, $cmdOptions, $parametersList, $fire_time, $time_interval, $only_once);
192+
$this->ModuleComponent->Executable->initAndSchedule($this->userSession->Dao, $itemDao, $_POST['name'], $cmdOptions, $parametersList, $fire_time, $time_interval, $only_once);
208193
}
209194
}
210195

@@ -264,6 +249,7 @@ function viewAction()
264249
}
265250

266251
$this->view->job = $jobDao;
252+
$this->view->header = $this->t("Job: ".$jobDao->getName());
267253
$items = $jobDao->getItems();
268254
$inputs = array();
269255
$outputs = array();

modules/remoteprocessing/controllers/components/ExecutableComponent.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function getExecutable($itemDao)
5757
}
5858

5959
/** schedule Job (create script and set parameters).*/
60-
function initAndSchedule($userDao, $executableItemDao, $cmdOptions, $parametersList, $fire_time = false, $time_interval = false, $only_once = true)
60+
function initAndSchedule($userDao, $executableItemDao, $jobName, $cmdOptions, $parametersList, $fire_time = false, $time_interval = false, $only_once = true)
6161
{
6262
$componentLoader = new MIDAS_ComponentLoader();
6363
$modelLoader = new MIDAS_ModelLoader();
@@ -73,6 +73,7 @@ function initAndSchedule($userDao, $executableItemDao, $cmdOptions, $parametersL
7373

7474
$parameters['cmdOptions'] = $cmdOptions;
7575
$parameters['creator_id'] = $userDao->getKey();
76+
$parameters['job_name'] = $jobName;
7677
$parameters['parametersList'] = $parametersList;
7778
$parameters['executable'] = $executableItemDao->getKey();
7879

@@ -130,7 +131,7 @@ public function processScheduledJobParameters($params)
130131
}
131132

132133
$commandMatrix = $this->_createParametersMatrix($cmdOptions);
133-
$tmp = $this->_createScript($commandMatrix, $executable, $ouputArray);
134+
$tmp = $this->_createScript($params['params']['parametersList'], $commandMatrix, $executable, $ouputArray);
134135

135136
$ouputArray = $tmp['outputArray'];
136137
$script = $tmp['script'];
@@ -142,20 +143,25 @@ public function processScheduledJobParameters($params)
142143
}
143144

144145
/** create Script */
145-
private function _createScript($commandMatrix, $executable, $ouputArray)
146+
private function _createScript($parametersList, $commandMatrix, $executable, $ouputArray)
146147
{
147148
$script = "#! /usr/bin/python\n";
148149
$script .= "import subprocess\n";
150+
$script .= "import time\n";
149151
foreach($commandMatrix as $key => $commandList)
150152
{
151153
$command = $executable->getName().' '. join('', $commandList);
152-
$command = str_replace('{{key}}', '.'.$key, $command);
154+
$command = str_replace('{{key}}', '.'.$this->_generateSuffixOutputName($commandList, $parametersList).'.'.$key, $command);
153155

156+
$script .= "start = time.clock()\n";
154157
$script .= "process = subprocess.Popen('".$command."', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n";
155158
$script .= "process.wait()\n";
156159
$script .= "returnArray = process.communicate()\n";
160+
$script .= "end = time.clock()\n";
157161
$script .= "print '-COMMAND'\n";
158162
$script .= "print '".$command."'\n";
163+
$script .= "print '-EXECUTION TIME'\n";
164+
$script .= "print '%.2gs' % (end-start)\n";
159165
$script .= "print '-STDOUT'\n";
160166
$script .= "print returnArray[0]\n";
161167
$script .= "print '-STDERR'\n";
@@ -169,11 +175,28 @@ private function _createScript($commandMatrix, $executable, $ouputArray)
169175
$ext = end(explode('.', $ouput));
170176
foreach($commandMatrix as $key => $commandList)
171177
{
172-
$ouputArray[] = str_replace('.'.$ext, '.'.$key.'.'.$ext, $ouput);
178+
$ouputArray[] = str_replace('.'.$ext, '.'.$this->_generateSuffixOutputName($commandList, $parametersList).'.'.$key.'.'.$ext, $ouput);
173179
}
174180
}
175181
return array('script' => $script, 'outputArray' => $ouputArray);
176182
}
183+
184+
/** generate suffix output name */
185+
private function _generateSuffixOutputName($commandList, $parametersList)
186+
{
187+
$return = "";
188+
foreach($commandList as $key => $command)
189+
{
190+
if(isset($parametersList[$key]) && !empty($parametersList[$key]))
191+
{
192+
$return = $return.substr($parametersList[$key], 0, 6)."-";
193+
$command = str_replace('"', '', $command);
194+
$command = (string)str_replace(' ', '', $command);
195+
$return = $return.$command."_";
196+
}
197+
}
198+
return substr($return,0,-1);
199+
}
177200
/** create cmd option matrix*/
178201
private function _createParametersMatrix($cmdOptions)
179202
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
class Remoteprocessing_Upgrade_1_0_2 extends MIDASUpgrade
14+
{
15+
public function preUpgrade()
16+
{
17+
18+
}
19+
20+
public function mysql()
21+
{
22+
$sql = "ALTER TABLE remoteprocessing_job ADD name varchar(512)";
23+
$this->db->query($sql);
24+
}
25+
26+
public function pgsql()
27+
{
28+
29+
}
30+
31+
public function postUpgrade()
32+
{
33+
}
34+
}
35+
?>

modules/remoteprocessing/models/base/JobModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct()
2525
'condition' => array('type' => MIDAS_DATA),
2626
'script' => array('type' => MIDAS_DATA),
2727
'params' => array('type' => MIDAS_DATA),
28+
'name' => array('type' => MIDAS_DATA),
2829
'status' => array('type' => MIDAS_DATA),
2930
'creator_id' => array('type' => MIDAS_DATA),
3031
'expiration_date' => array('type' => MIDAS_DATA),

modules/remoteprocessing/models/pdo/JobModel.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,33 @@ function getRelatedJob($item)
120120
}
121121
return $return;
122122
}
123+
124+
/** get job by user */
125+
function getByUser($user, $limit = 10)
126+
{
127+
if(!$user instanceof UserDao)
128+
{
129+
throw new Zend_Exception("Should be an user.");
130+
}
131+
132+
$sql = $this->database->select()
133+
->from('remoteprocessing_job')
134+
->setIntegrityCheck(false)
135+
->where('creator_id = ?', $user->getKey())
136+
->limit($limit)
137+
->order('job_id DESC');
138+
139+
$rowset = $this->database->fetchAll($sql);
140+
$return = array();
141+
foreach($rowset as $row)
142+
{
143+
$tmpDao = $this->load($row['job_id']);
144+
if($tmpDao != false)
145+
{
146+
$return[] = $tmpDao;
147+
unset($tmpDao);
148+
}
149+
}
150+
return $return;
151+
}
123152
} // end class

modules/remoteprocessing/public/css/job/job.init.css

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.optionWrapper{
1+
.optionWrapper, .nameWrapper{
22
border: 1px solid grey;
33
margin-bottom: 2px;
44

@@ -12,7 +12,7 @@
1212
-moz-box-shadow: 0px 0px 5px #666;
1313
padding: 0px 5px 6px 5px;
1414
}
15-
.optionWrapper h4{
15+
.optionWrapper h4, .nameWrapper h4{
1616
margin-bottom: 0px;
1717
margin-top: 2px;
1818
font-size: 14px;
@@ -43,4 +43,22 @@ background: #F8F8F8!important;
4343

4444
#wizard{
4545
display:none;
46+
}
47+
48+
#uploadTabs{
49+
width: 571px!important;
50+
}
51+
52+
#browseExecutableFile a img{
53+
position:relative;
54+
top:2px;
55+
margin-right: 2px;
56+
}
57+
58+
#metaWrapper{
59+
display:none;
60+
}
61+
62+
#metaWrapper .viewMain{
63+
width: 95%!important;
4664
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#tableJobsList{
2-
width: 80%;
3-
}
4-
5-
#tableJobsList td{
6-
border-bottom: 1px solid grey;
1+
.midasTree td{
2+
cursor: pointer!important;
73
}

0 commit comments

Comments
 (0)