parent
aecb1e33d4
commit
27abf3ec1d
|
@ -22,6 +22,7 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda
|
||||||
|
|
||||||
private toggledWidgets: string[] = [];
|
private toggledWidgets: string[] = [];
|
||||||
private wrapperUrl = "";
|
private wrapperUrl = "";
|
||||||
|
private requestedEditId: string = null;
|
||||||
|
|
||||||
constructor(public dialog: DialogRef<ConfigModalContext>,
|
constructor(public dialog: DialogRef<ConfigModalContext>,
|
||||||
private toaster: ToasterService,
|
private toaster: ToasterService,
|
||||||
|
@ -29,6 +30,8 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda
|
||||||
window: Window) {
|
window: Window) {
|
||||||
super(scalarService, dialog.context.roomId);
|
super(scalarService, dialog.context.roomId);
|
||||||
|
|
||||||
|
this.requestedEditId = dialog.context.integrationId;
|
||||||
|
|
||||||
this.getWidgetsOfType(WIDGET_DIM_CUSTOM, WIDGET_SCALAR_CUSTOM).then(widgets => {
|
this.getWidgetsOfType(WIDGET_DIM_CUSTOM, WIDGET_SCALAR_CUSTOM).then(widgets => {
|
||||||
this.widgets = widgets;
|
this.widgets = widgets;
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -38,6 +41,16 @@ export class CustomWidgetConfigComponent extends WidgetComponent implements Moda
|
||||||
for (let widget of this.widgets) {
|
for (let widget of this.widgets) {
|
||||||
widget.url = this.getWrappedUrl(widget.url);
|
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=";
|
this.wrapperUrl = window.location.origin + "/widgets/generic?url=";
|
||||||
|
|
|
@ -8,6 +8,7 @@ export class ConfigModalContext extends BSModalContext {
|
||||||
public integration: Integration;
|
public integration: Integration;
|
||||||
public roomId: string;
|
public roomId: string;
|
||||||
public scalarToken: string;
|
public scalarToken: string;
|
||||||
|
public integrationId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -22,8 +23,7 @@ export class IntegrationComponent {
|
||||||
@Input() scalarToken: string;
|
@Input() scalarToken: string;
|
||||||
@Output() updated: EventEmitter<any> = new EventEmitter();
|
@Output() updated: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
constructor(/*overlay: Overlay, vcRef: ViewContainerRef, */public modal: Modal) {
|
constructor(public modal: Modal) {
|
||||||
// overlay.defaultViewContainer = vcRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(): void {
|
public update(): void {
|
||||||
|
@ -31,12 +31,13 @@ export class IntegrationComponent {
|
||||||
this.updated.emit();
|
this.updated.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public configureIntegration(): void {
|
public configureIntegration(integrationId:string=null): void {
|
||||||
this.modal.open(IntegrationService.getConfigComponent(this.integration), overlayConfigFactory({
|
this.modal.open(IntegrationService.getConfigComponent(this.integration), overlayConfigFactory({
|
||||||
integration: this.integration,
|
integration: this.integration,
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
scalarToken: this.scalarToken,
|
scalarToken: this.scalarToken,
|
||||||
isBlocking: false,
|
isBlocking: false,
|
||||||
|
integrationId: integrationId,
|
||||||
size: "lg"
|
size: "lg"
|
||||||
}, BSModalContext));
|
}, BSModalContext));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component } from "@angular/core";
|
import { Component, ViewChildren } from "@angular/core";
|
||||||
import { ActivatedRoute } from "@angular/router";
|
import { ActivatedRoute } from "@angular/router";
|
||||||
import { ApiService } from "../shared/api.service";
|
import { ApiService } from "../shared/api.service";
|
||||||
import { ScalarService } from "../shared/scalar.service";
|
import { ScalarService } from "../shared/scalar.service";
|
||||||
|
@ -6,6 +6,8 @@ import { ToasterService } from "angular2-toaster";
|
||||||
import { Integration } from "../shared/models/integration";
|
import { Integration } from "../shared/models/integration";
|
||||||
import { IntegrationService } from "../shared/integration.service";
|
import { IntegrationService } from "../shared/integration.service";
|
||||||
import * as _ from "lodash";
|
import * as _ from "lodash";
|
||||||
|
import { WIDGET_DIM_CUSTOM } from "../shared/models/widget";
|
||||||
|
import { IntegrationComponent } from "../integration/integration.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "my-riot",
|
selector: "my-riot",
|
||||||
|
@ -13,6 +15,7 @@ import * as _ from "lodash";
|
||||||
styleUrls: ["./riot.component.scss"],
|
styleUrls: ["./riot.component.scss"],
|
||||||
})
|
})
|
||||||
export class RiotComponent {
|
export class RiotComponent {
|
||||||
|
@ViewChildren(IntegrationComponent) integrationComponents: Array<IntegrationComponent>;
|
||||||
|
|
||||||
public error: string;
|
public error: string;
|
||||||
public integrations: Integration[] = [];
|
public integrations: Integration[] = [];
|
||||||
|
@ -20,11 +23,18 @@ export class RiotComponent {
|
||||||
public roomId: string;
|
public roomId: string;
|
||||||
public scalarToken: string;
|
public scalarToken: string;
|
||||||
|
|
||||||
|
private requestedScreen: string = null;
|
||||||
|
private requestedIntegration: string = null;
|
||||||
|
|
||||||
constructor(private activatedRoute: ActivatedRoute,
|
constructor(private activatedRoute: ActivatedRoute,
|
||||||
private api: ApiService,
|
private api: ApiService,
|
||||||
private scalar: ScalarService,
|
private scalar: ScalarService,
|
||||||
private toaster: ToasterService) {
|
private toaster: ToasterService) {
|
||||||
let params: any = this.activatedRoute.snapshot.queryParams;
|
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";
|
if (!params.scalar_token || !params.room_id) this.error = "Missing scalar token or room ID";
|
||||||
else {
|
else {
|
||||||
this.roomId = params.room_id;
|
this.roomId = params.room_id;
|
||||||
|
@ -45,12 +55,41 @@ export class RiotComponent {
|
||||||
this.integrations = _.filter(integrations, i => IntegrationService.isSupported(i));
|
this.integrations = _.filter(integrations, i => IntegrationService.isSupported(i));
|
||||||
let promises = integrations.map(b => this.updateIntegrationState(b));
|
let promises = integrations.map(b => this.updateIntegrationState(b));
|
||||||
return Promise.all(promises);
|
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";
|
this.error = "Unable to communicate with Dimension";
|
||||||
console.error(err);
|
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) {
|
private updateIntegrationState(integration: Integration) {
|
||||||
integration.hasConfig = IntegrationService.hasConfig(integration);
|
integration.hasConfig = IntegrationService.hasConfig(integration);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue