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