diff --git a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js index 463a7bebf14eb..3adc38bfea5dd 100644 --- a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js @@ -20,6 +20,7 @@ import _ from 'lodash'; import React from 'react'; import angular from 'angular'; +import moment from 'moment'; import chrome from 'ui/chrome'; import dateMath from '@elastic/datemath'; @@ -32,7 +33,6 @@ import * as filterActions from '../doc_table/actions/filter'; import 'ui/listen'; import 'ui/visualize'; import 'ui/fixed_scroll'; -import 'ui/filters/moment'; import 'ui/index_patterns'; import 'ui/state_management/app_state'; import { timefilter } from 'ui/timefilter'; @@ -792,6 +792,10 @@ function discoverController( $scope.time = timefilter.getTime(); }; + $scope.toMoment = function (datetime) { + return moment(datetime).format(config.get('dateFormat')); + }; + $scope.updateRefreshInterval = function () { $scope.refreshInterval = timefilter.getRefreshInterval(); }; diff --git a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html index 9a595b293254b..b254461f70429 100644 --- a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html +++ b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html @@ -29,7 +29,7 @@ - {{name | shortDots}} + {{getShortDotsName(name)}} — diff --git a/src/legacy/ui/public/agg_types/agg_params.js b/src/legacy/ui/public/agg_types/agg_params.js index 7a4e360484b90..13c7cc0db57e8 100644 --- a/src/legacy/ui/public/agg_types/agg_params.js +++ b/src/legacy/ui/public/agg_types/agg_params.js @@ -17,7 +17,6 @@ * under the License. */ -import '../filters/label'; import { IndexedArray } from '../indexed_array'; import { FieldParamType } from './param_types/field'; import { OptionedParamType } from './param_types/optioned'; diff --git a/src/legacy/ui/public/agg_types/buckets/date_histogram.js b/src/legacy/ui/public/agg_types/buckets/date_histogram.js index c3c13c823f581..38630882650a1 100644 --- a/src/legacy/ui/public/agg_types/buckets/date_histogram.js +++ b/src/legacy/ui/public/agg_types/buckets/date_histogram.js @@ -20,7 +20,6 @@ import _ from 'lodash'; import chrome from '../../chrome'; import moment from 'moment-timezone'; -import '../../filters/field_type'; import '../directives/validate_date_interval'; import { BucketAggType } from './_bucket_agg_type'; import { TimeBuckets } from '../../time_buckets'; diff --git a/src/legacy/ui/public/agg_types/param_types/field.js b/src/legacy/ui/public/agg_types/param_types/field.js index 4974559225f33..5c883c2c588b5 100644 --- a/src/legacy/ui/public/agg_types/param_types/field.js +++ b/src/legacy/ui/public/agg_types/param_types/field.js @@ -23,7 +23,6 @@ import { FieldParamEditor } from '../controls/field'; import '../directives/scroll_bottom'; import { BaseParamType } from './base'; import '../filters/sort_prefix_first'; -import '../../filters/field_type'; import { IndexedArray } from '../../indexed_array'; import { toastNotifications } from '../../notify'; import { createLegacyClass } from '../../utils/legacy_class'; diff --git a/src/legacy/ui/public/directives/field_name.js b/src/legacy/ui/public/directives/field_name.js index 383d7cdc18e0c..bc8a2932ed181 100644 --- a/src/legacy/ui/public/directives/field_name.js +++ b/src/legacy/ui/public/directives/field_name.js @@ -19,7 +19,7 @@ import $ from 'jquery'; import { template } from 'lodash'; -import '../filters/short_dots'; +import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string'; import booleanFieldNameIcon from './field_name_icons/boolean_field_name_icon.html'; import conflictFieldNameIcon from './field_name_icons/conflict_field_name_icon.html'; import dateFieldNameIcon from './field_name_icons/date_field_name_icon.html'; @@ -45,7 +45,7 @@ const compiledSourceFieldNameIcon = template(sourceFieldNameIcon); const compiledStringFieldNameIcon = template(stringFieldNameIcon); const compiledUnknownFieldNameIcon = template(unknownFieldNameIcon); -module.directive('fieldName', function ($compile, $rootScope, $filter, i18n) { +module.directive('fieldName', function ($compile, $rootScope, config, i18n) { return { restrict: 'AE', scope: { @@ -126,7 +126,9 @@ module.directive('fieldName', function ($compile, $rootScope, $filter, i18n) { const results = $scope.field ? !$scope.field.rowCount && !$scope.field.scripted : false; const scripted = $scope.field ? $scope.field.scripted : false; - const displayName = $filter('shortDots')(name); + + const isShortDots = config.get('shortDots:enable'); + const displayName = isShortDots ? shortenDottedString(name) : name; $el .attr('title', name) diff --git a/src/legacy/ui/public/directives/partials/saved_object_finder.html b/src/legacy/ui/public/directives/partials/saved_object_finder.html index 3ce944c41f7ad..adf7f5dacae9a 100644 --- a/src/legacy/ui/public/directives/partials/saved_object_finder.html +++ b/src/legacy/ui/public/directives/partials/saved_object_finder.html @@ -11,7 +11,7 @@ input-focus disable-input-focus="disableAutoFocus" ng-model="filter" - ng-attr-placeholder="{{ finder.properties.nouns | label }} Filter..." + ng-attr-placeholder="{{ finder.getLabel() }} Filter..." ng-keydown="finder.filterKeyDown($event)" name="filter" type="text" diff --git a/src/legacy/ui/public/directives/saved_object_finder.js b/src/legacy/ui/public/directives/saved_object_finder.js index 34ca72a174b40..4a6813d9c4b86 100644 --- a/src/legacy/ui/public/directives/saved_object_finder.js +++ b/src/legacy/ui/public/directives/saved_object_finder.js @@ -22,7 +22,7 @@ import rison from 'rison-node'; import { keyMap } from '../utils/key_map'; import { SavedObjectRegistryProvider } from '../saved_objects/saved_object_registry'; import { uiModules } from '../modules'; -import '../filters/label'; + import savedObjectFinderTemplate from './partials/saved_object_finder.html'; import './input_focus'; import './paginate'; @@ -158,6 +158,10 @@ module.directive('savedObjectFinder', function ($location, kbnUrl, Private, conf index: -1 }; + self.getLabel = function () { + return _.words(self.properties.nouns).map(_.capitalize).join(' '); + }; + //key handler for the filter text box self.filterKeyDown = function ($event) { switch (keyMap[$event.keyCode]) { diff --git a/src/legacy/ui/public/filters/__tests__/field_type.js b/src/legacy/ui/public/filters/__tests__/field_type.js deleted file mode 100644 index 0b969095eb499..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/field_type.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import _ from 'lodash'; -import ngMock from 'ng_mock'; -import 'plugins/kibana/discover/index'; -import '../field_type'; - -let filter; - -let types; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - types = [ - { name: 's1', type: 'string' }, - { name: 's2', type: 'string' }, - { name: 's3', type: 'string' }, - - { name: 'n1', type: 'number' }, - { name: 'n2', type: 'number' }, - - { name: 'i1', type: 'ip' }, - { name: 'd1', type: 'date' }, - ]; - - // Create the scope - ngMock.inject(function ($filter) { - filter = $filter('fieldType'); - }); -}; - - -describe('fieldType array filter', function () { - - beforeEach(function () { - init(); - }); - - it('should have a fieldType filter', function () { - expect(filter).to.not.be(null); - }); - - it('should have 3 string fields', function () { - expect(filter(types, 'string').length).to.be(3); - }); - - it('should have 2 number fields', function () { - expect(filter(types, 'number').length).to.be(2); - }); - - it('should have 1 ip field and 1 date field', function () { - expect(_.pluck(filter(types, ['date', 'ip']), 'name')).to.eql(['i1', 'd1']); - }); - - it('should return all fields when passed *', function () { - expect(filter(types, '*').length).to.be(7); - }); - - it('should allow negation', function () { - const resultNames = _.pluck(filter(types, '!string'), 'name'); - expect(resultNames).to.eql(['n1', 'n2', 'i1', 'd1']); - }); -}); diff --git a/src/legacy/ui/public/filters/__tests__/label.js b/src/legacy/ui/public/filters/__tests__/label.js deleted file mode 100644 index 1696415229749..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/label.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; -import 'plugins/kibana/discover/index'; - -// Load kibana and its applications - -let filter; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - // Create the scope - ngMock.inject(function ($filter) { - filter = $filter('label'); - }); -}; - -describe('label filter', function () { - beforeEach(function () { - init(); - }); - - it('should have a label filter', function () { - expect(filter).to.not.be(null); - }); - - it('should capitalize the first letter in a string', function () { - expect(filter('something')).to.be('Something'); - }); - - it('should capitalize the first letter in every word', function () { - expect(filter('foo bar fizz buzz')).to.be('Foo Bar Fizz Buzz'); - }); -}); diff --git a/src/legacy/ui/public/filters/__tests__/moment.js b/src/legacy/ui/public/filters/__tests__/moment.js deleted file mode 100644 index 39d7a520851d4..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/moment.js +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import sinon from 'sinon'; -import moment from 'moment'; -import ngMock from 'ng_mock'; -import '../moment'; - - -let filter; -const anchor = '2014-01-01T06:06:06.666'; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - // Create the scope - ngMock.inject(function ($filter) { - filter = $filter('moment'); - }); -}; - - -describe('moment formatting filter', function () { - const sandbox = sinon.createSandbox(); - - beforeEach(function () { - sandbox.useFakeTimers(moment(anchor).valueOf()); - - init(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('should have a moment filter', function () { - expect(filter).to.not.be(null); - }); - - // MMMM Do YYYY, HH:mm:ss.SSS - it('should format moments', function () { - expect(filter(moment())).to.be('Jan 1, 2014 @ 06:06:06.666'); - }); - - it('should format dates', function () { - expect(filter(new Date())).to.be('Jan 1, 2014 @ 06:06:06.666'); - }); - - it('should return the original value if passed anything other than a moment or Date', function () { - expect(filter('beer')).to.be('beer'); - expect(filter(1)).to.be(1); - expect(filter([])).to.eql([]); - }); -}); diff --git a/src/legacy/ui/public/filters/__tests__/rison.js b/src/legacy/ui/public/filters/__tests__/rison.js deleted file mode 100644 index 62accfa8118a7..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/rison.js +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; -import 'plugins/kibana/discover/index'; - -// Load kibana and its applications - -let rison; -let risonDecode; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - // Create the scope - ngMock.inject(function ($filter) { - rison = $filter('rison'); - risonDecode = $filter('risonDecode'); - }); -}; - -describe('rison filters', function () { - const testObj = { - time: { - from: 'now-15m', - to: 'now' - } - }; - const testRison = '(time:(from:now-15m,to:now))'; - - beforeEach(function () { - init(); - }); - - describe('rison', function () { - it('should have the filter', function () { - expect(rison).to.not.be(null); - }); - - it('should rison encode data', function () { - expect(rison(testObj)).to.be(testRison); - }); - }); - - describe('risonDecode', function () { - it('should have the filter', function () { - expect(risonDecode).to.not.be(null); - }); - - it('should decode rison data', function () { - expect(risonDecode(testRison)).to.eql(testObj); - }); - }); -}); diff --git a/src/legacy/ui/public/filters/__tests__/short_dots.js b/src/legacy/ui/public/filters/__tests__/short_dots.js deleted file mode 100644 index 747c2c280750e..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/short_dots.js +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; -import 'plugins/kibana/discover/index'; -import '../short_dots'; - - -let filter; - -let config; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - // Create the scope - ngMock.inject(function ($filter, _config_) { - config = _config_; - filter = $filter('shortDots'); - }); -}; - - -describe('shortDots filter', function () { - - beforeEach(function () { - init(); - }); - - it('should have a uriescape filter', function () { - expect(filter).to.not.be(null); - }); - - it('should shorten foo.bar.baz to f.b.baz when shortDots:enable is true', function () { - config.set('shortDots:enable', true); - expect(filter('foo.bar.baz')).to.be('f.b.baz'); - }); - - it('should not shorten when shortDots:enable is false', function () { - config.set('shortDots:enable', false); - expect(filter('foo.bar.baz')).to.be('foo.bar.baz'); - }); - - it('should not shorten floating point numbers in any case', function () { - config.set('shortDots:enable', false); - expect(filter(12345.6789)).to.be(12345.6789); - config.set('shortDots:enable', true); - expect(filter(12345.6789)).to.be(12345.6789); - }); - - -}); diff --git a/src/legacy/ui/public/filters/__tests__/uriescape.js b/src/legacy/ui/public/filters/__tests__/uriescape.js deleted file mode 100644 index 49a7034593821..0000000000000 --- a/src/legacy/ui/public/filters/__tests__/uriescape.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; -import 'plugins/kibana/discover/index'; - - -let filter; - -const init = function () { - // Load the application - ngMock.module('kibana'); - - // Create the scope - ngMock.inject(function ($filter) { - filter = $filter('uriescape'); - }); -}; - - -describe('uriescape filter', function () { - - beforeEach(function () { - init(); - }); - - it('should have a uriescape filter', function () { - expect(filter).to.not.be(null); - }); - - it('should encodeURIComponent a string', function () { - expect(filter('this and that')).to.be('this%20and%20that'); - }); - -}); diff --git a/src/legacy/ui/public/filters/field_type.js b/src/legacy/ui/public/filters/field_type.js deleted file mode 100644 index eab29762b5508..0000000000000 --- a/src/legacy/ui/public/filters/field_type.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { propFilter } from './_prop_filter'; -import { uiModules } from '../modules'; -// Gets all fields of a given type. -// You may also pass "*" to get all types -// Or an array of types to get all fields of that type - -uiModules - .get('kibana') - .filter('fieldType', function () { - return propFilter('type'); - }); diff --git a/src/legacy/ui/public/filters/label.js b/src/legacy/ui/public/filters/label.js deleted file mode 100644 index 34824448c793d..0000000000000 --- a/src/legacy/ui/public/filters/label.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { uiModules } from '../modules'; -import { words, capitalize } from 'lodash'; - -uiModules - .get('kibana') - .filter('label', function () { - return function (str) { - return words(str).map(capitalize).join(' '); - }; - }); diff --git a/src/legacy/ui/public/filters/moment.js b/src/legacy/ui/public/filters/moment.js deleted file mode 100644 index dc1be7dd20a53..0000000000000 --- a/src/legacy/ui/public/filters/moment.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import moment from 'moment'; -import _ from 'lodash'; -import { uiModules } from '../modules'; - -uiModules - .get('kibana') - .filter('moment', function (config) { - return function (datetime) { - const format = config.get('dateFormat'); - if (moment.isMoment(datetime)) return datetime.format(format); - if (_.isDate(datetime)) return moment(datetime).format(format); - return datetime; - }; - }); diff --git a/src/legacy/ui/public/filters/rison.js b/src/legacy/ui/public/filters/rison.js deleted file mode 100644 index 32a794963b455..0000000000000 --- a/src/legacy/ui/public/filters/rison.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import rison from 'rison-node'; -import { uiModules } from '../modules'; -const module = uiModules.get('kibana'); - -module.filter('rison', function () { - return function (str) { - return rison.encode(str); - }; -}); - -module.filter('risonDecode', function () { - return function (str) { - return rison.decode(str); - }; -}); diff --git a/src/legacy/ui/public/filters/short_dots.js b/src/legacy/ui/public/filters/short_dots.js deleted file mode 100644 index 02a7672165c79..0000000000000 --- a/src/legacy/ui/public/filters/short_dots.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import _ from 'lodash'; -import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string'; -import { uiModules } from '../modules'; -// Shorts dot notated strings -// e.g., foo.bar.baz becomes f.b.baz -// 'foo.bar.baz'.replace(/(.+?\.)/g,function(v) {return v[0]+'.';}); - -uiModules - .get('kibana') - .filter('shortDots', function (Private) { - return Private(shortDotsFilterProvider); - }); - -function shortDotsFilterProvider(config) { - let filter; - - config.watch('shortDots:enable', updateFilter); - - return wrapper; - - function updateFilter(enabled) { - filter = enabled ? shortenDottedString : _.identity; - } - function wrapper(str) { - return filter(str); - } -} diff --git a/src/legacy/ui/public/filters/uriescape.js b/src/legacy/ui/public/filters/uriescape.js deleted file mode 100644 index c4fc4fe178fe1..0000000000000 --- a/src/legacy/ui/public/filters/uriescape.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { uiModules } from '../modules'; -uiModules - .get('kibana') - .filter('uriescape', function () { - return function (str) { - return encodeURIComponent(str); - }; - }); diff --git a/src/legacy/ui/public/url/__tests__/url.js b/src/legacy/ui/public/url/__tests__/url.js index 52af742492aed..122c17428f945 100644 --- a/src/legacy/ui/public/url/__tests__/url.js +++ b/src/legacy/ui/public/url/__tests__/url.js @@ -210,7 +210,7 @@ describe('kbnUrl', function () { const wrappers = [ ['{{', '}}'], ['{{ ', ' }}'], ['{{', ' }}'], ['{{ ', '}}'], ['{{ ', ' }}']]; // make sure filters are evaluated via angular expressions const objIndex = 4; // used to case one replace as an object - const filters = ['', 'uppercase', '', 'uppercase', 'rison']; + const filters = ['', 'uppercase', '', 'uppercase', '']; // the words (template keys) used must all be unique const words = _.uniq(faker.Lorem.words(10)).slice(0, urlParts.length).map(function (word, i) { diff --git a/src/legacy/ui/public/url/url.js b/src/legacy/ui/public/url/url.js index dbb454b80dbc6..c2de5a9bd3eaf 100644 --- a/src/legacy/ui/public/url/url.js +++ b/src/legacy/ui/public/url/url.js @@ -18,8 +18,6 @@ */ import _ from 'lodash'; -import '../filters/uriescape'; -import '../filters/rison'; import { uiModules } from '../modules'; import { AppStateProvider } from '../state_management/app_state'; @@ -121,12 +119,7 @@ export function KbnUrlProvider($injector, $location, $rootScope, $parse, Private })); } - // append uriescape filter if not included - if (expr.indexOf('uriescape') === -1) { - expr += '|uriescape'; - } - - return $parse(expr)(paramObj); + return encodeURIComponent($parse(expr)(paramObj)); }); }; diff --git a/x-pack/plugins/ml/public/components/field_data_card/content_types/card_date.html b/x-pack/plugins/ml/public/components/field_data_card/content_types/card_date.html index c6be130f4ea01..6841252132cf8 100644 --- a/x-pack/plugins/ml/public/components/field_data_card/content_types/card_date.html +++ b/x-pack/plugins/ml/public/components/field_data_card/content_types/card_date.html @@ -15,7 +15,7 @@ i18n-id="xpack.ml.fieldDataCard.cardDate.earliestLabel" i18n-default-message="earliest {earliestCardStats}" i18n-values="{ - earliestCardStats: (card.stats.earliest | moment), + earliestCardStats: (toMoment(card.stats.earliest)), }" >
diff --git a/x-pack/plugins/ml/public/components/field_data_card/field_data_card_directive.js b/x-pack/plugins/ml/public/components/field_data_card/field_data_card_directive.js index 269ec52955442..ff3a7b6238ae1 100644 --- a/x-pack/plugins/ml/public/components/field_data_card/field_data_card_directive.js +++ b/x-pack/plugins/ml/public/components/field_data_card/field_data_card_directive.js @@ -12,8 +12,8 @@ import _ from 'lodash'; import $ from 'jquery'; +import moment from 'moment'; import chrome from 'ui/chrome'; -import 'ui/filters/moment'; import template from './field_data_card.html'; import { ML_JOB_FIELD_TYPES } from 'plugins/ml/../common/constants/field_types'; @@ -22,7 +22,7 @@ import { mlEscape } from 'plugins/ml/util/string_utils'; import { uiModules } from 'ui/modules'; const module = uiModules.get('apps/ml'); -module.directive('mlFieldDataCard', function () { +module.directive('mlFieldDataCard', function (config) { function link(scope, element) { scope.ML_JOB_FIELD_TYPES = ML_JOB_FIELD_TYPES; @@ -55,6 +55,10 @@ module.directive('mlFieldDataCard', function () { }, true); } + scope.toMoment = function (datetime) { + return moment(datetime).format(config.get('dateFormat')); + }; + scope.getCardUrl = function () { const urlBasePath = chrome.getBasePath(); const baseCardPath = `${urlBasePath}/plugins/ml/components/field_data_card/content_types`; diff --git a/x-pack/plugins/watcher/public/components/threshold_preview_chart/threshold_preview_chart.js b/x-pack/plugins/watcher/public/components/threshold_preview_chart/threshold_preview_chart.js index 9d598dc14e3c4..5823fab842730 100644 --- a/x-pack/plugins/watcher/public/components/threshold_preview_chart/threshold_preview_chart.js +++ b/x-pack/plugins/watcher/public/components/threshold_preview_chart/threshold_preview_chart.js @@ -5,7 +5,7 @@ */ import moment from 'moment'; -import 'ui/filters/moment'; +import '../../directives/moment'; import { isNumber, forEach, merge } from 'lodash'; import { uiModules } from 'ui/modules'; import { TimeBuckets } from 'ui/time_buckets'; diff --git a/x-pack/plugins/watcher/public/directives/moment.js b/x-pack/plugins/watcher/public/directives/moment.js new file mode 100644 index 0000000000000..e6c0aa27b6914 --- /dev/null +++ b/x-pack/plugins/watcher/public/directives/moment.js @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import moment from 'moment'; +import _ from 'lodash'; +import { uiModules } from 'ui/modules'; + +uiModules + .get('xpack/watcher') + .filter('moment', function (config) { + return function (datetime) { + const format = config.get('dateFormat'); + if (moment.isMoment(datetime)) return datetime.format(format); + if (_.isDate(datetime)) return moment(datetime).format(format); + return datetime; + }; + }); diff --git a/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history/watch_history.js b/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history/watch_history.js index 1dcf96f86f8de..381ee9483bb44 100644 --- a/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history/watch_history.js +++ b/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history/watch_history.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import 'ui/filters/moment'; +import '../../../../directives/moment'; import { uiModules } from 'ui/modules'; import 'ui/pager_control'; import 'ui/pager'; diff --git a/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history_table/watch_history_table.js b/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history_table/watch_history_table.js index 8a19931113afd..53851902e7292 100644 --- a/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history_table/watch_history_table.js +++ b/x-pack/plugins/watcher/public/sections/watch_detail/components/watch_history_table/watch_history_table.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import 'ui/filters/moment'; +import '../../../../directives/moment'; import { uiModules } from 'ui/modules'; import template from './watch_history_table.html'; import 'plugins/watcher/components/watch_state_icon';