service.component.ts 1.13 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 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

import { UserService } from '../user.service';

@Component({
  selector: 'app-service',
  templateUrl: './service.component.html',
  styleUrls: ['./service.component.css']
})
export class ServiceComponent implements OnInit {
  @Input() serviceData: any;

  constructor(
    public userService: UserService,
  ) {
  }

  ngOnInit() {
  }

22 23 24 25 26 27 28
  public getDeployment() {
    const deployment = this.userService.user.deployments.find(
      d => {
        return d.service.name  === this.serviceData.name;
      }
    );
    return deployment;
Lukas Burgey's avatar
Lukas Burgey committed
29 30
  }

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  public isDeployed(key): boolean {
    const deployment = this.getDeployment();
    if (deployment) {

      return deployment.ssh_keys.some(k => {
        return k.name === key.name;
      });
    }
    return false;
  }

  public deploymentChange(key) {
    console.log('changing', key);
    if (!this.isDeployed(key)) {
      this.userService.addDeployment(this.serviceData.name, key.name);
    } else {
      this.userService.removeDeployment(this.serviceData.name, key.name);
    }
Lukas Burgey's avatar
Lukas Burgey committed
49 50
  }
}