From 984d90094c0e1b262d38d14791487b9e448c096f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 23 Jul 2018 13:56:24 +0200 Subject: [PATCH] Allow bootstrapping in legacy context --- .../legacy/typings/open-project-legacy.typings.d.ts | 1 + .../components/ckeditor/ckeditor-setup.service.ts | 1 + .../ckeditor/op-ckeditor-form.component.ts | 9 ++++++--- frontend/src/app/modules/plugins/plugin-context.ts | 12 ++++++++++-- spec/support/components/wysiwyg/wysiwyg_editor.rb | 6 +++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend/legacy/typings/open-project-legacy.typings.d.ts b/frontend/legacy/typings/open-project-legacy.typings.d.ts index a8422bd2dd..0cc864e9da 100644 --- a/frontend/legacy/typings/open-project-legacy.typings.d.ts +++ b/frontend/legacy/typings/open-project-legacy.typings.d.ts @@ -39,6 +39,7 @@ import {GlobalI18n} from "../../src/app/modules/common/i18n/i18n.service"; export interface IPluginContext { classes:any; services:any; + bootstrap(element:HTMLElement):void; } declare global { diff --git a/frontend/src/app/components/ckeditor/ckeditor-setup.service.ts b/frontend/src/app/components/ckeditor/ckeditor-setup.service.ts index b4cd53acb8..c9ebafb684 100644 --- a/frontend/src/app/components/ckeditor/ckeditor-setup.service.ts +++ b/frontend/src/app/components/ckeditor/ckeditor-setup.service.ts @@ -5,6 +5,7 @@ import {Injectable} from "@angular/core"; export interface ICKEditorInstance { getData():string; setData(content:string):void; + model:any; editing:any; config:any; } diff --git a/frontend/src/app/components/ckeditor/op-ckeditor-form.component.ts b/frontend/src/app/components/ckeditor/op-ckeditor-form.component.ts index fc2984a8a7..c3f2ba7598 100644 --- a/frontend/src/app/components/ckeditor/op-ckeditor-form.component.ts +++ b/frontend/src/app/components/ckeditor/op-ckeditor-form.component.ts @@ -66,7 +66,6 @@ export class OpCkeditorFormComponent implements OnInit { protected halResourceService:HalResourceService, protected ckEditorSetup:CKEditorSetupService, protected ConfigurationService:ConfigurationService) { - } public ngOnInit() { @@ -110,7 +109,7 @@ export class OpCkeditorFormComponent implements OnInit { } // Listen for form submission to set textarea content - this.formElement.on('submit.ckeditor', () => { + this.formElement.on('submit.ckeditor change.ckeditor', () => { const value = this.ckeditor.getData(); this.wrappedTextArea.val(value); @@ -138,4 +137,8 @@ export class OpCkeditorFormComponent implements OnInit { } } -DynamicBootstrapper.register({ selector: 'op-ckeditor-form', cls: OpCkeditorFormComponent }); +DynamicBootstrapper.register({ + selector: 'op-ckeditor-form', + cls: OpCkeditorFormComponent, + embeddable: true +}); diff --git a/frontend/src/app/modules/plugins/plugin-context.ts b/frontend/src/app/modules/plugins/plugin-context.ts index 928f7a9eac..304e2ee47f 100644 --- a/frontend/src/app/modules/plugins/plugin-context.ts +++ b/frontend/src/app/modules/plugins/plugin-context.ts @@ -1,4 +1,4 @@ -import {Injector} from "@angular/core"; +import {ApplicationRef, Injector} from "@angular/core"; import {HookService} from "core-app/modules/plugins/hook-service"; import {NotificationsService} from "core-app/modules/common/notifications/notifications.service"; import {ConfirmDialogService} from "core-components/modals/confirm-dialog/confirm-dialog.service"; @@ -22,6 +22,7 @@ import {EditorMacrosService} from "core-components/modals/editor/editor-macros.s import {HTMLSanitizeService} from "../common/html-sanitize/html-sanitize.service"; import {PathHelperService} from "../common/path-helper/path-helper.service"; import {CKEditorPreviewService} from "core-components/ckeditor/ckeditor-preview.service"; +import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper"; /** * Plugin context bridge for plugins outside the CLI compiler context @@ -53,7 +54,7 @@ export class OpenProjectPluginContext { macros: this.injector.get(EditorMacrosService), htmlSanitizeService: this.injector.get(HTMLSanitizeService), ckEditorPreview: this.injector.get(CKEditorPreviewService), - pathHelperService: this.injector.get(PathHelperService) + pathHelperService: this.injector.get(PathHelperService), }; // Random collection of classes needed outside of angular @@ -78,4 +79,11 @@ export class OpenProjectPluginContext { this.hooks[hook] = (callback:Function) => this.services.hooks.register(hook, callback); }); } + + public bootstrap(element:HTMLElement) { + DynamicBootstrapper.bootstrapOptionalEmbeddable( + this.injector.get(ApplicationRef), + element + ) + } } diff --git a/spec/support/components/wysiwyg/wysiwyg_editor.rb b/spec/support/components/wysiwyg/wysiwyg_editor.rb index 9a11c7f306..865ca936e3 100644 --- a/spec/support/components/wysiwyg/wysiwyg_editor.rb +++ b/spec/support/components/wysiwyg/wysiwyg_editor.rb @@ -24,7 +24,7 @@ module Components end def expect_value(value) - expect(input_element.text).to eq(value) + expect(editor_element.text).to eq(value) end def within_enabled_preview @@ -43,10 +43,10 @@ module Components def click_and_type_slowly(text) sleep 0.5 - input_element.click + editor_element.click sleep 0.5 - input_element.send_keys text + editor_element.send_keys text sleep 0.5 end