Skip to content

Commit a9a27b5

Browse files
committed
Make software versions element more dynamic
1 parent a5c2921 commit a9a27b5

7 files changed

Lines changed: 140 additions & 16 deletions

File tree

controllers/builder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ public function run() {
9191

9292
$user = Auth_Library::getInstance()->getUser();
9393
$data = json_decode($experiment->getPostData(), true);
94+
95+
// Set version elements information
96+
$versionInputs = Util::extractSoftwareVersionElements($experiment);
97+
if (!empty($versionInputs)) {
98+
foreach ($versionInputs as $versionInput) {
99+
foreach ($versionInput->inputs as $input) {
100+
$data[$input->name] = $this->post[$input->name];
101+
}
102+
}
103+
var_dump($data);
104+
}
105+
94106
$evaluation = new Evaluation_Library($experiment);
95107

96108
$allElements = Util::getDefaultParameterElements();

controllers/experiment.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public function detail() {
152152

153153
$this->view->assign('system', Factory::getSystemFactory()->get($experiment->getSystemId()));
154154

155+
// Build software version information (versionInputs)
156+
// stdClass(name="versionAlias", inputs => stdClass(label="", name="", default="") )
157+
$versionInputs = Util::extractSoftwareVersionElements($experiment);
158+
$this->view->assign('versionInputs', $versionInputs);
159+
155160
// Build environments info
156161
// cem-navy => stdClass(key="cem-navy", name="navy", type="cem", displayStr="navy (15 nodes)", default)
157162
$environments = [];
@@ -199,4 +204,5 @@ public function detail() {
199204
throw new Exception("No experiment id provided!");
200205
}
201206
}
207+
202208
}

core/util.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use DBA\Evaluation;
3131
use DBA\Event;
3232
use DBA\Experiment;
33-
use DBA\System;
3433
use DBA\Factory;
3534
use DBA\Job;
3635
use DBA\OrderFilter;
@@ -580,4 +579,35 @@ public static function getExecutedPhases($excludedPhases) {
580579
return $executedPhases;
581580
}
582581

582+
/**
583+
* This extracts software version elements from the experiment post data.
584+
*/
585+
public static function extractSoftwareVersionElements($experiment): array {
586+
$versionInputs = [];
587+
$postData = json_decode($experiment->getPostData(), true);
588+
$allElements = Util::getDefaultParameterElements();
589+
$system = Factory::getSystemFactory()->get(Factory::getProjectFactory()->get($experiment->getProjectId())->getSystemId());
590+
$sys = new System($system->getId());
591+
$sys->getParameterElements($allElements);
592+
foreach ($postData['elements'] as $element) {
593+
if ($postData[$element . '-type'] == "software-versions-list") {
594+
;
595+
$data = new stdClass();
596+
$data->name = $postData[$element . "-parameter"];
597+
$data->inputs = [];
598+
$i = 0;
599+
while (isset($postData[$data->name . "-version-" . $i])) {
600+
$input = new stdClass();
601+
$input->label = "Version " . ($i + 1);
602+
$input->name = $data->name . "-version-" . $i;
603+
$input->default = $postData[$data->name . "-version-" . $i];
604+
$data->inputs[] = $input;
605+
$i++;
606+
}
607+
$versionInputs[] = $data;
608+
}
609+
}
610+
return $versionInputs;
611+
}
612+
583613
}

libraries/elements/software-version-list/build.template.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ <h4>Software Versions Element</h4>
1010
<input name="parameter" type="text" class="form-control" placeholder="Parameter name" value="{{IF [[parameter]] != false}}[[parameter]]{{ENDIF}}">
1111
<label>Git Repository</label>
1212
<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}}">
1713
</div>
1814
</div>
1915
</div>

libraries/elements/software-version-list/copy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/** @var $copyData array */
1212
/** @var $copyValue string */
1313

