From 74054c3962c6e9a3546f6e9f833a39b873833eaf Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 31 Jan 2018 16:30:08 -0700 Subject: [PATCH] Add ability to create self-hosted go-neb instances They can't be provisioned or configured correctly yet, but they exist. --- .../DimensionAppserviceAdminService.ts | 5 +++ .../add_selfhosted.component.html | 24 ++++++++++++ .../add_selfhosted.component.scss | 0 .../add_selfhosted.component.ts | 38 +++++++++++++++++++ web/app/admin/neb/edit/edit.component.ts | 4 +- web/app/admin/neb/neb.component.html | 5 ++- web/app/admin/neb/neb.component.ts | 7 +++- web/app/admin/widgets/config-dialog.scss | 5 --- web/app/app.module.ts | 2 + web/app/app.routing.ts | 6 +++ .../admin/admin-appservice-api.service.ts | 4 ++ web/style/app.scss | 5 +++ 12 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 web/app/admin/neb/add_selfhosted/add_selfhosted.component.html create mode 100644 web/app/admin/neb/add_selfhosted/add_selfhosted.component.scss create mode 100644 web/app/admin/neb/add_selfhosted/add_selfhosted.component.ts diff --git a/src/api/dimension/DimensionAppserviceAdminService.ts b/src/api/dimension/DimensionAppserviceAdminService.ts index 942058e..b253562 100644 --- a/src/api/dimension/DimensionAppserviceAdminService.ts +++ b/src/api/dimension/DimensionAppserviceAdminService.ts @@ -44,6 +44,11 @@ export class DimensionAppserviceAdminService { @POST @Path("new") public createAppservice(@QueryParam("scalar_token") scalarToken: string, request: AppserviceCreateRequest): Promise { + // Trim off the @ sign if it's on the prefix + if (request.userPrefix[0] === "@") { + request.userPrefix = request.userPrefix.substring(1); + } + return DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken).then(_userId => { return AppserviceStore.getAllByUserPrefix(request.userPrefix); }).then(appservices => { diff --git a/web/app/admin/neb/add_selfhosted/add_selfhosted.component.html b/web/app/admin/neb/add_selfhosted/add_selfhosted.component.html new file mode 100644 index 0000000..b868a69 --- /dev/null +++ b/web/app/admin/neb/add_selfhosted/add_selfhosted.component.html @@ -0,0 +1,24 @@ + +
+

Self-hosted go-neb instances are powered by application services installed on your homeserver. The application service is responsible for creating the bots dynamically.

+ + + + + +
+
\ No newline at end of file diff --git a/web/app/admin/neb/add_selfhosted/add_selfhosted.component.scss b/web/app/admin/neb/add_selfhosted/add_selfhosted.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/web/app/admin/neb/add_selfhosted/add_selfhosted.component.ts b/web/app/admin/neb/add_selfhosted/add_selfhosted.component.ts new file mode 100644 index 0000000..1ccd6d0 --- /dev/null +++ b/web/app/admin/neb/add_selfhosted/add_selfhosted.component.ts @@ -0,0 +1,38 @@ +import { Component } from "@angular/core"; +import { AdminAppserviceApiService } from "../../../shared/services/admin/admin-appservice-api.service"; +import { AdminNebApiService } from "../../../shared/services/admin/admin-neb-api.service"; +import { ToasterService } from "angular2-toaster"; +import { ActivatedRoute, Router } from "@angular/router"; + + +@Component({ + templateUrl: "./add_selfhosted.component.html", + styleUrls: ["./add_selfhosted.component.scss"], +}) +export class AdminAddSelfhostedNebComponent { + + public isSaving = false; + public userPrefix = "@_neb"; + public adminUrl = "http://localhost:4050"; + + constructor(private asApi: AdminAppserviceApiService, + private nebApi: AdminNebApiService, + private toaster: ToasterService, + private router: Router, + private activatedRoute: ActivatedRoute) { + } + + public save(): void { + this.isSaving = true; + this.asApi.createAppservice(this.userPrefix).then(appservice => { + return this.nebApi.newAppserviceConfiguration(this.adminUrl, appservice); + }).then(() => { + this.toaster.pop("success", "New go-neb created"); + this.router.navigate(["../.."], {relativeTo: this.activatedRoute}); + }).catch(err => { + console.error(err); + this.isSaving = false; + this.toaster.pop("error", "Error creating appservice"); + }); + } +} diff --git a/web/app/admin/neb/edit/edit.component.ts b/web/app/admin/neb/edit/edit.component.ts index 245b7b3..52955a2 100644 --- a/web/app/admin/neb/edit/edit.component.ts +++ b/web/app/admin/neb/edit/edit.component.ts @@ -19,8 +19,8 @@ export class AdminEditNebComponent implements OnInit, OnDestroy { public nebConfig: FE_NebConfiguration; private subscription: any; - private overlappingTypes: string[]; - private botTypes: string[]; + private overlappingTypes: string[] = []; + private botTypes: string[] = []; constructor(private nebApi: AdminNebApiService, private route: ActivatedRoute, private toaster: ToasterService) { } diff --git a/web/app/admin/neb/neb.component.html b/web/app/admin/neb/neb.component.html index 11d5803..a80a802 100644 --- a/web/app/admin/neb/neb.component.html +++ b/web/app/admin/neb/neb.component.html @@ -21,7 +21,10 @@ No go-neb configurations. - {{ neb.upstreamId ? "matrix.org's go-neb" : "Self-hosted go-neb" }} + + {{ neb.upstreamId ? "matrix.org's go-neb" : "Self-hosted go-neb" }} + ({{ neb.adminUrl }}) + diff --git a/web/app/admin/neb/neb.component.ts b/web/app/admin/neb/neb.component.ts index 619da60..f81e2a0 100644 --- a/web/app/admin/neb/neb.component.ts +++ b/web/app/admin/neb/neb.component.ts @@ -4,6 +4,7 @@ import { AdminNebApiService } from "../../shared/services/admin/admin-neb-api.se import { AdminUpstreamApiService } from "../../shared/services/admin/admin-upstream-api.service"; import { AdminAppserviceApiService } from "../../shared/services/admin/admin-appservice-api.service"; import { FE_Appservice, FE_NebConfiguration, FE_Upstream } from "../../shared/models/admin_responses"; +import { ActivatedRoute, Router } from "@angular/router"; @Component({ templateUrl: "./neb.component.html", @@ -21,7 +22,9 @@ export class AdminNebComponent { constructor(private nebApi: AdminNebApiService, private upstreamApi: AdminUpstreamApiService, private appserviceApi: AdminAppserviceApiService, - private toaster: ToasterService) { + private toaster: ToasterService, + private router: Router, + private activatedRoute:ActivatedRoute) { this.reload().then(() => this.isLoading = false).catch(error => { console.error(error); @@ -69,7 +72,7 @@ export class AdminNebComponent { } public addSelfHostedNeb() { - console.log("ADD Hosted"); + this.router.navigate(["new", "selfhosted"], {relativeTo: this.activatedRoute}); } public addModularHostedNeb() { diff --git a/web/app/admin/widgets/config-dialog.scss b/web/app/admin/widgets/config-dialog.scss index dd4814b..0cb632f 100644 --- a/web/app/admin/widgets/config-dialog.scss +++ b/web/app/admin/widgets/config-dialog.scss @@ -1,8 +1,3 @@ -.text-muted { - display: block; - font-size: 12px; -} - .label-block { margin-bottom: 15px; } \ No newline at end of file diff --git a/web/app/app.module.ts b/web/app/app.module.ts index ab11e38..61e51c1 100644 --- a/web/app/app.module.ts +++ b/web/app/app.module.ts @@ -52,6 +52,7 @@ import { AdminNebApiService } from "./shared/services/admin/admin-neb-api.servic import { AdminUpstreamApiService } from "./shared/services/admin/admin-upstream-api.service"; 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"; @NgModule({ imports: [ @@ -98,6 +99,7 @@ import { AdminEditNebComponent } from "./admin/neb/edit/edit.component"; AdminWidgetJitsiConfigComponent, AdminNebComponent, AdminEditNebComponent, + AdminAddSelfhostedNebComponent, // Vendor ], diff --git a/web/app/app.routing.ts b/web/app/app.routing.ts index f2ad93f..fe80441 100644 --- a/web/app/app.routing.ts +++ b/web/app/app.routing.ts @@ -18,6 +18,7 @@ import { AdminHomeComponent } from "./admin/home/home.component"; import { AdminWidgetsComponent } from "./admin/widgets/widgets.component"; 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"; const routes: Routes = [ {path: "", component: HomeComponent}, @@ -57,6 +58,11 @@ const routes: Routes = [ path: ":nebId/edit", component: AdminEditNebComponent, data: {breadcrumb: "Edit go-neb", name: "Edit go-neb"}, + }, + { + path: "new/selfhosted", + component: AdminAddSelfhostedNebComponent, + data: {breadcrumb: "Add self-hosted go-neb", name: "Add self-hosted go-neb"}, } ] }, diff --git a/web/app/shared/services/admin/admin-appservice-api.service.ts b/web/app/shared/services/admin/admin-appservice-api.service.ts index 81b2bf3..5263036 100644 --- a/web/app/shared/services/admin/admin-appservice-api.service.ts +++ b/web/app/shared/services/admin/admin-appservice-api.service.ts @@ -12,4 +12,8 @@ export class AdminAppserviceApiService extends AuthedApi { public getAppservices(): Promise { return this.authedGet("/api/v1/dimension/admin/appservices/all").map(r => r.json()).toPromise(); } + + public createAppservice(userPrefix: string): Promise { + return this.authedPost("/api/v1/dimension/admin/appservices/new", {userPrefix: userPrefix}).map(r => r.json()).toPromise(); + } } diff --git a/web/style/app.scss b/web/style/app.scss index 28c6b31..ea70abf 100644 --- a/web/style/app.scss +++ b/web/style/app.scss @@ -35,4 +35,9 @@ button { .label-block { display: block; +} + +.text-muted { + display: block; + font-size: 12px; } \ No newline at end of file