account.component.ts 1.44 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
import { Component, OnInit } from '@angular/core';
Lukas Burgey's avatar
Lukas Burgey committed
2
import { DataSource } from '@angular/cdk/collections';
3
import { MatDialog } from '@angular/material/dialog';
Lukas Burgey's avatar
Lukas Burgey committed
4

Lukas Burgey's avatar
Lukas Burgey committed
5
import { UserService } from '../../user.service';
6
7
import { ProfileComponent } from '../profile/profile.component';

Lukas Burgey's avatar
Lukas Burgey committed
8
9
import { SSHKey, NewSSHKey } from '../../types/types.module';
import { SSHKeysDataSource } from './sshkeys-data-source';
Lukas Burgey's avatar
Lukas Burgey committed
10
11
12
13
14
15
16

@Component({
  selector: 'app-account',
  templateUrl: './account.component.html',
  styleUrls: ['./account.component.css']
})
export class AccountComponent implements OnInit {
Lukas Burgey's avatar
Lukas Burgey committed
17
18
19
20
21
22
23
24
25
26
27
28
29

  columns = ['name', 'key', 'action'];

  // ssh upload form
  // does the user want to upload a key?
  upload: boolean;
  formKey: NewSSHKey;
  sshKeyTable: DataSource<SSHKey>;

  // account deletion form
  sure: boolean = false;


Lukas Burgey's avatar
Lukas Burgey committed
30
31
32

  constructor(
    public userService: UserService,
33
    public dialog: MatDialog,
Lukas Burgey's avatar
Lukas Burgey committed
34
  ) {
Lukas Burgey's avatar
Lukas Burgey committed
35
    this.resetKeyUpload();
Lukas Burgey's avatar
Lukas Burgey committed
36
37
38
  }

  ngOnInit() {
Lukas Burgey's avatar
Lukas Burgey committed
39
40
41
    this.sshKeyTable = new SSHKeysDataSource(this.userService);
  }

42
43
44
45
  public openProfile(user) {
    this.dialog.open(
      ProfileComponent,
      {
46
        width: '70%',
47
48
49
50
51
52
53
        data: {
          user: user,
        }
      }
    );
  }

Lukas Burgey's avatar
Lukas Burgey committed
54
55
56
57
58
59
60
61
62
63
64
  resetKeyUpload() {
    this.upload = false;
    this.formKey = {
      name: '',
      key: '',
    }
  }

  uploadKey() {
    this.userService.uploadSshKey(this.formKey);
    this.resetKeyUpload();
Lukas Burgey's avatar
Lukas Burgey committed
65
66
  }

Lukas Burgey's avatar
Lukas Burgey committed
67
68
  keyDeleteable(key: SSHKey): boolean {
    return key.name !== "unity_key";
Lukas Burgey's avatar
Lukas Burgey committed
69
70
  }
}