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 { AdminWidgetJitsiConfigComponent } from "./jitsi/jitsi.component";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { AdminIntegrationsApiService } from "../../shared/services/admin/admin-integrations-api.service";
|
2020-12-04 11:47:45 -05:00
|
|
|
import { AdminWidgetWhiteboardConfigComponent } from "./whiteboard/whiteboard.component";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2021-08-16 18:00:59 -04:00
|
|
|
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
|
2017-12-23 23:40:01 -05:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
export interface WidgetConfigDialogContext {
|
|
|
|
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
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
constructor(private adminIntegrationsApi: AdminIntegrationsApiService, private toaster: ToasterService, private modal: NgbModal, public translate: TranslateService) {
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate = translate;
|
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);
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Failed to load widgets').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
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;
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Widget updated').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("success", res);
|
|
|
|
});
|
2017-12-23 23:40:01 -05:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
widget.isEnabled = !widget.isEnabled; // revert change
|
|
|
|
this.isUpdating = false;
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Error updating widget').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
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;
|
2020-12-04 11:47:45 -05:00
|
|
|
if (widget.type === "whiteboard") component = AdminWidgetWhiteboardConfigComponent;
|
2017-12-23 23:40:01 -05:00
|
|
|
|
|
|
|
if (!component) {
|
|
|
|
console.error("No known dialog component for " + widget.type);
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Error opening configuration page').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
2017-12-23 23:40:01 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
const widgetConfigRef = this.modal.open(component, {
|
|
|
|
backdrop: 'static'
|
|
|
|
});
|
|
|
|
const widgetConfigInterface = widgetConfigRef.componentInstance as WidgetConfigDialogContext;
|
|
|
|
widgetConfigInterface.widget = widget;
|
2017-12-23 23:40:01 -05:00
|
|
|
}
|
|
|
|
|
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
|
2020-12-04 11:47:45 -05:00
|
|
|
return widget.type === "jitsi" || widget.type === "etherpad" || widget.type === "whiteboard";
|
2017-12-23 23:40:01 -05:00
|
|
|
}
|
|
|
|
}
|