accessibility-checker
Version:
An automated testing tools for accessibility testing using Puppeteer, Selenium, or Zombie
931 lines (928 loc) • 98.5 kB
JavaScript
"use strict";
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
// import ReportSummaryUtil from '../../../util/reportSummaryUtil';
// import ExcelJS from "exceljs"
var ExcelJS = require('exceljs');
var fs = require('fs');
var MultiScanReport = /** @class */ (function () {
function MultiScanReport() {
}
MultiScanReport.multiScanXlsxDownload = function (storedScans, scanType, storedScanCount, archives, toolID, fileName) {
return __awaiter(this, void 0, void 0, function () {
var reportWorkbook, buffer;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
reportWorkbook = MultiScanReport.createReportWorkbook(storedScans, scanType, storedScanCount, archives, toolID);
return [4 /*yield*/, reportWorkbook.xlsx.writeBuffer()];
case 1:
buffer = _a.sent();
fs.writeFileSync(fileName, buffer);
return [2 /*return*/];
}
});
});
};
MultiScanReport.createReportWorkbook = function (storedScans, scanType, storedScanCount, archives, toolID) {
// create workbook
// @ts-ignore
var workbook = new ExcelJS.Workbook({ useStyles: true });
// create worksheets
this.createOverviewSheet(storedScans, scanType, storedScanCount, archives, workbook, toolID);
this.createScanSummarySheet(storedScans, scanType, workbook);
this.createIssueSummarySheet(storedScans, scanType, workbook);
this.createIssuesSheet(storedScans, scanType, workbook);
this.createDefinitionsSheet(workbook);
return workbook;
};
MultiScanReport.createOverviewSheet = function (storedScans, scanType, storedScanCount, archives, workbook, toolID) {
var violations = 0;
var needsReviews = 0;
var recommendations = 0;
var totalIssues = 0;
// if scanType is "selected" need to recalculate storedScanCount
var selectedStoredScanCount = 0;
// BIG QUESTION: is report
// 1. for current scan (from menu)
// 2. all stored scans (from menu)
// 3. selected stored scans (from scan manager)
var theCurrentScan = storedScans[storedScans.length - 1];
if (scanType === "current") {
violations = theCurrentScan.violations;
needsReviews = theCurrentScan.needsReviews;
recommendations = theCurrentScan.recommendations;
totalIssues = theCurrentScan.violations + theCurrentScan.needsReviews + theCurrentScan.recommendations;
}
else if (scanType === "all") {
for (var i = 0; i < storedScans.length; i++) {
violations += storedScans[i].violations;
needsReviews += storedScans[i].needsReviews;
recommendations += storedScans[i].recommendations;
}
totalIssues = violations + needsReviews + recommendations;
}
else if (scanType === "selected") {
for (var i = 0; i < storedScans.length; i++) {
if (storedScans[i].isSelected === true) {
selectedStoredScanCount++;
violations += storedScans[i].violations;
needsReviews += storedScans[i].needsReviews;
recommendations += storedScans[i].recommendations;
}
}
totalIssues = violations + needsReviews + recommendations;
}
var worksheet = workbook.addWorksheet("Overview");
// Report Title
worksheet.mergeCells('A1', "D1");
var titleRow = worksheet.getRow(1);
titleRow.height = "27";
var cellA1 = worksheet.getCell('A1');
cellA1.value = "Accessibility Scan Report";
cellA1.alignment = { vertical: "middle", horizontal: "left" };
cellA1.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellA1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
// what are column widths - can't get it till you set it
var colWidthData = [
{ col: 'A', width: '15.1' },
{ col: 'B', width: '15.9' },
{ col: 'C', width: '16.23' },
{ col: 'D', width: '19.4' },
];
for (var i = 0; i < 4; i++) {
worksheet.getColumn(colWidthData[i].col).width = colWidthData[i].width;
}
// set row height for rows 2-10
for (var i = 2; i < 11; i++) {
if (i == 7) {
worksheet.getRow(i).height = 36;
}
else {
worksheet.getRow(i).height = 12; // results in a row height of 16
}
}
// note except for Report Date this is the same for all scans
var rowData = [
{ key1: 'Tool:', key2: 'IBM Equal Access Accessibility Checker' },
// {key1: 'Version:', key2: "chrome.runtime.getManifest().version"},
{ key1: 'Version:', key2: toolID },
//@ts-ignore
// {key1: 'Rule set:', key2: (theCurrentScan.ruleSet === "Latest Deployment") ? archives[1].name : theCurrentScan.ruleSet },
{ key1: 'Rule set:', key2: theCurrentScan.ruleSet },
{ key1: 'Guidelines:', key2: theCurrentScan.guidelines },
{ key1: 'Report date:', key2: theCurrentScan.reportDate },
{ key1: 'Platform:', key2: "N/A" },
{ key1: 'Scans:', key2: scanType === "current" ? 1 : scanType === "all" ? storedScanCount : selectedStoredScanCount },
{ key1: 'Pages:', key2: "" }
];
worksheet.mergeCells('B2', "D2");
worksheet.mergeCells('B3', "D3");
worksheet.mergeCells('B4', "D4");
worksheet.mergeCells('B5', "D5");
worksheet.mergeCells('B6', "D6");
worksheet.mergeCells('B7', "D7");
worksheet.mergeCells('B8', "D8");
worksheet.mergeCells('B9', "D9");
worksheet.mergeCells('A10', "D10");
for (var i = 2; i < 10; i++) {
worksheet.getRow(i).getCell(1).font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
worksheet.getRow(i).getCell(2).font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
worksheet.getRow(i).getCell(1).alignment = { horizontal: "left" };
worksheet.getRow(i).getCell(2).alignment = { horizontal: "left" };
if (i == 7) {
worksheet.getRow(i).getCell(1).alignment = { vertical: "top" };
worksheet.getRow(i).getCell(2).alignment = { wrapText: true };
}
}
for (var i = 2; i < 10; i++) {
worksheet.getRow(i).getCell(1).value = rowData[i - 2].key1;
worksheet.getRow(i).getCell(2).value = rowData[i - 2].key2;
}
// Summary Title
worksheet.mergeCells('A11', "D11");
var summaryRow = worksheet.getRow(11);
summaryRow.height = "27";
var cellA11 = worksheet.getCell('A11');
cellA11.value = "Summary";
cellA11.alignment = { vertical: "middle", horizontal: "left" };
cellA11.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellA11.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
// Scans info Headers
worksheet.getRow(12).height = 16; // actual height is
var cellA12 = worksheet.getCell('A12');
cellA12.value = "Total issues";
var cellB12 = worksheet.getCell('B12');
cellB12.value = "Violations";
var cellC12 = worksheet.getCell('C12');
cellC12.value = "Needs review";
var cellD12 = worksheet.getCell('D12');
cellD12.value = "Recommendations";
var cellObjects1 = [cellA12, cellB12, cellC12, cellD12];
for (var i = 0; i < 4; i++) {
cellObjects1[i].alignment = { vertical: "middle", horizontal: "center" };
if (i == 1 || i == 2 || i == 3) {
cellObjects1[i].font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
}
else {
cellObjects1[i].font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "12" };
}
// cellObjects1[i].fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFC65911'} };
cellObjects1[i].border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
cellA12.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF000000' } };
cellB12.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE4AAAF' } };
cellC12.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4E08A' } };
cellD12.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF96A9D7' } };
// Scans info Values
worksheet.getRow(13).height = 27; // actual height is
var cellA13 = worksheet.getCell('A13');
cellA13.value = totalIssues;
var cellB13 = worksheet.getCell('B13');
cellB13.value = violations;
var cellC13 = worksheet.getCell('C13');
cellC13.value = needsReviews;
var cellD13 = worksheet.getCell('D13');
cellD13.value = recommendations;
var cellObjects2 = [cellA13, cellB13, cellC13, cellD13];
for (var i = 0; i < 4; i++) {
cellObjects2[i].alignment = { vertical: "middle", horizontal: "center" };
cellObjects2[i].font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
// cellObjects2[i].fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
cellObjects2[i].border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
};
MultiScanReport.createScanSummarySheet = function (storedScans, scanType, workbook) {
var worksheet = workbook.addWorksheet("Scan summary");
// Scans info Headers
worksheet.getRow(1).height = 39; // actual height is 52
var colWidthData = [
{ col: 'A', width: '27.0' },
{ col: 'B', width: '46.0' },
{ col: 'C', width: '20.17' },
{ col: 'D', width: '18.5' },
{ col: 'E', width: '17.17' },
{ col: 'F', width: '17.17' },
{ col: 'G', width: '17.17' },
{ col: 'H', width: '17.17' },
{ col: 'I', width: '17.17' },
];
for (var i = 0; i < 9; i++) {
worksheet.getColumn(colWidthData[i].col).width = colWidthData[i].width;
}
var cellA1 = worksheet.getCell('A1');
cellA1.value = "Page title";
var cellB1 = worksheet.getCell('B1');
cellB1.value = "Page url";
var cellC1 = worksheet.getCell('C1');
cellC1.value = "Scan label";
var cellD1 = worksheet.getCell('D1');
cellD1.value = "Base scan";
var cellObjects1 = [cellA1, cellB1, cellC1, cellD1];
for (var i = 0; i < 4; i++) {
cellObjects1[i].alignment = { vertical: "middle", horizontal: "left" };
cellObjects1[i].font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "12" };
cellObjects1[i].fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
cellObjects1[i].border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
var cellE1 = worksheet.getCell('E1');
cellE1.value = "Violations";
var cellF1 = worksheet.getCell('F1');
cellF1.value = "Needs review";
var cellG1 = worksheet.getCell('G1');
cellG1.value = "Recommendations";
var cellH1 = worksheet.getCell('H1');
cellH1.value = "% elements without violations";
var cellI1 = worksheet.getCell('I1');
cellI1.value = "% elements without violations or items to review";
var cellObjects2 = [cellE1, cellF1, cellG1, cellH1, cellI1];
for (var i = 0; i < 5; i++) {
cellObjects2[i].alignment = { vertical: "middle", horizontal: "center", wrapText: true };
if (i == 0 || i == 1 || i == 2) {
cellObjects2[i].font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
}
else {
cellObjects2[i].font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "12" };
}
// cellObjects2[i].fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFC65911'} };
cellObjects2[i].border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
cellE1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE4AAAF' } };
cellF1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4E08A' } };
cellG1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF96A9D7' } };
cellH1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF000000' } };
cellI1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF000000' } };
// if current scan use last scan, if
// if current scan use only the last scan otherwise loop through each scan an create row
var j = scanType === "current" ? storedScans.length - 1 : 0; // NEED TO FIX for selected
for (j; j < storedScans.length; j++) { // for each scan
// console.log("scanType = ", scanType, " storedScans[j].isSelected = ", storedScans[j].isSelected);
if (scanType === "selected" && storedScans[j].isSelected === true) {
var row = worksheet.addRow([storedScans[j].pageTitle,
storedScans[j].url,
storedScans[j].userScanLabel,
"none",
storedScans[j].violations,
storedScans[j].needsReviews,
storedScans[j].recommendations,
storedScans[j].elementsNoViolations,
storedScans[j].elementsNoFailures
]);
row.height = 37; // actual height is
for (var i = 1; i < 5; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "left", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
}
for (var i = 5; i < 10; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "center", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
// row.getCell(i).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(i).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
}
else if (scanType === "all") {
var row = worksheet.addRow([storedScans[j].pageTitle,
storedScans[j].url,
storedScans[j].userScanLabel,
"none",
storedScans[j].violations,
storedScans[j].needsReviews,
storedScans[j].recommendations,
storedScans[j].elementsNoViolations,
storedScans[j].elementsNoFailures
]);
row.height = 37; // actual height is
for (var i = 1; i < 5; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "left", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
}
for (var i = 5; i < 10; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "center", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
// row.getCell(i).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(i).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
}
else if (scanType === "current") {
var row = worksheet.addRow([storedScans[j].pageTitle,
storedScans[j].url,
storedScans[j].userScanLabel,
"none",
storedScans[j].violations,
storedScans[j].needsReviews,
storedScans[j].recommendations,
storedScans[j].elementsNoViolations,
storedScans[j].elementsNoFailures
]);
row.height = 37; // actual height is
for (var i = 1; i < 5; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "left", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
}
for (var i = 5; i < 10; i++) {
row.getCell(i).alignment = { vertical: "middle", horizontal: "center", wrapText: true };
row.getCell(i).font = { name: "Calibri", color: { argb: "00000000" }, size: "12" };
// row.getCell(i).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(i).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
}
}
}
};
MultiScanReport.createIssueSummarySheet = function (storedScans, scanType, workbook) {
var violations = 0;
var needsReviews = 0;
var recommendations = 0;
var totalIssues = 0;
// question 1: is report for current scans or all available scans?
var theCurrentScan = storedScans[storedScans.length - 1];
if (scanType === "current") {
violations = theCurrentScan.violations;
needsReviews = theCurrentScan.needsReviews;
recommendations = theCurrentScan.recommendations;
totalIssues = theCurrentScan.violations + theCurrentScan.needsReviews + theCurrentScan.recommendations;
}
else if (scanType === "all") {
for (var i = 0; i < storedScans.length; i++) {
violations += storedScans[i].violations;
needsReviews += storedScans[i].needsReviews;
recommendations += storedScans[i].recommendations;
}
totalIssues = violations + needsReviews + recommendations;
}
else if (scanType === "selected") {
for (var i = 0; i < storedScans.length; i++) {
if (storedScans[i].isSelected === true) {
violations += storedScans[i].violations;
needsReviews += storedScans[i].needsReviews;
recommendations += storedScans[i].recommendations;
}
}
totalIssues = violations + needsReviews + recommendations;
}
// counts
var level1Counts = [0, 0, 0, 0]; // level 1 total issues, violations, needs reviews, recommendations
var level2Counts = [0, 0, 0, 0];
var level3Counts = [0, 0, 0, 0];
var level4Counts = [0, 0, 0, 0];
var level1V = [];
var level2V = [];
var level3V = [];
var level4V = [];
var level1NR = [];
var level2NR = [];
var level3NR = [];
var level4NR = [];
var level1R = [];
var level2R = [];
var level3R = [];
var level4R = [];
var j = scanType === "current" ? storedScans.length - 1 : 0; // NEED TO FIX for selected
for (j; j < storedScans.length; j++) { // for each scan
var myStoredData = storedScans[j].storedScanData;
if (scanType === "selected" && storedScans[j].isSelected === true) {
for (var i = 0; i < myStoredData.length; i++) { // for each issue row
if (myStoredData[i][5] == 1) { // if level 1
level1Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level1Counts[1]++;
level1V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level1Counts[2]++;
level1NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level1Counts[3]++;
level1R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 2) { // if level 2
level2Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level2Counts[1]++;
level2V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level2Counts[2]++;
level2NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level2Counts[3]++;
level2R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 3) { // if level 3
level3Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level3Counts[1]++;
level3V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level3Counts[2]++;
level3NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level3Counts[3]++;
level3R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 4) { // if level 4
level4Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level4Counts[1]++;
level4V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level4Counts[2]++;
level4NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level4Counts[3]++;
level4R.push(myStoredData[i][9]);
}
}
}
}
else if (scanType === "all") {
for (var i = 0; i < myStoredData.length; i++) { // for each issue row
if (myStoredData[i][5] == 1) { // if level 1
level1Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level1Counts[1]++;
level1V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level1Counts[2]++;
level1NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level1Counts[3]++;
level1R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 2) { // if level 2
level2Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level2Counts[1]++;
level2V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level2Counts[2]++;
level2NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level2Counts[3]++;
level2R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 3) { // if level 3
level3Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level3Counts[1]++;
level3V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level3Counts[2]++;
level3NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level3Counts[3]++;
level3R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 4) { // if level 4
level4Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level4Counts[1]++;
level4V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level4Counts[2]++;
level4NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level4Counts[3]++;
level4R.push(myStoredData[i][9]);
}
}
}
}
else if (scanType === "current") {
for (var i = 0; i < myStoredData.length; i++) { // for each issue row
if (myStoredData[i][5] == 1) { // if level 1
level1Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level1Counts[1]++;
level1V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level1Counts[2]++;
level1NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level1Counts[3]++;
level1R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 2) { // if level 2
level2Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level2Counts[1]++;
level2V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level2Counts[2]++;
level2NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level2Counts[3]++;
level2R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 3) { // if level 3
level3Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level3Counts[1]++;
level3V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level3Counts[2]++;
level3NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level3Counts[3]++;
level3R.push(myStoredData[i][9]);
}
}
if (myStoredData[i][5] == 4) { // if level 4
level4Counts[0]++;
if (myStoredData[i][4] === "Violation") {
level4Counts[1]++;
level4V.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Needs review") {
level4Counts[2]++;
level4NR.push(myStoredData[i][9]);
}
if (myStoredData[i][4] === "Recommendation") {
level4Counts[3]++;
level4R.push(myStoredData[i][9]);
}
}
}
}
}
// @ts-ignore
var level1VrowValues = this.countDuplicatesInArray(level1V); // note this returns an object
// @ts-ignore
var level1NRrowValues = this.countDuplicatesInArray(level1NR);
// @ts-ignore
var level1RrowValues = this.countDuplicatesInArray(level1R);
// @ts-ignore
var level2VrowValues = this.countDuplicatesInArray(level2V); // note this returns an object
// @ts-ignore
var level2NRrowValues = this.countDuplicatesInArray(level2NR);
// @ts-ignore
var level2RrowValues = this.countDuplicatesInArray(level2R);
// @ts-ignore
var level3VrowValues = this.countDuplicatesInArray(level3V); // note this returns an object
// @ts-ignore
var level3NRrowValues = this.countDuplicatesInArray(level3NR);
// @ts-ignore
var level3RrowValues = this.countDuplicatesInArray(level3R);
// @ts-ignore
var level4VrowValues = this.countDuplicatesInArray(level4V); // note this returns an object
// @ts-ignore
var level4NRrowValues = this.countDuplicatesInArray(level4NR);
// @ts-ignore
var level4RrowValues = this.countDuplicatesInArray(level4R);
var worksheet = workbook.addWorksheet("Issue summary");
// Approach:
// 1. sort by levels
// 2. for each level sort by V, NR and R
// 3. for each V, NR, and R in a level get issue dup counts
// 4. build the rows
// build Issue summary title
worksheet.mergeCells('A1', "B1");
var titleRow = worksheet.getRow(1);
titleRow.height = "27"; // actual is 36
var cellA1 = worksheet.getCell('A1');
cellA1.value = "Issue summary";
cellA1.alignment = { vertical: "middle", horizontal: "left" };
cellA1.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellA1.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
var colWidthData = [
{ col: 'A', width: '155.51' },
{ col: 'B', width: '21.16' },
];
for (var i = 0; i < 2; i++) {
worksheet.getColumn(colWidthData[i].col).width = colWidthData[i].width;
}
// build Description title
worksheet.mergeCells('A2', "B2");
var descriptionRow = worksheet.getRow(2);
descriptionRow.height = "20.25"; // actual is 27
var cellA2 = worksheet.getCell("A2");
cellA2.value = " In the IBM Equal Access Toolkit, issues are divided into three levels (1-3). Tackle the levels in order to address some of the most impactful issues first.";
cellA2.alignment = { vertical: "middle", horizontal: "left" };
cellA2.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
// cellA2.fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFCCC0DA'} };
// build Total issues found: title
// worksheet.mergeCells('A3', "B3");
var totalIssuesRow = worksheet.getRow(3);
totalIssuesRow.height = "27"; // actual is 36
var cellA3 = worksheet.getCell("A3");
cellA3.value = "Total issues found:";
cellA3.alignment = { vertical: "middle", horizontal: "left" };
cellA3.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellA3.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF000000' } };
var cellB3 = worksheet.getCell("B3");
cellB3.value = totalIssues;
cellB3.alignment = { vertical: "middle", horizontal: "right" };
cellB3.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellB3.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF000000' } };
// build Number of issues title
var numberOfIssuesRow = worksheet.getRow(4);
numberOfIssuesRow.height = "20.25"; // actual is 27
var cellA4 = worksheet.getCell("A4");
// no value
cellA4.alignment = { vertical: "middle", horizontal: "left" };
cellA4.border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFFFFFFF' } }
};
var cellB4 = worksheet.getCell("B4");
cellB4.value = "Number of issues";
cellB4.alignment = { vertical: "middle", horizontal: "right" };
cellB4.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
cellB4.border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFFFFFFF' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
/////////////////////////////
// build Level 1 title
/////////////////////////////
var level1Row = worksheet.getRow(5);
level1Row.height = "27"; // actual is 36
var cellA5 = worksheet.getCell("A5");
cellA5.value = "Level 1 - the most essential issues to address";
cellA5.alignment = { vertical: "middle", horizontal: "left" };
cellA5.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellA5.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
var cellB5 = worksheet.getCell("B5");
cellB5.value = level1Counts[0]; // total Level 1 issues
cellB5.alignment = { vertical: "middle", horizontal: "right" };
cellB5.font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "16" };
cellB5.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF403151' } };
// Level 1 Violation title
var level1ViolationRow = worksheet.getRow(6);
level1ViolationRow.height = "18"; // target is 21
var cellA6 = worksheet.getCell("A6");
cellA6.value = " Violation";
cellA6.alignment = { vertical: "middle", horizontal: "left" };
cellA6.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
cellA6.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE4AAAF' } };
level1ViolationRow.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
var cellB6 = worksheet.getCell("B6");
cellB6.value = level1Counts[1]; // total level 1 violations
cellB6.alignment = { vertical: "middle", horizontal: "right" };
cellB6.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
cellB6.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE4AAAF' } };
level1ViolationRow.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {argb: 'FFA6A6A6'}},
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
// Level 1 Violation Rows
// build rows
var rowArray = [];
// let row:any =[];
for (var property in level1VrowValues) {
var row = [" " + "".concat(property), parseInt("".concat(level1VrowValues[property]))
];
rowArray.push(row);
}
// sort array according to count
rowArray.sort(function (a, b) { return (a[1] < b[1]) ? 1 : -1; });
// add array of rows
var rows = worksheet.addRows(rowArray);
rows.forEach(function (row) {
row.height = 14;
row.getCell(1).alignment = { vertical: "middle", horizontal: "left" };
row.getCell(2).alignment = { vertical: "middle", horizontal: "right" };
row.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
// row.getCell(1).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
// row.getCell(2).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
row.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {argb: 'FFA6A6A6'}},
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
});
// Level 1 Needs review title
var level1NeedsReviewRow = worksheet.addRow(["", 0]);
level1NeedsReviewRow.height = "18"; // target is 21
level1NeedsReviewRow.getCell(1).value = " Needs review";
level1NeedsReviewRow.getCell(1).alignment = { vertical: "middle", horizontal: "left" };
level1NeedsReviewRow.getCell(1).font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
level1NeedsReviewRow.getCell(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4E08A' } };
level1NeedsReviewRow.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
level1NeedsReviewRow.getCell(2).value = level1Counts[2]; // total level 1 needs review
level1NeedsReviewRow.getCell(2).alignment = { vertical: "middle", horizontal: "right" };
level1NeedsReviewRow.getCell(2).font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
level1NeedsReviewRow.getCell(2).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4E08A' } };
level1NeedsReviewRow.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {argb: 'FFA6A6A6'}},
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
// Level 1 Needs review Rows
// build rows
rowArray = [];
for (var property in level1NRrowValues) {
var row = [" " + "".concat(property), parseInt("".concat(level1NRrowValues[property]))
];
rowArray.push(row);
}
// sort array according to count
rowArray.sort(function (a, b) { return (a[1] < b[1]) ? 1 : -1; });
// add array of rows
rows = [];
rows = worksheet.addRows(rowArray);
rows.forEach(function (row) {
row.height = 14;
row.getCell(1).alignment = { vertical: "middle", horizontal: "left" };
row.getCell(2).alignment = { vertical: "middle", horizontal: "right" };
row.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
//row.getCell(1).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
//row.getCell(2).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
row.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {argb: 'FFA6A6A6'}},
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
});
// Level 1 Recommendation title
var level1RecommendationRow = worksheet.addRow(["", 0]);
level1RecommendationRow.height = "18"; // target is 21
level1RecommendationRow.getCell(1).value = " Recommendation";
level1RecommendationRow.getCell(1).alignment = { vertical: "middle", horizontal: "left" };
level1RecommendationRow.getCell(1).font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
level1RecommendationRow.getCell(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF96A9D7' } };
level1RecommendationRow.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
level1RecommendationRow.getCell(2).value = level1Counts[3]; // total level 1 recommendations
level1RecommendationRow.getCell(2).alignment = { vertical: "middle", horizontal: "right" };
level1RecommendationRow.getCell(2).font = { name: "Calibri", color: { argb: "FFFFFFFF" }, size: "12" };
level1RecommendationRow.getCell(2).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF96A9D7' } };
level1RecommendationRow.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {argb: 'FFA6A6A6'}},
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
right: { style: 'thin', color: { argb: 'FFA6A6A6' } }
};
// Level 1 Recommendation Rows
// build rows
rowArray = [];
for (var property in level1RrowValues) {
var row = [" " + "".concat(property), parseInt("".concat(level1RrowValues[property]))
];
rowArray.push(row);
}
// sort array according to count
rowArray.sort(function (a, b) { return (a[1] < b[1]) ? 1 : -1; });
// add array of rows
rows = [];
rows = worksheet.addRows(rowArray);
rows.forEach(function (row) {
row.height = 14;
row.getCell(1).alignment = { vertical: "middle", horizontal: "left" };
row.getCell(2).alignment = { vertical: "middle", horizontal: "right" };
row.font = { name: "Calibri", color: { argb: "FF000000" }, size: "12" };
//row.getCell(1).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
//row.getCell(2).fill = { type: 'pattern', pattern: 'solid', fgColor:{argb:'FFf8cbad'} };
row.getCell(1).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
left: { style: 'thin', color: { argb: 'FFA6A6A6' } },
bottom: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// right: {style:'thin', color: {argb: 'FFA6A6A6'}}
};
row.getCell(2).border = {
top: { style: 'thin', color: { argb: 'FFA6A6A6' } },
// left: {style:'thin', color: {