Skip to content

Commit 7e02746

Browse files
committed
Add a missing activities table in gocam-app
1 parent e21ce72 commit 7e02746

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

gocam_app/templates/gocam_app/index.html

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<style>
88
body {
99
margin-left: 1em;
10-
font-size: 150%;
10+
font-size: 140%;
1111
}
1212
#id_ids {
1313
width: 40em;
@@ -17,6 +17,23 @@
1717
margin-top: 1em;
1818
font-size: 110%;
1919
}
20+
#missing-activities table {
21+
border-collapse: collapse;
22+
width: 95%;
23+
}
24+
#missing-activities thead {
25+
border-bottom: 3px solid #ccc;
26+
}
27+
#missing-activities {
28+
font-size: 90%;
29+
}
30+
#missing-activities td, #missing-activities th {
31+
vertical-align: top;
32+
padding: 0.4em;
33+
}
34+
#missing-activities tr:nth-child(2n+1) {
35+
background-color: #f3f3fa;
36+
}
2037
</style>
2138
</head>
2239
<body>
@@ -47,5 +64,83 @@ <h4>Create a diagram from IDs:</h4>
4764
<input id="ids-submit" type="submit" value="View GO-CAM(s)">
4865
</form>
4966

67+
<h4>Missing activities</h4>
68+
<div id="missing-activities">
69+
<table>
70+
<thead>
71+
<tr>
72+
<th>
73+
Pathway
74+
</th>
75+
<th>
76+
Missing activity
77+
</th>
78+
<th>
79+
Process
80+
</th>
81+
<th>
82+
Input/output
83+
</th>
84+
<th>
85+
Occurs in
86+
</th>
87+
</tr>
88+
</thead>
89+
<tbody>
90+
</tbody>
91+
</table>
92+
</div>
93+
94+
<script type="module">
95+
const appPath = '{{app_path}}';
96+
const apiPath = '{{api_path}}';
97+
const holesUrl = `${apiPath}/missing_activities`;
98+
const response = await fetch(holesUrl);
99+
const holes = await response.json();
100+
const holesDiv = document.querySelector('#missing-activities');
101+
const tbody = holesDiv.querySelector('tbody');
102+
103+
for (const hole of holes) {
104+
const rowEl = document.createElement("tr");
105+
tbody.appendChild(rowEl);
106+
let [modelId, modelTitle] = hole.models[0];
107+
modelId = modelId.replace('gomodel:', '');
108+
109+
const modelEl = document.createElement("td");
110+
rowEl.appendChild(modelEl);
111+
const modelLinkEl = document.createElement('a');
112+
modelEl.appendChild(modelLinkEl);
113+
modelLinkEl.textContent = modelTitle;
114+
modelLinkEl.setAttribute('target', '_blank');
115+
modelLinkEl.setAttribute('href', appPath + '/view/model/' +modelId);
116+
117+
const missingActivityEl = document.createElement("td");
118+
rowEl.appendChild(missingActivityEl);
119+
missingActivityEl.textContent =
120+
hole.label + ' (' + hole.node_id + ')';
121+
122+
const processEl = document.createElement("td");
123+
rowEl.appendChild(processEl);
124+
processEl.textContent = hole.part_of_process.label + ' (' +
125+
hole.part_of_process.id + ')';
126+
127+
let inputs = hole.has_input.map(input => input.label).join(',');
128+
if (inputs.length == 0) {
129+
inputs = '?';
130+
}
131+
let outputs = hole.has_output.map(output => output.label).join(',');
132+
if (outputs.length == 0) {
133+
outputs = '?';
134+
}
135+
const inputOutputEl = document.createElement("td");
136+
rowEl.appendChild(inputOutputEl);
137+
inputOutputEl.textContent = inputs + ' / ' + outputs;
138+
139+
let occursInText = hole.has_input.map(input => input.label).join(',');
140+
const occursInEl = document.createElement("td");
141+
rowEl.appendChild(occursInEl);
142+
occursInEl.textContent = occursInText;
143+
}
144+
</script>
50145
</body>
51146
</html>

gocam_app/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
def index(request):
1010
app_path = request.GET.get('app_path', '').strip()
11+
api_path = request.GET.get('api_path', '').strip()
1112

1213
context = {
1314
'app_path': app_path,
15+
'api_path': api_path,
1416
}
1517

1618
if request.method == "POST":

0 commit comments

Comments
 (0)