Skip to content

Commit c46f309

Browse files
committed
Fix rendering issues. Separate data access from rendering.
1 parent cef5027 commit c46f309

4 files changed

Lines changed: 51 additions & 64 deletions

File tree

assets/css/common.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
html {
33
overflow-y: scroll;
44
}
5+
6+
.form-radio {
7+
display: inline-block;
8+
}

data.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
<?php
22
require_once("functions.php");
33

4-
$dimensions = array();
4+
$showPerformed = ($_GET['performed'] ?? false) == "true" ? "true" : false;
5+
$showPlanned = ($_GET['planned'] ?? false) == "true" ? "true" : false;
56

7+
$dimensions = array();
68
$files = scandir("data");
7-
89
$dimensions = readYaml("data/dimensions.yaml");
910

11+
// reorder in-place $dimensions.
1012
ksort($dimensions);
1113
foreach ($dimensions as $dimensionName => $subDimension) {
1214
ksort($subDimension);
1315
foreach ($subDimension as $subDimensionName => $elements) {
16+
17+
// Q: should I retain this?
1418
if (substr($subDimensionName, 0, 1) == "_")
1519
continue;
20+
21+
// Upgrade old configuration to `references:`
22+
// this code can be modified to other models.
23+
foreach ($elements as $activityName => $content) {
24+
25+
if ($content["references"] ?? null) // ignore new lines
26+
continue;
27+
28+
$content["references"]["samm2"] = $content["samm2"] ?? array();
29+
unset($content["samm2"]);
30+
$content["references"]["iso27001-2017"] = $content["iso27001-2017"] ?? array();
31+
unset($content["iso27001-2017"]);
32+
//echo var_dump($elements[$activityName]);
33+
//echo "<hr>";
34+
$elements[$activityName] = $content;
35+
36+
}
1637
$newElements = $elements;
1738
ksort($newElements);
1839
$dimensions[$dimensionName][$subDimensionName] = $newElements;
1940
}
2041
}
2142

