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

     1  
     2  
     3  
     4  import { AsyncSubject } from 'rxjs';
     5  import {HttpClient, HttpHeaders } from '@angular/common/http';
     6  import { AuthService } from '../services/auth.service';
     7  import { environment } from '../../environments/environment';
     8  
     9  
    10  export class DeploymentList {
    11    constructor(public deployments: string[], public services: string[]) { }
    12  }
    13  
    14  import { Injectable } from '@angular/core';
    15  
    16  @Injectable()
    17  export class DeploymentListService {
    18  
    19    private dl$: AsyncSubject<DeploymentList>
    20    private dl: DeploymentList = new DeploymentList([], [])
    21  
    22    constructor(private http: HttpClient, private auth: AuthService) { } 
    23  
    24    dateOptions = { year: "numeric", month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", timeZoneName: "short"} as const;
    25  
    26    getDeploymentList(serviceName: string) {
    27      this.dl$ = new AsyncSubject<DeploymentList>()
    28      this.dl.deployments = []
    29      this.getDeployments(serviceName)
    30      this.getServices()
    31      return this.dl$
    32    }
    33  
    34    getDeployments(serviceName: string) {
    35      var url
    36      if(serviceName == "") {
    37        url = "/ecs-deploy/api/v1/deploy/list"
    38      } else {
    39        url = "/ecs-deploy/api/v1/deploy/list/" + serviceName
    40      }
    41      this.http.get(url, {headers: new HttpHeaders().set('Authorization', "Bearer " + this.auth.getToken())})
    42        .subscribe(data => {
    43        // Read the result field from the JSON response.
    44        this.dl.deployments = data["deployments"]
    45        if(this.dl.deployments == null) {
    46          return
    47        }
    48        for(let i=0; i<this.dl.deployments.length; i++){
    49          this.dl.deployments[i]["Date"] = new Date(this.dl.deployments[i]["Time"]).toLocaleString("en-US", this.dateOptions)
    50          var s = this.dl.deployments[i]["TaskDefinitionArn"].split('/')
    51          if(s.length > 1){
    52            this.dl.deployments[i]["TaskDefinitionVersion"] = s[1]
    53          }
    54        }
    55        this.dl.deployments.sort(function(a,b) {return (a["Time"] > b["Time"]) ? -1 : ((b["Time"] > a["Time"]) ? 1 : 0);} ); 
    56        if(this.dl.services.length > 0) {
    57          this.dl$.next(this.dl)
    58          this.dl$.complete()
    59          console.log("getDeployment: complete()")
    60        } else {
    61          console.log("getDeployments: dl$ complete not triggered")
    62        }
    63      })
    64    }
    65    getServices() {
    66      this.http.get('/ecs-deploy/api/v1/service/list', {headers: new HttpHeaders().set('Authorization', "Bearer " + this.auth.getToken())}).subscribe(data => {
    67        // Read the result field from the JSON response.
    68        this.dl.services = data['services'];
    69        if(this.dl.deployments == null) {
    70          return
    71        }
    72        if(this.dl.deployments.length > 0) {
    73          this.dl$.next(this.dl)
    74          this.dl$.complete()
    75          console.log("getServices: complete()")
    76        } else {
    77          console.log("getServices: dl$ complete not triggered")
    78        }
    79      });
    80      
    81    }
    82  }