Skip to content

Commit

Permalink
adds a button to select module dependencies of selected modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
drhodes committed May 7, 2017
1 parent ee049d2 commit 25c587c
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions jade.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,43 @@ jade_defs.top_level = function(jade) {
dialog('Select modules to load',contents,upload,offset);
};

// given a single module name M, generate a set of all the module
// names that M depends on.
function module_deps(mname) {
var depNames = [];

var allMods = jade.model.json_modules().json;
var allModNames = Object.keys(allMods);

var findSubMods = function(modName) {
curMod = allMods[modName];
if (curMod === undefined) throw "module name not found: " + modName;

schems = curMod.schematic;
if (schems === undefined) return; // atomic unit of jade universe?

schems.forEach(function(el) {
subName = el[0];
// is this schematic element a sub module?
if (allModNames.indexOf(subName) == -1) return; // nope.
// has it been processed already?
if (depNames.indexOf(subName) != -1) return; // yep.
// don't export built-ins?
if (subName.startsWith("/gate")) return;

depNames.push(subName);
findSubMods(subName);
});
};
findSubMods(mname);
return depNames;
}

// let user select which modules to export to their Downloads directory
function export_modules(j) {
var all_modules = jade.model.json_modules().json;
var mnames = Object.keys(all_modules).sort();

var win;
var contents = module_table(mnames);

Expand All @@ -675,9 +707,37 @@ jade_defs.top_level = function(jade) {
// close dialog box
window_close(win[0]);
});

// add a button to checkoff all module dependencies
var depsButton = $('<a "_blank"><button>select module depencies</button></a>');
depsButton.on('click',function (e) {
var selected = {};
var deps = [];
$('input',contents).each(function (index,input) {
input = $(input);
var mname = input.attr('name');
if (input[0].checked) {
deps = deps.concat(module_deps(mname));
}
});
$('input',contents).each(function (index,input) {
input = $(input);
var mname = input.attr('name');
if (deps.indexOf(mname) != -1) {
input[0].checked = true;
}
});

});

var doDeps = $('<td></td>').attr('colspan',$('#select-all',contents).attr('colspan')).append(depsButton);
contents.append($('<tr align="center"></tr>').append(doDeps));

var doit = $('<td></td>').attr('colspan',$('#select-all',contents).attr('colspan')).append(a);
contents.append($('<tr align="center"></tr>').append(doit));




var offset = $('.jade-tabs-div',j.top_level).offset();
win = jade_window('Export modules', contents, offset);
};
Expand Down

0 comments on commit 25c587c

Please sign in to comment.