From 6b4f33de24f60e3d164ce17d8adddc80c68f11cc Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 24 Mar 2018 21:55:35 -0600 Subject: [PATCH] Add the configuration screen for Imgur --- .../neb/config/imgur/imgur.component.html | 32 +++++++++++ .../neb/config/imgur/imgur.component.scss | 0 .../admin/neb/config/imgur/imgur.component.ts | 54 +++++++++++++++++++ web/app/admin/neb/edit/edit.component.ts | 2 + web/app/app.module.ts | 3 ++ 5 files changed, 91 insertions(+) create mode 100644 web/app/admin/neb/config/imgur/imgur.component.html create mode 100644 web/app/admin/neb/config/imgur/imgur.component.scss create mode 100644 web/app/admin/neb/config/imgur/imgur.component.ts diff --git a/web/app/admin/neb/config/imgur/imgur.component.html b/web/app/admin/neb/config/imgur/imgur.component.html new file mode 100644 index 0000000..ed4e138 --- /dev/null +++ b/web/app/admin/neb/config/imgur/imgur.component.html @@ -0,0 +1,32 @@ +
+
+

Imgur Configuration

+
+
+ +
+
+ + +
+ +
\ No newline at end of file diff --git a/web/app/admin/neb/config/imgur/imgur.component.scss b/web/app/admin/neb/config/imgur/imgur.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/web/app/admin/neb/config/imgur/imgur.component.ts b/web/app/admin/neb/config/imgur/imgur.component.ts new file mode 100644 index 0000000..ac7c404 --- /dev/null +++ b/web/app/admin/neb/config/imgur/imgur.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 ImgurConfig { + client_id: string; + client_secret: string; +} + +@Component({ + templateUrl: "./imgur.component.html", + styleUrls: ["./imgur.component.scss", "../config-dialog.scss"], +}) +export class AdminNebImgurConfigComponent implements ModalComponent, OnInit { + + public isLoading = true; + public isUpdating = false; + public config: ImgurConfig; + 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.ts b/web/app/admin/neb/edit/edit.component.ts index 4f032b0..1facf5f 100644 --- a/web/app/admin/neb/edit/edit.component.ts +++ b/web/app/admin/neb/edit/edit.component.ts @@ -11,6 +11,7 @@ import { NebBotConfigurationDialogContext } from "../config/config-context"; import { ContainerContent } from "ngx-modialog/src/models/tokens"; import { AdminNebGuggyConfigComponent } from "../config/guggy/guggy.component"; import { AdminNebGoogleConfigComponent } from "../config/google/google.component"; +import { AdminNebImgurConfigComponent } from "../config/imgur/imgur.component"; @Component({ @@ -89,6 +90,7 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { if (bot.type === "giphy") component = AdminNebGiphyConfigComponent; if (bot.type === "guggy") component = AdminNebGuggyConfigComponent; if (bot.type === "google") component = AdminNebGoogleConfigComponent; + if (bot.type === "imgur") component = AdminNebImgurConfigComponent; if (!component) throw new Error("No config component for " + bot.type); this.modal.open(component, overlayConfigFactory({ diff --git a/web/app/app.module.ts b/web/app/app.module.ts index 6b3d1b4..aa0a86e 100644 --- a/web/app/app.module.ts +++ b/web/app/app.module.ts @@ -57,6 +57,7 @@ import { AdminNebAppserviceConfigComponent } from "./admin/neb/appservice-config import { AdminNebGiphyConfigComponent } from "./admin/neb/config/giphy/giphy.component"; import { AdminNebGuggyConfigComponent } from "./admin/neb/config/guggy/guggy.component"; import { AdminNebGoogleConfigComponent } from "./admin/neb/config/google/google.component"; +import { AdminNebImgurConfigComponent } from "./admin/neb/config/imgur/imgur.component"; @NgModule({ imports: [ @@ -108,6 +109,7 @@ import { AdminNebGoogleConfigComponent } from "./admin/neb/config/google/google. AdminNebGiphyConfigComponent, AdminNebGuggyConfigComponent, AdminNebGoogleConfigComponent, + AdminNebImgurConfigComponent, // Vendor ], @@ -134,6 +136,7 @@ import { AdminNebGoogleConfigComponent } from "./admin/neb/config/google/google. AdminNebGiphyConfigComponent, AdminNebGuggyConfigComponent, AdminNebGoogleConfigComponent, + AdminNebImgurConfigComponent, ] }) export class AppModule {