Permalink
Browse files

cmd/bosun: more keyboard-tab ui friendly (build: Travis go1.6 -> 1.7)

Also make it so shift-enter executes on the graph page on text input fields (similar to expr page). Also set focus on the config editor.
  • Loading branch information...
1 parent 9f7f8bf commit 14f4b03694082e20ce0db558a107fadbe9ef02a6 @kylebrandt kylebrandt committed on GitHub Sep 2, 2016
View
@@ -1,7 +1,7 @@
language: go
sudo: false
go:
- - 1.6
+ - 1.7
notifications:
email: false
View
Oops, something went wrong.
@@ -620,6 +620,7 @@ bosunControllers.controller('ConfigCtrl', ['$scope', '$http', '$location', '$rou
$scope.aceLoaded = function (_editor) {
editor = _editor;
$scope.editor = editor;
+ editor.focus();
editor.getSession().setUseWrapMode(true);
editor.on("blur", function () {
$scope.$apply(function () {
@@ -970,6 +971,7 @@ bosunControllers.controller('DashboardCtrl', ['$scope', '$http', '$location', fu
}
};
}]);
+/// <reference path="0-bosun.ts" />
bosunApp.directive('tsResults', function () {
return {
templateUrl: '/partials/results.html',
@@ -1168,6 +1170,17 @@ bosunApp.directive('tsTableSort', ['$timeout', function ($timeout) {
}
};
}]);
+// https://gist.github.com/mlynch/dd407b93ed288d499778
+bosunApp.directive('autofocus', ['$timeout', function ($timeout) {
+ return {
+ restrict: 'A',
+ link: function ($scope, $element) {
+ $timeout(function () {
+ $element[0].focus();
+ });
+ }
+ };
+ }]);
bosunApp.directive('tsTimeLine', function () {
var tsdbFormat = d3.time.format.utc("%Y/%m/%d-%X");
function parseDate(s) {
@@ -2145,6 +2158,7 @@ bosunControllers.controller('ExprCtrl', ['$scope', '$http', '$location', '$route
}
};
}]);
+/// <reference path="0-bosun.ts" />
var TagSet = (function () {
function TagSet() {
}
@@ -2542,6 +2556,11 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
});
return request;
}
+ $scope.keydown = function ($event) {
+ if ($event.shiftKey && $event.keyCode == 13) {
+ $scope.Query();
+ }
+ };
$scope.Query = function () {
var r = getRequest();
angular.forEach($scope.query_p, function (q, index) {
@@ -168,6 +168,7 @@ bosunControllers.controller('ConfigCtrl', ['$scope', '$http', '$location', '$rou
$scope.aceLoaded = function (_editor) {
editor = _editor;
$scope.editor = editor;
+ editor.focus();
editor.getSession().setUseWrapMode(true);
editor.on("blur", function () {
$scope.$apply(function () {
@@ -1,3 +1,5 @@
+/// <reference path="0-bosun.ts" />
+
bosunApp.directive('tsResults', function() {
return {
templateUrl: '/partials/results.html',
@@ -215,6 +217,18 @@ bosunApp.directive('tsTableSort', ['$timeout', ($timeout: ng.ITimeoutService) =>
};
}]);
+// https://gist.github.com/mlynch/dd407b93ed288d499778
+bosunApp.directive('autofocus', ['$timeout', function($timeout) {
+ return {
+ restrict: 'A',
+ link : function($scope, $element) {
+ $timeout(function() {
+ $element[0].focus();
+ });
+ }
+ }
+}]);
+
bosunApp.directive('tsTimeLine', () => {
var tsdbFormat = d3.time.format.utc("%Y/%m/%d-%X");
function parseDate(s: any) {
@@ -1,3 +1,5 @@
+/// <reference path="0-bosun.ts" />
+
class TagSet {
[tagk: string]: string;
}
@@ -69,7 +71,7 @@ class Query {
var that = this;
// Copy tags with values to group by filters so old links work
if (filterSupport) {
- _.each(this.tags, function(v, k) {
+ _.each(this.tags, function (v, k) {
if (v === "") {
return
}
@@ -82,7 +84,7 @@ class Query {
// Load filters from raw query and turn them into gb and nGbFilters.
// This makes links from other pages work (i.e. the expr page)
if (_.has(q, 'filters')) {
- _.each(q.filters, function(filter: Filter) {
+ _.each(q.filters, function (filter: Filter) {
if (filter.groupBy) {
that.gbFilters[filter.tagk] = filter;
return;
@@ -98,12 +100,12 @@ class Query {
setFilters() {
this.filters = [];
var that = this;
- _.each(this.gbFilters, function(filter: Filter, tagk) {
+ _.each(this.gbFilters, function (filter: Filter, tagk) {
if (filter.filter && filter.type) {
that.filters.push(filter);
}
});
- _.each(this.nGbFilters, function(filter: Filter, tagk) {
+ _.each(this.nGbFilters, function (filter: Filter, tagk) {
if (filter.filter && filter.type) {
that.filters.push(filter);
}
@@ -233,9 +235,10 @@ interface IGraphScope extends ng.IScope {
showAnnotations: boolean;
setShowAnnotations: (something: any) => void;
exprText: string;
+ keydown: ($event: any) => void;
}
-bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$route', '$timeout', function($scope: IGraphScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService, $timeout: ng.ITimeoutService) {
+bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$route', '$timeout', function ($scope: IGraphScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService, $timeout: ng.ITimeoutService) {
$scope.aggregators = ["sum", "min", "max", "avg", "dev", "zimsum", "mimmin", "minmax"];
$scope.dsaggregators = ["", "sum", "min", "max", "avg", "dev", "zimsum", "mimmin", "minmax"];
$scope.filters = ["auto", "iliteral_or", "iwildcard", "literal_or", "not_iliteral_or", "not_literal_or", "regexp", "wildcard"];
@@ -327,15 +330,15 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
.error((error) => {
$scope.error = error;
});
- $scope.SwitchTimes = function() {
+ $scope.SwitchTimes = function () {
$scope.start = SwapTime($scope.start);
$scope.end = SwapTime($scope.end);
};
- $scope.AddTab = function() {
+ $scope.AddTab = function () {
$scope.index = $scope.query_p.length;
$scope.query_p.push(new Query($scope.filterSupport));
};
- $scope.setIndex = function(i: number) {
+ $scope.setIndex = function (i: number) {
$scope.index = i;
};
var alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
@@ -353,15 +356,15 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
$scope.hosts = data;
});
}
- $scope.GetTagKByMetric = function(index: number) {
+ $scope.GetTagKByMetric = function (index: number) {
$scope.tagvs[index] = new TagV;
var metric = $scope.query_p[index].metric;
if (!metric) {
$scope.canAuto[metric] = true;
return;
}
$http.get('/api/tagk/' + metric)
- .success(function(data: string[]) {
+ .success(function (data: string[]) {
var q = $scope.query_p[index];
var tags = new TagSet;
q.metric_tags = {};
@@ -412,7 +415,7 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
return a.localeCompare(b);
});
})
- .error(function(error) {
+ .error(function (error) {
$scope.error = 'Unable to fetch metrics: ' + error;
});
$http.get('/api/metadata/metrics?metric=' + metric)
@@ -428,35 +431,35 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
$scope.AddTab();
}
$http.get('/api/metric' + "?since=" + moment().utc().subtract(2, "days").unix())
- .success(function(data: string[]) {
+ .success(function (data: string[]) {
$scope.metrics = data;
})
- .error(function(error) {
+ .error(function (error) {
$scope.error = 'Unable to fetch metrics: ' + error;
});
function GetTagVs(k: string, index: number) {
$http.get('/api/tagv/' + k + '/' + $scope.query_p[index].metric)
- .success(function(data: string[]) {
+ .success(function (data: string[]) {
data.sort();
$scope.tagvs[index][k] = data;
})
- .error(function(error) {
+ .error(function (error) {
$scope.error = 'Unable to fetch metrics: ' + error;
});
}
function getRequest() {
request = new Request;
request.start = $scope.start;
request.end = $scope.end;
- angular.forEach($scope.query_p, function(p) {
+ angular.forEach($scope.query_p, function (p) {
if (!p.metric) {
return;
}
var q = new Query($scope.filterSupport, p);
var tags = q.tags;
q.tags = new TagSet;
if (!$scope.filterSupport) {
- angular.forEach(tags, function(v, k) {
+ angular.forEach(tags, function (v, k) {
if (v && k) {
q.tags[k] = v;
}
@@ -466,7 +469,12 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
});
return request;
}
- $scope.Query = function() {
+ $scope.keydown = function ($event: any) {
+ if ($event.shiftKey && $event.keyCode == 13) {
+ $scope.Query();
+ }
+ };
+ $scope.Query = function () {
var r = getRequest();
angular.forEach($scope.query_p, (q, index) => {
var m = q.metric_tags;
@@ -489,7 +497,7 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
}
delete r.queries[index].nGbFilters[f.tagk];
delete r.queries[index].gbFilters[f.tagk];
- r.queries[index].filters = _.without(r.queries[index].filters, _.findWhere(r.queries[index].filters, {tagk: f.tagk}));
+ r.queries[index].filters = _.without(r.queries[index].filters, _.findWhere(r.queries[index].filters, { tagk: f.tagk }));
});
}
});
@@ -571,10 +579,10 @@ bosunControllers.controller('GraphCtrl', ['$scope', '$http', '$location', '$rout
$scope.queries = data.Queries;
$scope.exprText = "";
_.each($scope.queries, (q, i) => {
- $scope.exprText += "$" + alphabet[i] + " = " + q + "\n";
- if ( i == $scope.queries.length-1) {
- $scope.exprText += "avg($" + alphabet[i] + ")"
- }
+ $scope.exprText += "$" + alphabet[i] + " = " + q + "\n";
+ if (i == $scope.queries.length - 1) {
+ $scope.exprText += "avg($" + alphabet[i] + ")"
+ }
});
$scope.running = '';
$scope.error = '';
@@ -45,7 +45,7 @@
<div class="col-sm-12">
<form>
<div class="form-group">
- <textarea id="exprTextArea" class="form-control" ng-model="expr" ng-keydown="keydown($event)" ng-init="eval()" spellcheck="false" elastic></textarea>
+ <textarea id="exprTextArea" class="form-control" ng-model="expr" ng-keydown="keydown($event)" ng-init="eval()" spellcheck="false" elastic autofocus></textarea>
</div>
</form>
<form class="form-inline">
Oops, something went wrong.

0 comments on commit 14f4b03

Please sign in to comment.