Skip to content

Commit a5c2921

Browse files
committed
New parameter element for software versions
1 parent bcc9a50 commit a5c2921

8 files changed

Lines changed: 147 additions & 40 deletions

File tree

core/util.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public static function pass($input) {
5252
return $input;
5353
}
5454

55+
public static function getElementFromArray($arr,$i) {
56+
return $arr[$i];
57+
}
58+
59+
public static function issetElementOfArray($arr,$i) {
60+
return isset($arr[$i]);
61+
}
62+
63+
public static function increment($int) {
64+
return intval($int)+1;
65+
}
66+
5567
/**
5668
* @param $path
5769
* @return Element[]

libraries/elements/checkbox-selection/copy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/** @var $copyValue string */
1313

1414
// when generating multi-job, we need to copy the current configurations and apply our setting for every of them
15-
// we have the interval, so we need to go from min to max in steps and copy all configurations and add the corresponding setting for each of them
1615
if (!empty($copyData[$e['id'] . "-parameter"])) { // special handle for checkbox selections
1716
$arr = [];
1817
foreach ($copyData as $key => $value) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="row" id="[[id]]">
2+
<div class="col-md-12">
3+
<a href="#" class="text-red pull-right" onclick="deleteElement('[[id]]')">Delete</a>
4+
<h4>Software Versions Element</h4>
5+
<div class="form-group">
6+
<label>Name</label>
7+
<input type="hidden" name="type" value="software-versions-list">
8+
<input name="name" type="text" class="form-control" placeholder="Element Name" value="[[name]]">
9+
<label>Parameter name (for client parsing)</label>
10+
<input name="parameter" type="text" class="form-control" placeholder="Parameter name" value="{{IF [[parameter]] != false}}[[parameter]]{{ENDIF}}">
11+
<label>Git Repository</label>
12+
<input name="repository" type="text" class="form-control" placeholder="Git Repository Url (https://github.com/OWNER/REPOSITORY/)" value="{{IF [[repository]] != false}}[[repository]]{{ENDIF}}">
13+
<label>Number of versions to compare</label>
14+
<input name="numberOfVersions" type="number" class="form-control" placeholder="Integer > 0" value="{{IF [[numberOfVersions]] != false}}[[numberOfVersions]]{{ENDIF}}">
15+
<label>Default List (comma separated; format: (branch,tag):name)</label>
16+
<input name="default" type="text" class="form-control" placeholder="Default List" value="{{IF [[default]] != false}}[[default]]{{ENDIF}}">
17+
</div>
18+
</div>
19+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Software Versions Element",
3+
"type": "software-versions-list",
4+
"multiJob": true
5+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* Given values:
5+
* - $e: settings of the element from the parameter configuration
6+
* - $copyData: full postData from the experiment to copy
7+
* - $copyValue: write in here the copied value which is needed on the form to fill in
8+
*/
9+
10+
/** @var $e array */
11+
/** @var $copyData array */
12+
/** @var $copyValue string */
13+
14+
// when generating multi-job, we need to copy the current configurations and apply our setting for every of them
15+
if (!empty($copyData[$e['id'] . "-parameter"])) { // special handle for checkbox selections
16+
$parameterName = $copyData[$e['id'] . "-parameter"];
17+
if (empty($copyData[$parameterName . "-numberOfVersions"])) {
18+
var_dump($copyData);
19+
throw new Exception("Invalid number of versions!");
20+
}
21+
$numberOfVersions = $copyData[$parameterName . "-numberOfVersions"];
22+
23+
$copyValue = [];
24+
for ($i = 0; $i < $numberOfVersions; $i++) {
25+
$copyValue[$i] = $copyData[$parameterName . "-version-" . $i];
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Given values:
5+
* - $data: containing the full post data of the experiment creation
6+
* - $parameter: containing the name/basename of the parameter
7+
* - $allConfigurations: containing all current configurations defined (this value is passed by reference, this is the only way to save stuff)
8+
*/
9+
10+
/** @var $data array */
11+
/** @var $parameter string */
12+
/** @var $allConfigurations [] */
13+
14+
// when generating multi-job, we need to copy the current configurations and apply our setting for every of them
15+
$newConfigurations = [];
16+
17+
$numOfVersions = $data[$parameter . "-numberOfVersions"];
18+
for ($i = 0; $i < $numOfVersions; $i++) {
19+
foreach ($allConfigurations as $configuration) {
20+
$copy = $configuration;
21+
$copy[Define::CONFIGURATION_PARAMETERS][$parameter] = $data[$parameter . "-version-" . $i];
22+
$newConfigurations[] = $copy;
23+
}
24+
}
25+
26+
$allConfigurations = $newConfigurations;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="row" id="[[id]]">
2+
<div class="col-md-12">
3+
<input type="hidden" name="elements[]" value="[[id]]">
4+
<input type="hidden" name="[[id]]-type" value="[[type]]">
5+
<input type="hidden" name="[[id]]-parameter" value="[[parameter]]">
6+
<input type="hidden" name="[[parameter]]-numberOfVersions" value="[[numberOfVersions]]">
7+
8+
<b>[[name]]</b> (<i>[[parameter]]</i>)
9+
{{FOR i;0;[[numberOfVersions]]}}
10+
<div class="input-group" style="margin-bottom: 0.3em;">
11+
<span class="input-group-addon text-bold" style="background-color: #f7f7f7;">Version [[Util::increment([[i]])]]</span>
12+
<input name="[[parameter]]-version-[[i]]" type="text" class="form-control" placeholder="Branch for version [[Util::increment([[i]])]]"
13+
{{IF Util::issetElementOfArray([[copy]],[[i]])}} value="[[Util::getElementFromArray([[copy]],[[i]])]]"{{ENDIF}}
14+
{{IF !Util::issetElementOfArray([[copy]],[[i]]) && Util::issetElementOfArray(explode(',',[[default]]),[[i]])}} value="[[Util::getElementFromArray([[explode(',',[[default]])]],[[i]])]]"{{ENDIF}}>
15+
</div>
16+
{{ENDFOR}}
17+
18+
</div>
19+
</div>

libraries/templating/Template.class.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function parse($content) {
126126
$endContent = $closePos;
127127
$subContent = substr($content, $startContent, $endContent - $startContent);
128128
$contentStatement = new Statement("CONTENT", $subContent, []);
129-
129+
130130
//create if statement
131131
$ifStatement = new Statement("IF", [$contentStatement], $setting);
132132
$statements[] = $ifStatement;
@@ -242,44 +242,44 @@ private function parse($content) {
242242
}
243243
}
244244
break;
245-
case 'FOR':
246-
$nextPos = strpos($content, "{{", $loopPos + 2);
247-
$closePos = strpos($content, "{{ENDFOR}}", $loopPos + 2);
248-
if ($closePos === false) {
249-
throw new Exception("Syntax error: FOR statement at $loopPos not closed!");
250-
}
251-
$startCondition = $loopPos + 6;
252-
$endCondition = strpos($content, "}}", $startCondition);
253-
$setting = explode(";", substr($content, $startCondition, $endCondition - $startCondition));
254-
if (sizeof($setting) != 3) {
255-
throw new Exception("Invalid condition size on FOR on $loopPos");
256-
}
257-
if ($nextPos == $closePos) {
258-
//we have a simple for statement
259-
$startContent = $endCondition + 2;
260-
$endContent = $closePos;
261-
$subContent = substr($content, $startContent, $endContent - $startContent);
262-
$contentStatement = new Statement("CONTENT", $subContent, []);
263-
264-
//create for statement
265-
$forStatement = new Statement("FOR", [$contentStatement], $setting);
266-
$statements[] = $forStatement;
267-
$pos = $closePos + 10;
268-
}
269-
else {
270-
//the for statement has some inner statements
271-
$innerContent = substr($content, $endCondition + 2);
272-
$result = $this->parse($innerContent);
273-
$endPos = $result[1] + $endCondition + 2;
274-
if ($endPos != strpos($content, "{{ENDFOR}}", $endPos)) {
275-
throw new Exception("FOR statement not closed correctly at $endPos!");
276-
}
277-
$forStatement = new Statement("FOR", $result[0], $setting);
278-
$statements[] = $forStatement;
279-
$pos = $endPos + 10;
280-
}
281-
break;
282-
case 'FOREACH':
245+
case 'FOR':
246+
$nextPos = strpos($content, "{{", $loopPos + 2);
247+
$closePos = strpos($content, "{{ENDFOR}}", $loopPos + 2);
248+
if ($closePos === false) {
249+
throw new Exception("Syntax error: FOR statement at $loopPos not closed!");
250+
}
251+
$startCondition = $loopPos + 6;
252+
$endCondition = strpos($content, "}}", $startCondition);
253+
$setting = explode(";", substr($content, $startCondition, $endCondition - $startCondition));
254+
255+
if (sizeof($setting) != 3) {
256+
throw new Exception("Invalid condition size on FOR on $loopPos");
257+
}
258+
if ($nextPos == $closePos) {
259+
// Simple for loop
260+
$startContent = $endCondition + 2;
261+
$endContent = $closePos;
262+
$subContent = substr($content, $startContent, $endContent - $startContent);
263+
264+
$contentStatement = new Statement("CONTENT", $subContent, []);
265+
$forStatement = new Statement("FOR", [$contentStatement], $setting);
266+
$statements[] = $forStatement;
267+
$pos = $closePos + 10;
268+
} else {
269+
// The for statement has some inner statements
270+
$innerContent = substr($content, $endCondition + 2);
271+
272+
$result = $this->parse($innerContent);
273+
$endPos = $result[1] + $endCondition + 2;
274+
if ($endPos != strpos($content, "{{ENDFOR}}", $endPos)) {
275+
throw new Exception("FOR statement not closed correctly at $endPos!");
276+
}
277+
$forStatement = new Statement("FOR", $result[0], $setting);
278+
$statements[] = $forStatement;
279+
$pos = $endPos + 10;
280+
}
281+
break;
282+
case 'FOREACH':
283283
$nextPos = strpos($content, "{{", $loopPos + 2);
284284
$closePos = strpos($content, "{{ENDFOREACH}}", $loopPos + 2);
285285
if ($closePos === false) {

0 commit comments

Comments
 (0)