2017-12-23 23:40:01 -05:00
|
|
|
import { Component } from "@angular/core";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { FE_Widget } from "../../shared/models/integration";
|
2017-12-23 23:40:01 -05:00
|
|
|
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";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { AdminIntegrationsApiService } from "../../shared/services/admin/admin-integrations-api.service";
|
2017-12-23 23:40:01 -05:00
|
|
|
|
|
|
|
export class WidgetConfigDialogContext extends BSModalContext {
|
2017-12-24 04:02:57 -05:00
|
|
|
public widget: FE_Widget;
|
2017-12-23 23:40:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./widgets.component.html",
|
|
|
|
styleUrls: ["./widgets.component.scss"],
|
|
|
|
})
|
|
|
|
export class AdminWidgetsComponent {
|
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public isUpdating = false;
|
2017-12-24 04:02:57 -05:00
|
|
|
public widgets: FE_Widget[];
|
2017-12-23 23:40:01 -05:00
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
constructor(private adminIntegrationsApi: AdminIntegrationsApiService, private toaster: ToasterService, private modal: Modal) {
|
2018-03-30 21:22:15 -04:00
|
|
|
this.adminIntegrationsApi.getAllWidgets().then(widgets => {
|
2017-12-23 23:40:01 -05:00
|
|
|
this.isLoading = false;
|
2018-03-30 21:22:15 -04:00
|
|
|
this.widgets = widgets;
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.toaster.pop("error", "Failed to load widgets");
|
2017-12-23 23:40:01 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-28 20:22:50 -05:00
|
|
|
public toggleWidget(widget: FE_Widget) {
|
2017-12-23 23:40:01 -05:00
|
|
|
widget.isEnabled = !widget.isEnabled;
|
|
|
|
this.isUpdating = true;
|
2017-12-24 04:02:57 -05:00
|
|
|
this.adminIntegrationsApi.toggleIntegration(widget.category, widget.type, widget.isEnabled).then(() => {
|
2017-12-23 23:40:01 -05:00
|
|
|
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");
|
2017-12-28 20:22:50 -05:00
|
|
|
});
|
2017-12-23 23:40:01 -05:00
|
|
|
}
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
public editWidget(widget: FE_Widget) {
|
2017-12-23 23:40:01 -05:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
public hasConfiguration(widget: FE_Widget) {
|
2017-12-23 23:40:01 -05:00
|
|
|
// Currently only Jitsi and Etherpad have additional configuration
|
|
|
|
return widget.type === "jitsi" || widget.type === "etherpad";
|
|
|
|
}
|
|
|
|
}
|