Skip to content

Commit 65d44e5

Browse files
committed
Display policy report
1 parent 9755a96 commit 65d44e5

4 files changed

Lines changed: 34 additions & 23 deletions

File tree

public/.hermes/process/transport.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@
482482
{"conflict": "Curation"}
483483
],
484484

485-
"policies": [{"policy 1": {"conforms": true}},
486-
{"policy 2": {"conforms": false,
485+
"policies": [{"Policy 1": {"conforms": true}},
486+
{"Policy 2": {"conforms": false,
487487
"resultMessage": "String length not >= Literal(\"100\", datatype=xsd:integer)" ,
488488
"resultPath": "https://schema.org/description" ,
489489
"resultSeverity": "Violation" ,

public/curation/curation.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { extract_info } from "./extract.js";
22

3+
/**
4+
* Fetches json_document and displays their contents in a table.
5+
* @param {Path} json_document - document do fetch data from.
6+
*/
37
export function displayJSON(json_document){
4-
58
fetch(json_document)
69
.then(response => response.json())
710
.then(data => {
11+
//Get data snippet from url
812
const params = new URLSearchParams(location.search);
913
if(params.has("id")){
1014
const id = params.get("id")
1115
data = get_data_snippet(data, "@id", id);
1216

17+
//If your seeing a data snippet, create button to go back
1318
const back = document.createElement("button");
1419
back.innerText = "Back to Overview";
1520
back.onclick = () => {window.location = window.location.href.split('?')[0];}
1621
document.body.appendChild(back);
1722
}
1823

24+
// Apply and fill in the template for Metadata
1925
const keys = Object.keys(data);
2026

2127
const metadateTemp = document.querySelector("#metadate");
@@ -27,60 +33,58 @@ export function displayJSON(json_document){
2733
const header = document.querySelector("#header-policies");
2834
header.style.display = "none";
2935

36+
3037
keys.forEach(element => {
38+
// Get a something with Name as p Header
3139
if(element.toLowerCase().includes("name")){
32-
console.log(element);
3340
document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' <b> '+data[element][0]+'</b>';
3441
}
42+
// Apply and fill in the template for Policies
3543
if(element=="policies"){
3644
header.style.display = "block";
37-
console.log("policies");
3845
data[element].forEach(pol =>{
39-
console.log(pol);
4046
const policy = document.importNode(policyTemp.content, true);
41-
console.log(policy);
4247
const tbodyPol = policy.querySelector("tbody"),
43-
polname = policy.querySelector("#policy-name");
48+
polname = policy.querySelector("#policy-name"),
49+
pconforms = policy.querySelector("#policy-conforms");
4450
const policyId = Object.keys(pol)[0];
4551
polname.textContent = `${policyId}`;
4652
policyDiv.appendChild(policy);
4753
const policyReportTemp = document.querySelector("#policy-report");
4854
const polKeys = Object.keys(pol[policyId]);
49-
console.log(polKeys);
5055
polKeys.forEach(report =>{
51-
console.log(report);
5256
const prow = document.importNode(policyReportTemp.content, true);
5357

5458
const pkey = prow.querySelector("#pkey"),
5559
pvalue = prow.querySelector("#pvalue");
56-
//pconforms = prow.querySelector("#policy-conforms");
60+
5761
if(report=="conforms"){
58-
console.log("conforms");
62+
pconforms.innerText = `${policyId} ${(pol[policyId][report]) ? 'is' : 'is not'} conform.`;
63+
pconforms.style.color = (pol[policyId][report]) ? 'black' : 'red';
5964
}
60-
console.log(report,pol[policyId][report]);
6165
pkey.textContent = `${report}`;
6266
extract_info(pvalue, pol[policyId][report]);
63-
//pvalue.textContent = `${pol[policyId][report]}`;
67+
6468
tbodyPol.appendChild(prow);
6569
})
6670
})
6771

6872
return;
69-
}
73+
}
74+
75+
// Apply and fill in the template for Metadata
7076
const row = document.importNode(metadateTemp.content, true);
71-
console.log(row);
7277
const mkey = row.querySelector("#key"),
7378
mvalue = row.querySelector("#value"),
7479
mtag = row.querySelector("#tag");
7580

7681
mkey.textContent = `${element}`;
7782
extract_info(mvalue, data[element], mtag);
78-
/*
79-
mvalue.textContent = `${data[element][0]}`;
80-
mtag.textContent = `${data[element][1]["local_path"]}`;*/
83+
8184
tbody.appendChild(row);
8285
})
8386
})
87+
//Extend Checkbox for metadata source
8488
const checkbox = document.querySelector("#extended");
8589
checkbox.addEventListener('change', (event)=>{
8690
if(checkbox.checked){
@@ -93,7 +97,16 @@ checkbox.addEventListener('change', (event)=>{
9397

9498

9599
}
100+
101+
/**
102+
* Function to get a smaller object from the orginal object.
103+
* searches through data till skey and svalue match and return the data from this point.
104+
* @param {Dictonary} data - Object(dict) to search from
105+
* @param {string} skey - search key for key-value pair to get data from
106+
* @param {} svalue - search value for key-value pair to get data from
107+
*/
96108
function get_data_snippet(data, skey, svalue){
109+
97110
const stack = [data];
98111
while (stack?.length > 0) {
99112
const obj = stack.pop();

public/curation/extract.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ function extract_info(cell, obj, tag, category){
44
}
55
if(typeof obj[0] === "string" || typeof obj[0] == "number" || typeof obj[0] == "boolean"){
66
if(obj[2] && obj[2]["conflict"] == "Curation"){
7-
console.log(`${Object.keys(obj[2])}`);
87
const element = document.createElement("div");
98
element.className += " error";
109
element.appendChild(document.createTextNode(` ${obj[0]}`));
@@ -23,7 +22,6 @@ function extract_info(cell, obj, tag, category){
2322
})}
2423
else if(Array.isArray(obj[0])){
2524
obj[0].forEach(e =>{
26-
console.log(e);
2725
const element = document.createElement("div");
2826
extract_info(element, e, tag);
2927
//element.appendChild(document.createTextNode(`hh ${e}`));
@@ -65,10 +63,9 @@ function extract_info(cell, obj, tag, category){
6563
tooltiptag.appendChild(document.createTextNode("See Details"));
6664
tooltiptag.appendChild(document.createElement("br"));
6765
tooltiptag.onclick = function(){link_to_person(e)};
68-
console.log(e);
6966
tag.appendChild(tooltiptag);
7067
//const data = JSON.stringify(e, null, 2);
71-
68+
7269
const names = [];
7370
Object.keys(e).forEach(k => {
7471
const pair = document.createElement("p");

public/curation/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h1><a href="../">Software CaRD</a>
5050
<h3 id="header-policies">Policy Report</h3>
5151
<template id="policy">
5252
<b id="policy-name"></b>
53+
<p id="policy-conforms"></p>
5354
<table>
5455
<tbody>
5556
<template id="policy-report">

0 commit comments

Comments
 (0)