matrix-dimension/web/app/configs/widget/twitch/twitch-config.component.ts

73 lines
2.4 KiB
TypeScript
Raw Normal View History

2017-11-10 12:31:46 -05:00
import { Component } from "@angular/core";
2017-12-09 18:34:59 -05:00
import { DialogRef, ModalComponent } from "ngx-modialog";
2017-11-10 12:31:46 -05:00
import { WidgetComponent } from "../widget.component";
import { ScalarService } from "../../../shared/scalar.service";
import { ConfigModalContext } from "../../../integration/integration.component";
import { ToasterService } from "angular2-toaster";
import { EditableWidget, WIDGET_TWITCH } from "../../../shared/models/widget";
2017-11-10 12:31:46 -05:00
@Component({
selector: "my-twitchwidget-config",
templateUrl: "twitch-config.component.html",
styleUrls: ["twitch-config.component.scss", "./../../config.component.scss"],
})
export class TwitchWidgetConfigComponent extends WidgetComponent implements ModalComponent<ConfigModalContext> {
constructor(public dialog: DialogRef<ConfigModalContext>,
toaster: ToasterService,
scalarService: ScalarService,
window: Window) {
super(
window,
2017-11-10 12:31:46 -05:00
toaster,
scalarService,
dialog.context.roomId,
dialog.context.integration,
2017-11-10 12:31:46 -05:00
dialog.context.integrationId,
WIDGET_TWITCH,
2017-11-10 12:31:46 -05:00
"Twitch Widget",
"video", // wrapper
"twitch" // scalar wrapper
);
}
protected onNewWidgetPrepared() {
this.newWidget.dimension.newData.channelName = "";
}
protected onWidgetsDiscovered() {
for (const widget of this.widgets) {
// Convert dimChannelName to channelName
if (!widget.data.channelName) {
widget.data.channelName = widget.data.dimChannelName;
}
}
}
2017-11-10 12:31:46 -05:00
public validateAndAddWidget() {
if (!this.newWidget.dimension.newData.channelName) {
this.toaster.pop("warning", "Please enter a Twitch Livestream channel name");
2017-11-10 12:31:46 -05:00
return;
}
this.setTwitchUrl(this.newWidget);
this.addWidget();
2017-11-10 12:31:46 -05:00
}
public validateAndSaveWidget(widget: EditableWidget) {
if (!widget.dimension.newData.channelName) {
this.toaster.pop("warning", "Please enter a Twitch Livestream channel name");
2017-11-10 12:31:46 -05:00
return;
}
this.setTwitchUrl(widget);
2017-11-10 12:31:46 -05:00
this.saveWidget(widget);
}
private setTwitchUrl(widget: EditableWidget) {
// TODO: This should use templating when mobile riot supports it
widget.dimension.newUrl = "https://player.twitch.tv/?channel=" + widget.dimension.newData.channelName;
2017-11-10 12:31:46 -05:00
}
}