Commit 8d615bd8 authored by Ryan Sturmer's avatar Ryan Sturmer
Browse files

Intitial commit of fabmo app, basic functionality works OK.

parent 54cb3066
node_modules
.DS_Store
*.swp
*.swo
*.bak
*~
build/fabmo-mods-app.fma : clean
mkdir -p build
zip -r build/fabmo-mods-app.fma index.html package.json icon.png css js
cd ..; \
zip -r fabmo/build/fabmo-mods-app.fma package.json files.html js modules programs
clean:
rm -f build/fabmo-mods-app.fma
.PHONY: clean
body {
background: #fff;
font-family: monospace;
font-size: 11px;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 5% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
min-height: 200px;
max-height: 70%;
border-radius: 10px;
overflow: scroll;
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
<html>
<head><meta charset="utf-8">
<title>mods</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body link="black" alink="black" vlink="black">
<script src="js/fabmo.js"></script>
<script type="text/javascript">
var fabmo = new FabMoDashboard();
</script>
<script src="js/fabmo-mods.js"></script>
<script src="js/mods.js"></script>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div id="modal-text">
</div>
</div>
</div>
</body>
<script type="text/javascript">
/*
showModal({
html : "X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>X<br/>"
});*/
</script>
</html>
\ No newline at end of file
window._open = window.open
window._close = window.close
window._alert = window.alert
var fakeWindow = {
document : {
createTextNode : function(args) {return window.document.createTextNode(...arguments);},
createElement : function(args) {return window.document.createElement(...arguments);},
getElementById : function(args) {return window.document.createElement(...arguments);}
},
close : function() {
hideModal();
}
};
window.alert = function(msg) {
showModal({html : '<h2>Alert!</h2><p>' + msg + '</p>'})
}
function showModal(options) {
var modalContent = document.getElementById('modal-text');
if('html' in options) {
modalContent.innerHTML = options['html']
}
fakeWindow.document.body = modalContent;
var modal = document.getElementById('myModal');
modal.style.display = "block";
}
function hideModal() {
var modal = document.getElementById('myModal')
modal.style.display = "none"
}
function httpGet(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
var handler = function(uri) {
console.log("Handler called");
console.log(callback)
window.callback(uri)
hideModal();
//window.close()
}
window.open = function(url, callback) {
console.info('Got a call to window.open for : ' + url)
console.info(callback)
console.trace()
if(url) {
httpGet(url, function(responseText) {
showModal({
html : responseText
})
})
} else {
showModal({
html : ''
});
}
return fakeWindow;
/* Open the prescribed window, but in a modal dialog */
}
window.addEventListener('click', function(event) {
var modal = document.getElementById('myModal');
if (event.target == modal) {
modal.style.display = "none";
}
});
window.addEventListener('keypress', function(evt){
evt = evt || window.event;
if (evt.keyCode == 27) {
hideModal();
}
});
function get_current_program() {
//mods.ui.progname = filename
var prog = {modules:{},links:[]}
var modules = document.getElementById('modules')
//
// save modules
//
for (var c = 0; c < modules.childNodes.length; ++c) {
var module = modules.childNodes[c]
var idnumber = module.id
prog.modules[idnumber] = {
definition:module.dataset.definition,
top:module.dataset.top,
left:module.dataset.left,
inputs:{},
outputs:{}
}
}
//
// save links
//
var svg = document.getElementById('svg')
var links = svg.getElementById('links')
for (var l = 0; l < links.childNodes.length; ++l) {
var link = links.childNodes[l]
var linkid = link.id
prog.links.push(linkid)
}
//
// download
//
var text = JSON.stringify(prog)
return text
}
function load_program() {
fabmo.getAppConfig(function(err, cfg) {
if(err) {
return log.error(err);
}
console.log(cfg)
try {
var p = JSON.parse(cfg.current_program);
fabModules.prog_load(p);
} catch(e) {
console.warn('No program to load.')
}
})
}
function init() {
var btn = document.createElement('button')
btn.appendChild(document.createTextNode('Save...'))
document.body.appendChild(btn)
btn.addEventListener('click', function(evt) {
fabmo.setAppConfig({'current_program' : get_current_program()});
});
}
init();
load_program();
This diff is collapsed.
{
"name": "Mods",
"license": "MIT",
"main": "./index.html",
"icon": "icon.png",
"icon_color": "#ffffff",
"version": "0.0.1",
"author": "Ryan Sturmer",
"description": "MIT CBA's FabModules for FabMo"
}
......@@ -8,9 +8,24 @@
window.close()
}
</script>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.git</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./.DS_Store'>.DS_Store</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.git</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./.gitignore'>.gitignore</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./README.md'>README.md</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fabmo</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/.DS_Store'>.DS_Store</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/Makefile'>Makefile</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/build/fabmo-mods-app.fma'>fabmo-mods-app.fma</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/build/icon.png'>icon.png</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;css</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/css/style.css'>style.css</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/icon.png'>icon.png</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/index.html'>index.html</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;js</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/js/fabmo-mods.js'>fabmo-mods.js</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/js/fabmo.js'>fabmo.js</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./fabmo/package.json'>package.json</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./files.html'>files.html</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./index.html'>index.html</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;js</i><br>
......@@ -26,6 +41,7 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./js/udpserver.js'>udpserver.js</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./make'>make</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modules</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/.DS_Store'>.DS_Store</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apa</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/apa/node'>node</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character</i><br>
......@@ -45,6 +61,9 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/event/delay'>delay</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/event/generate'>generate</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/event/pause'>pause</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fabmo</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/fabmo/status'>status</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/fabmo/submit%20job'>submit job</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./modules/file/save'>save</a><br>
<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph</i><br>
......
......@@ -12,7 +12,9 @@
//
// closure
//
(function(){
var fabModules;
(function() {
//
// globals
//
......@@ -28,6 +30,7 @@ mods.ui = {source:null,
link_highlight:'rgb(255,0,0)'
}
mods.globals = {}
fabModules = mods;
//
// set up UI
//
......@@ -1379,4 +1382,9 @@ function window_touchup(evt) {
window.removeEventListener('touchmove',window_touchmove)
window.removeEventListener('touchend',window_touchup)
}
})()
// Things to pass into the global fabModules object
mods.prog_load = prog_load;
}
)()
//
// ui button
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2015,6
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// module globals
//
var mod = {
count : 0
}
//
// name
//
var name = 'Status Report'
//
// initialization
//
var init = function() {
fabmo.on('status', function(stat) {
console.log(outputs)
mod.count++;
outputs.status.event(stat)
});
fabmo.requestStatus();
}
//
// inputs
//
var inputs = {
}
//
// outputs
//
var outputs = {
status:{type:"Object",
label:"Status",
event:function(obj){
mod.content.innerHTML = "Status Reports:<br/>" + mod.count;
mods.output(mod,"status",obj)}
}
}
//
// interface
//
var interface = function(div){
mod.div = div
mod.content = document.createElement('div')
mod.content.innerHTML = 'Status Reports:<br/>0'
//mod.content.style.padding = mods.ui.padding
//mod.content.style.margin = 1
div.appendChild(mod.content)
}
//
// return values
//
return ({
name:name,
init:init,
inputs:inputs,
outputs:outputs,
interface:interface
})
}())
//
// save file
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2016
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// module globals
//
var mod = {}
//
// name
//
var name = 'fabmo submit job'
//
// initialization
//
var init = function() {
}
//
// inputs
//
var inputs = {
file:{type:'object',
event:function(evt){
mod.name = evt.detail.name
mod.contents = evt.detail.contents
submit_job()
}}}
//
// outputs
//
var outputs = {}
//
// interface
//
var interface = function(div){
mod.div = div
//
// info
//
var text = document.createTextNode('name:')
div.appendChild(text)
mod.nametext = text
div.appendChild(document.createElement('br'))
var text = document.createTextNode('size:')
div.appendChild(text)
mod.sizetext = text
div.appendChild(document.createElement('br'))
}
//
// local functions
//
function submit_job() {
/* var a = document.createElement('a')
a.setAttribute('href','data:text/plain;charset=utf-8,'+ encodeURIComponent(mod.contents))
*/
var code = mod.contents
console.log(code);
fabmo.submitJob({
file : code,
filename : mod.name
}, { stayHere : true });
/*
a.setAttribute('download',mod.namea)
a.style.display = 'none'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
*/
mod.nametext.nodeValue = 'name: '+mod.name
mods.fit(mod.div)
mod.sizetext.nodeValue = 'size: '+mod.contents.length
mods.fit(mod.div)
}
//
// return values
//
return ({
name:name,
init:init,
inputs:inputs,
outputs:outputs,
interface:interface
})
}())
......@@ -28,6 +28,9 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/event/delay')">delay</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/event/generate')">generate</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/event/pause')">pause</a><br>
<i>fabmo</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/fabmo/status')">status</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/fabmo/submit%20job')">submit job</a><br>
<i>file</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:handler('modules/file/save')">save</a><br>
<i>graph</i><br>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment