Init hotkeys system

This commit is contained in:
Floran Brutel 2017-05-30 14:02:30 +02:00
parent 09758fa713
commit 7b2cac0f2f
6 changed files with 182 additions and 225 deletions

View File

@ -5,6 +5,7 @@
"angular": "^1.5.8", "angular": "^1.5.8",
"angular-route": "^1.5.8", "angular-route": "^1.5.8",
"lodash": "^4.13.1", "lodash": "^4.13.1",
"favico.js": "^0.3.10" "favico.js": "^0.3.10",
"angular-hotkeys-light": "^1.1.1"
} }
} }

View File

@ -1,4 +1,4 @@
var glancesApp = angular.module('glancesApp', ['ngRoute', 'glances.config']) var glancesApp = angular.module('glancesApp', ['ngRoute', 'glances.config', 'fps.hotkeys'])
.config(function($routeProvider, $locationProvider) { .config(function($routeProvider, $locationProvider) {
$routeProvider.when('/', { $routeProvider.when('/', {

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function GlancesController($interval, GlancesStats, REFRESH_TIME) { function GlancesController($interval, GlancesStats, REFRESH_TIME, Hotkeys) {
var vm = this; var vm = this;
vm.dataLoaded = false; vm.dataLoaded = false;
@ -25,4 +25,13 @@ function GlancesController($interval, GlancesStats, REFRESH_TIME) {
$interval(function () { $interval(function () {
vm.refreshData(); vm.refreshData();
}, REFRESH_TIME * 1000); // in milliseconds }, REFRESH_TIME * 1000); // in milliseconds
Hotkeys.registerHotkey(Hotkeys.createHotkey({
key: 'm',
callback: function () {
console.log('Sort processes by MEM%');
}
}));
Hotkeys.registerHotkey( hotkey);
} }

View File

@ -1,4 +1,4 @@
var glancesApp = angular.module('glancesApp', ['ngRoute', 'glances.config']) var glancesApp = angular.module('glancesApp', ['ngRoute', 'glances.config', 'fps.hotkeys'])
.config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) { .config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) {
$routeProvider.when('/', { $routeProvider.when('/', {
@ -315,7 +315,7 @@ glancesApp.component('glances', {
'use strict'; 'use strict';
function GlancesController($interval, GlancesStats, REFRESH_TIME) { function GlancesController($interval, GlancesStats, REFRESH_TIME, Hotkeys) {
var vm = this; var vm = this;
vm.dataLoaded = false; vm.dataLoaded = false;
@ -340,26 +340,15 @@ function GlancesController($interval, GlancesStats, REFRESH_TIME) {
$interval(function () { $interval(function () {
vm.refreshData(); vm.refreshData();
}, REFRESH_TIME * 1000); // in milliseconds }, REFRESH_TIME * 1000); // in milliseconds
}
'use strict'; Hotkeys.registerHotkey(Hotkeys.createHotkey({
key: 'm',
callback: function () {
console.log('Sort processes by MEM%');
}
}));
glancesApp.component('glancesHelp', { Hotkeys.registerHotkey( hotkey);
controller: GlancesHelpController,
controllerAs: 'vm',
bindings: {
},
templateUrl: 'components/help/view.html'
});
'use strict';
function GlancesHelpController(GlancesStats) {
var vm = this;
GlancesStats.getHelp().then(function(help) {
vm.help = help;
});
} }
'use strict'; 'use strict';
@ -449,38 +438,22 @@ function GlancesPluginAlertController(favicoService) {
'use strict'; 'use strict';
glancesApp.component('glancesPluginCloud', { glancesApp.component('glancesHelp', {
controller: GlancesPluginCloudController, controller: GlancesHelpController,
controllerAs: 'vm', controllerAs: 'vm',
bindings: { bindings: {
stats: '<'
}, },
templateUrl: 'components/plugin-cloud/view.html' templateUrl: 'components/help/view.html'
}); });
'use strict'; 'use strict';
function GlancesPluginCloudController() { function GlancesHelpController(GlancesStats) {
var vm = this; var vm = this;
vm.provider = null; GlancesStats.getHelp().then(function(help) {
vm.instance = null; vm.help = help;
});
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
var data = stats.stats['cloud'];
if (data['ami-id'] !== undefined) {
vm.provider = 'AWS EC2';
vm.instance = data['instance-type'] + ' instance ' + data['instance-id'] + ' (' + data['region'] + ')';
}
data = undefined;
};
} }
'use strict'; 'use strict';
@ -613,6 +586,42 @@ function GlancesPluginDiskioController($filter) {
'use strict'; 'use strict';
glancesApp.component('glancesPluginCloud', {
controller: GlancesPluginCloudController,
controllerAs: 'vm',
bindings: {
stats: '<'
},
templateUrl: 'components/plugin-cloud/view.html'
});
'use strict';
function GlancesPluginCloudController() {
var vm = this;
vm.provider = null;
vm.instance = null;
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
var data = stats.stats['cloud'];
if (data['ami-id'] !== undefined) {
vm.provider = 'AWS EC2';
vm.instance = data['instance-type'] + ' instance ' + data['instance-id'] + ' (' + data['region'] + ')';
}
data = undefined;
};
}
'use strict';
glancesApp.component('glancesPluginFs', { glancesApp.component('glancesPluginFs', {
controller: GlancesPluginFsController, controller: GlancesPluginFsController,
controllerAs: 'vm', controllerAs: 'vm',
@ -851,54 +860,6 @@ function GlancesPluginMemMoreController() {
'use strict'; 'use strict';
glancesApp.component('glancesPluginMemswap', {
controller: GlancesPluginMemswapController,
controllerAs: 'vm',
bindings: {
stats: '<'
},
templateUrl: 'components/plugin-memswap/view.html'
});
'use strict';
function GlancesPluginMemswapController() {
var vm = this;
var _view = {};
vm.percent = null;
vm.total = null;
vm.used = null;
vm.free = null;
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
var data = stats.stats['memswap'];
_view = stats.view['memswap'];
vm.percent = data['percent'];
vm.total = data['total'];
vm.used = data['used'];
vm.free = data['free'];
data = undefined;
};
this.getDecoration = function (value) {
if (_view[value] === undefined) {
return;
}
return _view[value].decoration.toLowerCase();
};
}
'use strict';
glancesApp.component('glancesPluginNetwork', { glancesApp.component('glancesPluginNetwork', {
controller: GlancesPluginNetworkController, controller: GlancesPluginNetworkController,
controllerAs: 'vm', controllerAs: 'vm',
@ -950,6 +911,54 @@ function GlancesPluginNetworkController($filter) {
'use strict'; 'use strict';
glancesApp.component('glancesPluginMemswap', {
controller: GlancesPluginMemswapController,
controllerAs: 'vm',
bindings: {
stats: '<'
},
templateUrl: 'components/plugin-memswap/view.html'
});
'use strict';
function GlancesPluginMemswapController() {
var vm = this;
var _view = {};
vm.percent = null;
vm.total = null;
vm.used = null;
vm.free = null;
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
var data = stats.stats['memswap'];
_view = stats.view['memswap'];
vm.percent = data['percent'];
vm.total = data['total'];
vm.used = data['used'];
vm.free = data['free'];
data = undefined;
};
this.getDecoration = function (value) {
if (_view[value] === undefined) {
return;
}
return _view[value].decoration.toLowerCase();
};
}
'use strict';
glancesApp.component('glancesPluginPercpu', { glancesApp.component('glancesPluginPercpu', {
controller: GlancesPluginPercpuController, controller: GlancesPluginPercpuController,
controllerAs: 'vm', controllerAs: 'vm',
@ -1053,39 +1062,6 @@ function GlancesPluginPortsController() {
'use strict'; 'use strict';
glancesApp.component('glancesPluginProcess', {
controller: GlancesPluginProcessController,
controllerAs: 'vm',
bindings: {
stats: '<',
arguments: '<'
},
templateUrl: 'components/plugin-process/view.html'
});
'use strict';
function GlancesPluginProcessController() {
var vm = this;
vm.sorter = {
column: "cpu_percent",
auto: true,
isReverseColumn: function (column) {
return !(column === 'username' || column === 'name');
},
getColumnLabel: function (column) {
if (_.isEqual(column, ['io_read', 'io_write'])) {
return 'io_counters';
} else {
return column;
}
}
};
}
'use strict';
glancesApp.component('glancesPluginProcesscount', { glancesApp.component('glancesPluginProcesscount', {
controller: GlancesPluginProcesscountController, controller: GlancesPluginProcesscountController,
controllerAs: 'vm', controllerAs: 'vm',
@ -1127,6 +1103,39 @@ function GlancesPluginProcesscountController() {
'use strict'; 'use strict';
glancesApp.component('glancesPluginProcess', {
controller: GlancesPluginProcessController,
controllerAs: 'vm',
bindings: {
stats: '<',
arguments: '<'
},
templateUrl: 'components/plugin-process/view.html'
});
'use strict';
function GlancesPluginProcessController() {
var vm = this;
vm.sorter = {
column: "cpu_percent",
auto: true,
isReverseColumn: function (column) {
return !(column === 'username' || column === 'name');
},
getColumnLabel: function (column) {
if (_.isEqual(column, ['io_read', 'io_write'])) {
return 'io_counters';
} else {
return column;
}
}
};
}
'use strict';
glancesApp.component('glancesPluginProcesslist', { glancesApp.component('glancesPluginProcesslist', {
controller: GlancesPluginProcesslistController, controller: GlancesPluginProcesslistController,
controllerAs: 'vm', controllerAs: 'vm',
@ -1278,6 +1287,34 @@ function GlancesPluginQuicklookController() {
'use strict'; 'use strict';
glancesApp.component('glancesPluginUptime', {
controller: GlancesPluginUptimeController,
controllerAs: 'vm',
bindings: {
stats: '<'
},
templateUrl: 'components/plugin-uptime/view.html'
});
'use strict';
function GlancesPluginUptimeController() {
var vm = this;
vm.value = null;
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
vm.value = stats.stats['uptime'];
};
}
'use strict';
glancesApp.component('glancesPluginSystem', { glancesApp.component('glancesPluginSystem', {
controller: GlancesPluginSystemController, controller: GlancesPluginSystemController,
controllerAs: 'vm', controllerAs: 'vm',
@ -1321,34 +1358,6 @@ function GlancesPluginSystemController() {
'use strict'; 'use strict';
glancesApp.component('glancesPluginUptime', {
controller: GlancesPluginUptimeController,
controllerAs: 'vm',
bindings: {
stats: '<'
},
templateUrl: 'components/plugin-uptime/view.html'
});
'use strict';
function GlancesPluginUptimeController() {
var vm = this;
vm.value = null;
vm.$onChanges = function (changes) {
var stats = changes.stats.currentValue;
if (stats === undefined || stats.stats === undefined) {
return;
}
vm.value = stats.stats['uptime'];
};
}
'use strict';
glancesApp.component('glancesPluginWifi', { glancesApp.component('glancesPluginWifi', {
controller: GlancesPluginWifiController, controller: GlancesPluginWifiController,
controllerAs: 'vm', controllerAs: 'vm',
@ -1404,68 +1413,3 @@ function GlancesPluginWifiController($filter) {
return _view[hotpost.ssid][field].decoration.toLowerCase(); return _view[hotpost.ssid][field].decoration.toLowerCase();
}; };
} }
glancesApp.service('GlancesPluginProcessList', ["$filter", "GlancesPlugin", function($filter, GlancesPlugin) {
var _pluginName = "processlist";
var _maxProcessesToDisplay = undefined;
this.processes = [];
this.ioReadWritePresent = false;
this.setData = function(data, views, config) {
this.processes = [];
this.ioReadWritePresent = false;
_maxProcessesToDisplay = config.outputs !== undefined ? config.outputs.max_processes_display : undefined;;
for (var i = 0; i < data[_pluginName].length; i++) {
var process = data[_pluginName][i];
process.memvirt = process.memory_info[1];
process.memres = process.memory_info[0];
process.timeplus = $filter('timedelta')(process.cpu_times);
process.timemillis = $filter('timemillis')(process.cpu_times);
process.ioRead = null;
process.ioWrite = null;
if (process.io_counters) {
this.ioReadWritePresent = true;
process.ioRead = (process.io_counters[0] - process.io_counters[2]) / process.time_since_update;
if (process.ioRead != 0) {
process.ioRead = $filter('bytes')(process.ioRead);
}
process.ioWrite = (process.io_counters[1] - process.io_counters[3]) / process.time_since_update;
if (process.ioWrite != 0) {
process.ioWrite = $filter('bytes')(process.ioWrite);
}
}
process.isNice = process.nice !== undefined && ((data['system'].os_name === 'Windows' && process.nice != 32) || (data['system'].os_name !== 'Windows' && process.nice != 0));
if (Array.isArray(process.cmdline)) {
process.cmdline = process.cmdline.join(' ');
}
if (data['system'].os_name === 'Windows') {
process.username = _.last(process.username.split('\\'));
}
this.processes.push(process);
}
};
this.getCpuPercentAlert = function(process) {
return GlancesPlugin.getAlert(_pluginName, 'processlist_cpu_', process.cpu_percent);
};
this.getMemoryPercentAlert = function(process) {
return GlancesPlugin.getAlert(_pluginName, 'processlist_mem_', process.cpu_percent);
};
this.getLimit = function() {
return _maxProcessesToDisplay;
};
}]);

File diff suppressed because one or more lines are too long

View File

@ -52139,3 +52139,6 @@ function ngViewFillContentFactory($compile, $controller, $route) {
} }
})(); })();
!function(a){!function(a){a.module("fps.hotkeys",[]).service("Hotkeys",["$Hotkeys",function(a){return new a}]).provider("$Hotkeys",function(){function a(){function a(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}var b=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},c=function(a){for(var b={},c=[],d=0;d<a.length;++d)b[a[d]]||c.push(a[d]),b[a[d]]=!0;return c},d=this.KEY_CODES={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"escape",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12"};this.$get=["$rootScope","$window",function(e,f){var g=function(a){return function(b,c){e.$apply(function(){a.call(this,b,c)}.bind(this))}},h=function(b){this.id=b.id||a(),this.key=b.key,this.context=b.context||null,this.callback=b.callback,this.args=b.args,this.onKeyUp=!1};h.prototype.clone=function(){return new h(this)};var i=function(){this._hotkeys={},this._hotkeysUp={},this._onKeydown=this._onKeydown.bind(this),this._onKeyup=this._onKeyup.bind(this),this.initialize()};return Object.defineProperty(i.prototype,"initialize",{value:function(){f.addEventListener("keydown",this._onKeydown,!0),f.addEventListener("keyup",this._onKeyup,!0)}}),Object.defineProperty(i.prototype,"_invokeHotkeyHandlers",{value:function(a,b,c){for(var d=0,e=c.length;d<e;d++)try{var f=c[d];f.callback.call(f.context,a,f.args)}catch(g){console.error("HotKeys: ",f.key,g.message)}}}),Object.defineProperty(i.prototype,"_onKeydown",{value:function(a){var b=this.keyStringFromEvent(a);this._hotkeys[b]&&this._invokeHotkeyHandlers(a,b,this._hotkeys[b])},writable:!0}),Object.defineProperty(i.prototype,"_onKeyup",{value:function(a){var b=this.keyStringFromEvent(a);this._hotkeysUp[b]&&this._invokeHotkeyHandlers(this._hotkeysUp[b],b)},writable:!0}),Object.defineProperty(i.prototype,"keyStringFromEvent",{value:function(a){var b=[],e=a.which;return e=d[e]?d[e]:String.fromCharCode(e).toLowerCase(),a.ctrlKey&&b.push("ctrl"),a.altKey&&b.push("alt"),a.shiftKey&&b.push("shift"),a.metaKey&&b.push("meta"),b.push(e),c(b).join("+")}}),Object.defineProperty(i.prototype,"_deregisterHotkey",{value:function(a){var b,c=this._hotkeys;if(a.onKeyUp&&(c=this._hotkeysUp),c[a.key])for(var d=c[a.key],e=0;e<d.length;++e){var f=d[e];(a.callback===f.callback&&f.context===a.context||a.id===f.id)&&(b=d.splice(e,1))}return b}}),Object.defineProperty(i.prototype,"deregisterHotkey",{value:function(a){var c=[];if(this._validateHotkey(a),b(a.key))for(var d=a.key.length-1;d>=0;d--){var e=a.clone();e.key=a.key[d];var f=this._deregisterHotkey(e);void 0!==f&&c.push(f[0])}else c.push(this._deregisterHotkey(a));return c}}),Object.defineProperty(i.prototype,"_validateHotkey",{value:function(a){if(!(a instanceof h))throw new TypeError("Hotkeys: Expected a hotkey object be instance of HotKey")}}),Object.defineProperty(i.prototype,"_registerKey",{value:function(a){var b=this._hotkeys;return a.onKeyUp&&(b=this._hotkeysUp),b[a.key]=b[a.key]||[],b[a.key].push(a),a}}),Object.defineProperty(i.prototype,"_registerKeys",{value:function(c){var d=[];if(b(c.key))for(var e=c.key.length-1;e>=0;e--){var f=c.clone();f.id=a(),f.key=c.key[e],d.push(this._registerKey(f))}else d.push(this._registerKey(c));return d}}),Object.defineProperty(i.prototype,"registerHotkey",{value:function(a){return this._validateHotkey(a),this._registerKeys(a)}}),Object.defineProperty(i.prototype,"registerHotkeyUp",{value:function(a){this._validateHotkey(a),a.onKeyUp=!0,this._registerKeys(a)}}),Object.defineProperty(i.prototype,"createHotkey",{value:function(a){if(null===a.key||void 0===a.key)throw new TypeError('HotKeys: Argument "key" is required');if(null===a.callback||void 0===a.callback)throw new TypeError('HotKeys: Argument "callback" is required');return a.callback=g(a.callback),new h(a)}}),Object.defineProperty(i.prototype,"match",{value:function(a,c){b(c)||(c=[c]);var d=this.keyStringFromEvent(a);return Boolean(~c.indexOf(d))}}),i}]})}(window.angular)}(angular);
//# sourceMappingURL=angular-hotkeys-light.map.js