service.component.ts 1.28 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
import { Component, OnInit, Input } from '@angular/core';
2
import { MatCheckboxChange } from '@angular/material/checkbox';
Lukas Burgey's avatar
Lukas Burgey committed
3

4
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Lukas Burgey's avatar
Lukas Burgey committed
5

Lukas Burgey's avatar
Lukas Burgey committed
6
import { UserService } from '../user.service';
Lukas Burgey's avatar
Lukas Burgey committed
7
import { DialogService } from '../dialogues/dialog.service';
Lukas Burgey's avatar
Lukas Burgey committed
8

Lukas Burgey's avatar
Lukas Burgey committed
9 10
import * as t from '../types/types.module';

Lukas Burgey's avatar
Lukas Burgey committed
11 12 13 14 15 16
@Component({
  selector: 'app-service',
  templateUrl: './service.component.html',
  styleUrls: ['./service.component.css']
})
export class ServiceComponent implements OnInit {
17
  @Input() service: t.Service;
Lukas Burgey's avatar
Lukas Burgey committed
18
  @Input() deployment: t.Deployment;
Lukas Burgey's avatar
Lukas Burgey committed
19 20 21

  constructor(
    public userService: UserService,
22
    public dialog: DialogService,
Lukas Burgey's avatar
Lukas Burgey committed
23
    public http: HttpClient,
Lukas Burgey's avatar
Lukas Burgey committed
24 25 26 27 28 29
  ) {
  }

  ngOnInit() {
  }

Lukas Burgey's avatar
Lukas Burgey committed
30
  public stateItem(site: t.Site): t.DeploymentState | undefined {
Lukas Burgey's avatar
Lukas Burgey committed
31
    if (this.deployment) {
Lukas Burgey's avatar
Lukas Burgey committed
32
      return this.deployment.states.find(
33 34
        item => {
          return item.site.id === site.id
Lukas Burgey's avatar
Lukas Burgey committed
35 36 37
        }
      );
    }
38
    return undefined;
Lukas Burgey's avatar
Lukas Burgey committed
39 40
  }

41
  public changeDeployment(action: string) {
Lukas Burgey's avatar
Lukas Burgey committed
42 43 44 45 46 47 48 49 50 51 52
    const body = {
      'type': action,
      'service': this.service.id,
    };
    return this.http.post('/backend/api/deployments', body).subscribe(
      (newDep: t.Deployment) => {
        // update the deployment
        this.deployment = newDep;
      },
    );
  }
Lukas Burgey's avatar
Lukas Burgey committed
53
}