-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathnotification-form.component.html
214 lines (210 loc) · 10.9 KB
/
notification-form.component.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<div class="content-container">
<div class="container">
<main class="notification-add-main">
<chef-breadcrumbs>
<chef-breadcrumb [link]="['/settings/notifications']">Notifications</chef-breadcrumb>
{{ isEditRule ? 'Edit notification' : 'Add notification' }}
</chef-breadcrumbs>
<chef-page-header>
<chef-heading> {{ isEditRule ? 'Edit your notification' : 'Add a new notification' }}</chef-heading>
<chef-subheading *ngIf="!isEditRule">
<ng-container>
Select Slack, ServiceNow, or webhook integration to setup notifications
</ng-container>
</chef-subheading>
</chef-page-header>
<div class="page-body">
<chef-loading-spinner *ngIf="showLoading" size="100"></chef-loading-spinner>
<form *ngIf="!showLoading" class="notification-form" (ngSubmit)="onSubmit()" #createForm="ngForm">
<p class="notification-form-heading">
Select Slack, ServiceNow, or webhook <span class="asterisk">*</span>
</p>
<label class="notification-type-label">
<input (change)="onSelectionChange(SLACK)" [checked]="getTargetTypeChecked(model.rule, SLACK)"
class="notification-type-radio" type="radio" name="notification-type"/>
<span class="notification-type-checkbox">
<chef-icon contrast>check</chef-icon>
</span>
<img class="notification-type-logo" src="/assets/img/logo-slack-full.svg" alt="Slack"/>
</label>
<label class="notification-type-label">
<input (change)="onSelectionChange(SERVICENOW)" [checked]="getTargetTypeChecked(model.rule, SERVICENOW)"
class="notification-type-radio" type="radio" name="notification-type"/>
<span class="notification-type-checkbox">
<chef-icon contrast>check</chef-icon>
</span>
<img class="notification-type-logo" src="/assets/img/logo-servicenow-full.svg" alt="ServiceNow"/>
</label>
<label class="notification-type-label">
<input (change)="onSelectionChange(WEBHOOK)" [checked]="getTargetTypeChecked(model.rule, WEBHOOK)"
class="notification-type-radio" type="radio" name="notification-type"/>
<span class="notification-type-checkbox">
<chef-icon contrast>check</chef-icon>
</span>
<img class="notification-type-logo" src="/assets/img/logo-webhooks-full.svg" alt="Webhook"/>
</label>
<div *ngIf="targetTypeChosen() || isEditRule">
<chef-form-field>
<label>Assign a unique name for your notification <span class="asterisk">*</span></label>
<input chefInput
type="text"
name="name"
placeholder="Enter notification name"
pattern="^[^\s].*"
[(ngModel)]="model.rule.name"
#name="ngModel"
[class.invalid]="name.invalid && name.dirty"
required>
<div *ngIf="!name.invalid && name.dirty" class="check-icon"><chef-icon>check</chef-icon></div>
<chef-error *ngIf="name.invalid && name.dirty">Name must be supplied</chef-error>
</chef-form-field>
<label>Select a failure type <span class="asterisk">*</span></label>
<chef-select
(change)="setFailureType($event)"
class="notification-select-menu"
[value]="model.rule.ruleType">
<chef-option selected>Select Failure Type</chef-option>
<chef-option *ngFor="let key of getAlertTypeKeys()" [value]="key">
{{model.rule.AlertTypeLabels[key]}}
</chef-option>
</chef-select>
<div *ngIf="displayCriticalControlsCheckbox()">
<p class="small">
<chef-checkbox
(change)="updateCriticalControlsOnly($event.detail)"
[checked]="model.rule.criticalControlsOnly">
</chef-checkbox>
Only send notifications for critical control failures
</p>
</div>
<chef-form-field>
<label>Enter your
<span *ngIf="targetType === WEBHOOK">webhook URL</span>
<span *ngIf="targetType === SLACK">Slack webhook</span>
<span *ngIf="targetType === SERVICENOW">ServiceNow webhook</span>
<span class="asterisk">*</span>
<chef-button tertiary *ngIf="targetType === SLACK" class="label-link" url="https://my.slack.com/services/new/incoming-webhook" target="_blank">
What's this?
</chef-button>
</label>
<input chefInput
type="text"
name="targetUrl"
placeholder="e.g. https://webhook.{{model.rule.targetType}}.com/T0000000/W99999999"
pattern="https?://[^.]+\..+"
[(ngModel)]="model.rule.targetUrl"
#targetUrl="ngModel"
[class.invalid]="targetUrl.invalid && targetUrl.dirty"
required>
<div *ngIf="!targetUrl.invalid && name.dirty" class="check-icon"><chef-icon>check</chef-icon></div>
<chef-error *ngIf="targetUrl.invalid && targetUrl.dirty">
URL must be either http://... or https://...
</chef-error>
</chef-form-field>
<ng-container *ngIf="targetType === SERVICENOW && !isEditRule">
<label class="label-divider">ServiceNow Credentials</label>
<p class="small">
<em>
Your ServiceNow username and password are required to use the ServiceNow API. These values will
only be used for accessing the ServiceNow API and will be encrypted.
</em>
</p>
<chef-form-field>
<label>Username <span class="asterisk">*</span></label>
<input chefInput
type="text"
name="targetUsername"
[(ngModel)]="model.targetUsername"
#targetUsername="ngModel"
[class.invalid]="targetUsername.invalid && targetUsername.dirty"
required>
<div *ngIf="!targetUsername.invalid && targetUsername.dirty" class="check-icon"><chef-icon>check</chef-icon></div>
<chef-error *ngIf="targetUsername.invalid && targetUsername.dirty">
Username must be supplied
</chef-error>
</chef-form-field>
<chef-form-field>
<label>Password <span class="asterisk">*</span></label>
<input chefInput
type="password"
name="targetPassword"
[(ngModel)]="model.targetPassword"
#targetPassword="ngModel"
[class.invalid]="targetPassword.invalid && targetPassword.dirty"
required>
<div *ngIf="!targetPassword.invalid && targetPassword.dirty" class="check-icon"><chef-icon>check</chef-icon></div>
<chef-error *ngIf="targetPassword.invalid && targetPassword.dirty">
Password must be supplied.
</chef-error>
</chef-form-field>
</ng-container>
<div class="notification-buttons">
<chef-button primary
(click)="testHook($event)"
[disabled]="!targetUrl || targetUrl.invalid">
<span *ngIf="hookStatus === urlState.Loading; then showInProgress else showReady"></span>
<ng-template #showInProgress>Sending test...</ng-template>
<ng-template #showReady>Send a test</ng-template>
</chef-button>
<chef-button primary id="save_button"
[disabled]="!createForm.form.valid || !model.rule.ruleType"
type="submit">Save Notification</chef-button>
<chef-button tertiary [routerLink]="['/settings/notifications']">Cancel</chef-button>
</div>
</div>
<!-- Why duplicate? To overcome an Angular limitation: see http://bit.ly/2kuR0El -->
<div *ngIf="!targetTypeChosen()" class="notification-buttons">
<chef-button primary disabled>Send a test</chef-button>
<chef-button primary disabled>Save Notification</chef-button>
<chef-button tertiary [routerLink]="['/settings/notifications']">Cancel</chef-button>
</div>
</form>
</div>
</main>
</div>
</div>
<chef-modal label="url-modal-label" [visible]="urlStatusModalVisible" (closeModal)="closeModal('url')">
<div class="status-modal">
<ng-container *ngIf="hookStatus === urlState.Failure">
<div class="status-icon failure">
<chef-icon>warning</chef-icon>
</div>
<h3 id="url-modal-label" class="status-heading display3 failure">
We were unable to connect to your
<span *ngIf="targetType === SLACK">Slack account</span>
<span *ngIf="targetType === WEBHOOK">webhook url</span>
<span *ngIf="targetType === SERVICENOW">ServiceNow webhook</span>
</h3>
<p>Please update your webhook details and try again.</p>
<chef-button primary (click)="closeModal('url')">Edit details</chef-button>
</ng-container>
<ng-container *ngIf="hookStatus === urlState.Success">
<div class="status-icon success">
<chef-icon>done</chef-icon>
</div>
<h3 class="status-heading display3">Successfully posted to the URL provided!</h3>
<chef-button primary (click)="closeModal('url')">Close</chef-button>
</ng-container>
</div>
</chef-modal>
<chef-modal label="save-modal-label" [visible]="saveStatusModalVisible" (closeModal)="closeModal('save')">
<div class="status-modal">
<ng-container *ngIf="saveStatus === saveState.Failure">
<div class="status-icon failure">
<chef-icon>warning</chef-icon>
</div>
<h3 class="status-heading display3 failure" *ngIf="!isEditRule">Could not create rule "{{model.rule.name}}"</h3>
<h3 class="status-heading display3 failure" *ngIf="isEditRule">Could not save changes to rule "{{model.rule.name}}"</h3>
<chef-button primary (click)="closeModal('save')">Edit details</chef-button>
</ng-container>
<ng-container *ngIf="saveStatus === saveState.Success">
<div class="status-icon success">
<chef-icon>done</chef-icon>
</div>
<h3 id="save-modal-label" class="status-heading display3" *ngIf="!isEditRule">New rule "{{model.rule.name}}" saved.</h3>
<h3 class="status-heading display3" *ngIf="isEditRule">Changes to rule "{{model.rule.name}}" have been saved.</h3>
<chef-button primary [routerLink]="['/settings/notifications']" (click)="closeModal('save')">Return to Notifications</chef-button>
</ng-container>
</div>
</chef-modal>