diff --git a/src/legacy/core_plugins/timelion/public/app.js b/src/legacy/core_plugins/timelion/public/app.js index 82f6d56f8f22aa..bff847becb7a82 100644 --- a/src/legacy/core_plugins/timelion/public/app.js +++ b/src/legacy/core_plugins/timelion/public/app.js @@ -40,6 +40,9 @@ import 'ui/directives/saved_object_finder'; import 'ui/directives/listen'; import 'ui/kbn_top_nav'; import 'ui/saved_objects/ui/saved_object_save_as_checkbox'; +import './services/saved_sheets'; +import './services/_saved_sheet'; +import './services/saved_sheet_register'; import rootTemplate from 'plugins/timelion/index.html'; @@ -57,13 +60,8 @@ document.title = 'Timelion - Kibana'; const app = require('ui/modules').get('apps/timelion', []); -require('plugins/timelion/services/saved_sheets'); -require('plugins/timelion/services/_saved_sheet'); - require('./vis'); -SavedObjectRegistryProvider.register(require('plugins/timelion/services/saved_sheet_register')); - require('ui/routes').enable(); require('ui/routes').when('/:id?', { diff --git a/src/legacy/core_plugins/timelion/public/services/_saved_sheet.js b/src/legacy/core_plugins/timelion/public/services/_saved_sheet.js deleted file mode 100644 index 8875a84d4d3a1d..00000000000000 --- a/src/legacy/core_plugins/timelion/public/services/_saved_sheet.js +++ /dev/null @@ -1,82 +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 'ui/modules'; -import { createLegacyClass } from 'ui/utils/legacy_class'; -import { SavedObjectProvider } from 'ui/saved_objects/saved_object'; -const module = uiModules.get('app/timelion'); - -// Used only by the savedSheets service, usually no reason to change this -module.factory('SavedSheet', function(Private, config) { - // SavedSheet constructor. Usually you'd interact with an instance of this. - // ID is option, without it one will be generated on save. - const SavedObject = Private(SavedObjectProvider); - createLegacyClass(SavedSheet).inherits(SavedObject); - function SavedSheet(id) { - // Gives our SavedSheet the properties of a SavedObject - SavedObject.call(this, { - type: SavedSheet.type, - mapping: SavedSheet.mapping, - - // if this is null/undefined then the SavedObject will be assigned the defaults - id: id, - - // default values that will get assigned if the doc is new - defaults: { - title: 'New TimeLion Sheet', - hits: 0, - description: '', - timelion_sheet: ['.es(*)'], - timelion_interval: 'auto', - timelion_chart_height: 275, - timelion_columns: config.get('timelion:default_columns') || 2, - timelion_rows: config.get('timelion:default_rows') || 2, - version: 1, - }, - }); - - this.showInRecentlyAccessed = true; - } - - // save these objects with the 'sheet' type - SavedSheet.type = 'timelion-sheet'; - - // if type:sheet has no mapping, we push this mapping into ES - SavedSheet.mapping = { - title: 'text', - hits: 'integer', - description: 'text', - timelion_sheet: 'text', - timelion_interval: 'keyword', - timelion_other_interval: 'keyword', - timelion_chart_height: 'integer', - timelion_columns: 'integer', - timelion_rows: 'integer', - version: 'integer', - }; - - // Order these fields to the top, the rest are alphabetical - SavedSheet.fieldOrder = ['title', 'description']; - - SavedSheet.prototype.getFullPath = function() { - return `/app/timelion#/${this.id}`; - }; - - return SavedSheet; -}); diff --git a/src/legacy/core_plugins/timelion/public/services/_saved_sheet.ts b/src/legacy/core_plugins/timelion/public/services/_saved_sheet.ts new file mode 100644 index 00000000000000..1e956cbd3e5ac9 --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/services/_saved_sheet.ts @@ -0,0 +1,79 @@ +/* + * 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 { createSavedObjectClass } from 'ui/saved_objects/saved_object'; +import { SavedObjectKibanaServices } from 'ui/saved_objects/types'; +import { IUiSettingsClient } from 'kibana/public'; + +// Used only by the savedSheets service, usually no reason to change this +export function createSavedSheetClass( + services: SavedObjectKibanaServices, + config: IUiSettingsClient +) { + const SavedObjectClass = createSavedObjectClass(services); + + class SavedSheet extends SavedObjectClass { + static type = 'timelion-sheet'; + + // if type:sheet has no mapping, we push this mapping into ES + static mapping = { + title: 'text', + hits: 'integer', + description: 'text', + timelion_sheet: 'text', + timelion_interval: 'keyword', + timelion_other_interval: 'keyword', + timelion_chart_height: 'integer', + timelion_columns: 'integer', + timelion_rows: 'integer', + version: 'integer', + }; + + // Order these fields to the top, the rest are alphabetical + static fieldOrder = ['title', 'description']; + // SavedSheet constructor. Usually you'd interact with an instance of this. + // ID is option, without it one will be generated on save. + constructor(id: string) { + super({ + type: SavedSheet.type, + mapping: SavedSheet.mapping, + + // if this is null/undefined then the SavedObject will be assigned the defaults + id, + + // default values that will get assigned if the doc is new + defaults: { + title: 'New TimeLion Sheet', + hits: 0, + description: '', + timelion_sheet: ['.es(*)'], + timelion_interval: 'auto', + timelion_chart_height: 275, + timelion_columns: config.get('timelion:default_columns') || 2, + timelion_rows: config.get('timelion:default_rows') || 2, + version: 1, + }, + }); + this.showInRecentlyAccessed = true; + this.getFullPath = () => `/app/timelion#/${this.id}`; + } + } + + return SavedSheet; +} diff --git a/src/legacy/core_plugins/timelion/public/services/saved_sheet_register.js b/src/legacy/core_plugins/timelion/public/services/saved_sheet_register.ts similarity index 84% rename from src/legacy/core_plugins/timelion/public/services/saved_sheet_register.js rename to src/legacy/core_plugins/timelion/public/services/saved_sheet_register.ts index 0353a4d742dd37..6bfbacb95b62e9 100644 --- a/src/legacy/core_plugins/timelion/public/services/saved_sheet_register.js +++ b/src/legacy/core_plugins/timelion/public/services/saved_sheet_register.ts @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ - +import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry'; import './saved_sheets'; -export default function savedSearchObjectFn(savedSheets) { +SavedObjectRegistryProvider.register((savedSheets: any) => { return savedSheets; -} +}); diff --git a/src/legacy/core_plugins/timelion/public/services/saved_sheets.js b/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts similarity index 71% rename from src/legacy/core_plugins/timelion/public/services/saved_sheets.js rename to src/legacy/core_plugins/timelion/public/services/saved_sheets.ts index 064b59a0d45d9c..d851b5a8636581 100644 --- a/src/legacy/core_plugins/timelion/public/services/saved_sheets.js +++ b/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts @@ -16,12 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - -import { SavedObjectLoader, SavedObjectsClientProvider } from 'ui/saved_objects'; +import { npStart } from 'ui/new_platform'; +import { SavedObjectLoader } from 'ui/saved_objects'; +// @ts-ignore import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry'; +// @ts-ignore import { uiModules } from 'ui/modules'; -import './_saved_sheet.js'; -import { npStart } from '../../../../ui/public/new_platform'; +import { createSavedSheetClass } from './_saved_sheet'; const module = uiModules.get('app/sheet'); @@ -33,17 +34,23 @@ savedObjectManagementRegistry.register({ }); // This is the only thing that gets injected into controllers -module.service('savedSheets', function(Private, SavedSheet, kbnUrl) { - const savedObjectClient = Private(SavedObjectsClientProvider); +module.service('savedSheets', function() { + const savedObjectsClient = npStart.core.savedObjects.client; + const services = { + savedObjectsClient, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, + }; + + const SavedSheet = createSavedSheetClass(services, npStart.core.uiSettings); + const savedSheetLoader = new SavedObjectLoader( SavedSheet, - savedObjectClient, + savedObjectsClient, npStart.core.chrome ); - savedSheetLoader.urlFor = function(id) { - return kbnUrl.eval('#/{{id}}', { id: id }); - }; - + savedSheetLoader.urlFor = id => `#/${encodeURIComponent(id)}`; // Customize loader properties since adding an 's' on type doesn't work for type 'timelion-sheet'. savedSheetLoader.loaderProperties = { name: 'timelion-sheet',