1 import {Component, Inject, Input, Output, OnInit, EventEmitter} from "@angular/core";
2 import {URLSearchParams} from '@angular/http';
3 import {Plugin} from "app/models";
4 import {EventBusService} from "../../../services/event-bus.service";
7 selector: 'plugin-frame',
8 templateUrl: './plugin-frame.component.html',
9 styleUrls: ['plugin-frame.component.less']
12 export class PluginFrameComponent implements OnInit {
14 @Input() plugin: Plugin;
15 @Input() queryParams: Object;
16 @Output() onLoadingDone: EventEmitter<void> = new EventEmitter<void>();
18 private urlSearchParams: URLSearchParams;
19 private isClosed: boolean;
21 constructor(private eventBusService: EventBusService,
22 @Inject('$scope') private $scope: ng.IScope,
23 @Inject('$state') private $state: ng.ui.IStateService) {
24 this.urlSearchParams = new URLSearchParams();
28 if (this.plugin.isOnline) {
33 private initPlugin() {
34 this.pluginUrl = this.plugin.pluginSourceUrl;
35 this.isClosed = false;
37 if (this.queryParams && !_.isEmpty(this.queryParams)) {
38 _.forOwn(this.queryParams, (value, key) => {
39 this.urlSearchParams.set(key, value);
42 this.pluginUrl += '?';
43 this.pluginUrl += this.urlSearchParams.toString();
46 let readyEvent = (eventData) => {
47 if (eventData.originId === this.plugin.pluginId) {
48 if (eventData.type == "READY") {
49 this.onLoadingDone.emit();
50 this.eventBusService.off(readyEvent)
55 this.eventBusService.on(readyEvent);
57 // Listening to the stateChangeStart event in order to notify the plugin about it being closed
58 // before moving to a new state
59 this.$scope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
60 if ((fromState.name !== toState.name) || (fromState.name === toState.name) && (toParams.path !== fromParams.path)) {
61 if(this.eventBusService.NoWindowOutEvents.indexOf(this.eventBusService.lastEventNotified) == -1) {
63 event.preventDefault();
65 this.eventBusService.notify("WINDOW_OUT").subscribe(() => {
67 this.eventBusService.unregister(this.plugin.pluginId);
69 this.$state.go(toState.name, toParams);
74 this.eventBusService.unregister(this.plugin.pluginId);