matrix-dimension/web/app/configs/widget/whiteboard/whiteboard.widget.component.ts

49 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-09-02 03:45:56 -04:00
import { WidgetComponent } from "../widget.component";
import { Component } from "@angular/core";
import { EditableWidget, WIDGET_WHITEBOARD } from "../../../shared/models/widget";
import * as url from "url";
import { SessionStorage } from "../../../shared/SessionStorage";
import { NameService } from "../../../shared/services/name.service";
import { FE_WhiteBoardWidget } from "../../../shared/models/integration";
2020-12-28 22:49:24 -05:00
import { TranslateService } from "@ngx-translate/core";
2020-09-02 03:45:56 -04:00
@Component({
templateUrl: "whiteboard.widget.component.html",
styleUrls: ["whiteboard.widget.component.scss"],
})
export class WhiteboardWidgetComponent extends WidgetComponent {
private whiteBoardWidget: FE_WhiteBoardWidget = <FE_WhiteBoardWidget>SessionStorage.editIntegration;
2020-12-28 22:49:24 -05:00
constructor(private nameService: NameService, public translate: TranslateService) {
super(WIDGET_WHITEBOARD, "Whiteboard", "generic", translate, "whiteboard", "boardName");
2020-09-02 03:45:56 -04:00
}
2020-12-28 22:51:21 -05:00
2020-09-02 03:45:56 -04:00
protected OnWidgetsDiscovered(widgets: EditableWidget[]): void {
console.log(widgets);
for (const widget of widgets) {
if (!widget.dimension.newUrl.startsWith("http://") && !widget.dimension.newUrl.startsWith("https://")) {
const parsedUrl = url.parse(widget.url, true);
const boardName = parsedUrl.query["boardName"];
// Set the new URL so that it unpacks correctly
2020-12-28 22:51:21 -05:00
widget.url = `https://cloud13.de/testwhiteboard/?whiteboardid=${boardName}`;
2020-09-02 03:45:56 -04:00
}
}
}
protected OnNewWidgetPrepared(widget: EditableWidget): void {
const name = this.nameService.getHumanReadableName();
2020-12-28 22:51:21 -05:00
let template = "https://cloud13.de/testwhiteboard/?whiteboardid=$roomId_$boardName";
2020-09-02 03:45:56 -04:00
if (this.whiteBoardWidget.options && this.whiteBoardWidget.options.defaultUrl) {
template = this.whiteBoardWidget.options.defaultUrl;
}
template = template.replace("$roomId", encodeURIComponent(SessionStorage.roomId));
template = template.replace("$boardName", encodeURIComponent(name));
widget.dimension.newUrl = template;
widget.dimension.newName = name;
}
}