Support the edit widget button

Adds #120
This commit is contained in:
Travis Ralston 2017-10-09 21:55:45 -06:00
parent aecb1e33d4
commit 27abf3ec1d
3 changed files with 58 additions and 5 deletions

View file

@ -22,6 +22,7 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda
private toggledWidgets: string[] = [];
private wrapperUrl = "";
private requestedEditId: string = null;
constructor(public dialog: DialogRef<ConfigModalContext>,
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=";

View file

@ -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<any> = 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));
}

View file

@ -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<IntegrationComponent>;
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);