2017-05-29 00:51:04 -04:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
import { Integration } from "./models/integration";
|
|
|
|
import { RssConfigComponent } from "../configs/rss/rss-config.component";
|
2017-08-27 01:26:00 -04:00
|
|
|
import { ContainerContent } from "ngx-modialog";
|
2017-06-04 23:31:31 -04:00
|
|
|
import { IrcConfigComponent } from "../configs/irc/irc-config.component";
|
2017-08-27 21:05:38 -04:00
|
|
|
import { TravisCiConfigComponent } from "../configs/travisci/travisci-config.component";
|
2017-08-29 00:08:32 -04:00
|
|
|
import { CustomWidgetConfigComponent } from "../configs/widget/custom_widget/custom_widget-config.component";
|
2017-10-10 22:44:09 -04:00
|
|
|
import { YoutubeWidgetConfigComponent } from "../configs/widget/youtube/youtube-config.component";
|
2017-11-10 12:31:46 -05:00
|
|
|
import { TwitchWidgetConfigComponent } from "../configs/widget/twitch/twitch-config.component";
|
2017-11-18 16:33:47 -05:00
|
|
|
import { EtherpadWidgetConfigComponent } from "../configs/widget/etherpad/etherpad-config.component";
|
2017-12-10 02:59:36 -05:00
|
|
|
import { JitsiWidgetConfigComponent } from "../configs/widget/jitsi/jitsi-config.component";
|
2017-12-10 04:35:24 -05:00
|
|
|
import {
|
|
|
|
WIDGET_DIM_CUSTOM,
|
|
|
|
WIDGET_DIM_ETHERPAD,
|
|
|
|
WIDGET_DIM_JITSI,
|
|
|
|
WIDGET_DIM_TWITCH,
|
|
|
|
WIDGET_DIM_YOUTUBE
|
|
|
|
} from "./models/widget";
|
2017-05-29 00:51:04 -04:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class IntegrationService {
|
|
|
|
|
2017-12-10 04:35:24 -05:00
|
|
|
private static supportedIntegrationsMap = {
|
|
|
|
"bot": {}, // empty == supported
|
2017-05-29 00:51:04 -04:00
|
|
|
"complex-bot": {
|
2017-12-10 04:35:24 -05:00
|
|
|
"rss": {
|
|
|
|
component: RssConfigComponent,
|
|
|
|
},
|
|
|
|
"travisci": {
|
|
|
|
component: TravisCiConfigComponent,
|
|
|
|
},
|
2017-06-04 23:31:31 -04:00
|
|
|
},
|
|
|
|
"bridge": {
|
2017-12-10 04:35:24 -05:00
|
|
|
"irc": {
|
|
|
|
component: IrcConfigComponent,
|
|
|
|
},
|
2017-08-29 00:08:32 -04:00
|
|
|
},
|
|
|
|
"widget": {
|
2017-12-10 04:35:24 -05:00
|
|
|
"customwidget": {
|
|
|
|
component: CustomWidgetConfigComponent,
|
|
|
|
screenId: "type_" + WIDGET_DIM_CUSTOM,
|
|
|
|
},
|
|
|
|
"youtube": {
|
|
|
|
component: YoutubeWidgetConfigComponent,
|
|
|
|
screenId: "type_" + WIDGET_DIM_YOUTUBE,
|
|
|
|
},
|
|
|
|
"etherpad": {
|
|
|
|
component: EtherpadWidgetConfigComponent,
|
|
|
|
screenId: "type_" + WIDGET_DIM_ETHERPAD,
|
|
|
|
},
|
|
|
|
"twitch": {
|
|
|
|
component: TwitchWidgetConfigComponent,
|
|
|
|
screenId: "type_" + WIDGET_DIM_TWITCH,
|
|
|
|
},
|
|
|
|
"jitsi": {
|
|
|
|
component: JitsiWidgetConfigComponent,
|
|
|
|
screenId: "type_" + WIDGET_DIM_JITSI,
|
|
|
|
},
|
2017-08-29 00:08:32 -04:00
|
|
|
},
|
2017-05-29 00:51:04 -04:00
|
|
|
};
|
|
|
|
|
2017-12-10 04:35:24 -05:00
|
|
|
static getAllConfigComponents(): ContainerContent[] {
|
|
|
|
const components = [];
|
|
|
|
|
|
|
|
for (const iType of Object.keys(IntegrationService.supportedIntegrationsMap)) {
|
|
|
|
for (const iiType of Object.keys(IntegrationService.supportedIntegrationsMap[iType])) {
|
|
|
|
const component = IntegrationService.supportedIntegrationsMap[iType][iiType].component;
|
|
|
|
if (component) components.push(component);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return components;
|
|
|
|
}
|
2017-05-29 00:51:04 -04:00
|
|
|
|
|
|
|
static isSupported(integration: Integration): boolean {
|
2017-12-10 04:35:24 -05:00
|
|
|
const forType = IntegrationService.supportedIntegrationsMap[integration.type];
|
|
|
|
if (!forType) return false;
|
|
|
|
|
|
|
|
if (Object.keys(forType).length === 0) return true;
|
|
|
|
|
|
|
|
return forType[integration.integrationType]; // has sub type
|
2017-05-29 00:51:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static hasConfig(integration: Integration): boolean {
|
|
|
|
return integration.type !== "bot";
|
|
|
|
}
|
|
|
|
|
|
|
|
static getConfigComponent(integration: Integration): ContainerContent {
|
2017-12-10 04:35:24 -05:00
|
|
|
return IntegrationService.supportedIntegrationsMap[integration.type][integration.integrationType].component;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getIntegrationForScreen(screen: string): { type: string, integrationType: string } {
|
|
|
|
for (const iType of Object.keys(IntegrationService.supportedIntegrationsMap)) {
|
|
|
|
for (const iiType of Object.keys(IntegrationService.supportedIntegrationsMap[iType])) {
|
|
|
|
const iScreen = IntegrationService.supportedIntegrationsMap[iType][iiType].screenId;
|
|
|
|
if (screen === iScreen) return {type: iType, integrationType: iiType};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2017-05-29 00:51:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
}
|