matrix-dimension/web/app/admin/neb/config/guggy/guggy.component.ts

54 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-03-24 23:44:05 -04:00
import { Component, OnInit } from "@angular/core";
import { ToasterService } from "angular2-toaster";
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";
import { TranslateService } from "@ngx-translate/core";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
2018-03-24 23:44:05 -04:00
interface GuggyConfig {
api_key: string;
}
@Component({
templateUrl: "./guggy.component.html",
styleUrls: ["./guggy.component.scss", "../config-dialog.scss"],
})
export class AdminNebGuggyConfigComponent implements OnInit {
2018-03-24 23:44:05 -04:00
public isLoading = true;
public isUpdating = false;
public config: GuggyConfig;
public integration: FE_Integration;
public neb: FE_NebConfiguration;
constructor(public modal: NgbActiveModal,
2018-03-24 23:44:05 -04:00
private adminNebApi: AdminNebApiService,
private toaster: ToasterService,
public translate: TranslateService) {
this.translate = translate;
2018-03-24 23:44:05 -04:00
}
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.translate.get('Error loading configuration').subscribe((res: string) => {this.toaster.pop("error", res); });
2018-03-24 23:44:05 -04:00
});
}
public save() {
this.isUpdating = true;
this.adminNebApi.setIntegrationConfiguration(this.neb.id, this.integration.type, this.config).then(() => {
this.translate.get('Configuration updated').subscribe((res: string) => {this.toaster.pop("success", res); });
this.modal.close();
2018-03-24 23:44:05 -04:00
}).catch(err => {
this.isUpdating = false;
console.error(err);
this.translate.get('Error updating integration').subscribe((res: string) => {this.toaster.pop("error", res); });
2018-03-24 23:44:05 -04:00
});
}
}