Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test file contents to Svelte #407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions frontend/src/TestFile.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script>
import SyncLoader from "./SyncLoader.svelte";

export let url;
export let path;
export let max_bytes;
let folded = false;
let fetched = false;
let data = null;

async function getRawFile() {
if (!fetched) {
const res = await fetch(url);
fetched = true;
if (res.ok && parseInt(res.headers.get("Content-Length")) <= parseInt(max_bytes)) {
data = await res.text();
}
}
}
</script>

<div class="card mb-3">
<div class="card-header d-flex align-items-center justify-content-between">
<button class="btn p-0" on:click={() => folded = !folded}>
<h5>{ path }</h5>
</button>
<a href="{ url }">Raw content</a>
</div>
{#if !folded}
<div class="card-body">
{#await getRawFile()}
<SyncLoader />
{:then}
{#if data == null}
Content too large, show <a href="{ url }">raw content</a>.
{:else}
<pre>{ data }</pre>
{/if}
{/await}
</div>
{/if}
</div>
2 changes: 2 additions & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import PipelineStatus from './PipelineStatus.svelte'
import {safeMarkdown} from './markdown.js'
import CtrlP from './CtrlP.svelte'
import ColorTheme from "./ColorTheme.svelte"
import TestFile from "./TestFile.svelte"

class ReplaceHtmlElement extends HTMLElement {
constructor() {
Expand Down Expand Up @@ -108,6 +109,7 @@ createElement('upload-solution', UploadSolution);
createElement('pipeline-status', PipelineStatus);
createElement('ctrlp', CtrlP);
createElement("color-theme", ColorTheme);
createElement('test-file', TestFile);

function focusTab() {
const hash = document.location.hash.replace('#', '').split('-')[0].split(';')[0];
Expand Down
16 changes: 1 addition & 15 deletions templates/web/task_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,7 @@ <h2>{{ input.title }}{% if input.title != input.name %} <span class="text-muted"
{% endif %}

{% for path, file in input.sorted_files %}
<div class="card mb-3">
<div class="card-header">
<h5>
{{ path }}
(<a href="{% url 'raw_test_content' task.code input.name path %}{% if submit %}?student={{submit.student}}{%endif%}">Raw content</a>)
</h5>
</div>
<div class="card-body">
{% if file.size < max_inline_content_bytes or not max_inline_content_bytes %}
<pre>{{ file.read }}</pre>
{% else %}
Content too large, show <a href='{% url 'raw_test_content' task.code input.name path %}'>raw content</a>.
{% endif %}
</div>
</div>
<kelvin-test-file url="{% url 'raw_test_content' task.code input.name path %}{% if submit %}?student={{ submit.student }}{% endif %}" path="{{ path }}" max-bytes="{{ max_inline_content_bytes }}"></kelvin-test-file>
{% endfor %}

{% endfor %}
Expand Down
Loading