github.com/in4it/ecs-deploy@v0.0.42-0.20240508120354-ed77ff16df25/webapp/src/app/service-detail/confirm.component.ts (about)

     1  import { Component, OnInit, ViewChild, Output, EventEmitter } from '@angular/core';
     2  import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
     3  import { ServiceDetail, ServiceDetailService }  from './service-detail.service';
     4  
     5  import * as moment from 'moment';
     6  
     7  @Component({
     8    selector: 'app-service-detail-confirm',
     9    templateUrl: './confirm.component.html',
    10  })
    11  export class ConfirmChildComponent implements OnInit {
    12  
    13    closeResult: string;
    14    selectedItem: string;
    15    loading: boolean = false;
    16    serviceName: string;
    17    confirmType: string;
    18  
    19    @ViewChild('confirm', { static: true }) confirmModal : NgbModal;
    20  
    21    @Output() deletedItem: EventEmitter<any> = new EventEmitter<any>();
    22    @Output() deletingItem: EventEmitter<any> = new EventEmitter<any>();
    23  
    24  
    25    constructor(
    26      private modalService: NgbModal,
    27      private sds: ServiceDetailService
    28    ) {}
    29  
    30    ngOnInit(): void { 
    31  
    32    }
    33  
    34    open(action, confirmType, serviceName, selectedItem) {
    35      if(!selectedItem) {
    36        return
    37      }
    38      this.loading = true
    39      this.serviceName = serviceName
    40      this.selectedItem = selectedItem
    41      this.confirmType = confirmType
    42      this.modalService.open(this.confirmModal, { windowClass: 'confirm-modal' } ).result.then((result) => {
    43        this.closeResult = `Closed with: ${result}`;
    44        if(result == "DeleteItem") {
    45          if(action == 'deleteParameter') {
    46            this.loading = true
    47            this.deletingItem.emit(true)
    48            this.sds.deleteParameter(this.serviceName, selectedItem).subscribe(data => {
    49              this.loading = false
    50              this.deletingItem.emit(false)
    51              this.deletedItem.emit({ "action": action, "selectedItem": selectedItem })
    52            })
    53          } else if(action == 'deleteAutoscalingPolicy') {
    54            this.loading = true
    55            this.deletingItem.emit(true)
    56            this.sds.deleteAutoscalingPolicy(this.serviceName, selectedItem).subscribe(data => {
    57              this.loading = false
    58              this.deletingItem.emit(false)
    59              this.deletedItem.emit({ "action": action, "selectedItem": selectedItem })
    60            })
    61          } else if(action == 'disableAutoscaling') {
    62            this.loading = true
    63            this.deletingItem.emit(true)
    64            this.sds.disableAutoscaling(this.serviceName).subscribe(data => {
    65              this.loading = false
    66              this.deletingItem.emit(false)
    67              this.deletedItem.emit({ "action": action, "selectedItem": "" })
    68            })
    69          }
    70        }
    71      }, (reason) => {
    72        this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    73      });
    74    }
    75    private getDismissReason(reason: any): string {
    76      if (reason === ModalDismissReasons.ESC) {
    77        return 'by pressing ESC';
    78      } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
    79        return 'by clicking on a backdrop';
    80      } else {
    81        return  `with: ${reason}`;
    82      }
    83    }
    84  }