2017-12-20 23:28:43 -05:00
|
|
|
import { Component, Injectable } from "@angular/core";
|
2017-12-10 04:35:24 -05:00
|
|
|
import {
|
2017-12-14 00:44:20 -05:00
|
|
|
WIDGET_CUSTOM, WIDGET_ETHERPAD, WIDGET_GOOGLE_CALENDAR, WIDGET_GOOGLE_DOCS, WIDGET_JITSI, WIDGET_TWITCH,
|
|
|
|
WIDGET_YOUTUBE
|
2017-12-15 01:46:17 -05:00
|
|
|
} from "../models/widget";
|
2017-12-20 23:28:43 -05:00
|
|
|
import { Integration } from "../models/integration";
|
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": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: RssConfigComponent,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"travisci": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: TravisCiConfigComponent,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
2017-12-15 23:23:57 -05:00
|
|
|
"circleci": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: CircleCiConfigComponent,
|
2017-12-15 23:23:57 -05:00
|
|
|
},
|
2017-06-04 23:31:31 -04:00
|
|
|
},
|
|
|
|
"bridge": {
|
2017-12-10 04:35:24 -05:00
|
|
|
"irc": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: IrcConfigComponent,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
2017-08-29 00:08:32 -04:00
|
|
|
},
|
|
|
|
"widget": {
|
2017-12-10 04:35:24 -05:00
|
|
|
"customwidget": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: CustomWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_CUSTOM,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"youtube": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: YoutubeWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_YOUTUBE
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"etherpad": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: EtherpadWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_ETHERPAD,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"twitch": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: TwitchWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_TWITCH,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"jitsi": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: JitsiWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_JITSI,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
2017-12-11 18:43:50 -05:00
|
|
|
"googledocs": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: GoogleDocsWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_GOOGLE_DOCS,
|
2017-12-11 19:29:57 -05:00
|
|
|
},
|
|
|
|
"googlecalendar": {
|
2017-12-20 23:28:43 -05:00
|
|
|
//component: GoogleCalendarWidgetConfigComponent,
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_GOOGLE_CALENDAR,
|
2017-12-11 18:43:50 -05:00
|
|
|
},
|
2017-08-29 00:08:32 -04:00
|
|
|
},
|
2017-05-29 00:51:04 -04:00
|
|
|
};
|
|
|
|
|
2017-12-20 23:28:43 -05:00
|
|
|
static getAllConfigComponents(): Component[] {
|
2017-12-10 04:35:24 -05:00
|
|
|
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-20 23:28:43 -05:00
|
|
|
const forType = IntegrationService.supportedIntegrationsMap[integration.category];
|
2017-12-10 04:35:24 -05:00
|
|
|
if (!forType) return false;
|
|
|
|
|
|
|
|
if (Object.keys(forType).length === 0) return true;
|
|
|
|
|
2017-12-20 23:28:43 -05:00
|
|
|
return forType[integration.type]; // has sub type
|
2017-05-29 00:51:04 -04:00
|
|
|
}
|
|
|
|
|
2017-12-20 23:28:43 -05:00
|
|
|
static getConfigComponent(integration: Integration): Component {
|
|
|
|
return IntegrationService.supportedIntegrationsMap[integration.category][integration.type].component;
|
2017-12-10 04:35:24 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 23:28:43 -05:00
|
|
|
static getIntegrationForScreen(screen: string): { category: string, type: string } {
|
2017-12-10 04:35:24 -05:00
|
|
|
for (const iType of Object.keys(IntegrationService.supportedIntegrationsMap)) {
|
|
|
|
for (const iiType of Object.keys(IntegrationService.supportedIntegrationsMap[iType])) {
|
2017-12-14 00:44:20 -05:00
|
|
|
const integrationTypes = IntegrationService.supportedIntegrationsMap[iType][iiType].types;
|
|
|
|
const integrationScreens = integrationTypes.map(t => "type_" + t);
|
2017-12-20 23:28:43 -05:00
|
|
|
if (integrationScreens.includes(screen)) return {category: iType, type: iiType};
|
2017-12-10 04:35:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2017-05-29 00:51:04 -04:00
|
|
|
}
|
|
|
|
|
2017-12-20 23:28:43 -05:00
|
|
|
private constructor() {
|
2017-05-29 00:51:04 -04:00
|
|
|
}
|
|
|
|
}
|