Skip to content

Commit 312674f

Browse files
committed
Handle boundary condition in snippet navigation
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 587328e commit 312674f

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

vulnerabilities/templates/pipeline_run_details.html

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
{% block title %}Run Log{% endblock %}
66

77
{% block extrahead %}
8+
89
<style>
910
pre {
1011
background-color: #282a36;
1112
color: #f8f8f2;
1213
padding: 1rem;
1314
border-radius: 4px;
1415
overflow-x: auto;
15-
max-height: 500px;
16+
height: 800px;
17+
position: relative;
1618
}
1719

1820
.column {
1921
word-break: break-word;
2022
}
21-
</style>
22-
23-
<style>
24-
pre {
25-
background-color: #282a36;
26-
color: #f8f8f2;
27-
padding: 1.5rem 1rem 1rem 1rem;
28-
border-radius: 4px;
29-
overflow-x: auto;
30-
max-height: 500px;
31-
position: relative;
32-
}
3323

3424
.copy-btn {
3525
position: absolute;
@@ -113,7 +103,6 @@ <h1 class="title">{{ pipeline_name }} Run Log</h1>
113103
<i class="fa fa-external-link fa_link_custom"></i>
114104
</a>
115105
{% endif %}
116-
117106
</p>
118107
</div>
119108
<div class="column is-one-fifth-desktop is-one-quarter-tablet is-half-mobile">
@@ -123,7 +112,6 @@ <h1 class="title">{{ pipeline_name }} Run Log</h1>
123112
</div>
124113
</div>
125114

126-
127115
{% if run.run_output|strip %}
128116
<div class="box">
129117
<h2 class="subtitle mb-2">Run Error</h2>
@@ -150,27 +138,26 @@ <h2 class="subtitle mb-2">Log Output</h2>
150138
</span>
151139
</button>
152140

153-
<pre><code id="log-code" class="language-toml" style="all: unset; display: flex; justify-content: center;">
154-
<i class="fa fa-spinner fa-spin fa-3x my-5 py-5"></i>
155-
</code></pre>
141+
<pre style="display: flex; justify-content: center; align-items: center;">
142+
<code id="log-code" class="language-toml"><i class="fa fa-spinner fa-spin fa-4x"></i></code>
143+
</pre>
156144

157-
<div class="has-text-centered mt-3">
158-
<button class="button is-link is-small mr-2" onclick="prevSnippet()">
145+
<div id="snippet-paginater" class="has-text-centered mt-3">
146+
<button id="prev-button" class="button is-link is-small mr-2" onclick="prevSnippet()">
159147
<i class="fa fa-arrow-left mr-1"></i>
160148
Prev
161149
</button>
162150
<span id="snippet-indicator">Snippet 1</span>
163-
<button class="button is-link is-small ml-2" onclick="nextSnippet()">
151+
<button id="next-button" class="button is-link is-small ml-2" onclick="nextSnippet()">
164152
Next
165153
<i class="fa fa-arrow-right ml-1"></i>
166154
</button>
167155
</div>
156+
168157
</div>
169158
</div>
170-
171159
{% endif %}
172160

173-
174161
<a href="{% url 'runs-list' pipeline_id=run.pipeline.pipeline_id %}" class="button is-info mt-4">
175162
<i class="fa fa-arrow-left mr-2"></i>Back to AllRuns
176163
</a>
@@ -182,7 +169,6 @@ <h2 class="subtitle mb-2">Log Output</h2>
182169
{% block scripts %}
183170
<link rel="stylesheet" href="{% static 'css/highlight-10.6.0.css' %}" crossorigin="anonymous">
184171
<script src="{% static 'js/highlight-10.6.0.min.js' %}" crossorigin="anonymous"></script>
185-
<script>hljs.highlightAll();</script>
186172

187173
<script>
188174
const logText = `{{ run.log|escapejs }}`;
@@ -195,10 +181,26 @@ <h2 class="subtitle mb-2">Log Output</h2>
195181
const start = currentSnippet * linesPerSnippet;
196182
const end = start + linesPerSnippet;
197183
const pageLines = lines.slice(start, end).join('\n');
184+
198185
snippetIndicator = `Snippet ${currentSnippet + 1} of ${maxSnippetCount}`;
199-
document.getElementById("log-code").removeAttribute("style");
186+
document.getElementById("log-code").parentElement.removeAttribute("style");
200187
document.getElementById('log-code').textContent = pageLines;
201-
document.getElementById('snippet-indicator').textContent = snippetIndicator;
188+
hljs.highlightAll();
189+
190+
if (maxSnippetCount > 1) {
191+
const snippetIndicatorEl = document.getElementById('snippet-indicator');
192+
const nextButton = document.getElementById('next-button');
193+
const prevButton = document.getElementById('prev-button');
194+
195+
snippetIndicatorEl.textContent = snippetIndicator;
196+
197+
nextButton.disabled = (currentSnippet + 2 > maxSnippetCount);
198+
prevButton.disabled = (currentSnippet - 1 < 0);
199+
} else {
200+
const paginator = document.getElementById('snippet-paginater');
201+
paginator.innerHTML = '';
202+
}
203+
202204
}
203205

204206
function nextSnippet() {

0 commit comments

Comments
 (0)