Skip to content

Commit 0154650

Browse files
committed
add question bank properties
Signed-off-by: Aabid Sofi <[email protected]>
1 parent 2d44cff commit 0154650

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

layouts/partials/test/single.html

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,36 @@
22
{{- $prerequisites := partial "test/collect-prerequisites.html" . -}}
33
{{- $ctx := partial "resolve-tenant.html" . -}}
44
{{- $orgId := $ctx.uuid -}}
5+
{{- $id := partial "id.html" . -}}
6+
7+
{{- $totalQuestionsPerSet := $p.number_of_questions | default (len $p.questions) -}}
8+
9+
<!-- Validate: TotalQuestions should be multiple of totalQuestionsPerSet -->
10+
{{- if ne (mod (len $p.questions) $totalQuestionsPerSet) 0 -}}
11+
{{- errorf "Total questions (%d) is not a multiple of total_questions_per_set (%d)" (len $p.questions) $totalQuestionsPerSet -}}
12+
{{- end -}}
13+
14+
<!-- Validate all question ids are unique -->
15+
{{- $questionIds := (slice ) -}}
16+
{{- range $p.questions -}}
17+
{{- if in $questionIds .id -}}
18+
{{- errorf "Duplicate question id found: %s" .id -}}
19+
{{- end -}}
20+
{{- $questionIds = $questionIds | append (string $id) -}}
21+
{{- end -}}
22+
23+
{{- $numberOfQuestionSets := div (len $p.questions) $totalQuestionsPerSet -}}
524

625
{{- $total := 0 -}}
7-
{{- range $p.questions }}
26+
{{- range first $totalQuestionsPerSet $p.questions -}}
827
{{- $total = add $total (or .marks 0) }}
928
{{- end }}
1029

30+
{{- $maxAttempts := or $p.max_attempts 0 -}}
31+
{{- if and (eq $maxAttempts 0) (gt $numberOfQuestionSets 1) -}}
32+
{{ $maxAttempts = $numberOfQuestionSets -}}
33+
{{- end -}}
34+
1135
{{- $parent := (cond (ne .Parent nil) (dict
1236
"id" (partial "id.html" .Parent)
1337
"title" .Parent.Title
@@ -31,11 +55,13 @@
3155
"lastmod" (.Lastmod | time.Format "2006-01-02")
3256
"draft" .Draft
3357
"file_path" .File.Path
34-
"max_attempts" (or $p.max_attempts 0)
58+
"max_attempts" $maxAttempts
59+
"total_question_sets" $numberOfQuestionSets
60+
"total_questions_in_bank" (len $p.questions)
3561
"pass_percentage" (or $p.pass_percentage 70)
3662
"time_limit" (or $p.time_limit 0 | string)
3763
"questions" $p.questions
38-
"total_questions" (len $p.questions)
64+
"total_questions" $totalQuestionsPerSet
3965
"prerequisites" $prerequisites
4066
"total_marks" $total
4167
"parent" $parent

layouts/test/single.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,48 @@ <h1>{{ $title }}</h1>
301301
</div>
302302
</div>
303303

304+
{{ else }}
305+
306+
<!-- In production build, show a loader while redirecting to the test page -->
307+
<style>
308+
/* HTML: <div class="loader"></div> */
309+
.loader {
310+
width: 50px;
311+
padding: 8px;
312+
aspect-ratio: 1;
313+
border-radius: 50%;
314+
background: var(--bs-primary);
315+
--_m:
316+
conic-gradient(#0000 10%, #000),
317+
linear-gradient(#000 0 0) content-box;
318+
-webkit-mask: var(--_m);
319+
mask: var(--_m);
320+
-webkit-mask-composite: source-out;
321+
mask-composite: subtract;
322+
animation: l3 1s infinite linear;
323+
}
324+
325+
.loader-container {
326+
display: flex;
327+
flex-direction: column;
328+
justify-content: center;
329+
align-items: center;
330+
height: 90vh;
331+
text-align: center;
332+
}
333+
334+
@keyframes l3 {
335+
to {
336+
transform: rotate(1turn)
337+
}
338+
}
339+
</style>
340+
<div class="loader-container">
341+
<div class="loader">
342+
</div>
343+
<p class="loader-text">Preparing your test...</p>
344+
</div>
345+
304346
{{ end }}
305347

306348
{{ $test := partial "test/single.html" . }}

0 commit comments

Comments
 (0)