Skip to content

Commit

Permalink
Added ability to uninstall plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianAdams committed Aug 13, 2014
1 parent 545ea70 commit 0103345
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
51 changes: 48 additions & 3 deletions src/system-plugins/plugin-finder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,31 @@ function pluginFinder(name, deps) {
socket.on('plugin-finder.search', function (name) {
console.log('performing search for plugins');
bower.commands
.search('openrov-plugin-'+ name, {})
.on('end', function (results) {
.list( {}, { cwd: '/usr/share/cockpit' })

This comment has been minimized.

Copy link
@codewithpassion

codewithpassion Aug 20, 2014

Member

In regards of code quality, could we please put this path into the configuration object (CONFIG)?
It is used all over the place....

.on('end',function (listing) {
var list = listing.dependencies;
bower.commands
.search('openrov-plugin-'+ name, {})
.on('end', function (results) {
for(var result in results){
//console.log(list.keys());
if(results[result].name in list){
results[result].InstalledOnROV = true;
}
}
console.log('sending plugins list to browser');
client.emit('pluginfindersearchresults',results);
});
});
});

socket.on('plugin-finder.list', function (name) {
console.log('performing list for plugins');
bower.commands
.list( {}, { cwd: '/usr/share/cockpit' })
.on('end',function (results) {
console.log('sending plugins list to browser');
client.emit('pluginfindersearchresults',results);
client.emit('pluginfinderinstalled',results);
});
});

Expand Down Expand Up @@ -54,6 +75,30 @@ function pluginFinder(name, deps) {

});

socket.on('plugin-finder.uninstall', function (name) {
bower.commands
.uninstall([name], {}, { cwd: '/usr/share/cockpit' })
.on('error', function(err){
console.log(err);
})
.on('log', function(info){
console.log(info);
client.emit('pluginfinderuninstallstatus',info);
})
.on('end', function(uninstalled){
console.log('done processing plugin uninstall');
client.emit('pluginfinderuninstallresults',uninstalled);
client.emit('pluginfinderrestartRequired');
//There is a bug with bower, possibly around re-installing
//that causes the CPU to max out forever. This restart
//is as much a work-around as it is needed to load the
//server-side aspects of the plugin.
console.log("intentional restart");
setTimeout(process.exit(17),5000);
});

});

});
}

Expand Down
20 changes: 19 additions & 1 deletion src/system-plugins/plugin-finder/public/js/plugin-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
self.isLoading = ko.observable(false);
self.isInstalling = ko.observable(false);
self.install = ko.observable('');
self.uninstall = ko.observable('');
self.requestedPluginDetail = ko.observable('');

self.query.subscribe(function(value) {
Expand All @@ -27,6 +28,10 @@
self.install(plugin);
};

self.uninstallPlugin = function (plugin) {
self.uninstall(plugin);
};

self.launchPluginDetail = function (plugin) {
self.requestedPluginDetail(plugin);
};
Expand Down Expand Up @@ -91,6 +96,9 @@
self.homepage = ko.observable('');
self.description = ko.observable('');
self.raiting = ko.observable('');
self.installed = ko.computed(function () {
return self.rawPlugin.InstalledOnROV === true ? true : false;
});
//Get data from server
/*configManager.get(self.name(), function (pluginConfig) {
if (pluginConfig != undefined && pluginConfig.isEnabled != undefined) {
Expand Down Expand Up @@ -142,7 +150,12 @@

this.model.install.subscribe(function(plugin){
self.model.isInstalling(true);
self.cockpit.socket.emit('plugin-finder.install',plugin.name());
self.cockpit.socket.emit('plugin-finder.install',plugin.rawPlugin.name);
});

this.model.uninstall.subscribe(function(plugin){
self.model.isInstalling(true);
self.cockpit.socket.emit('plugin-finder.uninstall',plugin.rawPlugin.name);
});

this.model.requestedPluginDetail.subscribe(function(plugin){
Expand All @@ -165,6 +178,11 @@
self.model.isInstalling(false);
});

self.cockpit.socket.on('pluginfinderuninstallresults', function(result){
console.log(result);
self.model.isInstalling(false);
});

self.cockpit.socket.on('pluginfinderinstallstatus', function(status){
console.log(status);
});
Expand Down
4 changes: 3 additions & 1 deletion src/system-plugins/plugin-finder/public/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<span class="badge" ><span data-bind="text: raiting"></span> stars</span>
</td>
<td>
<button type="button" class="btn btn-xs btn-default pull-right" data-bind="click: $parent.installPlugin">Install</button>
<button type="button" class="btn btn-xs btn-default pull-right hide" data-bind="click: $parent.installPlugin, style: { display: installed() === false ? 'inherit' : ''}">Install</button>
<button type="button" class="btn btn-xs btn-default pull-right hide" data-bind="click: $parent.uninstallPlugin, style: { display: installed() === true ? 'inherit' : ''}">Uninstall</button>

</td>
</tr>
</tbody>
Expand Down

0 comments on commit 0103345

Please sign in to comment.