From 27abf3ec1dfde6e2a93b215ca092066683a76f5e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 9 Oct 2017 21:55:45 -0600 Subject: [PATCH] Support the edit widget button Adds #120 --- .../custom_widget-config.component.ts | 13 ++++++ web/app/integration/integration.component.ts | 7 +-- web/app/riot/riot.component.ts | 43 ++++++++++++++++++- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/web/app/configs/widget/custom_widget/custom_widget-config.component.ts b/web/app/configs/widget/custom_widget/custom_widget-config.component.ts index 1410b2b..3c9d5ee 100644 --- a/web/app/configs/widget/custom_widget/custom_widget-config.component.ts +++ b/web/app/configs/widget/custom_widget/custom_widget-config.component.ts @@ -22,6 +22,7 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda private toggledWidgets: string[] = []; private wrapperUrl = ""; + private requestedEditId: string = null; constructor(public dialog: DialogRef, private toaster: ToasterService, @@ -29,6 +30,8 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda window: Window) { super(scalarService, dialog.context.roomId); + this.requestedEditId = dialog.context.integrationId; + this.getWidgetsOfType(WIDGET_DIM_CUSTOM, WIDGET_SCALAR_CUSTOM).then(widgets => { this.widgets = widgets; this.isLoading = false; @@ -38,6 +41,16 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda for (let widget of this.widgets) { widget.url = this.getWrappedUrl(widget.url); } + + // See if we should request editing a particular widget + if (this.requestedEditId) { + for (let widget of this.widgets) { + if (widget.id === this.requestedEditId) { + console.log("Requesting edit for " + widget.id); + this.editWidget(widget); + } + } + } }); this.wrapperUrl = window.location.origin + "/widgets/generic?url="; diff --git a/web/app/integration/integration.component.ts b/web/app/integration/integration.component.ts index 7438a8a..3119e07 100644 --- a/web/app/integration/integration.component.ts +++ b/web/app/integration/integration.component.ts @@ -8,6 +8,7 @@ export class ConfigModalContext extends BSModalContext { public integration: Integration; public roomId: string; public scalarToken: string; + public integrationId: string; } @Component({ @@ -22,8 +23,7 @@ export class IntegrationComponent { @Input() scalarToken: string; @Output() updated: EventEmitter = new EventEmitter(); - constructor(/*overlay: Overlay, vcRef: ViewContainerRef, */public modal: Modal) { - // overlay.defaultViewContainer = vcRef; + constructor(public modal: Modal) { } public update(): void { @@ -31,12 +31,13 @@ export class IntegrationComponent { this.updated.emit(); } - public configureIntegration(): void { + public configureIntegration(integrationId:string=null): void { this.modal.open(IntegrationService.getConfigComponent(this.integration), overlayConfigFactory({ integration: this.integration, roomId: this.roomId, scalarToken: this.scalarToken, isBlocking: false, + integrationId: integrationId, size: "lg" }, BSModalContext)); } diff --git a/web/app/riot/riot.component.ts b/web/app/riot/riot.component.ts index e7f6efe..8fc17a2 100644 --- a/web/app/riot/riot.component.ts +++ b/web/app/riot/riot.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, ViewChildren } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ApiService } from "../shared/api.service"; import { ScalarService } from "../shared/scalar.service"; @@ -6,6 +6,8 @@ import { ToasterService } from "angular2-toaster"; import { Integration } from "../shared/models/integration"; import { IntegrationService } from "../shared/integration.service"; import * as _ from "lodash"; +import { WIDGET_DIM_CUSTOM } from "../shared/models/widget"; +import { IntegrationComponent } from "../integration/integration.component"; @Component({ selector: "my-riot", @@ -13,6 +15,7 @@ import * as _ from "lodash"; styleUrls: ["./riot.component.scss"], }) export class RiotComponent { + @ViewChildren(IntegrationComponent) integrationComponents: Array; public error: string; public integrations: Integration[] = []; @@ -20,11 +23,18 @@ export class RiotComponent { public roomId: string; public scalarToken: string; + private requestedScreen: string = null; + private requestedIntegration: string = null; + constructor(private activatedRoute: ActivatedRoute, private api: ApiService, private scalar: ScalarService, private toaster: ToasterService) { let params: any = this.activatedRoute.snapshot.queryParams; + + this.requestedScreen = params.screen; + this.requestedIntegration = params.integ_id; + if (!params.scalar_token || !params.room_id) this.error = "Missing scalar token or room ID"; else { this.roomId = params.room_id; @@ -45,12 +55,41 @@ export class RiotComponent { this.integrations = _.filter(integrations, i => IntegrationService.isSupported(i)); let promises = integrations.map(b => this.updateIntegrationState(b)); return Promise.all(promises); - }).then(() => this.loading = false).catch(err => { + }).then(() => { + this.loading = false; + + // HACK: We wait for the digest cycle so we actually have components to look at + setTimeout(() => this.tryOpenConfigScreen(), 20); + }).catch(err => { this.error = "Unable to communicate with Dimension"; console.error(err); }); } + private tryOpenConfigScreen() { + let type = null; + let integrationType = null; + if (!this.requestedScreen) return; + if (this.requestedScreen === "type_" + WIDGET_DIM_CUSTOM) { + type = "widget"; + integrationType = "customwidget"; + } else { + console.log("Unknown screen requested: " + this.requestedScreen); + } + + let opened = false; + this.integrationComponents.forEach(component => { + if (opened) return; + if (component.integration.type !== type || component.integration.integrationType !== integrationType) return; + console.log("Configuring integration " + this.requestedIntegration + " type=" + type + " integrationType=" + integrationType); + component.configureIntegration(this.requestedIntegration); + opened = true; + }); + if (!opened) { + console.log("Failed to find integration component for type=" + type + " integrationType=" + integrationType); + } + } + private updateIntegrationState(integration: Integration) { integration.hasConfig = IntegrationService.hasConfig(integration);