-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
271 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 > 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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 && !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 && datastores != null && manifest != null && \'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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters