Skip to content

Commit

Permalink
Remove last angular bindings to gis map saved object loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Apr 13, 2020
1 parent 9397439 commit ca40d71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { createSavedGisMapClass } from './saved_gis_map';
import { uiModules } from 'ui/modules';
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
import {
getCoreChrome,
Expand All @@ -15,7 +15,7 @@ import {
getData,
} from '../../kibana_services';

export function getMapsSavedObjectLoader() {
export const getMapsSavedObjectLoader = _.once(function() {
const services = {
savedObjectsClient: getSavedObjectsClient(),
indexPatterns: getIndexPatternService(),
Expand All @@ -26,11 +26,4 @@ export function getMapsSavedObjectLoader() {
const SavedGisMap = createSavedGisMapClass(services);

return new SavedObjectLoader(SavedGisMap, getSavedObjectsClient(), getCoreChrome());
}

const module = uiModules.get('app/maps');

// This is the only thing that gets injected into controllers
module.service('gisMapSavedObjectLoader', function() {
return getMapsSavedObjectLoader();
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { npSetup, npStart } from 'ui/new_platform';
import { IIndexPattern } from 'src/plugins/data/public';
import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader';
import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable';
import { getIndexPatternService, getHttp, getMapsCapabilties } from '../kibana_services';
import { getIndexPatternService, getHttp, getMapsCapabilities } from '../kibana_services';
import {
EmbeddableFactoryDefinition,
IContainer,
Expand Down Expand Up @@ -49,7 +49,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
}

async isEditable() {
return getMapsCapabilties().save as boolean;
return getMapsCapabilities().save as boolean;
}

// Not supported yet for maps types.
Expand Down
15 changes: 10 additions & 5 deletions x-pack/legacy/plugins/maps/public/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import routes from 'ui/routes';
import listingTemplate from './angular/listing_ng_wrapper.html';
import mapTemplate from './angular/map.html';
import { getSavedObjectsClient, getCoreChrome, getMapsCapabilities } from './kibana_services';
import { getMapsSavedObjectLoader } from './angular/services/gis_map_saved_object_loader';

routes.enable();

routes
.defaults(/.*/, {
badge: uiCapabilities => {
if (uiCapabilities.maps.save) {
badge: () => {
if (getMapsCapabilities().save) {
return undefined;
}

Expand All @@ -32,7 +33,8 @@ routes
})
.when('/', {
template: listingTemplate,
controller($scope, gisMapSavedObjectLoader, config) {
controller($scope, config) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
$scope.listingLimit = config.get('savedObjects:listingLimit');
$scope.find = search => {
return gisMapSavedObjectLoader.find(search, $scope.listingLimit);
Expand Down Expand Up @@ -60,7 +62,9 @@ routes
template: mapTemplate,
controller: 'GisMapController',
resolve: {
map: function(gisMapSavedObjectLoader, redirectWhenMissing) {
map: function(redirectWhenMissing, $scope, config) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
$scope.listingLimit = config.get('savedObjects:listingLimit');
return gisMapSavedObjectLoader.get().catch(
redirectWhenMissing({
map: '/',
Expand All @@ -73,7 +77,8 @@ routes
template: mapTemplate,
controller: 'GisMapController',
resolve: {
map: function(gisMapSavedObjectLoader, redirectWhenMissing, $route) {
map: function(redirectWhenMissing, $route) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
const id = $route.current.params.id;
return gisMapSavedObjectLoader
.get(id)
Expand Down

0 comments on commit ca40d71

Please sign in to comment.