-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation Frontend: Summary Page (#31)
* Added summary page * Newline & Typo * Implemented requested changes * Added target blank as requested
- Loading branch information
1 parent
ff8419d
commit d29837a
Showing
7 changed files
with
126 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(async () => { | ||
const getElem = (id: string) => document.getElementById(id); | ||
|
||
const urlString = window.location.href; | ||
const summaryId = urlString.substr(urlString.lastIndexOf('/') + 1); | ||
const rawResponse = await fetch( | ||
`http://localhost:3000/api/summary/${summaryId}` | ||
); | ||
const summary: UrlSummary = await rawResponse.json(); | ||
|
||
const urlContainer = getElem('urlContainer'); | ||
const numNodesContainer = getElem('numNodes'); | ||
const categoryTable = getElem('categoryTable'); | ||
if (!urlContainer || !numNodesContainer || !categoryTable) | ||
throw new ElemNotFound(); | ||
|
||
urlContainer.innerHTML = `<a href="${summary.url}" target="_blank">${summary.url}</a>`; | ||
numNodesContainer.innerText = summary.nodesOnPage.toString(); | ||
|
||
const stats = summary.stats.sort((a, b) => b.count - a.count); | ||
|
||
for (const stat of stats) { | ||
const categoryString = getFormattedCategoryHTML(stat.category); | ||
|
||
// Add a row of generated HTML to the category table. | ||
categoryTable.innerHTML += ` | ||
<tr> | ||
<td>${categoryString}</td> | ||
<td style="text-align:center;">${stat.count}</td> | ||
<td> | ||
<a href="/case/${stat.caseId}" target="_blank" rel="noopener noreferrer" class="invisibleLink" aria-label="View case ${stat.caseId}"> | ||
<div class="previewCard" style="margin:0;"> | ||
Case ${stat.caseId} | ||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" style="margin-left:auto;"> | ||
<path d="M0 0h24v24H0z" fill="none"/> | ||
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z" fill="white"/> | ||
</svg> | ||
</div> | ||
</a> | ||
</td> | ||
</tr> | ||
`; | ||
} | ||
})(); | ||
|
||
/** | ||
* Generates a string of HTML containing a formatted | ||
* representation of the Category provided. | ||
* @param category - The Category to be formatted | ||
*/ | ||
function getFormattedCategoryHTML(category: Category): string { | ||
let categoryString = | ||
'<strong>Agreement:</strong> ' + | ||
JSON.stringify(category.agreement) + | ||
'<br/>'; | ||
if (category.role) { | ||
categoryString += | ||
'<strong>Role:</strong> ' + '"' + category.role + '"' + '<br/>'; | ||
} | ||
if (category.rules) { | ||
categoryString += | ||
'<strong>Rules:</strong> ' + JSON.stringify(category.rules) + '<br/>'; | ||
} | ||
return categoryString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AccName Comparison</title> | ||
<!-- External Dependencies --> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono"> | ||
<!-- Local Dependencies --> | ||
<link rel="stylesheet" href="/static/styles/index.css"> | ||
<script src="/static/scripts/util.js"></script> | ||
<script src="/static/scripts/summary.js"></script> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<header class="titleContainer" style="margin-bottom: 20px;"> | ||
<h1 class="title">Web-page Summary</h1> | ||
</header> | ||
<section class="section"> | ||
<h2 class="heading" id="urlContainer"></h2> | ||
<div class="bluetext" style="margin-bottom: 10px;">Comparison run on <strong><span id="numNodes"></span></strong> Nodes in total</div> | ||
</section> | ||
<section class="section"> | ||
<table id="categoryTable"> | ||
<colgroup> | ||
<col span="1" style="width: 65%;"> | ||
<col span="1" style="width: 15%;"> | ||
<col span="1" style="width: 20%;"> | ||
</colgroup> | ||
<tr class="tableHeaderRow"> | ||
<th>Category</th> | ||
<th>Frequency</th> | ||
<th>Test-case</th> | ||
</tr> | ||
</table> | ||
</section> | ||
</div> | ||
</body> | ||
</html> |