/**
* @file K8 Action Component
*/
-import { Component, Injector } from '@angular/core';
+import { HttpHeaders } from '@angular/common/http';
+import { ChangeDetectorRef, Component, Injector } from '@angular/core';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
-import { MODALCLOSERESPONSEDATA } from 'CommonModel';
+import { NotifierService } from 'angular-notifier';
+import { ERRORDATA, GETAPIURLHEADER, MODALCLOSERESPONSEDATA } from 'CommonModel';
import { DeleteComponent } from 'DeleteComponent';
+import { environment } from 'environment';
import { K8sAddClusterComponent } from 'K8sAddClusterComponent';
import { K8sAttachProfileComponent } from 'K8sAttachProfileComponent';
import { K8sInfraConfigAddComponent } from 'K8sInfraConfigAddComponent';
import { INFRACONFIGPAYLOAD, K8SCLUSTERDATADISPLAY, K8SPayload, K8SREPODATADISPLAY } from 'K8sModel';
import { KSUAddComponent } from 'KSUAddComponent';
-import { SharedService } from 'SharedService';
+import { RestService } from 'RestService';
+import { isNullOrUndefined, SharedService } from 'SharedService';
import { ShowInfoComponent } from 'ShowInfoComponent';
/**
* Creating component
/** Check cluster or not @public */
public isCluster = false;
+ /** Check the loading results for loader status @public */
+ public isLoadingDownloadResult: boolean = false;
+
/** Instance of the modal service @private */
private modalService: NgbModal;
/** Contains instance ID @private */
private instanceID: string;
+ /** Utilizes rest service for any CRUD operations @private */
+ private restService: RestService;
+
+ /** Notifier service to popup notification @private */
+ private notifierService: NotifierService;
+
+ /** Detect changes for the User Input */
+ private cd: ChangeDetectorRef;
+
+ /** Set timeout @private */
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
+ private timeOut: number = 1000;
+
+ /** Controls the header form @private */
+ private headers: HttpHeaders;
+
constructor(injector: Injector) {
this.injector = injector;
this.modalService = this.injector.get(NgbModal);
+ this.notifierService = this.injector.get(NotifierService);
this.sharedService = this.injector.get(SharedService);
this.translateService = this.injector.get(TranslateService);
+ this.restService = this.injector.get(RestService);
+ this.cd = this.injector.get(ChangeDetectorRef);
}
/**
* Lifecyle Hooks the trigger before component is instantiate
*/
public ngOnInit(): void {
+ this.headers = new HttpHeaders({
+ Accept: 'application/zip, application/json',
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+ });
this.instanceID = this.value.identifier;
this.getK8sType = this.value.pageType;
this.state = this.value.state;
});
}
+ /** Download credentials @public */
+ public getCredentials(): void {
+ this.isLoadingDownloadResult = true;
+ const httpOptions: GETAPIURLHEADER = {
+ headers: this.headers,
+ responseType: 'blob'
+ };
+ this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.instanceID + '/get_creds')
+ .subscribe((res: { op_id: string }) => {
+ if (!isNullOrUndefined(res.op_id)) {
+ this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.instanceID + '/get_creds_file' + '/' + res.op_id, httpOptions)
+ .subscribe((response: Blob) => {
+ this.isLoadingDownloadResult = true;
+ if (!isNullOrUndefined(response)) {
+ this.isLoadingDownloadResult = false;
+ const binaryData: Blob[] = [];
+ binaryData.push(response);
+ this.sharedService.downloadFiles(this.value.name, binaryData, response.type);
+ this.isLoadingDownloadResult = false;
+ this.changeDetactionforDownload();
+ }
+ }, (error: ERRORDATA) => {
+ this.isLoadingDownloadResult = false;
+ this.notifierService.notify('error', this.translateService.instant('ERROR'));
+ this.changeDetactionforDownload();
+ if (typeof error.error === 'object') {
+ error.error.text().then((data: string): void => {
+ error.error = JSON.parse(data);
+ this.restService.handleError(error, 'getBlob');
+ });
+ }
+ });
+ }
+ }, (error: ERRORDATA) => {
+ this.isLoadingDownloadResult = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+
/** Clone KSU @public */
public cloneKsu(): void {
// eslint-disable-next-line security/detect-non-literal-fs-filename
// Catch Navigation Error
});
}
+
+ /** Change the detaction @public */
+ public changeDetactionforDownload(): void {
+ setTimeout(() => {
+ this.cd.detectChanges();
+ }, this.timeOut);
+ }
}