mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
Add google calendar configuration
This commit is contained in:
parent
00b7ddcc1a
commit
2fbd655c46
@ -35,6 +35,7 @@ import { CustomWidgetConfigComponent } from "./configs/widget/custom/custom.widg
|
|||||||
import { ConfigScreenWidgetComponent } from "./configs/widget/config_screen/config_screen.widget.component";
|
import { ConfigScreenWidgetComponent } from "./configs/widget/config_screen/config_screen.widget.component";
|
||||||
import { EtherpadWidgetConfigComponent } from "./configs/widget/etherpad/etherpad.widget.component";
|
import { EtherpadWidgetConfigComponent } from "./configs/widget/etherpad/etherpad.widget.component";
|
||||||
import { NameService } from "./shared/services/name.service";
|
import { NameService } from "./shared/services/name.service";
|
||||||
|
import { GoogleCalendarWidgetConfigComponent } from "./configs/widget/google_calendar/gcal.widget.component";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@ -69,6 +70,7 @@ import { NameService } from "./shared/services/name.service";
|
|||||||
ConfigScreenWidgetComponent,
|
ConfigScreenWidgetComponent,
|
||||||
CustomWidgetConfigComponent,
|
CustomWidgetConfigComponent,
|
||||||
EtherpadWidgetConfigComponent,
|
EtherpadWidgetConfigComponent,
|
||||||
|
GoogleCalendarWidgetConfigComponent,
|
||||||
|
|
||||||
// Vendor
|
// Vendor
|
||||||
],
|
],
|
||||||
|
@ -8,6 +8,7 @@ import { GCalWidgetWrapperComponent } from "./widget_wrappers/gcal/gcal.componen
|
|||||||
import { RiotHomeComponent } from "./riot/riot-home/home.component";
|
import { RiotHomeComponent } from "./riot/riot-home/home.component";
|
||||||
import { CustomWidgetConfigComponent } from "./configs/widget/custom/custom.widget.component";
|
import { CustomWidgetConfigComponent } from "./configs/widget/custom/custom.widget.component";
|
||||||
import { EtherpadWidgetConfigComponent } from "./configs/widget/etherpad/etherpad.widget.component";
|
import { EtherpadWidgetConfigComponent } from "./configs/widget/etherpad/etherpad.widget.component";
|
||||||
|
import { GoogleCalendarWidgetConfigComponent } from "./configs/widget/google_calendar/gcal.widget.component";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{path: "", component: HomeComponent},
|
{path: "", component: HomeComponent},
|
||||||
@ -34,6 +35,11 @@ const routes: Routes = [
|
|||||||
component: EtherpadWidgetConfigComponent,
|
component: EtherpadWidgetConfigComponent,
|
||||||
data: {breadcrumb: "Etherpad Widgets", name: "Etherpad Widgets"}
|
data: {breadcrumb: "Etherpad Widgets", name: "Etherpad Widgets"}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "googlecalendar",
|
||||||
|
component: GoogleCalendarWidgetConfigComponent,
|
||||||
|
data: {breadcrumb: "Google Calendar Widgets", name: "Google Calendar Widgets"}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { NewWidgetComponent } from "../widget.component";
|
import { WidgetComponent } from "../widget.component";
|
||||||
import { Component, ContentChild, Input, TemplateRef } from "@angular/core";
|
import { Component, ContentChild, Input, TemplateRef } from "@angular/core";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -8,7 +8,7 @@ import { Component, ContentChild, Input, TemplateRef } from "@angular/core";
|
|||||||
})
|
})
|
||||||
export class ConfigScreenWidgetComponent {
|
export class ConfigScreenWidgetComponent {
|
||||||
|
|
||||||
@Input() widgetComponent: NewWidgetComponent;
|
@Input() widgetComponent: WidgetComponent;
|
||||||
@ContentChild(TemplateRef) widgetParamsTemplate: TemplateRef<any>;
|
@ContentChild(TemplateRef) widgetParamsTemplate: TemplateRef<any>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { NewWidgetComponent } from "../widget.component";
|
import { WidgetComponent } from "../widget.component";
|
||||||
import { WIDGET_CUSTOM } from "../../../shared/models/widget";
|
import { WIDGET_CUSTOM } from "../../../shared/models/widget";
|
||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ import { Component } from "@angular/core";
|
|||||||
templateUrl: "custom.widget.component.html",
|
templateUrl: "custom.widget.component.html",
|
||||||
styleUrls: ["custom.widget.component.scss"],
|
styleUrls: ["custom.widget.component.scss"],
|
||||||
})
|
})
|
||||||
export class CustomWidgetConfigComponent extends NewWidgetComponent {
|
export class CustomWidgetConfigComponent extends WidgetComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(WIDGET_CUSTOM, "Custom Widget", "generic");
|
super(WIDGET_CUSTOM, "Custom Widget", "generic");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { NewWidgetComponent } from "../widget.component";
|
import { WidgetComponent } from "../widget.component";
|
||||||
import { EditableWidget, WIDGET_ETHERPAD } from "../../../shared/models/widget";
|
import { EditableWidget, WIDGET_ETHERPAD } from "../../../shared/models/widget";
|
||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { EtherpadWidget } from "../../../shared/models/integration";
|
import { EtherpadWidget } from "../../../shared/models/integration";
|
||||||
@ -9,7 +9,7 @@ import { NameService } from "../../../shared/services/name.service";
|
|||||||
templateUrl: "etherpad.widget.component.html",
|
templateUrl: "etherpad.widget.component.html",
|
||||||
styleUrls: ["etherpad.widget.component.scss"],
|
styleUrls: ["etherpad.widget.component.scss"],
|
||||||
})
|
})
|
||||||
export class EtherpadWidgetConfigComponent extends NewWidgetComponent {
|
export class EtherpadWidgetConfigComponent extends WidgetComponent {
|
||||||
|
|
||||||
private etherpadWidget: EtherpadWidget = <EtherpadWidget>SessionStorage.editIntegration;
|
private etherpadWidget: EtherpadWidget = <EtherpadWidget>SessionStorage.editIntegration;
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
<my-widget-config [widgetComponent]="this">
|
||||||
|
<ng-template #widgetParamsTemplate let-widget="widget">
|
||||||
|
<label class="label-block">
|
||||||
|
Shared Calendar ID
|
||||||
|
<input type="text" class="form-control"
|
||||||
|
placeholder="en.uk#holiday@group.v.calendar.google.com"
|
||||||
|
[(ngModel)]="widget.dimension.newData.src" name="widget-url-{{widget.id}}"
|
||||||
|
[disabled]="isUpdating"/>
|
||||||
|
</label>
|
||||||
|
</ng-template>
|
||||||
|
</my-widget-config>
|
@ -0,0 +1,39 @@
|
|||||||
|
import { DISABLE_AUTOMATIC_WRAPPING, WidgetComponent } from "../widget.component";
|
||||||
|
import { EditableWidget, WIDGET_GOOGLE_CALENDAR } from "../../../shared/models/widget";
|
||||||
|
import { Component } from "@angular/core";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
templateUrl: "gcal.widget.component.html",
|
||||||
|
styleUrls: ["gcal.widget.component.scss"],
|
||||||
|
})
|
||||||
|
export class GoogleCalendarWidgetConfigComponent extends WidgetComponent {
|
||||||
|
constructor() {
|
||||||
|
super(WIDGET_GOOGLE_CALENDAR, "Google Calendar Widget", DISABLE_AUTOMATIC_WRAPPING, "googleCalendar");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected OnWidgetBeforeAdd(widget: EditableWidget) {
|
||||||
|
this.setCalendarUrl(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected OnWidgetBeforeEdit(widget: EditableWidget) {
|
||||||
|
this.setCalendarUrl(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setCalendarUrl(widget: EditableWidget) {
|
||||||
|
if (!widget.dimension.newData.src || widget.dimension.newData.src.trim().length === 0) {
|
||||||
|
throw new Error("Please enter a shared calendar ID");
|
||||||
|
}
|
||||||
|
|
||||||
|
const encodedId = encodeURIComponent(widget.dimension.newData.src);
|
||||||
|
widget.dimension.newUrl = window.location.origin + "/widget/gcal?calendarId=" + encodedId;
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,9 @@ const SCALAR_WIDGET_LINKS = [
|
|||||||
"https://demo.riot.im/scalar/api/widgets/__TYPE__.html?url=",
|
"https://demo.riot.im/scalar/api/widgets/__TYPE__.html?url=",
|
||||||
];
|
];
|
||||||
|
|
||||||
export class NewWidgetComponent implements OnInit {
|
export const DISABLE_AUTOMATIC_WRAPPING = "";
|
||||||
|
|
||||||
|
export class WidgetComponent implements OnInit {
|
||||||
|
|
||||||
public isLoading = true;
|
public isLoading = true;
|
||||||
public isUpdating = false;
|
public isUpdating = false;
|
||||||
@ -223,6 +225,14 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
* with a new widget.
|
* with a new widget.
|
||||||
*/
|
*/
|
||||||
public addWidget(): Promise<any> {
|
public addWidget(): Promise<any> {
|
||||||
|
// Make sure we call "before add" before validating the URL
|
||||||
|
try {
|
||||||
|
this.OnWidgetBeforeAdd(this.newWidget);
|
||||||
|
} catch (error) {
|
||||||
|
this.toaster.pop("warning", error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.newWidget.dimension.newUrl || this.newWidget.dimension.newUrl.trim().length === 0) {
|
if (!this.newWidget.dimension.newUrl || this.newWidget.dimension.newUrl.trim().length === 0) {
|
||||||
this.toaster.pop("warning", "Please enter a URL for the widget");
|
this.toaster.pop("warning", "Please enter a URL for the widget");
|
||||||
return;
|
return;
|
||||||
@ -231,7 +241,6 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
this.packWidget(this.newWidget);
|
this.packWidget(this.newWidget);
|
||||||
|
|
||||||
this.isUpdating = true;
|
this.isUpdating = true;
|
||||||
this.OnWidgetBeforeAdd(this.newWidget);
|
|
||||||
return this.scalarApi.setWidget(SessionStorage.roomId, this.newWidget)
|
return this.scalarApi.setWidget(SessionStorage.roomId, this.newWidget)
|
||||||
.then(() => this.widgets.push(this.newWidget))
|
.then(() => this.widgets.push(this.newWidget))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -253,6 +262,14 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
* @returns {Promise<any>} Resolves when the widget has been updated in the room.
|
* @returns {Promise<any>} Resolves when the widget has been updated in the room.
|
||||||
*/
|
*/
|
||||||
public saveWidget(widget: EditableWidget): Promise<any> {
|
public saveWidget(widget: EditableWidget): Promise<any> {
|
||||||
|
// Make sure we call "before add" before validating the URL
|
||||||
|
try {
|
||||||
|
this.OnWidgetBeforeEdit(this.newWidget);
|
||||||
|
} catch (error) {
|
||||||
|
this.toaster.pop("warning", error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!widget.dimension.newUrl || widget.dimension.newUrl.trim().length === 0) {
|
if (!widget.dimension.newUrl || widget.dimension.newUrl.trim().length === 0) {
|
||||||
this.toaster.pop("warning", "Please enter a URL for the widget");
|
this.toaster.pop("warning", "Please enter a URL for the widget");
|
||||||
return;
|
return;
|
||||||
@ -261,7 +278,6 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
this.packWidget(widget);
|
this.packWidget(widget);
|
||||||
|
|
||||||
this.isUpdating = true;
|
this.isUpdating = true;
|
||||||
this.OnWidgetBeforeEdit(widget);
|
|
||||||
return this.scalarApi.setWidget(SessionStorage.roomId, widget)
|
return this.scalarApi.setWidget(SessionStorage.roomId, widget)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.isUpdating = false;
|
this.isUpdating = false;
|
||||||
@ -326,8 +342,8 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before the widget is added to the room, but after the Dimension-specific
|
* Called before the widget is added to the room, and before the Dimension properties
|
||||||
* settings have been copied over to the primary fields.
|
* have been copied over. This is a good time to do validation.
|
||||||
* @param {EditableWidget} _widget The widget that is about to be added
|
* @param {EditableWidget} _widget The widget that is about to be added
|
||||||
*/
|
*/
|
||||||
protected OnWidgetBeforeAdd(_widget: EditableWidget): void {
|
protected OnWidgetBeforeAdd(_widget: EditableWidget): void {
|
||||||
@ -354,8 +370,8 @@ export class NewWidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before the given widget has been updated in the room, but after the
|
* Called before the given widget has been updated in the room, and before the Dimension
|
||||||
* Dimension-specific settings have been copied over to the primary fields.
|
* properties have been copied over. This is a good time to do validation.
|
||||||
* This is not called for widgets being deleted.
|
* This is not called for widgets being deleted.
|
||||||
* @param {EditableWidget} _widget The widget about to be edited
|
* @param {EditableWidget} _widget The widget about to be edited
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user