✨ Improved question-type selection and fixed bug where Check Choice and ABCD were inverted
This commit is contained in:
@@ -57,6 +57,8 @@
|
|||||||
let edit_id;
|
let edit_id;
|
||||||
let confirm_to_leave = true;
|
let confirm_to_leave = true;
|
||||||
|
|
||||||
|
$: console.log('data', data);
|
||||||
|
|
||||||
const getEditID = async () => {
|
const getEditID = async () => {
|
||||||
let res;
|
let res;
|
||||||
if (quiz_id === null) {
|
if (quiz_id === null) {
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
const default_colors = ['#D6EDC9', '#B07156', '#7F7057', '#4E6E58'];
|
const default_colors = ['#D6EDC9', '#B07156', '#7F7057', '#4E6E58'];
|
||||||
|
|
||||||
console.log(get_foreground_color(default_colors[0]));
|
|
||||||
|
|
||||||
export let selected_question: number;
|
export let selected_question: number;
|
||||||
export let check_choice = false;
|
export let check_choice = false;
|
||||||
export let data: EditorData;
|
export let data: EditorData;
|
||||||
@@ -43,9 +41,8 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
$: save_colors(data);
|
$: save_colors(data);
|
||||||
data.questions[selected_question].type = check_choice
|
data.questions[selected_question].type =
|
||||||
? QuizQuestionType.ABCD
|
check_choice === true ? QuizQuestionType.CHECK : QuizQuestionType.ABCD;
|
||||||
: QuizQuestionType.CHECK;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-4 w-full px-10">
|
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-4 w-full px-10">
|
||||||
@@ -97,7 +94,6 @@
|
|||||||
type="button"
|
type="button"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
answer.right = !answer.right;
|
answer.right = !answer.right;
|
||||||
console.log(answer.right);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#if answer.right}
|
{#if answer.right}
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
<!--
|
||||||
|
- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import type { Answers, Question } from '$lib/quiz_types';
|
||||||
|
import { QuizQuestionType } from '$lib/quiz_types';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
import { getLocalization } from '$lib/i18n';
|
||||||
|
|
||||||
|
export let questions: Question[];
|
||||||
|
export let open: boolean;
|
||||||
|
|
||||||
|
const { t } = getLocalization();
|
||||||
|
onMount(() => {
|
||||||
|
document.body.addEventListener('keydown', close_start_game_if_esc_is_pressed);
|
||||||
|
});
|
||||||
|
const close_start_game_if_esc_is_pressed = (key: KeyboardEvent) => {
|
||||||
|
if (key.code === 'Escape') {
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const on_parent_click = (e: Event) => {
|
||||||
|
if (e.target === e.currentTarget) {
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const question_types: {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
answers: Answers;
|
||||||
|
type: QuizQuestionType;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
name: 'Multiple Choice',
|
||||||
|
description: '',
|
||||||
|
answers: [],
|
||||||
|
type: QuizQuestionType.ABCD
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Voting',
|
||||||
|
description: '',
|
||||||
|
answers: [],
|
||||||
|
type: QuizQuestionType.VOTING
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Check Choice',
|
||||||
|
description: '',
|
||||||
|
answers: [],
|
||||||
|
type: QuizQuestionType.CHECK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Order',
|
||||||
|
description: '',
|
||||||
|
answers: [],
|
||||||
|
type: QuizQuestionType.ORDER
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Text',
|
||||||
|
description: '',
|
||||||
|
answers: [],
|
||||||
|
type: QuizQuestionType.TEXT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Range',
|
||||||
|
description: '',
|
||||||
|
answers: {
|
||||||
|
max: 10,
|
||||||
|
min: 0,
|
||||||
|
max_correct: 7,
|
||||||
|
min_correct: 3
|
||||||
|
},
|
||||||
|
type: QuizQuestionType.RANGE
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const add_question = (index: number) => {
|
||||||
|
const empty_question: Question = {
|
||||||
|
type: question_types[index].type,
|
||||||
|
time: '20',
|
||||||
|
question: '',
|
||||||
|
image: undefined,
|
||||||
|
answers: question_types[index].answers
|
||||||
|
};
|
||||||
|
questions = [...questions, { ...empty_question }];
|
||||||
|
open = false;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed top-0 left-0 w-screen h-screen flex bg-black z-50 bg-opacity-50"
|
||||||
|
on:click={on_parent_click}
|
||||||
|
transition:fade|local={{ duration: 100 }}
|
||||||
|
>
|
||||||
|
<div class="m-auto w-2/3 h-5/6 rounded shadow-2xl bg-white dark:bg-gray-600 p-6">
|
||||||
|
<h1 class="text-center text-3xl mb-6">{$t('quiztivity.editor.select_page_type')}</h1>
|
||||||
|
<div class="grid grid-cols-4 gap-4 overflow-y-scroll">
|
||||||
|
{#each question_types as qt, i}
|
||||||
|
<div class="rounded p-6 border-[#B07156] border">
|
||||||
|
<button
|
||||||
|
class="text-xl text-black dark:text-white"
|
||||||
|
on:click={() => {
|
||||||
|
add_question(i);
|
||||||
|
}}>{qt.name}</button
|
||||||
|
>
|
||||||
|
<p class="text-sm">{qt.description}</p>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -17,15 +17,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const res = await fetch(`/api/v1/storage/info/${src}`);
|
const res = await fetch(`/api/v1/storage/info/${src}`);
|
||||||
console.log('Headers', res.headers);
|
|
||||||
const fileType = res.headers.get('Content-Type');
|
const fileType = res.headers.get('Content-Type');
|
||||||
console.log(fileType, 'fileType');
|
|
||||||
if (fileType.includes('video')) {
|
if (fileType.includes('video')) {
|
||||||
console.log('Setting type to video');
|
|
||||||
type = 'video';
|
type = 'video';
|
||||||
} else {
|
} else {
|
||||||
type = 'img';
|
type = 'img';
|
||||||
console.log(res);
|
|
||||||
const data = await fetch(`/api/v1/storage/download/${src}`);
|
const data = await fetch(`/api/v1/storage/download/${src}`);
|
||||||
return {
|
return {
|
||||||
data: URL.createObjectURL(await data.blob()),
|
data: URL.createObjectURL(await data.blob()),
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
min_correct: 3
|
min_correct: 3
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const correct_numbers = (data: number[]) => {
|
const correct_numbers = (data: number[]) => {
|
||||||
console.log(data, data[1] <= data[0])
|
console.log(data, data[1] <= data[0])
|
||||||
|
|||||||
@@ -80,7 +80,6 @@
|
|||||||
type="button"
|
type="button"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
answer.case_sensitive = !answer.case_sensitive;
|
answer.case_sensitive = !answer.case_sensitive;
|
||||||
console.log(answer.case_sensitive);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#if answer.case_sensitive}
|
{#if answer.case_sensitive}
|
||||||
|
|||||||
@@ -54,13 +54,22 @@
|
|||||||
|
|
||||||
const update_image_url = () => {
|
const update_image_url = () => {
|
||||||
image_url = data.questions[selected_question].image;
|
image_url = data.questions[selected_question].image;
|
||||||
console.log('updated!');
|
|
||||||
};
|
};
|
||||||
$: {
|
$: {
|
||||||
update_image_url();
|
update_image_url();
|
||||||
selected_question;
|
selected_question;
|
||||||
data.questions;
|
data.questions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const type_to_name = {
|
||||||
|
RANGE: $t('words.range'),
|
||||||
|
ABCD: $t('words.multiple_choice'),
|
||||||
|
VOTING: $t('words.voting'),
|
||||||
|
TEXT: $t('words.text'),
|
||||||
|
ORDER: $t('words.order'),
|
||||||
|
CHECK: $t('words.check_choice')
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (typeof data.questions[selected_question].type !== QuizQuestionType) {
|
if (typeof data.questions[selected_question].type !== QuizQuestionType) {
|
||||||
console.log(data.questions[selected_question].type !== QuizQuestionType.ABCD || data.questions[selected_question].type !== QuizQuestionType.RANGE)
|
console.log(data.questions[selected_question].type !== QuizQuestionType.ABCD || data.questions[selected_question].type !== QuizQuestionType.RANGE)
|
||||||
@@ -183,21 +192,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center pt-10">
|
<div class="flex justify-center pt-10">
|
||||||
<select
|
<p>{type_to_name[String(data.questions[selected_question].type)]}</p>
|
||||||
class="p-2 rounded-lg bg-gray-800 focus:ring-2 ring-blue-600 text-white"
|
|
||||||
name="Answer-Type"
|
|
||||||
bind:value={data.questions[selected_question].type}
|
|
||||||
>
|
|
||||||
<option value={QuizQuestionType.RANGE}>{$t('words.range')}</option>
|
|
||||||
<option value={QuizQuestionType.ABCD}>{$t('words.multiple_choice')}</option>
|
|
||||||
<option value={QuizQuestionType.VOTING}>{$t('words.voting')}</option>
|
|
||||||
<option value={QuizQuestionType.TEXT}>{$t('words.text')}</option>
|
|
||||||
<option value={QuizQuestionType.ORDER}>{$t('words.order')}</option>
|
|
||||||
<option value={QuizQuestionType.CHECK}>{$t('words.check_choice')}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center py-10 w-full">
|
<div class="flex justify-center py-10 w-full">
|
||||||
{#if type === QuizQuestionType.ABCD || QuizQuestionType.CHECK}
|
{#if type === QuizQuestionType.ABCD || type === QuizQuestionType.CHECK}
|
||||||
{#await import('$lib/editor/ABCDEditorPart.svelte')}
|
{#await import('$lib/editor/ABCDEditorPart.svelte')}
|
||||||
<Spinner my_20={false} />
|
<Spinner my_20={false} />
|
||||||
{:then c}
|
{:then c}
|
||||||
@@ -209,6 +207,7 @@
|
|||||||
/>
|
/>
|
||||||
{/await}
|
{/await}
|
||||||
{:else if type === QuizQuestionType.RANGE}
|
{:else if type === QuizQuestionType.RANGE}
|
||||||
|
<p>Range</p>
|
||||||
<RangeEditor bind:selected_question bind:data />
|
<RangeEditor bind:selected_question bind:data />
|
||||||
{:else if type === QuizQuestionType.VOTING}
|
{:else if type === QuizQuestionType.VOTING}
|
||||||
{#await import('$lib/editor/VotingEditorPart.svelte')}
|
{#await import('$lib/editor/VotingEditorPart.svelte')}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
import { ABCDQuestionSchema, dataSchema } from '../yupSchemas';
|
import { ABCDQuestionSchema, dataSchema } from '../yupSchemas';
|
||||||
import { createTippy } from 'svelte-tippy';
|
import { createTippy } from 'svelte-tippy';
|
||||||
import { getLocalization } from '$lib/i18n';
|
import { getLocalization } from '$lib/i18n';
|
||||||
|
import AddNewQuestionPopup from '$lib/editor/AddNewQuestionPopup.svelte';
|
||||||
|
|
||||||
const { t } = getLocalization();
|
const { t } = getLocalization();
|
||||||
|
|
||||||
export let data: EditorData;
|
export let data: EditorData;
|
||||||
@@ -22,13 +24,7 @@
|
|||||||
});
|
});
|
||||||
let arr_of_cards = Array(data.questions.length);
|
let arr_of_cards = Array(data.questions.length);
|
||||||
let propertyCard;
|
let propertyCard;
|
||||||
const empty_question: Question = {
|
let add_new_question_popup_open = false;
|
||||||
question: '',
|
|
||||||
time: '20',
|
|
||||||
image: '',
|
|
||||||
answers: [],
|
|
||||||
type: QuizQuestionType.ABCD
|
|
||||||
};
|
|
||||||
|
|
||||||
const empy_slide: Question = {
|
const empy_slide: Question = {
|
||||||
type: QuizQuestionType.SLIDE,
|
type: QuizQuestionType.SLIDE,
|
||||||
@@ -205,7 +201,7 @@
|
|||||||
class="h-10 border rounded-lg"
|
class="h-10 border rounded-lg"
|
||||||
alt="Not available"
|
alt="Not available"
|
||||||
use:tippy={{
|
use:tippy={{
|
||||||
content: `<img src='/api/v1/storage/download/${question.image}' alt='Not available' class='rounded'>`,
|
content: `<img src="/api/v1/storage/download/${question.image}" alt="Not available" class="rounded">`,
|
||||||
allowHTML: true
|
allowHTML: true
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -281,7 +277,7 @@
|
|||||||
type="button"
|
type="button"
|
||||||
class="h-full flex justify-center w-full dark:text-black flex-col border-r border-black"
|
class="h-full flex justify-center w-full dark:text-black flex-col border-r border-black"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
data.questions = [...data.questions, { ...empty_question }];
|
add_new_question_popup_open = true;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span class="w-full text-center">{$t('words.question')}</span>
|
<span class="w-full text-center">{$t('words.question')}</span>
|
||||||
@@ -325,3 +321,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#if add_new_question_popup_open}
|
||||||
|
<AddNewQuestionPopup bind:questions={data.questions} bind:open={add_new_question_popup_open} />
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -84,7 +84,6 @@
|
|||||||
fill: '#ff000d'
|
fill: '#ff000d'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(canvas.export.toJson());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
@@ -146,7 +145,6 @@
|
|||||||
interactive: false
|
interactive: false
|
||||||
}*/
|
}*/
|
||||||
});
|
});
|
||||||
console.log(data.answers);
|
|
||||||
if (data.answers) {
|
if (data.answers) {
|
||||||
if (typeof data.answers === 'string') {
|
if (typeof data.answers === 'string') {
|
||||||
canvas.import.json(JSON.parse(data.answers));
|
canvas.import.json(JSON.parse(data.answers));
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
const set_available_modifiers = () => {
|
const set_available_modifiers = () => {
|
||||||
available_modifiers = [];
|
available_modifiers = [];
|
||||||
console.log(selected_el, 'sel_el');
|
|
||||||
if (!selected_el) {
|
if (!selected_el) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -43,19 +42,16 @@
|
|||||||
|
|
||||||
const change_color = (e: Event) => {
|
const change_color = (e: Event) => {
|
||||||
if (available_modifiers.includes('text_color')) {
|
if (available_modifiers.includes('text_color')) {
|
||||||
console.log('text color');
|
|
||||||
selected_el.updateText({
|
selected_el.updateText({
|
||||||
fill: e.target.value
|
fill: e.target.value
|
||||||
});
|
});
|
||||||
} else if (available_modifiers.includes('fill_color')) {
|
} else if (available_modifiers.includes('fill_color')) {
|
||||||
console.log('fill color');
|
|
||||||
selected_el.update({ fill: e.target.value });
|
selected_el.update({ fill: e.target.value });
|
||||||
}
|
}
|
||||||
opened_dropdown = null;
|
opened_dropdown = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const change_fontsize = (e: Event) => {
|
const change_fontsize = (e: Event) => {
|
||||||
console.log(selected_el.node.children[1].attrs.fontSize);
|
|
||||||
selected_el.updateText({
|
selected_el.updateText({
|
||||||
fontSize: e.target.value
|
fontSize: e.target.value
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
data = '#ed333b';
|
data = '#ed333b';
|
||||||
}
|
}
|
||||||
$: console.log(data);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="rounded-full w-full h-full flex justify-center p-2" style="background-color: {data}">
|
<div class="rounded-full w-full h-full flex justify-center p-2" style="background-color: {data}">
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
data = '#ed333b';
|
data = '#ed333b';
|
||||||
}
|
}
|
||||||
$: console.log(data);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-full h-full flex justify-center p-2" style="background-color: {data}">
|
<div class="w-full h-full flex justify-center p-2" style="background-color: {data}">
|
||||||
|
|||||||
@@ -85,7 +85,6 @@
|
|||||||
} else {
|
} else {
|
||||||
data.questions[selected_question].image = image_id;
|
data.questions[selected_question].image = image_id;
|
||||||
}
|
}
|
||||||
console.log(selected_question, data);
|
|
||||||
|
|
||||||
modalOpen = false;
|
modalOpen = false;
|
||||||
selected_type = null;
|
selected_type = null;
|
||||||
@@ -109,7 +108,6 @@
|
|||||||
'popup=true,toolbar=false,menubar=false,location=false,'
|
'popup=true,toolbar=false,menubar=false,location=false,'
|
||||||
);
|
);
|
||||||
video_popup.addEventListener('beforeunload', () => {
|
video_popup.addEventListener('beforeunload', () => {
|
||||||
console.log('Unloaded');
|
|
||||||
video_popup = undefined;
|
video_popup = undefined;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,7 +73,6 @@
|
|||||||
})
|
})
|
||||||
.then((newEditor) => {
|
.then((newEditor) => {
|
||||||
editor = newEditor;
|
editor = newEditor;
|
||||||
console.log(editor);
|
|
||||||
editor.setData(text);
|
editor.setData(text);
|
||||||
editor.model.document.on('change:data', () => {
|
editor.model.document.on('change:data', () => {
|
||||||
triggerChange();
|
triggerChange();
|
||||||
|
|||||||
@@ -58,14 +58,16 @@ export interface Question {
|
|||||||
question: string;
|
question: string;
|
||||||
type?: QuizQuestionType;
|
type?: QuizQuestionType;
|
||||||
image?: string;
|
image?: string;
|
||||||
answers:
|
answers: Answers;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Answers =
|
||||||
| Answer[]
|
| Answer[]
|
||||||
| RangeQuizAnswer
|
| RangeQuizAnswer
|
||||||
| VotingAnswer[]
|
| VotingAnswer[]
|
||||||
| string
|
| string
|
||||||
| TextQuizAnswer[]
|
| TextQuizAnswer[]
|
||||||
| OrderQuizAnswer[];
|
| OrderQuizAnswer[];
|
||||||
}
|
|
||||||
|
|
||||||
export interface Answer {
|
export interface Answer {
|
||||||
right: boolean;
|
right: boolean;
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
let { quiz_id } = data;
|
let { quiz_id } = data;
|
||||||
console.log(quiz_id);
|
|
||||||
let quiz_data: Data;
|
let quiz_data: Data;
|
||||||
|
|
||||||
const get_quiz = async (): Promise<void> => {
|
const get_quiz = async (): Promise<void> => {
|
||||||
|
|||||||
Reference in New Issue
Block a user