Skip to content

Commit 9792745

Browse files
committed
Initial commit of plugin
1 parent 40ae16c commit 9792745

7 files changed

Lines changed: 2840 additions & 2 deletions

File tree

src/cockpit.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ function addPluginAssets(result) {
187187
var loader = new PluginLoader();
188188
loader.loadPlugins(path.join(__dirname, 'system-plugins'), '/system-plugin', deps, addPluginAssets);
189189
loader.loadPlugins(path.join(__dirname, 'plugins'), '/plugin', deps, addPluginAssets);
190+
/*
191+
Create a file .bowerrc in the project root (/usr/share/cockpit) with the content:
192+
193+
{
194+
"directory" : "plugins"
195+
}
196+
*/
197+
loader.loadPlugins(path.join('/usr/share/cockpit/plugins/'), '/plugin', deps, addPluginAssets);
190198

191199

192200
controller.start();

src/static/testviews.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
scripts.push('../system-plugins/input-controller/public/js/gamepad.js');
3333
scripts.push('../system-plugins/input-controller/public/js/input-controller.js');
3434
scripts.push('../system-plugins/input-controller/public/js/keyboard.js');
35+
scripts.push('../system-plugins/plugin-finder/public/js/config.js');
36+
scripts.push('../system-plugins/plugin-finder/public/js/plugin-finder.js');
37+
scripts.push('../system-plugins/plugin-manager/public/js/config.js');
38+
scripts.push('../system-plugins/plugin-manager/public/js/plugin-manager.js');
3539

3640
// Then the rest of the plugins
3741
scripts.push('../plugins/arduinofirmwareupload/public/js/arduinofirmwareupload.js');
@@ -49,8 +53,7 @@
4953
scripts.push('../plugins/horizon/public/js/horizon.js');
5054
scripts.push('../plugins/motor_diags/public/js/motor_diags.js');
5155
scripts.push('../plugins/photocapture/public/js/photocapture.js');
52-
scripts.push('../system-plugins/plugin-manager/public/js/config.js');
53-
scripts.push('../system-plugins/plugin-manager/public/js/plugin-manager.js');
56+
5457
scripts.push('../plugins/rovpilot/public/js/rovpilot.js');
5558
scripts.push('../plugins/serial-monitor/public/js/serial-monitor.js');
5659
scripts.push('../plugins/tankcontrol/public/js/tankcontrol.js');

src/system-plugins/plugin-finder/Readme.md

Lines changed: 2653 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var bower = require('bower');
2+
var PREFERENCES = 'plugins:plugin-finder';
3+
4+
function pluginFinder(name, deps) {
5+
console.log('Pugin Finder plugin loaded.');
6+
var preferences = getPreferences(deps.config);
7+
deps.app.get('/system-plugin/plugin-finder/config', function (req, res) {
8+
res.send(preferences);
9+
});
10+
deps.app.get('/system-plugin/plugin-finder/config/:pluginName', function (req, res) {
11+
res.send(preferences[req.params.pluginName]);
12+
});
13+
deps.app.post('/system-plugin/plugin-finder/config/:pluginName', function (req, res) {
14+
console.log(typeof req.body.isEnabled);
15+
preferences[req.params.pluginName] = req.body;
16+
res.status(200);
17+
res.send(preferences[req.params.pluginName]);
18+
deps.config.preferences.set(PREFERENCES, preferences);
19+
deps.config.savePreferences();
20+
});
21+
deps.io.sockets.on('connection', function (socket) {
22+
var client = socket;
23+
socket.on('plugin-finder.search', function (name) {
24+
bower.commands
25+
.search('plugin', {}) //.search('openrov-plugin-'+ name, {})
26+
.on('end', function (results) {
27+
client.emit('plugin-finder.search',results);
28+
});
29+
});
30+
31+
socket.on('plugin-finder.install', function (name) {
32+
bower.commands
33+
.install([name], { save: true }, { allow-root: true })
34+
.on('end', function (installed) {
35+
client.emit('plugin-finder.install',installed);
36+
});
37+
});
38+
39+
});
40+
}
41+
42+
43+
function getPreferences(config) {
44+
var preferences = config.preferences.get(PREFERENCES);
45+
if (preferences == undefined) {
46+
preferences = {};
47+
config.preferences.set(PREFERENCES, preferences);
48+
}
49+
console.log('Plugin Finder loaded preferences: ' + JSON.stringify(preferences));
50+
return preferences;
51+
}
52+
module.exports = pluginManager;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
var PluginFinderConfig;
3+
PluginFinderConfig = function PluginFinderConfig() {
4+
var self = this;
5+
self.get = function (pluginName, callback) {
6+
$.get('/system-plugin/plugin-finder/config/' + pluginName, function (config) {
7+
if (callback != undefined)
8+
callback(config);
9+
});
10+
};
11+
self.set = function (pluginName, config) {
12+
$.post('/system-plugin/plugin-finder/config/' + pluginName, config);
13+
};
14+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
(function (window, $, undefined) {
2+
'use strict';
3+
4+
var PluginFinderModel = function PluginFinderrModel() {
5+
var self = this;
6+
self.cachedAvailablePlugins = [];
7+
self.availablePlugins = ko.observableArray();
8+
self.query = ko.observable('');
9+
10+
self.query.subscribe(function(value) {
11+
// remove all the current beers, which removes them from the view
12+
self.availablePlugins.removeAll();
13+
14+
for(var x in self.cachedAvailablePlugins) {
15+
if(self.cachedAvailablePlugins[x].name().toLowerCase().indexOf(value.toLowerCase()) >= 0) {
16+
self.availablePlugins.push(self.cachedAvailablePlugins[x]);
17+
}
18+
}
19+
}
20+
);
21+
};
22+
23+
24+
var Plugin = function Plugin(rawPlugin, configManager) {
25+
var self = this;
26+
self.rawPlugin = rawPlugin;
27+
self.config = {};
28+
self.isEnabled = ko.observable(true);
29+
self.name = ko.computed(function () {
30+
return self.rawPlugin.name;
31+
});
32+
self.url = ko.computed(function () {
33+
return self.rawPlugin.url;
34+
});
35+
//Get data from server
36+
/*configManager.get(self.name(), function (pluginConfig) {
37+
if (pluginConfig != undefined && pluginConfig.isEnabled != undefined) {
38+
self.config = pluginConfig;
39+
self.isEnabled(pluginConfig.isEnabled.toBool());
40+
}
41+
});*/
42+
//Update data to server when changed
43+
self.isEnabled.subscribe(function (newIsEnabled) {
44+
if (newIsEnabled == true) {
45+
self.rawPlugin.enable();
46+
} else {
47+
self.rawPlugin.disable();
48+
}
49+
self.config.isEnabled = newIsEnabled.toString();
50+
configManager.set(self.name(), self.config);
51+
});
52+
};
53+
54+
55+
56+
var PluginFinder = function PluginFinder(cockpit) {
57+
console.log('Loading Plugin Finder plugin.');
58+
this.cockpit = cockpit;
59+
this.model = new PluginFinderModel();
60+
var self = this;
61+
var configManager = new PluginFinderConfig();
62+
$('#plugin-settings').append('<div id="plugin-finder-settings"></div>');
63+
//this technique forces relative path to the js file instead of the excution directory
64+
var jsFileLocation = urlOfJsFile('plugin-finder.js');
65+
$('#plugin-finder-settings').load(jsFileLocation + '../settings.html', function () {
66+
//Get plugins from somewhere and bind them somewhere
67+
ko.applyBindings(self.model, document.getElementById('pluginFinder-settings'));
68+
});
69+
70+
self.cockpit.socket.on('pluginfindersearchresults', function(results){
71+
console.log('evaluating plugin for pluginmanager');
72+
results.forEach(function (plugin) {
73+
var plg = new Plugin(plugin, configManager);
74+
self.model.availablePlugins.push(plg);
75+
self.model.cachedAvailablePlugins.push(plg)
76+
});
77+
78+
});
79+
};
80+
window.Cockpit.plugins.push(PluginFinder);
81+
}(window, jQuery));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div id="pluginFinder-settings">
2+
<div class="accordion-group">
3+
<div class="accordion-heading">
4+
<a class="accordion-toggle" data-toggle="collapse" data-parent="#plugin-settings" href="#collapsePluginFinder">
5+
Add new plugins
6+
</a>
7+
</div>
8+
<div id="collapsePluginFinder" class="accordion-body collapse">
9+
<div class="accordion-inner">
10+
<input placeholder="Filter…" type="search" data-bind="value: query, valueUpdate: 'keyup'" autocomplete="off">
11+
<div class="pre-scrollable">
12+
<table class="table table-striped">
13+
<tbody data-bind="foreach: availablePlugins">
14+
<tr>
15+
<td>
16+
<span data-bind="text: name">&nbsp;</span>
17+
<button type="button" class="btn btn-xs btn-default pull-right" data-bind="click: $parent.enablePlugin">Install</button>
18+
<button type="button" class="btn btn-xs btn-default pull-right" data-bind="click: $parent.disablePlugin">Learn More</button>
19+
</td>
20+
</tr>
21+
</tbody>
22+
</table>
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
</div>

0 commit comments

Comments
 (0)