mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
|
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 GoogleConfig {
|
||
|
api_key: string;
|
||
|
cx: string; // search engine id
|
||
|
}
|
||
|
|
||
|
@Component({
|
||
|
templateUrl: "./google.component.html",
|
||
|
styleUrls: ["./google.component.scss", "../config-dialog.scss"],
|
||
|
})
|
||
|
export class AdminNebGoogleConfigComponent implements ModalComponent<NebBotConfigurationDialogContext>, OnInit {
|
||
|
|
||
|
public isLoading = true;
|
||
|
public isUpdating = false;
|
||
|
public config: GoogleConfig;
|
||
|
public integration: FE_Integration;
|
||
|
public neb: FE_NebConfiguration;
|
||
|
|
||
|
constructor(public dialog: DialogRef<NebBotConfigurationDialogContext>,
|
||
|
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");
|
||
|
});
|
||
|
}
|
||
|
}
|