matrix-dimension/web/app/admin/widgets/widgets.component.ts
Travis Ralston 009b510779 Special case each integration, forcing simple bots to go through an NebProxy
This is so the different needs of each can be accounted for. For example, widgets are fairly unrestricted, so nothing really needs to prevent them. Bots on the other hand require an upstream token otherwise we can't get the bot IDs from Modular.
2018-03-25 13:13:50 -06:00

70 lines
2.5 KiB
TypeScript

import { Component } from "@angular/core";
import { FE_Widget } from "../../shared/models/integration";
import { ToasterService } from "angular2-toaster";
import { AdminWidgetEtherpadConfigComponent } from "./etherpad/etherpad.component";
import { Modal, overlayConfigFactory } from "ngx-modialog";
import { BSModalContext } from "ngx-modialog/plugins/bootstrap";
import { AdminWidgetJitsiConfigComponent } from "./jitsi/jitsi.component";
import { AdminIntegrationsApiService } from "../../shared/services/admin/admin-integrations-api.service";
export class WidgetConfigDialogContext extends BSModalContext {
public widget: FE_Widget;
}
@Component({
templateUrl: "./widgets.component.html",
styleUrls: ["./widgets.component.scss"],
})
export class AdminWidgetsComponent {
public isLoading = true;
public isUpdating = false;
public widgets: FE_Widget[];
constructor(private adminIntegrationsApi: AdminIntegrationsApiService, private toaster: ToasterService, private modal: Modal) {
this.adminIntegrationsApi.getAllWidgets().then(integrations => {
this.isLoading = false;
this.widgets = integrations.widgets;
});
}
public toggleWidget(widget: FE_Widget) {
widget.isEnabled = !widget.isEnabled;
this.isUpdating = true;
this.adminIntegrationsApi.toggleIntegration(widget.category, widget.type, widget.isEnabled).then(() => {
this.isUpdating = false;
this.toaster.pop("success", "Widget updated");
}).catch(err => {
console.error(err);
widget.isEnabled = !widget.isEnabled; // revert change
this.isUpdating = false;
this.toaster.pop("error", "Error updating widget");
});
}
public editWidget(widget: FE_Widget) {
let component = null;
if (widget.type === "etherpad") component = AdminWidgetEtherpadConfigComponent;
if (widget.type === "jitsi") component = AdminWidgetJitsiConfigComponent;
if (!component) {
console.error("No known dialog component for " + widget.type);
this.toaster.pop("error", "Error opening configuration page");
return;
}
this.modal.open(component, overlayConfigFactory({
widget: widget,
isBlocking: true,
size: 'lg',
}, WidgetConfigDialogContext));
}
public hasConfiguration(widget: FE_Widget) {
// Currently only Jitsi and Etherpad have additional configuration
return widget.type === "jitsi" || widget.type === "etherpad";
}
}