forked from devsecopsmaturitymodel/DevSecOps-MaturityModel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal-message.component.ts
More file actions
87 lines (77 loc) · 2.46 KB
/
modal-message.component.ts
File metadata and controls
87 lines (77 loc) · 2.46 KB
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
import { Inject, Component, OnInit } from '@angular/core';
import {
MAT_DIALOG_DATA,
MatDialogRef,
MatDialog,
MatDialogConfig,
} from '@angular/material/dialog';
import * as md from 'markdown-it';
@Component({
selector: 'app-modal-message',
templateUrl: './modal-message.component.html',
styleUrls: ['./modal-message.component.css'],
})
export class ModalMessageComponent implements OnInit {
data: DialogInfo;
markdown: md = md();
DSOMM_host: string = 'https://github.com/devsecopsmaturitymodel';
DSOMM_url: string = `${this.DSOMM_host}/DevSecOps-MaturityModel-data`;
meassageTemplates: Record<string, DialogInfo> = {
generated_yaml: new DialogInfo(
`{message}\n\n` +
`Please download the activity template \`generated.yaml\` ` +
`from [DSOMM-data](${this.DSOMM_url}) on GitHub.\n\n` +
'The DSOMM activities are maintained and distributed ' +
'separately from the software.',
'DSOMM startup problems'
),
};
constructor(
public dialog: MatDialog,
public dialogRef: MatDialogRef<ModalMessageComponent>,
@Inject(MAT_DIALOG_DATA) data: DialogInfo
) {
this.data = data;
}
// eslint-disable-next-line @angular-eslint/no-empty-lifecycle-method
ngOnInit(): void {}
openDialog(
dialogInfo: DialogInfo | string
): MatDialogRef<ModalMessageComponent> {
if (typeof dialogInfo === 'string') {
dialogInfo = new DialogInfo(dialogInfo);
}
if (
dialogInfo.template &&
this.meassageTemplates.hasOwnProperty(dialogInfo.template)
) {
let template: DialogInfo = this.meassageTemplates[dialogInfo.template];
dialogInfo.title = dialogInfo.title || template?.title;
dialogInfo.message = template?.message?.replace(
'{message}',
dialogInfo.message
);
}
dialogInfo.message = this.markdown.render(dialogInfo.message);
const dialogConfig = new MatDialogConfig();
dialogConfig.id = 'modal-message';
dialogConfig.disableClose = true;
dialogConfig.data = dialogInfo;
dialogConfig.autoFocus = false;
this.dialogRef = this.dialog.open(ModalMessageComponent, dialogConfig);
return this.dialogRef;
}
closeDialog(buttonName: string) {
this.dialogRef?.close(buttonName);
}
}
export class DialogInfo {
title: string = '';
template: string | null = '';
message: string = '';
buttons: string[] = ['OK'];
constructor(msg: string = '', title: string = '') {
this.message = msg;
this.title = title;
}
}