ssh-keys.component.ts 989 Bytes
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1 2 3
import { Component, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material';

Lukas Burgey's avatar
Lukas Burgey committed
4 5
import { UserService } from '../../user.service';
import { SSHKey, NewSSHKey } from '../../types/types.module';
Lukas Burgey's avatar
Lukas Burgey committed
6 7 8 9 10 11 12 13

@Component({
  selector: 'app-ssh-keys',
  templateUrl: './ssh-keys.component.html',
  styleUrls: ['./ssh-keys.component.css']
})
export class SshKeysComponent implements OnInit {
  columns = ['name', 'key', 'action'];
Lukas Burgey's avatar
Lukas Burgey committed
14
  // does the user want to upload a key?
Lukas Burgey's avatar
Lukas Burgey committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  upload: boolean;
  newKeyName: string;
  newKeyKey: string;

  constructor(
    public userService: UserService
  ) { }

  ngOnInit() {
    this.upload = false;
    this.newKeyName = '';
    this.newKeyKey = '';
  }

  public uploadKey() {
30 31 32 33
    const newKey: NewSSHKey = {
      name: this.newKeyName,
      key: this.newKeyKey,
    };
Lukas Burgey's avatar
Lukas Burgey committed
34
    this.userService.uploadSshKey(newKey);
Lukas Burgey's avatar
Lukas Burgey committed
35 36 37
    this.ngOnInit();
  }

38 39
  public deleteKey(key: SSHKey) {
    this.userService.removeSshKey(key);
Lukas Burgey's avatar
Lukas Burgey committed
40 41 42 43
    this.ngOnInit();
  }
}