From b3643548c7be18038efa6ff91e5ca5c16adccbab Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Fri, 13 Sep 2019 12:05:06 -0500 Subject: [PATCH] Add angular demo plugin --- src/plugins/angular_demo/kibana.json | 6 ++ .../angular_demo/public/application.js | 91 +++++++++++++++++++ src/plugins/angular_demo/public/index.js | 22 +++++ src/plugins/angular_demo/public/plugin.js | 36 ++++++++ 4 files changed, 155 insertions(+) create mode 100644 src/plugins/angular_demo/kibana.json create mode 100644 src/plugins/angular_demo/public/application.js create mode 100644 src/plugins/angular_demo/public/index.js create mode 100644 src/plugins/angular_demo/public/plugin.js diff --git a/src/plugins/angular_demo/kibana.json b/src/plugins/angular_demo/kibana.json new file mode 100644 index 00000000000000..46eaed6baff887 --- /dev/null +++ b/src/plugins/angular_demo/kibana.json @@ -0,0 +1,6 @@ +{ + "id": "angularDemo", + "version": "0.0.1", + "kibanaVersion": "kibana", + "ui": true +} diff --git a/src/plugins/angular_demo/public/application.js b/src/plugins/angular_demo/public/application.js new file mode 100644 index 00000000000000..1c67a9cd9bffc4 --- /dev/null +++ b/src/plugins/angular_demo/public/application.js @@ -0,0 +1,91 @@ +/* + * 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 angular from 'angular'; +import 'angular-route/angular-route'; + +const chapterTemplate = ` +controller: {{name}}
+Book Id: {{params.bookId}}
+Chapter Id: {{params.chapterId}} +`; + +const bookTemplate = ` +controller: {{name}}
+Book Id: {{params.bookId}}
+`; + +const mainTemplate = (basePath) => ` +
+ + + Choose: + Moby | + Moby: Ch1 | + Gatsby | + Gatsby: Ch4 | + Scarlet Letter
+ +
+ +
+ +
$location.path() = {{$location.path()}}
+
$route.current.templateUrl = {{$route.current.templateUrl}}
+
$route.current.params = {{$route.current.params}}
+
$route.current.scope.name = {{$route.current.scope.name}}
+
$routeParams = {{$routeParams}}
+
+`; + +export const renderApp = (context, { element, appBasePath }) => { + angular.module('ngRouteExample', ['ngRoute']) + .controller('MainController', function ($scope, $route, $routeParams, $location) { + $scope.$route = $route; + $scope.$location = $location; + $scope.$routeParams = $routeParams; + }) + .controller('BookController', function ($scope, $routeParams) { + $scope.name = 'BookController'; + $scope.params = $routeParams; + }) + .controller('ChapterController', function ($scope, $routeParams) { + $scope.name = 'ChapterController'; + $scope.params = $routeParams; + }) + .config(function ($routeProvider, $locationProvider) { + $routeProvider + .when('/Book/:bookId', { + template: bookTemplate, + controller: 'BookController' + }) + .when('/Book/:bookId/ch/:chapterId', { + template: chapterTemplate, + controller: 'ChapterController' + }); + + $locationProvider.html5Mode(false); + $locationProvider.hashPrefix(''); + }); + + // eslint-disable-next-line + element.innerHTML = mainTemplate(appBasePath); + const $injector = angular.bootstrap(element, ['ngRouteExample']); + return () => $injector.get('$rootScope').$destroy(); +}; diff --git a/src/plugins/angular_demo/public/index.js b/src/plugins/angular_demo/public/index.js new file mode 100644 index 00000000000000..7c81609b982b70 --- /dev/null +++ b/src/plugins/angular_demo/public/index.js @@ -0,0 +1,22 @@ +/* + * 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 { AngularDemoPlugin } from './plugin'; + +export const plugin = (core) => new AngularDemoPlugin(core); diff --git a/src/plugins/angular_demo/public/plugin.js b/src/plugins/angular_demo/public/plugin.js new file mode 100644 index 00000000000000..c29a17c4d56ec9 --- /dev/null +++ b/src/plugins/angular_demo/public/plugin.js @@ -0,0 +1,36 @@ +/* + * 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. + */ + + +export class AngularDemoPlugin { + setup(core) { + core.application.register({ + id: 'angularDemo', + title: 'Angular Demo', + async mount(context, params) { + const { renderApp } = await import('./application'); + return renderApp(context, params); + } + }); + } + + start() {} + + stop() {} +}