Skip to content

Commit

Permalink
Now the user can choose the executor for the program
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Karaulshchikov committed Dec 9, 2019
1 parent 2a8fbb9 commit b108b45
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
10 changes: 6 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ function getExcecutorURL(data) {
for(var j in solvers) {
// FIXME: The client should pass 'solver' parameter and not 'engine'
if(solvers[j].value === data.engine) {
// TODO let the user choose the executor. atm this is a missing data
// by default the first executor will be chosen
var executor = solvers[j].executors[0];
return executor.protocol + '://' + executor.url + ':' + executor.port + executor.path;
var executors = solvers[j].executors;
for(var k in executors) {
if(executors[k].value === data.executor) {
return executors[k].protocol + '://' + executors[k].url + ':' + executors[k].port + executors[k].path;
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LoIDE",
"version": "2.1.0",
"version": "2.2.0",
"description": "Web-based IDE for Logic Programming",
"main": "app.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions resources/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
<label for="inputEngine" class="col-sm-12 col-xs-12 mt-2 text-center">Solver</label>
<select name="engine" id="inputengine" class="form-control">
</select>
<label for="inputExecutor" class="col-sm-12 col-xs-12 mt-2 text-center">Executor</label>
<select name="executor" id="inputExecutor" class="form-control">
</select>
<label class="col-sm-12 mt-2 mb-1 text-center">Options</label>
<div id="solver-options">
</div>
Expand Down Expand Up @@ -340,6 +343,10 @@
div(name="solvers" value=language.value)
each solver in language.solvers
option(value=solver.value) #{solver.name}
//- Sets the executors
div(name="executors" value=solver.value)
each executor in solver.executors
option(value=executor.value) #{executor.name}
//- Sets the options
div(name="options" value=solver.value)
each option in solver.options
Expand Down
41 changes: 39 additions & 2 deletions resources/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ $(document).on('change', '#inputLanguage', function(event) {
// Sets the options on solver change
$(document).on('change', '#inputengine', function (event) {
loadSolverOptions( );
loadSolverExecutors( );

// Snippets
inizializeSnippets( );
Expand Down Expand Up @@ -705,6 +706,38 @@ function getLanguageSolvers( language ) {
return $('#servicesContainer [name="solvers"][value="' + language + '"] > option').clone( );
}

/**
* @description - Load the executors for a specific solver
*/
function loadSolverExecutors( ) {
var inputLanguage = $('#inputLanguage');
var inputSolver = $('#inputengine');
var inputExecutor = $('#inputExecutor');

var language = inputLanguage.val();
var solver = inputSolver.val();

// Check that the value is not empty
if(language !== '' && solver !== '') {
inputExecutor.empty();

// Append the executors to the DOM
inputExecutor.append( getSolverExecutors( language, solver ) );

// Select the first executor
inputExecutor.change();
}
}

/**
* @description - Get the executors for a specific solver
* @param {Object} language
* @param {Object} solver
*/
function getSolverExecutors( language, solver ) {
return $('#servicesContainer [name="solvers"][value="' + language + '"] [name="executors"][value="' + solver + '"] > option').clone( );
}

/**
* @description - Load the options for a specific solver
*/
Expand Down Expand Up @@ -734,7 +767,7 @@ function loadSolverOptions( ) {
*/
function getSolverOptions( language, solver ) {
return $('#servicesContainer [name="solvers"][value="' + language + '"] [name="options"][value="' + solver + '"] > option').clone( );
}
}

// Add or remove the 'input type value' based on the option
$(document).on('change', '.form-control-option', function () {
Expand Down Expand Up @@ -970,7 +1003,8 @@ function addInputValue(inputClass) {
* @description check if the configration file has the correct property to set. If not, return false and display the content of the file in the text editor
*/
function setJSONInput(config) {
if (config.hasOwnProperty('language') || config.hasOwnProperty('engine') || config.hasOwnProperty('option') || config.hasOwnProperty('program') || config.hasOwnProperty('output') || config.hasOwnProperty('tabname')) {
if (config.hasOwnProperty('language') || config.hasOwnProperty('engine') || config.hasOwnProperty('executor') || config.hasOwnProperty('option')
|| config.hasOwnProperty('program') || config.hasOwnProperty('output') || config.hasOwnProperty('tabname')) {
$('.nav-tabs li:not(:last)').each(function (index, element) {
var id = $(this).find("a").attr("data-target");
$(this).remove();
Expand All @@ -992,6 +1026,7 @@ function setJSONInput(config) {
}
$('#inputLanguage').val(config.language).change();
$('#inputengine').val(config.engine).change();
$('#inputExecutor').val(config.executor).change();
$('#output').text(config.output);
setOptions(config);
setTabsName(config);
Expand Down Expand Up @@ -1312,6 +1347,7 @@ function saveOption(key, value) {

/**
* @description Sets the saved options in the localStorage
* TODO: Restore executor
*/
function restoreOptions() {
if (!supportLocalStorage) {
Expand Down Expand Up @@ -2199,6 +2235,7 @@ function loadProjectFromLocalStorage() {
var obj = JSON.parse(opt);
$('#inputLanguage').val(obj.language).change();
$('#inputengine').val(obj.engine).change();
$('#inputExecutor').val(obj.executor).change();
if(obj.option != null) {
setOptions(obj);
}
Expand Down

0 comments on commit b108b45

Please sign in to comment.