Skip to content

Commit 3ac95dc

Browse files
authored
moved btn-radio directive to vis editor (#33373)
1 parent dfd9401 commit 3ac95dc

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed

src/legacy/ui/public/angular-bootstrap/buttons/buttons.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/legacy/ui/public/angular-bootstrap/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ angular.module('ui.bootstrap', [
2525
'ui.bootstrap.transition',
2626
'ui.bootstrap.alert',
2727
'ui.bootstrap.bindHtml',
28-
'ui.bootstrap.buttons',
2928
'ui.bootstrap.position',
3029
'ui.bootstrap.dropdown',
3130
'ui.bootstrap.modal',
@@ -57,7 +56,6 @@ angular.module('ui.bootstrap.tpls', [
5756

5857
import './alert/alert';
5958
import './bindHtml/bindHtml';
60-
import './buttons/buttons';
6159
import './dropdown/dropdown';
6260
import './modal/modal';
6361
import './pagination/pagination';

src/legacy/ui/public/vis/editors/default/schemas.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import _ from 'lodash';
21+
import '../directives/buttons';
2122
import { IndexedArray } from '../../../indexed_array';
2223
import { AggParams } from '../../../agg_types/agg_params';
2324

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import angular from 'angular';
21+
import { uiModules } from 'ui/modules';
22+
const module = uiModules.get('kibana');
23+
24+
module.constant('buttonConfig', {
25+
activeClass: 'active',
26+
toggleEvent: 'click'
27+
});
28+
29+
module.controller('ButtonsController', ['buttonConfig', function (buttonConfig) {
30+
this.activeClass = buttonConfig.activeClass || 'active';
31+
this.toggleEvent = buttonConfig.toggleEvent || 'click';
32+
}]);
33+
34+
module.directive('btnRadio', function () {
35+
return {
36+
require: ['btnRadio', 'ngModel'],
37+
controller: 'ButtonsController',
38+
link: function (scope, element, attrs, ctrls) {
39+
const buttonsCtrl = ctrls[0];
40+
const ngModelCtrl = ctrls[1];
41+
42+
//model -> UI
43+
ngModelCtrl.$render = function () {
44+
element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, scope.$eval(attrs.btnRadio)));
45+
};
46+
47+
//ui->model
48+
element.bind(buttonsCtrl.toggleEvent, function () {
49+
const isActive = element.hasClass(buttonsCtrl.activeClass);
50+
51+
if (!isActive || angular.isDefined(attrs.uncheckable)) {
52+
scope.$apply(function () {
53+
ngModelCtrl.$setViewValue(isActive ? null : scope.$eval(attrs.btnRadio));
54+
ngModelCtrl.$render();
55+
});
56+
}
57+
});
58+
}
59+
};
60+
});

x-pack/plugins/searchprofiler/public/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ uiRoutes.when('/dev_tools/searchprofiler', {
4545
});
4646

4747
uiModules
48-
.get('app/searchprofiler', ['ui.bootstrap.buttons', 'ui.ace'])
48+
.get('app/searchprofiler', ['ui.ace'])
4949
.controller('profileViz', profileVizController)
5050
.filter('nsToPretty', () => nsToPretty)
5151
.filter('msToPretty', () => msToPretty)

0 commit comments

Comments
 (0)