14-
// when generating multi-job, we need to copy the current configurations and apply our setting for every of them
14+
// when copy the experiment, we need to copy the current configurations and apply our setting for every of them
1515
if (!empty($copyData[$e['id'] . "-parameter"])) { // special handle for checkbox selections
1616
$parameterName = $copyData[$e['id'] . "-parameter"];
1717
if (empty($copyData[$parameterName . "-numberOfVersions"])) {

libraries/elements/software-version-list/render.template.html

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,84 @@
33
<input type="hidden" name="elements[]" value="[[id]]">
44
<input type="hidden" name="[[id]]-type" value="[[type]]">
55
<input type="hidden" name="[[id]]-parameter" value="[[parameter]]">
6-
<input type="hidden" name="[[parameter]]-numberOfVersions" value="[[numberOfVersions]]">
76

87
<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}}
8+
<div class="input-group">
9+
<span class="input-group-addon text-bold" style="background-color: #f7f7f7;">Number of Versions</span>
10+
<input id="numberOfVersionsInput" name="[[parameter]]-numberOfVersions" type="number" class="form-control" placeholder="Number of versions to compare" min="0">
11+
</div>
12+
<div id="versionInputsContainer"></div>
13+
14+
<script>
15+
const copy = JSON.parse('[[json_encode([[copy]])]]');
16+
const initialNumberOfVersions = copy.length;
17+
18+
document.addEventListener('DOMContentLoaded', function () {
19+
const numberOfVersionsInput = document.getElementById('numberOfVersionsInput');
20+
const versionInputsContainer = document.getElementById('versionInputsContainer');
21+
22+
// Set the initial value for the number of versions input based on the copy array length
23+
numberOfVersionsInput.value = initialNumberOfVersions;
24+
25+
function createVersionInput(index, value = '') {
26+
const div = document.createElement('div');
27+
div.classList.add('input-group');
28+
div.style.marginTop = '0.3em';
29+
30+
const span = document.createElement('span');
31+
span.classList.add('input-group-addon', 'text-bold');
32+
span.style.backgroundColor = '#f7f7f7';
33+
span.textContent = `Version ${index + 1}`;
34+
35+
const input = document.createElement('input');
36+
input.name = `[[parameter]]-version-${index}`;
37+
input.type = 'text';
38+
input.classList.add('form-control');
39+
input.placeholder = `Branch for version ${index + 1}`;
40+
if (value) {
41+
input.value = value;
42+
}
43+
44+
div.appendChild(span);
45+
div.appendChild(input);
46+
return div;
47+
}
48+
49+
function populateInitialInputs() {
50+
for (let i = 0; i < initialNumberOfVersions; i++) {
51+
const value = copy[i] !== undefined ? copy[i] : '';
52+
const versionInput = createVersionInput(i, value);
53+
versionInputsContainer.appendChild(versionInput);
54+
}
55+
}
56+
57+
function updateVersionInputs() {
58+
const currentInputs = versionInputsContainer.querySelectorAll('input');
59+
const numberOfVersions = parseInt(numberOfVersionsInput.value, 10) || 0;
60+
61+
if (numberOfVersions > currentInputs.length) {
62+
// Add new inputs
63+
for (let i = currentInputs.length; i < numberOfVersions; i++) {
64+
const versionInput = createVersionInput(i, '');
65+
versionInputsContainer.appendChild(versionInput);
66+
}
67+
} else if (numberOfVersions < currentInputs.length) {
68+
// Remove excess inputs
69+
for (let i = currentInputs.length - 1; i >= numberOfVersions; i--) {
70+
versionInputsContainer.removeChild(currentInputs[i].parentElement);
71+
}
72+
}
73+
}
74+
75+
// Populate inputs based on the initial number of versions and the copy array
76+
populateInitialInputs();
77+
78+
// Update the inputs whenever the number of versions changes
79+
numberOfVersionsInput.addEventListener('input', updateVersionInputs);
80+
});
81+
</script>
82+
83+
1784

1885
</div>
1986
</div>

views/experiment/detail.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function submitData() {
309309
<button type="button" class="close" data-dismiss="modal" aria-label="Close"
310310
onclick="document.getElementById('form').reset()">
311311
<span aria-hidden="true">&times;</span></button>
312-
<h4 class="modal-title">Select Environment</h4>
312+
<h4 class="modal-title">Run Configuration</h4>
313313
</div>
314314
<div class="modal-body">
315315
<input type="hidden" name="experimentId" value="<?php echo $data['experiment']->getId() ?>">
@@ -322,6 +322,19 @@ function submitData() {
322322
<?php } ?>
323323
<?php } ?>
324324
</select>
325+
326+
<?php if(!empty($data['versionInputs']) && is_array($data['versionInputs'])) { ?>
327+
<?php foreach ($data['versionInputs'] as $versionInput) { ?>
328+
<hr>
329+
<label>Software Versions to Compare (<?php echo $versionInput->name; ?>)</label>
330+
<?php foreach ($versionInput->inputs as $input) { ?>
331+
<div class="input-group" style="margin-bottom: 0.3em">
332+
<span class="input-group-addon text-bold" style="background-color: #f7f7f7;"><?php echo $input->label; ?></span>
333+
<input name="<?php echo $input->name; ?>" type="text" class="form-control" value="<?php echo $input->default; ?>">
334+
</div>
335+
<?php } ?>
336+
<?php } ?>
337+
<?php } ?>
325338
</div>
326339

327340
</div>

0 commit comments

Comments
 (0)