|
3 | 3 | <head>
|
4 | 4 | <script src="../lib/VSS.SDK.min.js"></script>
|
5 | 5 | <script src="../library.js"></script>
|
| 6 | + <script src="chart.js"></script> |
6 | 7 | <link rel="stylesheet" href="../styles.css" />
|
7 | 8 | </head>
|
8 | 9 | <body>
|
|
26 | 27 | return Services.ChartsService.getService().then(async function(chartService){
|
27 | 28 | consoleLog("Starting to create chart");
|
28 | 29 | var $container = $('#Chart-Container');
|
29 |
| - var $title = $('h2.title'); |
| 30 | + var $title = $('h2.ghazdo-title'); |
30 | 31 |
|
31 | 32 | const webContext = VSS.getWebContext();
|
32 | 33 | const project = webContext.project;
|
|
46 | 47 |
|
47 | 48 | let repoName
|
48 | 49 | let repoId
|
49 |
| - if (data && data.repo) { |
| 50 | + // init empty object first |
| 51 | + let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; |
| 52 | + if (data && data.repo && data.repo !== "") { |
50 | 53 | repoName = data.repo;
|
51 | 54 | repoId = data.repoId;
|
52 | 55 | consoleLog('loaded repoName from widgetSettings: ' + repoName);
|
53 | 56 |
|
54 | 57 | $title.text(`Advanced Security Alerts Trend`)
|
55 | 58 | $container.text(`${data.repo}`)
|
56 | 59 |
|
57 |
| - // load the alerts for the selected repo |
58 | 60 | try {
|
59 |
| - alerts = await getAlerts(organization, projectName, repoId); |
60 |
| - consoleLog('alerts: ' + JSON.stringify(alerts)); |
| 61 | + // get the trend data for alerts first |
| 62 | + alertTrendLines = await getAlertsTrendLines(organization, projectName, repoId) |
| 63 | + consoleLog('Dependencies AlertTrend: ' + JSON.stringify(alertTrendLines.dependencyAlertsTrend)); |
| 64 | + consoleLog('Code scanning AlertTrend: ' + JSON.stringify(alertTrendLines.codeAlertsTrend)); |
| 65 | + consoleLog('Secrets AlertTrend: ' + JSON.stringify(alertTrendLines.secretAlertsTrend)); |
| 66 | + |
| 67 | + createChart($container, chartService, alertTrendLines); |
61 | 68 | }
|
62 | 69 | catch (err) {
|
63 |
| - consoleLog(`Error loading the grouped alerts: ${err}`); |
| 70 | + consoleLog(`Error loading the alerts trend: ${err}`); |
64 | 71 | }
|
65 | 72 | }
|
66 | 73 | else {
|
|
69 | 76 | $title.text(`Configure the widget to get Advanced Security alerts trend information`);
|
70 | 77 | }
|
71 | 78 |
|
72 |
| - // init empty object first |
73 |
| - let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; |
74 |
| - try { |
75 |
| - // get the trend data for alerts first |
76 |
| - alertTrendLines = await getAlertsTrendLines(organization, projectName, repoId) |
77 |
| - consoleLog('Dependencies AlertTrend: ' + JSON.stringify(alertTrendLines.dependencyAlertsTrend)); |
78 |
| - consoleLog('Code scanning AlertTrend: ' + JSON.stringify(alertTrendLines.codeAlertsTrend)); |
79 |
| - consoleLog('Secrets AlertTrend: ' + JSON.stringify(alertTrendLines.secretAlertsTrend)); |
80 |
| - } |
81 |
| - catch (err) { |
82 |
| - consoleLog(`Error loading the alerts trend: ${err}`); |
83 |
| - } |
84 |
| - |
85 |
| - const datePoints = getDatePoints(); |
86 |
| - var chartOptions = { |
87 |
| - "hostOptions": { |
88 |
| - "height": "290", |
89 |
| - "width": "300" |
90 |
| - }, |
91 |
| - "chartType": "line", |
92 |
| - "series": |
93 |
| - [ |
94 |
| - { |
95 |
| - "name": "Dependencies", |
96 |
| - "data": alertTrendLines.dependencyAlertsTrend |
97 |
| - }, |
98 |
| - { |
99 |
| - "name": "Code scanning", |
100 |
| - "data": alertTrendLines.codeAlertsTrend |
101 |
| - }, |
102 |
| - { |
103 |
| - "name": "Secrets", |
104 |
| - "data": alertTrendLines.secretAlertsTrend |
105 |
| - } |
106 |
| - ], |
107 |
| - "xAxis": { |
108 |
| - "labelValues": datePoints, |
109 |
| - "labelFormatMode": "dateTime", // format is 2023-09-17 |
110 |
| - }, |
111 |
| - "specializedOptions": { |
112 |
| - "includeMarkers": "true" |
113 |
| - } |
114 |
| - }; |
115 |
| - |
116 |
| - try { |
117 |
| - chartService.createChart($container, chartOptions); |
118 |
| - } |
119 |
| - catch (err) { |
120 |
| - console.log(`Error creating chart: ${err}`); |
121 |
| - } |
122 | 79 | return WidgetHelpers.WidgetStatusHelper.Success();
|
123 | 80 | });
|
124 | 81 | }
|
|
133 | 90 | </script>
|
134 | 91 |
|
135 | 92 | <div class="widget">
|
136 |
| - <h2 class="title">Chart Widget</h2> |
| 93 | + <h2 class="ghazdo-title">GHAzDo Chart Widget</h2> |
137 | 94 | <div id="Chart-Container"></div>
|
138 | 95 | </div>
|
139 | 96 | </body>
|
|
0 commit comments