From 859c399646cff3911a630616a762acb1d55ea06c Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Wed, 4 Sep 2013 10:56:31 -0700 Subject: [PATCH] Namespace kibana url parameters --- dashboards/logstash.js | 35 +++++++++++++++++++---------------- js/app.js | 4 ++-- js/services.js | 8 ++++---- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/dashboards/logstash.js b/dashboards/logstash.js index eeb51074947..fb0edd2b3c7 100644 --- a/dashboards/logstash.js +++ b/dashboards/logstash.js @@ -18,14 +18,17 @@ * */ -var dashboard, ARGS, queries, _d_timespan; +'use strict'; + +// Setup some variables +var dashboard, queries, _d_timespan; + +// All url parameters are available via the ARGS object +var ARGS; // Set a default timespan if one isn't specified _d_timespan = '1h'; -// arguments[0] contains a hash of the URL parameters, make it shorter -ARGS = arguments[0]; - // Intialize a skeleton with nothing but a rows array and service object dashboard = { rows : [], @@ -40,7 +43,7 @@ if(!_.isUndefined(ARGS.index)) { dashboard.index = { default: ARGS.index, interval: 'none' - } + }; } else { // Don't fail to default dashboard.failover = false; @@ -48,7 +51,7 @@ if(!_.isUndefined(ARGS.index)) { default: ARGS.index||'ADD_A_TIME_FILTER', pattern: ARGS.pattern||'[logstash-]YYYY.MM.DD', interval: ARGS.interval||'day' - } + }; } // In this dashboard we let users pass queries as comma seperated list to the query parameter. @@ -59,7 +62,7 @@ if(!_.isUndefined(ARGS.query)) { queries = _.object(_.map(ARGS.query.split(ARGS.split||','), function(v,k) { return [k,{ query: v, - id: parseInt(k), + id: parseInt(k,10), alias: v }]; })); @@ -70,14 +73,14 @@ if(!_.isUndefined(ARGS.query)) { query: '*', id: 0 } - } + }; } // Now populate the query service with our objects dashboard.services.query = { list : queries, - ids : _.map(_.keys(queries),function(v){return parseInt(v);}) -} + ids : _.map(_.keys(queries),function(v){return parseInt(v,10);}) +}; // Lets also add a default time filter, the value of which can be specified by the user // This isn't strictly needed, but it gets rid of the info alert about the missing time filter @@ -93,7 +96,7 @@ dashboard.services.filter = { } }, ids: [0] -} +}; // Ok, lets make some rows. The Filters row is collapsed by default dashboard.rows = [ @@ -138,7 +141,7 @@ dashboard.rows[1].panels = [ { type: 'Query' } -] +]; // Add a filtering panel to the 3rd row @@ -146,7 +149,7 @@ dashboard.rows[2].panels = [ { type: 'filtering' } -] +]; // And a histogram that allows the user to specify the interval and time field dashboard.rows[3].panels = [ @@ -155,7 +158,7 @@ dashboard.rows[3].panels = [ time_field: ARGS.timefield||"@timestamp", auto_int: true } -] +]; // And a table row where you can specify field and sort order dashboard.rows[4].panels = [ @@ -165,7 +168,7 @@ dashboard.rows[4].panels = [ sort: !_.isUndefined(ARGS.sort) ? ARGS.sort.split(',') : [ARGS.timefield||'@timestamp','desc'], overflow: 'expand' } -] +]; // Now return the object and we're good! -return dashboard; \ No newline at end of file +return dashboard; diff --git a/js/app.js b/js/app.js index b812468c198..7a1903381c0 100644 --- a/js/app.js +++ b/js/app.js @@ -48,10 +48,10 @@ labjs.wait(function(){ .when('/dashboard', { templateUrl: 'partials/dashboard.html', }) - .when('/dashboard/:type/:id', { + .when('/dashboard/:kbnType/:kbnId', { templateUrl: 'partials/dashboard.html', }) - .when('/dashboard/:type/:id/:params', { + .when('/dashboard/:kbnType/:kbnId/:params', { templateUrl: 'partials/dashboard.html' }) .otherwise({ diff --git a/js/services.js b/js/services.js index 66c70448c87..372460d4a3b 100644 --- a/js/services.js +++ b/js/services.js @@ -606,9 +606,9 @@ angular.module('kibana.services', []) var route = function() { // Is there a dashboard type and id in the URL? - if(!(_.isUndefined($routeParams.type)) && !(_.isUndefined($routeParams.id))) { - var _type = $routeParams.type; - var _id = $routeParams.id; + if(!(_.isUndefined($routeParams.kbnType)) && !(_.isUndefined($routeParams.kbnId))) { + var _type = $routeParams.kbnType; + var _id = $routeParams.kbnId; switch(_type) { case ('elasticsearch'): @@ -827,7 +827,7 @@ angular.module('kibana.services', []) method: "GET", transformResponse: function(response) { /*jshint -W054 */ - var _f = new Function(response); + var _f = new Function("ARGS",response); return _f($routeParams); } }).then(function(result) {