state.component.ts 4.09 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Component, OnInit, Input } from '@angular/core';

import { Observable } from 'rxjs';

import { UserService } from '../user.service';
import { LanguageService } from '../language.service';
import { DialogService } from '../dialogues/dialog.service';
import { Site, Service, DeploymentState } from '../types/types.module';

@Component({
  selector: '[deployment-state-tr]',
  templateUrl: './state.component.html',
  styleUrls: ['./state.component.css']
})
export class StateComponent implements OnInit {

  @Input() service: Service;

Lukas Burgey's avatar
Lukas Burgey committed
19
20
21
22
23
24
  buttonStates: string[] = ['deployed', 'questionnaire', 'failed', 'rejected'];
  public buttonActive = false;
  public buttonColor = '';
  public buttonText = '';
  public buttonTooltip = '';

Lukas Burgey's avatar
Lukas Burgey committed
25
26
  public state$: Observable<DeploymentState>;

Lukas Burgey's avatar
Lukas Burgey committed
27
28
  public stateDescription = '';

Lukas Burgey's avatar
Lukas Burgey committed
29
30
31
32
33
34
35
36
37

  constructor(
    public userService: UserService,
    public lang: LanguageService,
    public dialog: DialogService,
  ) { }

  ngOnInit() {
    this.state$ = this.userService.subscribeStateFor(this.service);
Lukas Burgey's avatar
Lukas Burgey committed
38
39
40
41
    this.state$.subscribe(
      (state: DeploymentState) => {
        switch (state.state) {
          case 'not_deployed':
42
            this.stateDescription = `Your credentials are not deployed for ${ this.service.name }.`;
Lukas Burgey's avatar
Lukas Burgey committed
43
44
45
            this.buttonActive = false;
            break;
          case 'deployment_pending':
46
            this.stateDescription = `Waiting for the deployment of your credentials to ${ this.service.site.name }.`;
Lukas Burgey's avatar
Lukas Burgey committed
47
48
49
            this.buttonActive = false;
            break;
          case 'removal_pending':
50
            this.stateDescription = `Waiting for the removal of your credentials from ${ this.service.site.name }.`;
Lukas Burgey's avatar
Lukas Burgey committed
51
52
53
54
55
56
            this.buttonActive = false;
            break;

          case 'deployed':
            this.buttonActive = true;
            this.buttonColor = 'primary';
57
58
59
60
61
62
            this.buttonText = 'View Credentials';
            this.buttonTooltip = 'View detailed information about the deployed credentials';
            this.stateDescription = `
              The credentials are deployed for this service ${ this.service.name }.
              Click "${ this.buttonText }" see details on your deployed ssh keys and credentials.
            `;
Lukas Burgey's avatar
Lukas Burgey committed
63
64
65
66
67
68
            break;

          case 'questionnaire':
            this.buttonActive = true;
            this.buttonColor = 'warn';
            this.buttonText = 'Submit Data';
69
70
71
72
73
            this.buttonTooltip = 'Submit missing data';
            this.stateDescription = `
              More data is needed to deploy your credentials.
              Please click "${ this.buttonText }" to submit the missing data.
            `;
Lukas Burgey's avatar
Lukas Burgey committed
74
75
76
77
            break;
          case 'failed':
            this.buttonActive = true;
            this.buttonColor = 'warn';
78
            this.buttonText = 'Show Error';
Lukas Burgey's avatar
Lukas Burgey committed
79
            this.buttonTooltip = this.buttonText;
80
81
82
83
            this.stateDescription = `
              The deployment of your credentials failed, but will be tried again.
              Please click "${ this.buttonText }" for more details concerning this error.
            `;
Lukas Burgey's avatar
Lukas Burgey committed
84
85
86
87
            break;
          case 'rejected':
            this.buttonActive = true;
            this.buttonColor = 'warn';
88
            this.buttonText = 'Show message';
Lukas Burgey's avatar
Lukas Burgey committed
89
            this.buttonTooltip = this.buttonText;
90
91
92
93
            this.stateDescription = `
              The deployment of your credentials was rejected.
              Please click "${ this.buttonText }" to show more details.
            `;
Lukas Burgey's avatar
Lukas Burgey committed
94
95
96
            break;

          default:
97
            this.stateDescription = '';
Lukas Burgey's avatar
Lukas Burgey committed
98
99
100
101
            this.buttonActive = false;
        }
      }
    );
Lukas Burgey's avatar
Lukas Burgey committed
102
103
  }

Lukas Burgey's avatar
Lukas Burgey committed
104
  public buttonAction(state: DeploymentState): void {
Lukas Burgey's avatar
Lukas Burgey committed
105
106
    switch (state.state) {
      case 'deployed':
Lukas Burgey's avatar
Lukas Burgey committed
107
        return this.dialog.openCredentials(this.state$);
Lukas Burgey's avatar
Lukas Burgey committed
108
      case 'questionnaire':
Lukas Burgey's avatar
Lukas Burgey committed
109
        return this.dialog.openQuestionnaire(this.state$);
Lukas Burgey's avatar
Lukas Burgey committed
110
      case 'failed':
Lukas Burgey's avatar
Lukas Burgey committed
111
        return this.dialog.openMessage(state);
Lukas Burgey's avatar
Lukas Burgey committed
112
      case 'rejected':
Lukas Burgey's avatar
Lukas Burgey committed
113
        return this.dialog.openMessage(state);
Lukas Burgey's avatar
Lukas Burgey committed
114
115
116
    }
  }

Lukas Burgey's avatar
Lukas Burgey committed
117
118
119
120
  public contactSupport() {
    window.location.href = 'mailto:' + this.service.contact_email + '?subject=%5BFEUDAL%5D%20Help%20request%0A';
  }

Lukas Burgey's avatar
Lukas Burgey committed
121
}