1 import {Component, Inject, Input, Output, OnInit, EventEmitter, ViewChild, ElementRef} 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 this.pluginUrl = this.plugin.pluginSourceUrl;
29 this.isClosed = false;
31 if (this.queryParams && !_.isEmpty(this.queryParams)) {
32 _.forOwn(this.queryParams, (value, key) => {
33 this.urlSearchParams.set(key, value);
36 this.pluginUrl += '?';
37 this.pluginUrl += this.urlSearchParams.toString();
40 this.eventBusService.on((eventData) => {
41 if (eventData.originId === this.plugin.pluginId) {
42 if (eventData.type == "READY") {
43 this.onLoadingDone.emit();
48 // Listening to the stateChangeStart event in order to notify the plugin about it being closed
49 // before moving to a new state
50 this.$scope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
51 if (fromState.name !== toState.name) {
53 event.preventDefault();
55 this.eventBusService.notify("WINDOW_OUT");
60 this.$state.go(toState.name, toParams);