Add ability to add self-hosted IRC bridges

This commit is contained in:
Travis Ralston 2018-03-31 11:45:19 -06:00
parent aa8ec0ed58
commit 1e437a2f8b
6 changed files with 76 additions and 2 deletions

View File

@ -0,0 +1,24 @@
<div class="dialog">
<div class="dialog-header">
<h4>Add a new self-hosted IRC Bridge</h4>
</div>
<div class="dialog-content">
<p>Self-hosted IRC bridges must have <code>provisioning</code> enabled in the configuration.</p>
<label class="label-block">
Provisioning URL
<span class="text-muted ">The provisioning URL for the bridge. This is usually the same as the URL given in the registration. This API is not authenticated and should be treated with caution.</span>
<input type="text" class="form-control"
placeholder="http://localhost:9999"
[(ngModel)]="provisionUrl" [disabled]="isSaving"/>
</label>
</div>
<div class="dialog-footer">
<button type="button" (click)="add()" title="close" class="btn btn-primary btn-sm">
<i class="far fa-save"></i> Save
</button>
<button type="button" (click)="dialog.close()" title="close" class="btn btn-secondary btn-sm">
<i class="far fa-times-circle"></i> Cancel
</button>
</div>
</div>

View File

@ -0,0 +1,35 @@
import { Component } from "@angular/core";
import { ToasterService } from "angular2-toaster";
import { DialogRef, ModalComponent } from "ngx-modialog";
import { BSModalContext } from "ngx-modialog/plugins/bootstrap";
import { AdminIrcApiService } from "../../../../shared/services/admin/admin-irc-api.service";
export class AddSelfhostedIrcBridgeDialogContext extends BSModalContext {
}
@Component({
templateUrl: "./add-selfhosted.component.html",
styleUrls: ["./add-selfhosted.component.scss"],
})
export class AdminIrcBridgeAddSelfhostedComponent implements ModalComponent<AddSelfhostedIrcBridgeDialogContext> {
public isSaving = false;
public provisionUrl: string;
constructor(public dialog: DialogRef<AddSelfhostedIrcBridgeDialogContext>,
private ircApi: AdminIrcApiService,
private toaster: ToasterService) {
}
public add() {
this.isSaving = true;
this.ircApi.newSelfhosted(this.provisionUrl).then(() => {
this.toaster.pop("success", "IRC Bridge added");
this.dialog.close();
}).catch(err => {
console.error(err);
this.isSaving = false;
this.toaster.pop("error", "Failed to create IRC bridge");
});
}
}

View File

@ -25,7 +25,7 @@
<tr *ngFor="let bridge of configurations trackById">
<td>
{{ bridge.upstreamId ? "matrix.org's bridge" : "Self-hosted bridge" }}
<span class="text-muted" style="display: inline-block;" *ngIf="!bridge.upstreamId">({{ bridge.adminUrl }})</span>
<span class="text-muted" style="display: inline-block;" *ngIf="!bridge.upstreamId">({{ bridge.provisionUrl }})</span>
</td>
<td>
{{ getEnabledNetworksString(bridge) }}

View File

@ -6,6 +6,10 @@ import { AdminUpstreamApiService } from "../../../shared/services/admin/admin-up
import { FE_IrcBridge } from "../../../shared/models/irc";
import { Modal, overlayConfigFactory } from "ngx-modialog";
import { AdminIrcBridgeNetworksComponent, IrcNetworksDialogContext } from "./networks/networks.component";
import {
AddSelfhostedIrcBridgeDialogContext,
AdminIrcBridgeAddSelfhostedComponent
} from "./add-selfhosted/add-selfhosted.component";
@Component({
templateUrl: "./irc.component.html",
@ -87,7 +91,15 @@ export class AdminIrcBridgeComponent implements OnInit {
}
public addSelfHostedBridge() {
console.log("TODO: Dialog");
this.modal.open(AdminIrcBridgeAddSelfhostedComponent, overlayConfigFactory({
isBlocking: true,
size: 'lg',
}, AddSelfhostedIrcBridgeDialogContext)).result.then(() => {
this.reload().catch(err => {
console.error(err);
this.toaster.pop("error", "Failed to get an update IRC bridge list");
});
});
}
public editNetworks(bridge: FE_IrcBridge) {

View File

@ -67,6 +67,7 @@ import { AdminBridgesComponent } from "./admin/bridges/bridges.component";
import { AdminIrcBridgeComponent } from "./admin/bridges/irc/irc.component";
import { AdminIrcApiService } from "./shared/services/admin/admin-irc-api.service";
import { AdminIrcBridgeNetworksComponent } from "./admin/bridges/irc/networks/networks.component";
import { AdminIrcBridgeAddSelfhostedComponent } from "./admin/bridges/irc/add-selfhosted/add-selfhosted.component";
@NgModule({
imports: [
@ -127,6 +128,7 @@ import { AdminIrcBridgeNetworksComponent } from "./admin/bridges/irc/networks/ne
AdminBridgesComponent,
AdminIrcBridgeComponent,
AdminIrcBridgeNetworksComponent,
AdminIrcBridgeAddSelfhostedComponent,
// Vendor
],
@ -157,6 +159,7 @@ import { AdminIrcBridgeNetworksComponent } from "./admin/bridges/irc/networks/ne
AdminNebImgurConfigComponent,
ConfigSimpleBotComponent,
AdminIrcBridgeNetworksComponent,
AdminIrcBridgeAddSelfhostedComponent,
]
})
export class AppModule {