Skip to content

Commit

Permalink
Add generated file to git for arm
Browse files Browse the repository at this point in the history
  • Loading branch information
ktg committed Oct 13, 2016
1 parent 23b87c9 commit 5d0e68d
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 25 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@ node_modules
.idea
.vscode
#sla db
sladatastore.db

# Generated files
/src/www/templates/*.js
/src/www/styles/databox.css
sladatastore.db
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Databox OS container manager and dashboard server",
"scripts": {
"build": "riot --template pug src/www/templates && node-sass --output-style compressed src/www/styles/ -o src/www/styles/",
"watch": "riot --watch --template pug src/www/templates | node-sass -w src/www/styles/ -o src/www/styles/",
"watch": "riot --watch --template pug src/www/templates | node-sass --output-style compressed -w src/www/styles/ -o src/www/styles/",
"start": "node src/main.js",
"killall": "docker kill $(docker ps -a -q)",
"dockerclean": "docker kill $(docker ps -a -q) && docker rm $(docker ps -a -q) && docker rmi -f $(docker images -q)"
Expand All @@ -29,21 +29,20 @@
},
"homepage": "https://github.com/yousefamar/databox-container-manager-js#readme",
"dependencies": {
"promise": "",
"body-parser": "^1.14.2",
"docker-events": "0.0.2",
"dockerode": "^2.2.9",
"express": "",
"body-parser": "^1.15.2",
"docker-events": "^0.0.2",
"dockerode": "^2.3.1",
"express": "^4.14.0",
"material-design-lite": "^1.2.1",
"nedb": "^1.8.0",
"node-sass": "^3.10.0",
"pug": "^2.0.0-alpha7",
"promise": "^7.1.1",
"pug": "^2.0.0-beta6",
"request": "^2.69.0",
"socket.io": "^1.4.5",
"socket.io": "^1.5.0",
"ursa": "^0.9.4"
},
"devDependencies": {
"riot": "^2.4.0",
"stats-lite": "^2.0.1"
"node-sass": "^3.10.0",
"riot": "^2.6.3"
}
}
2 changes: 1 addition & 1 deletion src/container-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var generatingCMkeyPair = function () {
});
};

var getContrainerInfo = function(container) {
var getContrainerInfo = function (container) {
return dockerHelper.inspectContainer(container)
.then((info) => {
var response = {
Expand Down
1 change: 0 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var Promise = require('promise');
var conman = require('./container-manager.js');
var Config = require('./config.json');
var server = require('./server.js');
Expand Down
1 change: 1 addition & 0 deletions src/www/styles/databox.css

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions src/www/templates/app-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

riot.tag2('app-list', '<div class="mdl-typography--text-center"> <div class="mdl-spinner mdl-js-spinner is-active" if="{!loaded}"></div> </div> <div if="{listSections().length == 0}">Empty</div> <div each="{section in listSections()}"> <ul class="mdl-list"> <li class="mdl-list__item">{section}</li> <li class="mdl-list__item mdl-list__item--two-line" each="{listApps(section)}"><a class="mdl-list__item-primary-content" href="{Ports.length &gt; 0 ? \'ui\' + Names[0] + \'/\' : null}"><i class="material-icons mdl-list__item-icon">{icon}</i><span>{Names[0].startsWith(\'/\') ? Names[0].substring(1) : Names[0]}</span><span class="mdl-list__item-sub-title">{State}</span></a><span class="mdl-list__item-secondary-content"><span class="mdl-list__item-secondary-action"> <button class="mdl-button mdl-js-button mdl-button--icon" onclick="{parent.restartApp}" if="{State != \'installing\'}"><i class="material-icons">refresh</i></button> <button class="mdl-button mdl-js-button mdl-button--icon" onclick="{parent.uninstall}" if="{State != \'installing\'}" __disabled="{Section === \'System\'}"><i class="material-icons">close</i></button> <div class="mdl-spinner mdl-js-spinner is-active" if="{State == \'installing\'}"></div></span></span></li> </ul> </div>', '', '', function(opts) {
this.loaded = false;
this.listAll = true;
this.sections = {
"app": {name: "Apps", icon: "extension"},
"other": {name: "System", icon: "settings_applications"},
"store": {name: "Datastore", icon: "dns"},
"driver": {name: "Drivers", icon: "developer_board"}
};
this.apps = [];

this.reload = function(message)
{
if (message != null) {
console.log(message.status + " " + message.from);
}
$.get("/list-containers", this.reloaded);
}.bind(this)

this.setAppSection = function(app, sectionName)
{
var section = this.sections[sectionName];
app.Section = section.name;
app.icon = section.icon;
}.bind(this)

this.reloaded = function(data)
{
this.apps = data;
for (var app of this.apps) {
if (!('Labels' in app)) {
this.setAppSection(app, "app");
}
else if (app.Labels["databox.type"] in this.sections) {
this.setAppSection(app, app.Labels["databox.type"]);
}
else {
this.setAppSection(app, "other");
}
}
this.apps.sort(function (a, b) {
var nameA = a.Names[0].toUpperCase();
var nameB = b.Names[0].toUpperCase();
return nameA.localeCompare(nameB);
});
this.loaded = true;
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)

this.restartApp = function(e)
{
var app = e.item;
$.post("/restart", {"id": app.Id}, function (data) {
console.log(data);
});
}.bind(this)

this.listSections = function()
{
var sectionList = [];
for (var name in this.sections)
{
var section = this.sections[name].name;
if (this.listAll || section === "Apps") {
for (var app of this.apps) {
if (app.Section === section) {
sectionList.push(section);
break;
}
}
}
}
return sectionList;
}.bind(this)

this.listApps = function(section)
{
return this.apps.filter(function (value) {
return value.Section === section;
});
}.bind(this)

this.uninstall = function(e)
{
var app = e.item;
$.post("/uninstall", {"id": app.Id}, function (data) {
console.log(data);
});
}.bind(this)

var socket = io.connect(window.location.protocol + '//' + window.location.host);
socket.on('docker-connect', this.reload);
socket.on('docker-disconnect', function () {
loaded = false;
console.log('disconnect');
});
socket.on('docker-create', this.reload);
socket.on('docker-start', this.reload);
socket.on('docker-stop', this.reload);
socket.on('docker-die', this.reload);
socket.on('docker-destroy', this.reload);
});
132 changes: 132 additions & 0 deletions src/www/templates/app-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

riot.tag2('app-manifest', '<div class="padded">{manifest.description}</div> <div class="padded"> <div>{manifest.author}</div> <div><a href="{manifest.homepage}">{manifest.homepage}</a></div> </div> <div class="mdl-grid"> <div class="mdl-cell mdl-cell--4-col package {transparent: (!required &amp;&amp; !enabled)}" each="{manifest.packages}" onclick="{parent.togglePackage}"> <div class="dark" style="display: flex; align-items: center"> <div class="mdl-typography--title fill padded">{name}</div> <div class="badge material-icons" if="{required || enabled}">check</div> </div> <div class="mdl-color--cyan-800 fill padded">{purpose}</div> <div class="mdl-color--cyan-800 padded">{benefits}</div> <div class="exchange">in exchange for</div> <div class="dark padded">{risks} <div each="{datasource in datasources}">Access to {getDatasourceType(datasource)}</div> </div> <div class="mdl-color--red-700 mdl-typography--text-center padded">{selectedText(this)}</div> </div> </div> <div class="padded" if="{sensors != null &amp;&amp; datastores != null &amp;&amp; manifest != null &amp;&amp; \'datasources\' in manifest}"> <div class="padded mdl-color--cyan-800 mdl-typography--subhead mdl-color-text--white">Datasources</div> <ul class="mdl-list"> <li class="mdl-list__item mdl-list__item--two-line" each="{manifest.datasources}" id="{\'datasource_\' + clientid}"><span class="mdl-list__item-primary-content"><i class="material-icons mdl-list__item-icon">input</i><span>{name}</span><span class="mdl-list__item-sub-title">{sensor || ⁗Unbound⁗}</span></span> <ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect" for="{\'datasource_\' + clientid}"> <li class="mdl-menu__item" each="{getSensors(type)}" onclick="{parent.selectSensor(parent)}">{description}, {location}</li> <li class="mdl-menu__item" disabled if="{getSensors(type).length == 0}">No sensors found</li> </ul> </li> </ul> </div> <button class="mdl-button mdl-button--colored mdl-button--raised" style="float: right" onclick="{installApp}" __disabled="{!isValid()}">Install</button>', '', '', function(opts) {
this.manifest = null;
this.sensors = null;
this.datastores = null;
this.types = {};
this.on('mount', function () {
$.post("/store/app/get/", {name: opts.name}, this.setManifest);
$.get("/databox-directory/api/datastore", this.setDatastores);
$.get("/databox-directory/api/sensor", this.setSensors);
$.get("/databox-directory/api/sensor_type", this.setTypes);
});

this.getSensors = function(type) {
if (type == null) {
console.log(type + " == null");
return this.sensors;
}
else {
var typeObj = this.types[type];
if(typeObj != null)
{
return this.sensors.filter(function (sensor) {
return sensor.sensor_type_id === typeObj.id;
});
}
else {
return this.sensors.filter(function (sensor) {
return sensor.sensor_type_id === type;
});
}
}
}.bind(this)

this.isValid = function() {
if(opts.validate) {
for (var datasource of this.manifest.datasources) {
if (datasource.hostname == null) {
return false;
}
}
}
return true;
}.bind(this)

this.setManifest = function(data) {
this.manifest = data.manifest;
if('packages' in this.manifest && this.manifest.packages.length === 1)
{
this.manifest.packages[0].enabled = true;
}
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)

this.setDatastores = function(data) {
this.datastores = data;
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)

this.setTypes = function(data) {
for(var type of data) {
this.types[type.description] = {id: type.id, name: type.description}
}
console.log(JSON.stringify(this.types));
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)

this.setSensors = function(data) {
this.sensors = data;
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)

this.togglePackage = function(e) {
var package = e.item;
if (!package.required) {
package.enabled = !package.enabled;
}
return true;
}.bind(this)

this.selectSensor = function(source) {
return function (e) {
var sensor = e.item;
var datasource = source._item;
for (var datastore of this.datastores) {
if (datastore.id == sensor.datastore_id) {
datasource.hostname = datastore.hostname;
datasource.api_url = datastore.api_url;
datasource.sensor_id = sensor.id;
datasource.sensor = sensor.description + ", " + sensor.location;
}
}
}
}.bind(this)

this.getDatasourceType = function(datasource_id) {
for (datasource of this.manifest.datasources) {
if (datasource.clientid === datasource_id) {
var type = this.types[datasource.type];
if(type != null)
{
return type.name;
}
return datasource.type;
}
}
return {"type": "sensor"};
}.bind(this)

this.selectedText = function(item) {
if (item.required) {
return 'Required';
}
if (item.enabled) {
return 'Disable ' + item.name;
}
else {
return 'Enable ' + item.name;
}
}.bind(this)

this.installApp = function(e) {
$.post("/install", {"sla": JSON.stringify(this.manifest)}, function (data) {
console.log(data);
});
window.location.href = "/";
}.bind(this)
});
20 changes: 20 additions & 0 deletions src/www/templates/app-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

riot.tag2('app-store', '<div class="mdl-typography--text-center"> <div class="mdl-spinner mdl-js-spinner is-active" if="{!loaded}"></div> </div> <ul class="mdl-list"> <li class="mdl-list__item mdl-list__item--two-line" each="{apps}"><a class="mdl-list__item-primary-content" href="/install/{manifest.name}"><i class="material-icons mdl-list__item-icon">extension</i><span>{manifest.name}</span><span class="mdl-list__item-sub-title">{manifest.author}</span></a></li> </ul>', '', '', function(opts) {
this.loaded = false;
this.apps = [];
this.on('mount', function () {
$.get("/list-store", this.setApps);
});

this.setApps = function(data) {
this.apps = data;
this.apps.sort(function (a, b) {
var nameA = a.manifest.name.toUpperCase();
var nameB = b.manifest.name.toUpperCase();
return nameA.localeCompare(nameB);
});
this.loaded = true;
this.update();
componentHandler.upgradeAllRegistered();
}.bind(this)
});
6 changes: 2 additions & 4 deletions src/www/templates/app-store.tag
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ app-store
$.get("/list-store", this.setApps);
});

setApps(data)
{
setApps(data) {
this.apps = data;
this.apps.sort(function (a, b)
{
this.apps.sort(function (a, b) {
var nameA = a.manifest.name.toUpperCase(); // ignore upper and lowercase
var nameB = b.manifest.name.toUpperCase(); // ignore upper and lowercase
return nameA.localeCompare(nameB);
Expand Down
3 changes: 0 additions & 3 deletions src/www/ui.pug
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ html
span.mdl-layout-title
| #{appname}
iframe#content.mdl-layout__content(style="border: 0; padding: 0", src="/" + appname + "/")
script(src='https://code.jquery.com/jquery-3.1.0.min.js')
script(src='https://cdn.jsdelivr.net/riot/2.6/riot.min.js')
script(src='/templates/app-manifest.js')
script(src='https://code.getmdl.io/1.2.1/material.min.js', defer)

0 comments on commit 5d0e68d

Please sign in to comment.