github.com/in4it/ecs-deploy@v0.0.42-0.20240508120354-ed77ff16df25/webapp/src/app/service-detail/deploy.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-deploy',
     9    templateUrl: './deploy.component.html',
    10  })
    11  export class DeployChildComponent implements OnInit {
    12  
    13    closeResult: string;
    14    selectedVersion: string;
    15    loading: boolean = false;
    16    serviceName: string;
    17    versionMap: any;
    18  
    19    @ViewChild('deploy', { static: true }) deployModal : NgbModal;
    20  
    21    @Output() deployed: EventEmitter<any> = new EventEmitter<any>();
    22    @Output() deploying: EventEmitter<any> = new EventEmitter<any>();
    23  
    24    constructor(
    25      private modalService: NgbModal,
    26      private sds: ServiceDetailService
    27    ) {}
    28  
    29    ngOnInit(): void { 
    30  
    31    }
    32    setVersionMap(versionMap): void {
    33      this.versionMap = versionMap
    34    }
    35  
    36    open(serviceName, selectedVersion) {
    37      if(!selectedVersion) {
    38        return
    39      }
    40      this.serviceName = serviceName
    41      this.selectedVersion = selectedVersion
    42      this.modalService.open(this.deployModal, { windowClass: 'deploy-modal' } ).result.then((result) => {
    43       this.closeResult = `Closed with: ${result}`;
    44        if(result == "Deploy") {
    45          this.loading = true
    46          this.deploying.emit(true)
    47          this.sds.deploy(serviceName, selectedVersion).subscribe(data => {
    48            this.loading = false
    49            this.deploying.emit(false)
    50            this.deployed.emit(data)
    51          })
    52        }
    53      }, (reason) => {
    54        this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    55      });
    56    }
    57    private getDismissReason(reason: any): string {
    58      if (reason === ModalDismissReasons.ESC) {
    59        return 'by pressing ESC';
    60      } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
    61        return 'by clicking on a backdrop';
    62      } else {
    63        return  `with: ${reason}`;
    64      }
    65    }
    66  }