Skip to content

Commit

Permalink
Slack notification (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Aug 10, 2022
1 parent 815b17e commit 0a45aa4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ <h5 class="modal-title" id="modal-basic-title">MS Teams Webhook</h5>
Webhook</a> for a channel.
</div>
<p class="text-secondary"></p>

<select class="custom-select mb-3" (change)="changeNotification($event)" formControlName="notificationType">
<option value="">Choose notification type</option>
<option *ngFor="let notification of notifications" [value]="notification">
{{ notification }}
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { ScenarioService } from "src/app/scenario.service";
export class AddNewExternalNotificationComponent implements OnInit {
notificationConfig = new Map([
["MS Teams", { key: "ms-teams", helpUrl: "https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#add-an-incoming-webhook-to-a-teams-channel" }],
["GChat", { key: "gchat", helpUrl: "https://developers.google.com/chat/how-tos/webhooks#create_a_webhook" }]])
["GChat", { key: "gchat", helpUrl: "https://developers.google.com/chat/how-tos/webhooks#create_a_webhook" }],
["Slack", { key: "slack", helpUrl: "https://api.slack.com/messaging/webhooks#getting_started" }]
])

myform: FormGroup;
url;
Expand All @@ -25,6 +27,7 @@ export class AddNewExternalNotificationComponent implements OnInit {
notifications: string[] = Array.from(this.notificationConfig.keys());
helpUrl: string;
@Input() params;
private DEFAULT_NOTIFICATION = 0

constructor(
private modalService: NgbModal,
Expand All @@ -36,6 +39,7 @@ export class AddNewExternalNotificationComponent implements OnInit {
ngOnInit() {
this.createFormControls();
this.createForm();
this.setHelpUrl(this.notifications[this.DEFAULT_NOTIFICATION])
}

open(content) {
Expand All @@ -51,7 +55,7 @@ export class AddNewExternalNotificationComponent implements OnInit {
Validators.maxLength(100),
Validators.required
]);
this.notificationType = new FormControl("", [Validators.required])
this.notificationType = new FormControl(this.notifications[this.DEFAULT_NOTIFICATION], [Validators.required])
}

createForm() {
Expand All @@ -65,12 +69,15 @@ export class AddNewExternalNotificationComponent implements OnInit {
changeNotification(e) {
this.notificationType?.setValue(e.target.value);
if (this.notificationConfig.has(e.target.value)) {
const notification = this.notificationConfig.get(e.target.value)
this.helpUrl = notification.helpUrl
this.setHelpUrl(e.target.value)
} else {
this.helpUrl = null
}
}

setHelpUrl(notificationType: string) {
const notification = this.notificationConfig.get(notificationType)
this.helpUrl = notification.helpUrl
}

onSubmit() {
Expand All @@ -91,7 +98,8 @@ export class AddNewExternalNotificationComponent implements OnInit {
this.scenarioApiService.setData(message);
this.scenarioService.fetchScenarioNotifications(projectName, scenarioName);
});
this.myform.reset();
this.myform.reset({ notificationType: this.notifications[this.DEFAULT_NOTIFICATION ] });
this.setHelpUrl(this.notifications[this.DEFAULT_NOTIFICATION ])
this.modal.close();
}
}
Expand Down

0 comments on commit 0a45aa4

Please sign in to comment.