Skip to content

Commit

Permalink
Merge pull request #1952 from spenceralger/breakup-kibana-controller
Browse files Browse the repository at this point in the history
Breakup kibana controller
  • Loading branch information
spenceralger committed Nov 21, 2014
2 parents e281350 + 63c8abe commit 46e3977
Show file tree
Hide file tree
Showing 24 changed files with 586 additions and 326 deletions.
24 changes: 24 additions & 0 deletions src/kibana/components/listen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define(function (require) {
var _ = require('lodash');

require('modules').get('kibana')
.run(function ($rootScope) {

/**
* Helper that registers an event listener, and removes that listener when
* the $scope is destroyed.
*
* @param {EventEmitter} emitter - the event emitter to listen to
* @param {string} eventName - the event name
* @param {Function} handler - the event handler
* @return {undefined}
*/
$rootScope.constructor.prototype.$listen = function (emitter, eventName, handler) {
emitter.on(eventName, handler);
this.$on('$destroy', function () {
emitter.off(eventName, handler);
});
};

});
});
5 changes: 5 additions & 0 deletions src/kibana/components/notify/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ define(function (require) {
return Notifier;
});

module.run(function ($timeout) {
// provide alternate methods for setting timeouts, which will properly trigger digest cycles
rootNotifier._setTimerFns($timeout, $timeout.cancel);
});

/**
* Global Angular exception handler (NOT JUST UNCAUGHT EXCEPTIONS)
*/
Expand Down
6 changes: 6 additions & 0 deletions src/kibana/components/style_compile/style_compile.css.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.truncate-by-height {
max-height: <%= truncateMaxHeight %>;
}
.truncate-by-height::before {
top: <%= truncateGradientTop %>;
}
32 changes: 32 additions & 0 deletions src/kibana/components/style_compile/style_compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
define(function (require) {
var _ = require('lodash');
var $ = require('jquery');
var $style = $('<style>').appendTo('head').attr('id', 'style-compile');

require('modules')
.get('kibana')
.run(function ($rootScope, $compile, config) {
var truncateGradientHeight = 15;
var template = _.template(require('text!components/style_compile/style_compile.css.tmpl'));
var locals = {};

$rootScope.$on('$destroy', function () {
$style.remove();
});

// watch the value of the truncate:maxHeight config param
$rootScope.$watch(function () {
return config.get('truncate:maxHeight');
}, function (maxHeight) {
if (maxHeight > 0) {
locals.truncateMaxHeight = maxHeight + 'px !important';
locals.truncateGradientTop = maxHeight - truncateGradientHeight + 'px';
} else {
locals.truncateMaxHeight = 'none';
locals.truncateGradientTop = '-' + truncateGradientHeight + 'px';
}

$style.html(template(locals));
});
});
});
2 changes: 1 addition & 1 deletion src/kibana/components/timepicker/timepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</div>

<div class="kbn-timepicker-section">
<label>&nbsp</label><br>
<label>&nbsp;</label><br>
<div class="form-group">
<button
type="submit"
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions src/kibana/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
define(function (require) {
var html = require('text!components/tooltip/tooltip.html');

require('modules').get('kibana')
.config(function ($tooltipProvider) {
$tooltipProvider.options({
placement: 'bottom',
animation: true,
popupDelay: 150,
appendToBody: false
});
})
.directive('kbnTooltip', function () {
return {
restrict: 'E',
template: html,
transclude: true,
replace: true,
scope: true,
link: function ($scope, $el, attr) {
$scope.text = attr.text;
$scope.placement = attr.placement || 'top';
$scope.delay = attr.delay || 400;
$scope.appendToBody = attr.appendToBody || 0;
}
};
});
});
69 changes: 69 additions & 0 deletions src/kibana/components/watch_multi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
define(function (require) {
var _ = require('lodash');

require('modules').get('kibana')
.run(function ($rootScope) {

/**
* Watch multiple expressions with a single callback. Along
* with making code simpler it also merges all of the watcher
* handlers within a single tick.
*
* @param {array[string|function]} expressions - the list of expressions to $watch
* @param {Function} fn - the callback function
* @param {boolean} deep - should the watchers be created as deep watchers?
* @return {undefined}
*/
$rootScope.constructor.prototype.$watchMulti = function (expressions, fn, deep) {
if (!_.isArray(expressions)) throw new TypeError('expected an array of expressions to watch');
if (!_.isFunction(fn)) throw new TypeError('expexted a function that is triggered on each watch');

var $scope = this;
var initQueue = _.clone(expressions);
var fired = false;
var vals = {
new: new Array(expressions.length),
old: new Array(expressions.length)
};

expressions.forEach(function (expr, i) {
$scope.$watch(expr, function (newVal, oldVal) {
vals.new[i] = newVal;

if (initQueue) {
vals.old[i] = oldVal;

var qIdx = initQueue.indexOf(expr);
if (qIdx !== -1) initQueue.splice(qIdx, 1);
if (initQueue.length === 0) {
initQueue = false;
if (fn.length) {
fn(vals.new.slice(0), vals.old.slice(0));
} else {
fn();
}
}
return;
}

if (fired) return;
fired = true;
$scope.$evalAsync(function () {
fired = false;

if (fn.length) {
fn(vals.new.slice(0), vals.old.slice(0));
} else {
fn();
}

for (var i = 0; i < vals.new.length; i++) {
vals.old[i] = vals.new[i];
}
});
});
});
};

});
});
193 changes: 0 additions & 193 deletions src/kibana/controllers/kibana.js

This file was deleted.

Loading

0 comments on commit 46e3977

Please sign in to comment.