Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert reverts #1898

Merged
merged 2 commits into from
Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/kibana/components/clipboard/clipboard.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<span>
<a tooltip="{{shownText}}"
<a
ng-if="!disabled"
tooltip="{{shownText}}"
tooltip-placement="{{tipPlacement}}"
tooltip-animation="false"
tooltip-popup-delay="0"
Expand Down
72 changes: 40 additions & 32 deletions src/kibana/components/clipboard/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
define(function (require) {
// ng-clip expects ZeroClipboard to be global, but it's AMD, so it never is
var ZeroClipboard = window.ZeroClipboard = require('zeroclipboard');
require('ng-clip');

var $ = require('jquery');
var html = require('text!components/clipboard/clipboard.html');
var module = require('modules').get('kibana');

require('modules')
.get('kibana')
.directive('kbnClipboard', function ($compile, $timeout) {
return {
restrict: 'E',
template: html,
replace: true,
scope: {
copyText: '=copy'
},
transclude: true,
link: function ($scope, $el, attr) {
$scope.tipPlacement = attr.tipPlacement || 'top';
$scope.tipText = attr.tipText || 'Copy to clipboard';
$scope.tipConfirm = attr.tipConfirm = 'Copied!';
$scope.icon = attr.icon || 'fa-clipboard';
module.directive('kbnClipboard', function ($compile, $timeout) {
return {
restrict: 'E',
template: html,
replace: true,
scope: {
copyText: '=copy'
},
transclude: true,
link: function ($scope, $el, attr) {
if (ZeroClipboard.isFlashUnusable()) {
$scope.disabled = true;
return;
}

$scope.shownText = $scope.tipText;
$scope.tipPlacement = attr.tipPlacement || 'top';
$scope.tipText = attr.tipText || 'Copy to clipboard';
$scope.tipConfirm = attr.tipConfirm = 'Copied!';
$scope.icon = attr.icon || 'fa-clipboard';

$el.on('click', function () {
$scope.shownText = $scope.tipConfirm;
// Reposition tooltip to account for text length change
$('a', $el).mouseenter();
});
$scope.shownText = $scope.tipText;

$el.on('mouseleave', function () {
$scope.shownText = $scope.tipText;
});
$el.on('click', function () {
$scope.shownText = $scope.tipConfirm;
// Reposition tooltip to account for text length change
$('a', $el).mouseenter();
});

$scope.$on('$destroy', function () {
$el.off('click');
$el.off('mouseleave');
});
}
};
});
$el.on('mouseleave', function () {
$scope.shownText = $scope.tipText;
});

$scope.$on('$destroy', function () {
$el.off('click');
$el.off('mouseleave');
});
}
};
});
});
4 changes: 0 additions & 4 deletions src/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ define(function (require) {
require('angular-route');
require('angular-bindonce');

// Seems bad?
window.ZeroClipboard = require('zeroclipboard');
require('ng-clip');

var configFile = JSON.parse(require('text!config'));

var kibana = modules.get('kibana', [
Expand Down
13 changes: 10 additions & 3 deletions src/kibana/plugins/dashboard/partials/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

<p>
<div class="input-group">
<label>Embed this dashboard. <kbn-clipboard copy="opts.shareData().embed"></kbn-clipboard> <small>Add to your html source. Note all clients must still be able to access kibana</small></label>
<label>
Embed this dashboard.
<kbn-clipboard copy="opts.shareData().embed"></kbn-clipboard>
<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{opts.shareData().embed}}</div>
</div>
</p>

<p>
<div class="input-group">
<label>Share a link <kbn-clipboard copy="opts.shareData().link"></kbn-clipboard></i></a></label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
<label>
Share a link
<kbn-clipboard copy="opts.shareData().link"></kbn-clipboard>
</label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
</div>
</p>
</form>
8 changes: 7 additions & 1 deletion src/kibana/plugins/discover/directives/table_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ define(function (require) {
}

// The fields to loop over
row._fields = row._fields || _.keys(row._source).concat(config.get('metaFields')).sort();
if (!row._fields) {
row._fields = _.union(
_.keys(row._source),
config.get('metaFields')
);
row._fields.sort();
}
row._mode = 'table';

// empty the details and rebuild it
Expand Down
9 changes: 6 additions & 3 deletions src/kibana/plugins/visualize/editor/panels/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<p>
<div class="form-group">
<label>Embed this visualization.
<label>
Embed this visualization.
<kbn-clipboard copy="conf.shareData().embed"></kbn-clipboard>

<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{conf.shareData().embed}}</div>
Expand All @@ -13,7 +13,10 @@

<p>
<div class="form-group">
<label>Share a link <kbn-clipboard copy="conf.shareData().link"></kbn-clipboard></label>
<label>
Share a link
<kbn-clipboard copy="conf.shareData().link"></kbn-clipboard>
</label>
<div class="form-control" disabled>{{conf.shareData().link}}</div>
</div>
</p>
Expand Down
1 change: 0 additions & 1 deletion src/kibana/require.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ require.config({
leaflet: {
deps: ['css!bower_components/leaflet/dist/leaflet.css']
}

},
waitSeconds: 60
});
46 changes: 45 additions & 1 deletion test/unit/specs/apps/discover/directives/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define(function (require) {
timestamp: {
indexed: true,
type: 'date'
},
}
};

// Sets up the directive, take an element, and a list of properties to attach to the parent scope.
Expand Down Expand Up @@ -357,6 +357,50 @@ define(function (require) {
});
});

