From 21aba80f549d8188ad9812cd5947edfbcc4f4678 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 24 Mar 2018 21:17:44 -0600 Subject: [PATCH] Add the configuration screen for Giphy --- src/api/admin/AdminNebService.ts | 8 ++- web/app/admin/neb/config/config-context.ts | 8 +++ web/app/admin/neb/config/config-dialog.scss | 3 ++ .../neb/config/giphy/giphy.component.html | 33 ++++++++++++ .../neb/config/giphy/giphy.component.scss | 0 .../admin/neb/config/giphy/giphy.component.ts | 54 +++++++++++++++++++ web/app/admin/neb/edit/edit.component.html | 2 +- web/app/admin/neb/edit/edit.component.ts | 20 +++++-- web/app/app.module.ts | 3 ++ 9 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 web/app/admin/neb/config/config-context.ts create mode 100644 web/app/admin/neb/config/config-dialog.scss create mode 100644 web/app/admin/neb/config/giphy/giphy.component.html create mode 100644 web/app/admin/neb/config/giphy/giphy.component.scss create mode 100644 web/app/admin/neb/config/giphy/giphy.component.ts diff --git a/src/api/admin/AdminNebService.ts b/src/api/admin/AdminNebService.ts index 278e86d..91121c9 100644 --- a/src/api/admin/AdminNebService.ts +++ b/src/api/admin/AdminNebService.ts @@ -49,14 +49,18 @@ export class AdminNebService { @Path(":id/integration/:type/enabled") public async setIntegrationEnabled(@QueryParam("scalar_token") scalarToken: string, @PathParam("id") nebId: number, @PathParam("type") integrationType: string, request: SetEnabledRequest): Promise { await AdminService.validateAndGetAdminTokenOwner(scalarToken); - return NebStore.setIntegrationEnabled(nebId, integrationType, request.enabled); + await NebStore.setIntegrationEnabled(nebId, integrationType, request.enabled); + Cache.for(CACHE_NEB).clear(); + return {}; // 200 OK } @POST @Path(":id/integration/:type/config") public async setIntegrationConfig(@QueryParam("scalar_token") scalarToken: string, @PathParam("id") nebId: number, @PathParam("type") integrationType: string, newConfig: any): Promise { await AdminService.validateAndGetAdminTokenOwner(scalarToken); - return NebStore.setIntegrationConfig(nebId, integrationType, newConfig); + await NebStore.setIntegrationConfig(nebId, integrationType, newConfig); + Cache.for(CACHE_NEB).clear(); + return {}; // 200 OK } @GET diff --git a/web/app/admin/neb/config/config-context.ts b/web/app/admin/neb/config/config-context.ts new file mode 100644 index 0000000..a5f6d7f --- /dev/null +++ b/web/app/admin/neb/config/config-context.ts @@ -0,0 +1,8 @@ +import { BSModalContext } from "ngx-modialog/plugins/bootstrap"; +import { FE_Integration } from "../../../shared/models/integration"; +import { FE_NebConfiguration } from "../../../shared/models/admin-responses"; + +export class NebBotConfigurationDialogContext extends BSModalContext { + public integration: FE_Integration; + public neb: FE_NebConfiguration; +} \ No newline at end of file diff --git a/web/app/admin/neb/config/config-dialog.scss b/web/app/admin/neb/config/config-dialog.scss new file mode 100644 index 0000000..0cb632f --- /dev/null +++ b/web/app/admin/neb/config/config-dialog.scss @@ -0,0 +1,3 @@ +.label-block { + margin-bottom: 15px; +} \ No newline at end of file diff --git a/web/app/admin/neb/config/giphy/giphy.component.html b/web/app/admin/neb/config/giphy/giphy.component.html new file mode 100644 index 0000000..828ca1f --- /dev/null +++ b/web/app/admin/neb/config/giphy/giphy.component.html @@ -0,0 +1,33 @@ +
+
+

Giphy Configuration

+
+
+ +
+
+ + +
+ +
\ No newline at end of file diff --git a/web/app/admin/neb/config/giphy/giphy.component.scss b/web/app/admin/neb/config/giphy/giphy.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/web/app/admin/neb/config/giphy/giphy.component.ts b/web/app/admin/neb/config/giphy/giphy.component.ts new file mode 100644 index 0000000..eaee6ce --- /dev/null +++ b/web/app/admin/neb/config/giphy/giphy.component.ts @@ -0,0 +1,54 @@ +import { Component, OnInit } from "@angular/core"; +import { ToasterService } from "angular2-toaster"; +import { DialogRef, ModalComponent } from "ngx-modialog"; +import { NebBotConfigurationDialogContext } from "../config-context"; +import { AdminNebApiService } from "../../../../shared/services/admin/admin-neb-api.service"; +import { FE_NebConfiguration } from "../../../../shared/models/admin-responses"; +import { FE_Integration } from "../../../../shared/models/integration"; + +interface GiphyConfig { + api_key: string; + use_downsized: boolean; +} + +@Component({ + templateUrl: "./giphy.component.html", + styleUrls: ["./giphy.component.scss", "../config-dialog.scss"], +}) +export class AdminNebGiphyConfigComponent implements ModalComponent, OnInit { + + public isLoading = true; + public isUpdating = false; + public config: GiphyConfig; + public integration: FE_Integration; + public neb: FE_NebConfiguration; + + constructor(public dialog: DialogRef, + private adminNebApi: AdminNebApiService, + private toaster: ToasterService) { + this.neb = dialog.context.neb; + this.integration = dialog.context.integration; + } + + public ngOnInit() { + this.adminNebApi.getIntegrationConfiguration(this.neb.id, this.integration.type).then(config => { + this.config = config; + this.isLoading = false; + }).catch(err => { + console.error(err); + this.toaster.pop("error", "Error loading configuration"); + }); + } + + public save() { + this.isUpdating = true; + this.adminNebApi.setIntegrationConfiguration(this.neb.id, this.integration.type, this.config).then(() => { + this.toaster.pop("success", "Configuration updated"); + this.dialog.close(); + }).catch(err => { + this.isUpdating = false; + console.error(err); + this.toaster.pop("error", "Error updating integration"); + }); + } +} diff --git a/web/app/admin/neb/edit/edit.component.html b/web/app/admin/neb/edit/edit.component.html index 1fb290b..3d50063 100644 --- a/web/app/admin/neb/edit/edit.component.html +++ b/web/app/admin/neb/edit/edit.component.html @@ -20,7 +20,7 @@ {{ bot.displayName }} {{ bot.description }} - diff --git a/web/app/admin/neb/edit/edit.component.ts b/web/app/admin/neb/edit/edit.component.ts index 151307c..b6f45ff 100644 --- a/web/app/admin/neb/edit/edit.component.ts +++ b/web/app/admin/neb/edit/edit.component.ts @@ -5,6 +5,9 @@ import { ActivatedRoute } from "@angular/router"; import { ToasterService } from "angular2-toaster"; import { FE_Integration } from "../../../shared/models/integration"; import { NEB_HAS_CONFIG } from "../../../shared/models/neb"; +import { Modal, overlayConfigFactory } from "ngx-modialog"; +import { AdminNebGiphyConfigComponent } from "../config/giphy/giphy.component"; +import { NebBotConfigurationDialogContext } from "../config/config-context"; @Component({ @@ -21,7 +24,10 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { private subscription: any; private overlappingTypes: string[] = []; - constructor(private nebApi: AdminNebApiService, private route: ActivatedRoute, private toaster: ToasterService) { + constructor(private nebApi: AdminNebApiService, + private route: ActivatedRoute, + private modal: Modal, + private toaster: ToasterService) { } public ngOnInit() { @@ -39,7 +45,7 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { } public hasConfig(bot: FE_Integration): boolean { - return NEB_HAS_CONFIG.indexOf(bot.type) !== -1; + return NEB_HAS_CONFIG.indexOf(bot.type) !== -1 && !this.isUpstream; } public async toggleBot(bot: FE_Integration) { @@ -59,7 +65,7 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { } // Only update the service configuration if - if (bot.isEnabled) { + if (bot.isEnabled && !this.isUpstream) { if (this.hasConfig(bot)) { this.editBot(bot); } else { @@ -75,7 +81,13 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { } public editBot(bot: FE_Integration) { - console.log(bot); + this.modal.open(AdminNebGiphyConfigComponent, overlayConfigFactory({ + neb: this.nebConfig, + integration: bot, + + isBlocking: true, + size: 'lg', + }, NebBotConfigurationDialogContext)); } private loadNeb(nebId: number) { diff --git a/web/app/app.module.ts b/web/app/app.module.ts index 72f7e25..44f4530 100644 --- a/web/app/app.module.ts +++ b/web/app/app.module.ts @@ -54,6 +54,7 @@ import { AdminNebComponent } from "./admin/neb/neb.component"; import { AdminEditNebComponent } from "./admin/neb/edit/edit.component"; import { AdminAddSelfhostedNebComponent } from "./admin/neb/add-selfhosted/add-selfhosted.component"; import { AdminNebAppserviceConfigComponent } from "./admin/neb/appservice-config/appservice-config.component"; +import { AdminNebGiphyConfigComponent } from "./admin/neb/config/giphy/giphy.component"; @NgModule({ imports: [ @@ -102,6 +103,7 @@ import { AdminNebAppserviceConfigComponent } from "./admin/neb/appservice-config AdminEditNebComponent, AdminAddSelfhostedNebComponent, AdminNebAppserviceConfigComponent, + AdminNebGiphyConfigComponent, // Vendor ], @@ -125,6 +127,7 @@ import { AdminNebAppserviceConfigComponent } from "./admin/neb/appservice-config AdminWidgetEtherpadConfigComponent, AdminWidgetJitsiConfigComponent, AdminNebAppserviceConfigComponent, + AdminNebGiphyConfigComponent, ] }) export class AppModule {