diff --git a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js index 0eba30e0c4e9b..bd496f44aa8ac 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import './saved_gis_map'; +import { createSavedGisMapClass } from './saved_gis_map'; import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from 'ui/saved_objects'; import { npStart } from '../../../../../../../src/legacy/ui/public/new_platform'; @@ -12,6 +12,15 @@ import { npStart } from '../../../../../../../src/legacy/ui/public/new_platform' const module = uiModules.get('app/maps'); // This is the only thing that gets injected into controllers -module.service('gisMapSavedObjectLoader', function(SavedGisMap) { +module.service('gisMapSavedObjectLoader', function() { + const savedObjectsClient = npStart.core.savedObjects.client; + const services = { + savedObjectsClient, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, + }; + const SavedGisMap = createSavedGisMapClass(services); + return new SavedObjectLoader(SavedGisMap, npStart.core.savedObjects.client, npStart.core.chrome); }); diff --git a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js index b846bb5b77543..035ae4886920c 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js @@ -5,9 +5,7 @@ */ import _ from 'lodash'; -import { uiModules } from 'ui/modules'; -import { createLegacyClass } from 'ui/utils/legacy_class'; -import { SavedObjectProvider } from 'ui/saved_objects/saved_object'; +import { createSavedObjectClass } from 'ui/saved_objects/saved_object'; import { getTimeFilters, getMapZoom, @@ -24,95 +22,89 @@ import { copyPersistentState } from '../../reducers/util'; import { extractReferences, injectReferences } from '../../../common/migrations/references'; import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants'; -const module = uiModules.get('app/maps'); - -module.factory('SavedGisMap', function(Private) { - const SavedObject = Private(SavedObjectProvider); - createLegacyClass(SavedGisMap).inherits(SavedObject); - function SavedGisMap(id) { - SavedGisMap.Super.call(this, { - type: SavedGisMap.type, - mapping: SavedGisMap.mapping, - searchSource: SavedGisMap.searchsource, - extractReferences, - injectReferences: (savedObject, references) => { - const { attributes } = injectReferences({ - attributes: { layerListJSON: savedObject.layerListJSON }, - references, - }); - - savedObject.layerListJSON = attributes.layerListJSON; - - const indexPatternIds = references - .filter(reference => { - return reference.type === 'index-pattern'; - }) - .map(reference => { - return reference.id; - }); - savedObject.indexPatternIds = _.uniq(indexPatternIds); - }, - - // 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 Map', - description: '', +export function createSavedGisMapClass(services) { + const SavedObjectClass = createSavedObjectClass(services); + + class SavedGisMap extends SavedObjectClass { + static type = MAP_SAVED_OBJECT_TYPE; + + // Mappings are used to place object properties into saved object _source + static mapping = { + title: 'text', + description: 'text', + mapStateJSON: 'text', + layerListJSON: 'text', + uiStateJSON: 'text', + bounds: { + type: 'object', }, - }); + }; + static fieldOrder = ['title', 'description']; + static searchSource = false; + + constructor(id) { + super({ + type: SavedGisMap.type, + mapping: SavedGisMap.mapping, + searchSource: SavedGisMap.searchSource, + extractReferences, + injectReferences: (savedObject, references) => { + const { attributes } = injectReferences({ + attributes: { layerListJSON: savedObject.layerListJSON }, + references, + }); - this.showInRecentlyAccessed = true; + savedObject.layerListJSON = attributes.layerListJSON; + + const indexPatternIds = references + .filter(reference => { + return reference.type === 'index-pattern'; + }) + .map(reference => { + return reference.id; + }); + savedObject.indexPatternIds = _.uniq(indexPatternIds); + }, + + // 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 Map', + description: '', + }, + }); + this.showInRecentlyAccessed = true; + } + getFullPath() { + return `/app/maps#map/${this.id}`; + } + getLayerList() { + return this.layerListJSON ? JSON.parse(this.layerListJSON) : null; + } + + syncWithStore(state) { + const layerList = getLayerListRaw(state); + const layerListConfigOnly = copyPersistentState(layerList); + this.layerListJSON = JSON.stringify(layerListConfigOnly); + + this.mapStateJSON = JSON.stringify({ + zoom: getMapZoom(state), + center: getMapCenter(state), + timeFilters: getTimeFilters(state), + refreshConfig: getRefreshConfig(state), + query: _.omit(getQuery(state), 'queryLastTriggeredAt'), + filters: getFilters(state), + }); + + this.uiStateJSON = JSON.stringify({ + isLayerTOCOpen: getIsLayerTOCOpen(state), + openTOCDetails: getOpenTOCDetails(state), + }); + + this.bounds = convertMapExtentToPolygon(getMapExtent(state)); + } } - - SavedGisMap.type = MAP_SAVED_OBJECT_TYPE; - - // Mappings are used to place object properties into saved object _source - SavedGisMap.mapping = { - title: 'text', - description: 'text', - mapStateJSON: 'text', - layerListJSON: 'text', - uiStateJSON: 'text', - bounds: { - type: 'object', - }, - }; - - SavedGisMap.fieldOrder = ['title', 'description']; - - SavedGisMap.searchsource = false; - - SavedGisMap.prototype.getFullPath = function() { - return `/app/maps#map/${this.id}`; - }; - - SavedGisMap.prototype.getLayerList = function() { - return this.layerListJSON ? JSON.parse(this.layerListJSON) : null; - }; - - SavedGisMap.prototype.syncWithStore = function(state) { - const layerList = getLayerListRaw(state); - const layerListConfigOnly = copyPersistentState(layerList); - this.layerListJSON = JSON.stringify(layerListConfigOnly); - - this.mapStateJSON = JSON.stringify({ - zoom: getMapZoom(state), - center: getMapCenter(state), - timeFilters: getTimeFilters(state), - refreshConfig: getRefreshConfig(state), - query: _.omit(getQuery(state), 'queryLastTriggeredAt'), - filters: getFilters(state), - }); - - this.uiStateJSON = JSON.stringify({ - isLayerTOCOpen: getIsLayerTOCOpen(state), - openTOCDetails: getOpenTOCDetails(state), - }); - - this.bounds = convertMapExtentToPolygon(getMapExtent(state)); - }; - return SavedGisMap; -}); +}