2018-10-20 16:07:30 -04:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
|
|
|
import { Modal, overlayConfigFactory } from "ngx-modialog";
|
|
|
|
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";
|
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,
|
2020-10-23 07:30:20 -04:00
|
|
|
private modal: Modal,
|
|
|
|
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() {
|
|
|
|
this.modal.open(AdminWebhooksBridgeManageSelfhostedComponent, overlayConfigFactory({
|
|
|
|
isBlocking: true,
|
|
|
|
size: 'lg',
|
|
|
|
|
|
|
|
provisionUrl: '',
|
|
|
|
sharedSecret: '',
|
|
|
|
allowPuppets: false,
|
|
|
|
}, ManageSelfhostedWebhooksBridgeDialogContext)).result.then(() => {
|
|
|
|
this.reload().catch(err => {
|
|
|
|
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); });
|
2018-10-20 16:07:30 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public editBridge(bridge: FE_WebhooksBridge) {
|
|
|
|
this.modal.open(AdminWebhooksBridgeManageSelfhostedComponent, overlayConfigFactory({
|
|
|
|
isBlocking: true,
|
|
|
|
size: 'lg',
|
|
|
|
|
|
|
|
provisionUrl: bridge.provisionUrl,
|
|
|
|
sharedSecret: bridge.sharedSecret,
|
|
|
|
bridgeId: bridge.id,
|
|
|
|
}, ManageSelfhostedWebhooksBridgeDialogContext)).result.then(() => {
|
|
|
|
this.reload().catch(err => {
|
|
|
|
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); });
|
2018-10-20 16:07:30 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|