2017-12-22 23:08:10 -05:00
|
|
|
import { 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-22 23:08:10 -05:00
|
|
|
"rss": {},
|
|
|
|
"travisci": {},
|
|
|
|
"circleci": {},
|
2017-06-04 23:31:31 -04:00
|
|
|
},
|
|
|
|
"bridge": {
|
2017-12-22 23:08:10 -05:00
|
|
|
"irc": {},
|
2017-08-29 00:08:32 -04:00
|
|
|
},
|
|
|
|
"widget": {
|
2017-12-20 23:47:35 -05:00
|
|
|
"custom": {
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_CUSTOM,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"youtube": {
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_YOUTUBE
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"etherpad": {
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_ETHERPAD,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"twitch": {
|
2017-12-14 00:44:20 -05:00
|
|
|
types: WIDGET_TWITCH,
|
2017-12-10 04:35:24 -05:00
|
|
|
},
|
|
|
|
"jitsi": {
|
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-14 00:44:20 -05:00
|
|
|
types: WIDGET_GOOGLE_DOCS,
|
2017-12-11 19:29:57 -05:00
|
|
|
},
|
|
|
|
"googlecalendar": {
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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 getIntegrationForScreen(screen: string): { category: string, type: string } {
|
2017-12-22 23:42:43 -05:00
|
|
|
for (const category of Object.keys(IntegrationService.supportedIntegrationsMap)) {
|
|
|
|
for (const type of Object.keys(IntegrationService.supportedIntegrationsMap[category])) {
|
|
|
|
const integrationTypes = IntegrationService.supportedIntegrationsMap[category][type].types;
|
|
|
|
if (!integrationTypes) continue;
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
const integrationScreens = integrationTypes.map(t => "type_" + t);
|
2017-12-22 23:42:43 -05:00
|
|
|
if (integrationScreens.includes(screen)) return {category: category, type: type};
|
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
|
|
|
}
|
|
|
|
}
|