Skip to content

Commit

Permalink
simplify graph shim
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 18, 2019
1 parent 4eee3cd commit 4776eb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 89 deletions.
23 changes: 14 additions & 9 deletions x-pack/legacy/plugins/graph/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,20 @@ export function initGraphApp(angularModule, deps) {
$routeProvider.when('/home', {
template: listingTemplate,
badge: getReadonlyBadge,
controller($location, $scope, Private) {
const kbnUrl = Private(KbnUrlProvider);
controller($location, $scope) {
checkLicense(kbnBaseUrl);
const services = savedObjectRegistry.byLoaderPropertiesName;
const graphService = services['Graph workspace'];

$scope.listingLimit = config.get('savedObjects:listingLimit');
$scope.create = () => {
kbnUrl.change(getNewPath());
$location.url(getNewPath());
};
$scope.find = (search) => {
return graphService.find(search, $scope.listingLimit);
};
$scope.editItem = (workspace) => {
kbnUrl.change(getEditPath(workspace));
$location.url(getEditPath(workspace));
};
$scope.getViewUrl = (workspace) => getEditUrl(addBasePath, workspace);
$scope.delete = (workspaces) => {
Expand Down Expand Up @@ -189,8 +188,7 @@ export function initGraphApp(angularModule, deps) {


//======== Controller for basic UI ==================
app.controller('graphuiPlugin', function ($scope, $route, $location, Private) {
const kbnUrl = Private(KbnUrlProvider);
app.controller('graphuiPlugin', function ($scope, $route, $location) {
checkLicense(kbnBaseUrl);

function handleError(err) {
Expand Down Expand Up @@ -304,7 +302,7 @@ export function initGraphApp(angularModule, deps) {
savePolicy: graphSavePolicy,
changeUrl: (newUrl) => {
$scope.$evalAsync(() => {
kbnUrl.change(newUrl, {});
$location.url(newUrl);
});
},
notifyAngular: () => {
Expand Down Expand Up @@ -472,8 +470,15 @@ export function initGraphApp(angularModule, deps) {
}),
run: function () {
canWipeWorkspace(function () {
kbnUrl.change('/workspace/', {});
}); },
$scope.$evalAsync(() => {
if ($location.url() === '/workspace/') {
$route.reload();
} else {
$location.url('/workspace/');
}
});
});
},
testId: 'graphNewButton',
});

Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/graph/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ async function getAngularInjectedDependencies(): Promise<LegacyAngularInjectedDe
kbnBaseUrl: injector.get('kbnBaseUrl'),
savedGraphWorkspaces: Private(SavedWorkspacesProvider),
savedObjectsClient: Private(SavedObjectsClientProvider),
canEditDrillDownUrls: chrome.getInjected('canEditDrillDownUrls'),
graphSavePolicy: chrome.getInjected('graphSavePolicy'),
};
}

Expand Down
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/graph/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export class GraphPlugin implements Plugin {
xpackInfo,
addBasePath: core.http.basePath.prepend,
getBasePath: core.http.basePath.get,
canEditDrillDownUrls: core.injectedMetadata.getInjectedVar(
'canEditDrillDownUrls'
) as boolean,
graphSavePolicy: core.injectedMetadata.getInjectedVar('graphSavePolicy') as string,
Storage,
},
this.angularDependencies!
Expand Down
84 changes: 6 additions & 78 deletions x-pack/legacy/plugins/graph/public/render_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,13 @@ import 'ace';
import 'ui/kbn_top_nav';
import { configureAppAngularModule } from 'ui/legacy_compat';
// @ts-ignore
import { GlobalStateProvider } from 'ui/state_management/global_state';
// @ts-ignore
import { StateManagementConfigProvider } from 'ui/state_management/config_provider';
// @ts-ignore
import { PrivateProvider } from 'ui/private/private';
// @ts-ignore
import { EventsProvider } from 'ui/events';
// @ts-ignore
import { PersistedState } from 'ui/persisted_state';
// @ts-ignore
import { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
// @ts-ignore
import { PromiseServiceCreator } from 'ui/promises/promises';
// @ts-ignore
import { KbnUrlProvider } from 'ui/url';

// type imports
import { IPrivate } from 'ui/private';
import { DataStart } from 'src/legacy/core_plugins/data/public';
import { AppMountContext } from 'kibana/public';
import { AngularHttpError } from 'ui/notify/lib/format_angular_http_error';
Expand All @@ -55,6 +44,8 @@ export interface GraphDependencies {
addBasePath: (url: string) => string;
getBasePath: () => string;
Storage: any;
canEditDrillDownUrls: boolean;
graphSavePolicy: string;
}

/**
Expand Down Expand Up @@ -83,14 +74,6 @@ export interface LegacyAngularInjectedDependencies {
* Private(SavedObjectsClientProvider)
*/
savedObjectsClient: any;
/**
* Injected variable
*/
canEditDrillDownUrls: string;
/**
* Injected variable
*/
graphSavePolicy: string;
}

export const renderApp = (
Expand All @@ -105,6 +88,8 @@ export const renderApp = (
addBasePath,
getBasePath,
Storage,
canEditDrillDownUrls,
graphSavePolicy,
}: GraphDependencies,
angularDeps: LegacyAngularInjectedDependencies
) => {
Expand All @@ -122,6 +107,8 @@ export const renderApp = (
getBasePath,
KbnUrlProvider,
Storage,
canEditDrillDownUrls,
graphSavePolicy,
...angularDeps,
};

Expand Down Expand Up @@ -150,81 +137,22 @@ function mountGraphApp(appBasePath: string, element: HTMLElement) {
// bootstrap angular into detached element and attach it later to
// make angular-within-angular possible
const $injector = angular.bootstrap(mountpoint, [moduleName]);
// initialize global state handler
$injector.get('globalState');
element.appendChild(mountpoint);
return $injector;
}

function createLocalAngularModule(core: AppMountContext['core']) {
createLocalI18nModule();
createLocalPrivateModule();
createLocalPromiseModule();
createLocalConfigModule(core);
createLocalKbnUrlModule();
createLocalPersistedStateModule();
createLocalTopNavModule();
createLocalGlobalStateModule();

const graphAngularModule = angular.module(moduleName, [
...thirdPartyAngularDependencies,
'graphI18n',
'graphPrivate',
'graphPersistedState',
'graphTopNav',
'graphGlobalState',
]);
return graphAngularModule;
}

function createLocalGlobalStateModule() {
angular
.module('graphGlobalState', ['graphPrivate', 'graphConfig', 'graphKbnUrl', 'graphPromise'])
.service('globalState', function(Private: any) {
return Private(GlobalStateProvider);
});
}

function createLocalPersistedStateModule() {
angular
.module('graphPersistedState', ['graphPrivate', 'graphPromise'])
.factory('PersistedState', (Private: IPrivate) => {
const Events = Private(EventsProvider);
return class AngularPersistedState extends PersistedState {
constructor(value: any, path: any) {
super(value, path, Events);
}
};
});
}

function createLocalKbnUrlModule() {
angular
.module('graphKbnUrl', ['graphPrivate', 'ngRoute'])
.service('kbnUrl', (Private: IPrivate) => Private(KbnUrlProvider));
}

function createLocalConfigModule(core: AppMountContext['core']) {
angular
.module('graphConfig', ['graphPrivate'])
.provider('stateManagementConfig', StateManagementConfigProvider)
.provider('config', () => {
return {
$get: () => ({
get: core.uiSettings.get.bind(core.uiSettings),
}),
};
});
}

function createLocalPromiseModule() {
angular.module('graphPromise', []).service('Promise', PromiseServiceCreator);
}

function createLocalPrivateModule() {
angular.module('graphPrivate', []).provider('Private', PrivateProvider);
}

function createLocalTopNavModule() {
angular
.module('graphTopNav', ['react'])
Expand Down

0 comments on commit 4776eb1

Please sign in to comment.