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

50 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-12-23 20:32:07 +00:00
import { WidgetComponent } from "../widget.component";
2017-12-23 20:16:05 +00:00
import { EditableWidget, WIDGET_ETHERPAD } from "../../../shared/models/widget";
import { Component } from "@angular/core";
import { FE_EtherpadWidget } from "../../../shared/models/integration";
2017-12-23 20:16:05 +00:00
import { SessionStorage } from "../../../shared/SessionStorage";
import { NameService } from "../../../shared/services/name.service";
import * as url from "url";
import { TranslateService } from "@ngx-translate/core";
2017-12-23 20:16:05 +00:00
@Component({
templateUrl: "etherpad.widget.component.html",
styleUrls: ["etherpad.widget.component.scss"],
})
2017-12-23 20:32:07 +00:00
export class EtherpadWidgetConfigComponent extends WidgetComponent {
2017-12-23 20:16:05 +00:00
private etherpadWidget: FE_EtherpadWidget = <FE_EtherpadWidget>SessionStorage.editIntegration;
2017-12-23 20:16:05 +00:00
constructor(private nameService: NameService, public translate: TranslateService) {
2020-12-29 04:05:45 +00:00
super(WIDGET_ETHERPAD, "Notes", "generic", translate, "etherpad", "padName");
}
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 padName = parsedUrl.query["padName"];
// Set the new URL so that it unpacks correctly
2019-06-29 06:51:26 +00:00
widget.url = `https://scalar.vector.im/etherpad/p/${padName}`;
}
}
2017-12-23 20:16:05 +00:00
}
protected OnNewWidgetPrepared(widget: EditableWidget): void {
const name = this.nameService.getHumanReadableName();
2019-06-29 06:51:26 +00:00
let template = "https://scalar.vector.im/etherpad/p/$roomId_$padName";
2017-12-23 20:16:05 +00:00
if (this.etherpadWidget.options && this.etherpadWidget.options.defaultUrl) {
template = this.etherpadWidget.options.defaultUrl;
}
template = template.replace("$roomId", encodeURIComponent(SessionStorage.roomId));
template = template.replace("$padName", encodeURIComponent(name));
widget.dimension.newUrl = template;
widget.dimension.newName = name;
}
}