matrix-dimension/web/app/shared/registry/integrations.registry.ts

75 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-12-22 23:08:10 -05:00
import { Injectable } from "@angular/core";
import {
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";
import { FE_Integration } from "../models/integration";
@Injectable()
export class IntegrationsRegistry {
private static supportedIntegrationsMap = {
"bot": {}, // empty == supported
"complex-bot": {
2017-12-22 23:08:10 -05:00
"rss": {},
"travisci": {},
"circleci": {},
},
"bridge": {
2017-12-22 23:08:10 -05:00
"irc": {},
"telegram": {},
"webhooks": {},
"gitter": {},
},
"widget": {
2017-12-20 23:47:35 -05:00
"custom": {
types: WIDGET_CUSTOM,
},
"youtube": {
types: WIDGET_YOUTUBE
},
"etherpad": {
types: WIDGET_ETHERPAD,
},
"twitch": {
types: WIDGET_TWITCH,
},
"jitsi": {
types: WIDGET_JITSI,
},
2017-12-11 18:43:50 -05:00
"googledocs": {
types: WIDGET_GOOGLE_DOCS,
},
"googlecalendar": {
types: WIDGET_GOOGLE_CALENDAR,
2017-12-11 18:43:50 -05:00
},
},
};
static isSupported(integration: FE_Integration): boolean {
const forType = IntegrationsRegistry.supportedIntegrationsMap[integration.category];
if (!forType) return false;
if (Object.keys(forType).length === 0) return true;
return forType[integration.type]; // has sub type
}
static getIntegrationForScreen(screen: string): { category: string, type: string } {
for (const category of Object.keys(IntegrationsRegistry.supportedIntegrationsMap)) {
for (const type of Object.keys(IntegrationsRegistry.supportedIntegrationsMap[category])) {
const integrationTypes = IntegrationsRegistry.supportedIntegrationsMap[category][type].types;
2017-12-22 23:42:43 -05:00
if (!integrationTypes) continue;
const integrationScreens = integrationTypes.map(t => "type_" + t);
2017-12-22 23:42:43 -05:00
if (integrationScreens.includes(screen)) return {category: category, type: type};
}
}
return null;
}
private constructor() {
}
}