2018-10-20 16:07:30 -04:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
|
|
|
import {
|
|
|
|
AdminWebhooksBridgeManageSelfhostedComponent,
|
|
|
|
ManageSelfhostedWebhooksBridgeDialogContext
|
|
|
|
} from "./manage-selfhosted/manage-selfhosted.component";
|
|
|
|
import { FE_WebhooksBridge } from "../../../shared/models/webhooks";
|
|
|
|
import { AdminWebhooksApiService } from "../../../shared/services/admin/admin-webhooks-api.service";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2021-08-16 18:00:59 -04:00
|
|
|
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
|
2018-10-20 16:07:30 -04:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./webhooks.component.html",
|
|
|
|
styleUrls: ["./webhooks.component.scss"],
|
|
|
|
})
|
|
|
|
export class AdminWebhooksBridgeComponent implements OnInit {
|
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public isUpdating = false;
|
|
|
|
public configurations: FE_WebhooksBridge[] = [];
|
|
|
|
|
|
|
|
constructor(private webhooksApi: AdminWebhooksApiService,
|
|
|
|
private toaster: ToasterService,
|
2021-08-16 18:00:59 -04:00
|
|
|
private modal: NgbModal,
|
2020-10-23 07:30:20 -04:00
|
|
|
public translate: TranslateService) {
|
|
|
|
this.translate = translate;
|
2018-10-20 16:07:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.reload().then(() => this.isLoading = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async reload(): Promise<any> {
|
|
|
|
try {
|
|
|
|
this.configurations = await this.webhooksApi.getBridges();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Error loading bridges').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2018-10-20 16:07:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public addSelfHostedBridge() {
|
2021-08-16 18:00:59 -04:00
|
|
|
const selfhostedRef = this.modal.open(AdminWebhooksBridgeManageSelfhostedComponent, {
|
|
|
|
backdrop: 'static',
|
2018-10-20 16:07:30 -04:00
|
|
|
size: 'lg',
|
2021-08-16 18:00:59 -04:00
|
|
|
});
|
|
|
|
selfhostedRef.result.then(() => {
|
|
|
|
try {
|
|
|
|
this.reload()
|
|
|
|
} catch (err) {
|
2018-10-20 16:07:30 -04:00
|
|
|
console.error(err);
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Failed to get an update Webhooks bridge list').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2021-08-16 18:00:59 -04:00
|
|
|
}
|
2018-10-20 16:07:30 -04:00
|
|
|
});
|
2021-08-16 18:00:59 -04:00
|
|
|
const selfhostedInstance = selfhostedRef.componentInstance as ManageSelfhostedWebhooksBridgeDialogContext;
|
|
|
|
selfhostedInstance.provisionUrl = '';
|
|
|
|
selfhostedInstance.sharedSecret = '';
|
|
|
|
selfhostedInstance.allowMxPuppets = false;
|
|
|
|
selfhostedInstance.allowTgPuppets = false;
|
2018-10-20 16:07:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public editBridge(bridge: FE_WebhooksBridge) {
|
2021-08-16 18:00:59 -04:00
|
|
|
const selfhostedRef = this.modal.open(AdminWebhooksBridgeManageSelfhostedComponent, {
|
|
|
|
backdrop: 'static',
|
2018-10-20 16:07:30 -04:00
|
|
|
size: 'lg',
|
2021-08-16 18:00:59 -04:00
|
|
|
});
|
|
|
|
selfhostedRef.result.then(() => {
|
|
|
|
try {
|
|
|
|
this.reload()
|
|
|
|
} catch (err) {
|
2018-10-20 16:07:30 -04:00
|
|
|
console.error(err);
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Failed to get an update Webhooks bridge list').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2021-08-16 18:00:59 -04:00
|
|
|
}
|
2018-10-20 16:07:30 -04:00
|
|
|
});
|
2021-08-16 18:00:59 -04:00
|
|
|
const selfhostedInstance = selfhostedRef.componentInstance as ManageSelfhostedWebhooksBridgeDialogContext;
|
|
|
|
selfhostedInstance.provisionUrl = bridge.provisionUrl;
|
|
|
|
selfhostedInstance.sharedSecret = bridge.sharedSecret
|
|
|
|
selfhostedInstance.bridgeId = bridge.id;
|
|
|
|
selfhostedInstance.isAdding = !bridge.id;
|
2018-10-20 16:07:30 -04:00
|
|
|
}
|
|
|
|
}
|