22-
if (array_key_exists("performed", $_GET)) {
23-
$showPerformed = $_GET['performed'];
24-
25-
if ($showPerformed != "true") $showPerformed = false;
26-
} else {
27-
$showPerformed = false;
28-
}
29-
30-
if (array_key_exists("planned", $_GET)) {
31-
$showPlanned = $_GET['planned'];
3243

33-
if ($showPlanned != "true") $showPlanned = false;
34-
} else {
35-
$showPlanned = false;
36-
}
3744
$filteredDimensions = array();
3845
foreach ($dimensions as $dimensionName => $subDimension) {
3946
ksort($subDimension);
@@ -208,10 +215,10 @@ function build_table_tooltip($array, $headerWeight = 2)
208215
function getElementByName($dimensions, $name)
209216
{
210217
foreach ($dimensions as $dimensionName => $subDimension) {
211-
foreach ($subDimension as $subDimensionName => $elements) {
212-
foreach ($elements as $activityName => $element) {
218+
foreach ($subDimension as $subDimensionName => $activities) {
219+
foreach ($activities as $activityName => $content) {
213220
if ($activityName == $name) {
214-
return $element;
221+
return $content;
215222
}
216223
}
217224
}

functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ function getReferenceLabel($reference_id) {
4040
return $referenceLabels[$reference_id]["label"] ?? $reference_id;
4141
}
4242

43+
function thead($headings){
44+
echo '<thead><tr><th scope="col">'
45+
.implode('</th><th scope="col">', $headings)
46+
.'</th></tr></thead>';
47+
}
48+
4349

4450
function renderSamm($samm_reference){
4551
return "$samm_reference";

mappings.php

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<?php
66
include_once "navi.php";
77
?>
8+
89
<?php
9-
include_once "data.php";
10+
include_once "data.php"; // set showPlanned, showPerformed, filteredDimensions
1011
include_once "detail.php";
1112
include_once "functions.php";
1213

@@ -22,7 +23,7 @@ function formCheck($reference_id, $sort) {
2223
$checked = ($sort == $reference_id) ? "checked": "";
2324
$reference_label = getReferenceLabel($reference_id);
2425
return '
25-
<div class="form-check">
26+
<div class="form-radio">
2627
<input class="form-check-input" type="radio" name="sort"
2728
id="radio'.$reference_id.'"
2829
value="'.$reference_id.'"
@@ -31,25 +32,19 @@ function formCheck($reference_id, $sort) {
3132
</div>
3233
';
3334
}
34-
function thead($headings){
35-
echo '<thead><tr><th scope="col">'
36-
.implode('</th><th scope="col">', $headings)
37-
.'</th></tr></thead>';
38-
}
39-
4035

4136
?>
4237
<form method="get">
43-
<?php
44-
45-
// Print form headers
46-
echo formCheck("activity", $sort);
47-
foreach ($referenceLabels as $r => $metadata) {
48-
echo formCheck($r, $sort);
49-
}
50-
?>
51-
52-
</div>
38+
<div class="sort-by">
39+
Sort by:
40+
<?php
41+
// Print form headers
42+
echo formCheck("activity", $sort);
43+
foreach ($referenceLabels as $r => $metadata) {
44+
echo formCheck($r, $sort);
45+
}
46+
?>
47+
</div>
5348
<div class="form-check">
5449
<input type="checkbox" class="form-check-input" name="performed" id="exampleCheck1" value="true"
5550
<?php if($showPerformed) {echo " checked=checked";}?>>
@@ -83,12 +78,6 @@ function thead($headings){
8378
$activityLink = "detail.php?dimension=" . urlencode ( $dimension ) . "&subdimension=" . urlencode ( $subdimension ) . "&element=" . urlencode ( $activityName );
8479
echo "<td><a href='$activityLink'><div data-toggle=\"popover\" data-title=\"$activityName\" data-content=\"$tooltip\" type=\"button\" data-html=\"true \">" . $activityName . "</div></a></td>";
8580

86-
// uniform old content.
87-
if (!($content["references"] ?? NULL)){
88-
$content["references"]["samm2"] = $content["samm2"] ?? array();
89-
$content["references"]["iso27001-2017"] = $content["iso27001-2017"] ?? array();
90-
}
91-
9281
foreach($referenceLabels as $r => $rLabel){
9382
$rlist = $content["references"][$r] ?? array();
9483
echo "<td>". renderSamms($rlist) ."</td>";
@@ -113,21 +102,8 @@ function thead($headings){
113102
$content["dimension"] = $dimension;
114103
$content["subdimension"] = $subdimension;
115104

116-
if (! ($content["references"] ?? null)) {
117-
// default.
118-
if (!($content[$sort] ?? null)){
119-
error_log("No $sort mapping for $activityName");
120-
continue;
121-
}
122-
123-
foreach(as_list($content[$sort]) as $mappingContent) {
124-
$mapping[$mappingContent][$activityName] = $content;
125-
}
126-
continue;
127-
}
128-
129-
foreach($content["references"] as $mappingContent => $rlist) {
130-
echo var_dump("$mappingContent");
105+
$references = $content["references"][$sort] ?? array();
106+
foreach(as_list($references) as $mappingContent) {
131107
$mapping[$mappingContent][$activityName] = $content;
132108
}
133109
}
@@ -145,12 +121,6 @@ function thead($headings){
145121
$tooltip = "<div class='popoverdetails'>" . build_table_tooltip ( $activity ) . "</div>";
146122
$activityLink = "detail.php?dimension=" . urlencode ( $activity['dimension'] ) . "&subdimension=" . urlencode ( $activity['subdimension'] ) . "&element=" . urlencode ( $activityName );
147123
echo "<td><a href='$activityLink'><div data-toggle=\"popover\" data-title=\"$activityName\" data-content=\"$tooltip\" type=\"button\" data-html=\"true \">" . $activityName . "</div></></td>";
148-
149-
// uniform old content.
150-
if (!($activity["references"] ?? NULL)){
151-
$activity["references"]["samm2"] = $activity["samm2"] ?? array();
152-
$activity["references"]["iso27001-2017"] = $activity["iso27001-2017"] ?? array();
153-
}
154124

155125
foreach($referenceLabels as $r => $rLabel){
156126
$rlist = $activity["references"][$r] ?? array();

0 commit comments

Comments
 (0)