Skip to content

Commit e0537ce

Browse files
committed
Add clientside pagination for bigger log snippets
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 9578815 commit e0537ce

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

vulnerabilities/templates/pipeline_run_details.html

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,37 @@ <h2 class="subtitle mb-2">Run Error</h2>
143143
<div class="box">
144144
<h2 class="subtitle mb-2">Log Output</h2>
145145
<div class="log-wrapper" style="position: relative;">
146-
<button class="button is-medium is-light copy-btn" id="copy-code"
146+
<button class="button is-medium is-light copy-btn" id="copy-code"
147147
onclick="copyCode('log-code', 'copy-code')">
148148
<span class="icon is-medium">
149149
<i class="fa fa-copy"></i>
150150
</span>
151151
</button>
152-
<pre><code id="log-code" class="language-toml">{{ run.log }}</code></pre>
152+
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>
156+
157+
<div class="has-text-centered mt-3">
158+
<button class="button is-link is-small mr-2" onclick="prevSnippet()">
159+
<i class="fa fa-arrow-left mr-1"></i>
160+
Prev
161+
</button>
162+
<span id="snippet-indicator">Snippet 1</span>
163+
<button class="button is-link is-small ml-2" onclick="nextSnippet()">
164+
Next
165+
<i class="fa fa-arrow-right ml-1"></i>
166+
</button>
167+
</div>
153168
</div>
154169
</div>
170+
155171
{% endif %}
156172

157173

158-
<a href="{% url 'runs-list' pipeline_id=run.pipeline.pipeline_id %}" class="button is-info mt-4"><i class="fa fa-arrow-left mr-2"></i>Back to All
159-
Runs</a>
174+
<a href="{% url 'runs-list' pipeline_id=run.pipeline.pipeline_id %}" class="button is-info mt-4">
175+
<i class="fa fa-arrow-left mr-2"></i>Back to AllRuns
176+
</a>
160177
</div>
161178
</section>
162179
{% endblock %}
@@ -167,9 +184,44 @@ <h2 class="subtitle mb-2">Log Output</h2>
167184
<script src="{% static 'js/highlight-10.6.0.min.js' %}" crossorigin="anonymous"></script>
168185
<script>hljs.highlightAll();</script>
169186

187+
<script>
188+
const logText = `{{ run.log|escapejs }}`;
189+
const lines = logText.split('\n');
190+
const linesPerSnippet = 500;
191+
const maxSnippetCount = Math.ceil(lines.length / linesPerSnippet);
192+
let currentSnippet = 0;
193+
194+
function renderSnippet() {
195+
const start = currentSnippet * linesPerSnippet;
196+
const end = start + linesPerSnippet;
197+
const pageLines = lines.slice(start, end).join('\n');
198+
snippetIndicator = `Snippet ${currentSnippet + 1} of ${maxSnippetCount}`;
199+
document.getElementById("log-code").removeAttribute("style");
200+
document.getElementById('log-code').textContent = pageLines;
201+
document.getElementById('snippet-indicator').textContent = snippetIndicator;
202+
}
203+
204+
function nextSnippet() {
205+
if ((currentSnippet + 1) < maxSnippetCount) {
206+
currentSnippet++;
207+
renderSnippet();
208+
}
209+
}
210+
211+
function prevSnippet() {
212+
if (currentSnippet > 0) {
213+
currentSnippet--;
214+
renderSnippet();
215+
}
216+
}
217+
218+
renderSnippet();
219+
</script>
220+
221+
170222
<script>
171223
function copyCode(target, button) {
172-
const code = document.getElementById(target).innerText;
224+
const code = (target === "log-code") ? `{{ run.log|escapejs }}` : `{{ run.run_output|escapejs }}`;
173225
navigator.clipboard.writeText(code)
174226
.then(() => {
175227
const btn = document.getElementById(button);

0 commit comments

Comments
 (0)