describe('kbnTableRow meta', function () {
var $elem = angular.element(
'<tr kbn-table-row="row" ' +
'columns="columns" ' +
'sorting="sorting"' +
'filtering="filtering"' +
'mapping="mapping"' +
'timefield="timefield" ' +
'></tr>'
);
var $details;

beforeEach(function () {
var row = getFakeRow(0, mapping);
mapping._id = {indexed: true, type: 'string'};
row._source._id = 'foo';

init($elem, {
row: row,
columns: [],
sorting: [],
filtering: sinon.spy(),
maxLength: 50,
mapping: mapping
});

sinon.stub(config, 'get').withArgs('metaFields').returns(['_id']);

// Open the row
$scope.toggleRow();
$scope.$digest();
$details = $elem.next();
});

afterEach(function () {
delete mapping._id;
destroy();
});

it('should render even when the row source contains a field with the same name as a meta field', function () {
expect($details.find('tr').length).to.be(4);
});
});

describe('row diffing', function () {
var $row;
var $scope;
Expand Down
94 changes: 61 additions & 33 deletions test/unit/specs/components/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
define(function (require) {
var angular = require('angular');
var _ = require('lodash');
var sinon = require('sinon/sinon');
var sinon = require('test_utils/auto_release_sinon');
var $ = require('jquery');

require('components/clipboard/clipboard');

describe('Clipboard directive', function () {

var $scope, $rootScope, $compile, $interpolate, el, tips;

beforeEach(function (done) {
var $scope;
var $rootScope;
var $compile;
var $interpolate;
var el;
var tips;

function init() {
// load the application
module('kibana');

Expand All @@ -24,48 +28,72 @@ define(function (require) {

$scope = el.scope();
$scope.$digest();
});
}

done();
describe('With flash disabled', function () {
beforeEach(function () {
sinon.stub(window.ZeroClipboard, 'isFlashUnusable', _.constant(true));
init();
});

});
it('should be an empty element', function () {
expect(el.children()).to.have.length(0);
});

it('should contain an element with clip-copy', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(1);
it('should not show the tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(0);
});

it('should not show the clipboard button', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(0);
});
});

it('should have a tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(1);
describe('With flash enabled', function () {
beforeEach(function () {
sinon.stub(window.ZeroClipboard, 'isFlashUnusable', _.constant(false));
init();
});

it('should contain an element with clip-copy', function () {
var clip = el.find('[clip-copy]');
expect(clip).to.have.length(1);
});

var clipText = $interpolate($(clip).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
it('should have a tooltip', function () {
var clip = el.find('[tooltip]');
expect(clip).to.have.length(1);

});
var clipText = $interpolate($(clip).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');

it('should change the tooltip text when clicked, back when mouse leaves', function () {
el.mouseenter();
el.click();
$scope.$digest();
});

var clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copied!');
it('should change the tooltip text when clicked, back when mouse leaves', function () {
el.mouseenter();
el.click();
$scope.$digest();

el.mouseleave();
$scope.$digest();
var clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copied!');

clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
});
el.mouseleave();
$scope.$digest();

it('should unbind all handlers on destroy', function () {
var handlers = $._data(el.get(0), 'events');
expect(Object.keys(handlers)).to.have.length(2);
clipText = $interpolate($('[tooltip]', el).attr('tooltip'))();
expect(clipText).to.be('Copy to clipboard');
});

$scope.$destroy();
expect(Object.keys(handlers)).to.have.length(0);
});
it('should unbind all handlers on destroy', function () {
var handlers = $._data(el.get(0), 'events');
expect(Object.keys(handlers)).to.have.length(2);

$scope.$destroy();
expect(Object.keys(handlers)).to.have.length(0);
});
});
});
});