2017-12-23 15:32:07 -05:00
|
|
|
import { DISABLE_AUTOMATIC_WRAPPING, WidgetComponent } from "../widget.component";
|
|
|
|
import { EditableWidget, WIDGET_GOOGLE_CALENDAR } from "../../../shared/models/widget";
|
|
|
|
import { Component } from "@angular/core";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2017-12-23 15:32:07 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "gcal.widget.component.html",
|
|
|
|
styleUrls: ["gcal.widget.component.scss"],
|
|
|
|
})
|
|
|
|
export class GoogleCalendarWidgetConfigComponent extends WidgetComponent {
|
2020-10-23 07:30:20 -04:00
|
|
|
constructor(public translate: TranslateService) {
|
|
|
|
super(WIDGET_GOOGLE_CALENDAR, "Google Calendar", DISABLE_AUTOMATIC_WRAPPING, translate , "googleCalendar");
|
2017-12-23 17:03:24 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 00:17:16 -04:00
|
|
|
protected OnNewWidgetPrepared(widget: EditableWidget) {
|
2019-03-24 18:56:14 -04:00
|
|
|
widget.dimension.newData.shareId = "";
|
2017-12-23 15:32:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetsDiscovered(widgets: EditableWidget[]) {
|
|
|
|
for (const widget of widgets) {
|
|
|
|
if (widget.data.dimSrc && !widget.data.src) {
|
|
|
|
// Convert legacy Dimension widgets to new source
|
|
|
|
widget.data.src = widget.data.dimSrc;
|
|
|
|
}
|
2019-03-24 18:56:14 -04:00
|
|
|
if (widget.data.src && !widget.data.shareId) {
|
|
|
|
// Convert even more legacy Dimension widgets to new source
|
|
|
|
widget.data.shareId = widget.data.src;
|
|
|
|
}
|
2017-12-23 15:32:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeAdd(widget: EditableWidget) {
|
|
|
|
this.setCalendarUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeEdit(widget: EditableWidget) {
|
|
|
|
this.setCalendarUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
private setCalendarUrl(widget: EditableWidget) {
|
2019-03-24 18:56:14 -04:00
|
|
|
if (!widget.dimension.newData.shareId || widget.dimension.newData.shareId.trim().length === 0) {
|
2017-12-23 15:32:07 -05:00
|
|
|
throw new Error("Please enter a shared calendar ID");
|
|
|
|
}
|
|
|
|
|
2019-03-24 18:56:14 -04:00
|
|
|
widget.dimension.newUrl = window.location.origin + "/widgets/gcal?calendarId=$shareId";
|
2017-12-23 15:32:07 -05:00
|
|
|
}
|
2020-10-23 07:30:20 -04:00
|
|
|
}
|