Skip to content

Commit

Permalink
Moving code to js file
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos committed Dec 3, 2023
1 parent 725d991 commit c1578b2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 87 deletions.
2 changes: 1 addition & 1 deletion vss-extension-dev.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
92 changes: 6 additions & 86 deletions widgets/widgets/hub/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script src="../../../lib/VSS.SDK.min.js"></script>
<script src="../../library.js"></script>
<script src="../chart/chart.js"></script>
<script src="hub.js"></script>
<link rel="stylesheet" href="../../styles.css" />
</head>
<body>
Expand All @@ -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');
Expand All @@ -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()');
}
Expand Down
79 changes: 79 additions & 0 deletions widgets/widgets/hub/hub.js
Original file line number Diff line number Diff line change
@@ -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`);
}
}

0 comments on commit c1578b2

Please sign in to comment.