state.component.ts 3.85 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    this.state$.subscribe(
      (state: DeploymentState) => {
        switch (state.state) {
          case 'not_deployed':
            this.stateDescription = `The credentials are not deployed for the service ${ this.service.name }.`;
            this.buttonActive = false;
            break;
          case 'deployment_pending':
            this.stateDescription = `Waiting for the deployment of the credentials to the site ${ this.service.site.name }.`;
            this.buttonActive = false;
            break;
          case 'removal_pending':
            this.stateDescription = `Waiting for the removal of the credentials from the site ${ this.service.site.name }.`;
            this.buttonActive = false;
            break;

          case 'deployed':
            this.stateDescription = `The credentials are deployed for the service ${ this.service.name }. Click to see details.`;
            this.buttonActive = true;
            this.buttonColor = 'primary';
            this.buttonText = 'View credentials';
            this.buttonTooltip = this.buttonText;
            break;

          case 'questionnaire':
            this.stateDescription = `Site ${ this.service.site.name } needs more data to deploy the keys. Please click to submit the data.`;
            this.buttonActive = true;
            this.buttonColor = 'warn';
            this.buttonText = 'Submit Data';
            this.buttonTooltip = this.buttonText;
            break;
          case 'failed':
            this.stateDescription = `Site ${ this.service.site.name } failed to deploy the credentials.
              The deployment will be retried. Click for details.`;
            this.buttonActive = true;
            this.buttonColor = 'warn';
            this.buttonText = 'Submit Data';
            this.buttonTooltip = this.buttonText;
            break;
          case 'rejected':
            this.stateDescription = `Site ${ this.service.site.name } rejected the deployment of the credentials. Click for details.`;
            this.buttonActive = true;
            this.buttonColor = 'warn';
            this.buttonText = 'Submit Data';
            this.buttonTooltip = this.buttonText;
            break;

          default:
            this.stateDescription = 'Access to this service was never requested.';
            this.buttonActive = false;
        }
      }
    );
Lukas Burgey's avatar
Lukas Burgey committed
91
92
  }

Lukas Burgey's avatar
Lukas Burgey committed
93
  public buttonAction(state: DeploymentState): void {
Lukas Burgey's avatar
Lukas Burgey committed
94
95
    switch (state.state) {
      case 'deployed':
Lukas Burgey's avatar
Lukas Burgey committed
96
        return this.dialog.openCredentials(this.state$);
Lukas Burgey's avatar
Lukas Burgey committed
97
      case 'questionnaire':
Lukas Burgey's avatar
Lukas Burgey committed
98
        return this.dialog.openQuestionnaire(this.state$);
Lukas Burgey's avatar
Lukas Burgey committed
99
      case 'failed':
Lukas Burgey's avatar
Lukas Burgey committed
100
        return this.dialog.openMessage(state);
Lukas Burgey's avatar
Lukas Burgey committed
101
      case 'rejected':
Lukas Burgey's avatar
Lukas Burgey committed
102
        return this.dialog.openMessage(state);
Lukas Burgey's avatar
Lukas Burgey committed
103
104
105
    }
  }

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

Lukas Burgey's avatar
Lukas Burgey committed
110
}