From c1578b25f24038d8ccd17965501741e8ab7d37a6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 3 Dec 2023 23:18:16 +0100 Subject: [PATCH] Moving code to js file --- vss-extension-dev.json | 2 +- widgets/widgets/hub/hub.html | 92 +++--------------------------------- widgets/widgets/hub/hub.js | 79 +++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 87 deletions(-) create mode 100644 widgets/widgets/hub/hub.js diff --git a/vss-extension-dev.json b/vss-extension-dev.json index 2577e51..ebfc00c 100644 --- a/vss-extension-dev.json +++ b/vss-extension-dev.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "GHAzDoWidget-DEV", - "version": "0.2.306", + "version": "0.2.308", "public": false, "name": "Advanced Security dashboard Widgets [DEV]", "description": "[DEV] GitHub Advanced Security for Azure DevOps dashboard widgets", diff --git a/widgets/widgets/hub/hub.html b/widgets/widgets/hub/hub.html index a99c1f9..a8fa02b 100644 --- a/widgets/widgets/hub/hub.html +++ b/widgets/widgets/hub/hub.html @@ -4,6 +4,7 @@ + @@ -22,91 +23,6 @@ // top level function async function (WidgetHelpers, Services, context) { - - async function createCharts(chartService, organization, projectName) { - - const containerName = "#Chart-Container"; - var title = $('h2.ghazdoTitle'); - createChart(chartService, containerName, title, organization, projectName); - } - - async function createChart(chartService, containerName, title, organization, projectName) { - - consoleLog("Starting to create chart"); - var $container = $(containerName); - - if (!chartService) { - consoleLog("chartService is null"); - return; - } - - const data = { - chartType: 1, - alertType: 1, - repo: "eShopOnWeb", - repoId: "5e5195e1-1b44-4d4b-9310-5d33ee2c4d6c" - } - - let repoName - let repoId - // init empty object first - let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; - let chartType = 1; - let alertTypeConfig = 1; - if (data && data.chartType && data.chartType !== "") { - chartType = data.chartType; - consoleLog('loaded chartType from widgetSettings: ' + chartType); - } - else { - consoleLog('chartType is not set, using default value: ' + chartType); - } - - if (data && data.alertType) { - alertTypeConfig = data.alertType; - consoleLog('loaded alertType from widgetSettings: ' + alertTypeConfig); - } - - if (data && data.repo && data.repo !== "") { - repoName = data.repo; - repoId = data.repoId; - - $container.text(`${data.repo}`) - - const chartSize = { - columnSpan: 2 - } - - switch (chartType) { - case "2": - try { - const alertType = GetAlertTypeFromValue(alertTypeConfig); - title.text(`${alertType.display} Alerts by Severity`) - renderPieChart(organization, projectName, repoId, $container, chartService, alertType, chartSize); - } - catch (err) { - consoleLog(`Error loading the alerts pie: ${err}`); - } - break; - default: - try { - title.text(`Advanced Security Alerts Trend`) - renderTrendLine(organization, projectName, repoId, $container, chartService, chartSize); - } - catch (err) { - consoleLog(`Error loading the alerts trend: ${err}`); - } - break; - } - consoleLog('rendered chart'); - } - else { - consoleLog('configuration is needed first, opening with empty values'); - // set the tile to indicate config is needed - title.text(`Configure the widget to get Advanced Security alerts trend information`); - } - - } - consoleLog('VSS.require function'); try { consoleLog('VSS.register Hub function'); @@ -123,7 +39,11 @@ consoleLog('project name: ' + projectName); consoleLog('organization name: ' + organization); - createCharts(chartService, organization, projectName); + const titleElement = $('h2.ghazdoTitle'); + const containerElement = $('#Chart-Container'); + + // create the charts + createCharts(chartService, organization, projectName, containerElement, titleElement); consoleLog('returning WidgetStatusHelper.Success()'); } diff --git a/widgets/widgets/hub/hub.js b/widgets/widgets/hub/hub.js new file mode 100644 index 0000000..f9549e3 --- /dev/null +++ b/widgets/widgets/hub/hub.js @@ -0,0 +1,79 @@ +async function createCharts(chartService, organization, projectName, containerElement, titleElement) { + + createChart(chartService, containerElement, titleElement, organization, projectName); +} + +async function createChart(chartService, containerElement, titleElement, organization, projectName) { + + consoleLog("Starting to create chart"); + + if (!chartService) { + consoleLog("chartService is null"); + return; + } + + const data = { + chartType: 1, + alertType: 1, + repo: "eShopOnWeb", + repoId: "5e5195e1-1b44-4d4b-9310-5d33ee2c4d6c" + } + + let repoName + let repoId + // init empty object first + let alertTrendLines = {secretAlertTrend: [], dependencyAlertTrend: [], codeAlertsTrend: []}; + let chartType = 1; + let alertTypeConfig = 1; + if (data && data.chartType && data.chartType !== "") { + chartType = data.chartType; + consoleLog('loaded chartType from widgetSettings: ' + chartType); + } + else { + consoleLog('chartType is not set, using default value: ' + chartType); + } + + if (data && data.alertType) { + alertTypeConfig = data.alertType; + consoleLog('loaded alertType from widgetSettings: ' + alertTypeConfig); + } + + if (data && data.repo && data.repo !== "") { + repoName = data.repo; + repoId = data.repoId; + + containerElement.text(`${data.repo}`) + + const chartSize = { + columnSpan: 2 + } + + switch (chartType) { + case "2": + try { + const alertType = GetAlertTypeFromValue(alertTypeConfig); + titleElement.text(`${alertType.display} Alerts by Severity`) + renderPieChart(organization, projectName, repoId, containerElement, chartService, alertType, chartSize); + } + catch (err) { + consoleLog(`Error loading the alerts pie: ${err}`); + } + break; + default: + try { + titleElement.text(`Advanced Security Alerts Trend`) + renderTrendLine(organization, projectName, repoId, containerElement, chartService, chartSize); + } + catch (err) { + consoleLog(`Error loading the alerts trend: ${err}`); + } + break; + } + consoleLog('rendered chart'); + } + else { + consoleLog('configuration is needed first, opening with empty values'); + // set the tile to indicate config is needed + titleElement.text(`Configure the widget to get Advanced Security alerts trend information`); + } +} \ No newline at end of file