- time limit and repeatable options added to content editor
This commit is contained in:
parent
53a72e0a2c
commit
20364feda8
@ -16,6 +16,7 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
|
|||||||
<title>SpreadQuiz</title>
|
<title>SpreadQuiz</title>
|
||||||
<script src="js/req.js"></script>
|
<script src="js/req.js"></script>
|
||||||
<script src="js/spreadquiz.js"></script>
|
<script src="js/spreadquiz.js"></script>
|
||||||
|
<script src="js/common.js"></script>
|
||||||
<script src="js/o.js"></script>
|
<script src="js/o.js"></script>
|
||||||
<script src="js/hintbox.js"></script>
|
<script src="js/hintbox.js"></script>
|
||||||
<script src="js/usermgr.js"></script>
|
<script src="js/usermgr.js"></script>
|
||||||
@ -55,6 +56,15 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
|
|||||||
<input type="file" id="game_file" shown="false">
|
<input type="file" id="game_file" shown="false">
|
||||||
<input type="button" value="Mégse" id="cancel_game_file_upload" shown="false" onclick="show_hide_gamefile_upload(false);"></span><br>
|
<input type="button" value="Mégse" id="cancel_game_file_upload" shown="false" onclick="show_hide_gamefile_upload(false);"></span><br>
|
||||||
<span>Csoportok: <input type="text" id="game_groups"></span><br>
|
<span>Csoportok: <input type="text" id="game_groups"></span><br>
|
||||||
|
<span>
|
||||||
|
<input type="checkbox" id="time_limited" oninput="handle_time_limit_chkbox()">
|
||||||
|
<label for="time_limited">Időkorlátos:</label>
|
||||||
|
<input type="time" id="time_limit" step="1">
|
||||||
|
</span><br>
|
||||||
|
<span>
|
||||||
|
<input type="checkbox" id="repeatable">
|
||||||
|
<label for="repeatable">Megismételhető</label>
|
||||||
|
</span>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<span><input type="button" value="" id="game_editor_submit_btn"><input type="button" value="Mégse" onclick="hide('game_editor_window')"></span>
|
<span><input type="button" value="" id="game_editor_submit_btn"><input type="button" value="Mégse" onclick="hide('game_editor_window')"></span>
|
||||||
|
@ -7,7 +7,7 @@ $gamedb = new \SleekDB\Store(GAMEDB, DATADIR, ["timeout" => false]);
|
|||||||
|
|
||||||
const DEFAULT_GAME_PROPERTIES = [
|
const DEFAULT_GAME_PROPERTIES = [
|
||||||
"forward_only" => false, // player may traverse back and forth between challenges
|
"forward_only" => false, // player may traverse back and forth between challenges
|
||||||
"time_limit" => -1, // no time limit; otherwise, this field indicates time limit in seconds
|
"time_limit" => 0, // no time limit; otherwise, this field indicates time limit in seconds
|
||||||
"repeatable" => false // this test can be taken multiple times
|
"repeatable" => false // this test can be taken multiple times
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -161,6 +161,7 @@ switch ($action) {
|
|||||||
$contributors = explode_list($data["contributors"] ?: "");
|
$contributors = explode_list($data["contributors"] ?: "");
|
||||||
$owner = $update ? trim($data["owner"] ?: $nickname) : $nickname;
|
$owner = $update ? trim($data["owner"] ?: $nickname) : $nickname;
|
||||||
$groups = explode_list($data["groups"] ?: "");
|
$groups = explode_list($data["groups"] ?: "");
|
||||||
|
$properties = $data["properties"] ?: [];
|
||||||
|
|
||||||
$groupids = get_groupids_by_compounds($groups); // convert group compounds to _ids
|
$groupids = get_groupids_by_compounds($groups); // convert group compounds to _ids
|
||||||
|
|
||||||
@ -200,6 +201,8 @@ switch ($action) {
|
|||||||
$game_data["owner"] = $owner;
|
$game_data["owner"] = $owner;
|
||||||
}
|
}
|
||||||
$game_data["contributors"] = array_intersect($contributors, get_all_nicknames());
|
$game_data["contributors"] = array_intersect($contributors, get_all_nicknames());
|
||||||
|
$game_data["properties"]["time_limit"] = $properties["time_limit"];
|
||||||
|
$game_data["properties"]["repeatable"] = $properties["repeatable"];
|
||||||
update_game($game_data);
|
update_game($game_data);
|
||||||
|
|
||||||
// update game file if supplied
|
// update game file if supplied
|
||||||
|
28
js/common.js
28
js/common.js
@ -3,3 +3,31 @@ function unix_time_to_human_readable(tunix) {
|
|||||||
return date.getFullYear() + ". " + String(date.getMonth() + 1).padStart(2, "0") + ". " + String(date.getDate()).padStart(2, "0") + ". "
|
return date.getFullYear() + ". " + String(date.getMonth() + 1).padStart(2, "0") + ". " + String(date.getDate()).padStart(2, "0") + ". "
|
||||||
+ String(date.getHours()).padStart(2, "0") + ":" + String(date.getMinutes()).padStart(2, "0") + ":" + String(date.getSeconds()).padStart(2, "0");
|
+ String(date.getHours()).padStart(2, "0") + ":" + String(date.getMinutes()).padStart(2, "0") + ":" + String(date.getSeconds()).padStart(2, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function seconds_to_time(s) {
|
||||||
|
let hours = Math.floor(s / 3600);
|
||||||
|
s -= hours * 3600;
|
||||||
|
let minutes = Math.floor(s / 60);
|
||||||
|
s -= minutes * 60;
|
||||||
|
let seconds = s;
|
||||||
|
return String(hours).padStart(2, "0") + ":"
|
||||||
|
+ String(minutes).padStart(2, "0") + ":"
|
||||||
|
+ String(seconds).padStart(2, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
function time_to_seconds(t) {
|
||||||
|
let s = 0;
|
||||||
|
let parts = t.split(":").reverse();
|
||||||
|
if (parts.length >= 1) {
|
||||||
|
s += Number(parts[0]);
|
||||||
|
|
||||||
|
if (parts.length >= 2) {
|
||||||
|
s += Number(parts[1]) * 60;
|
||||||
|
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
s += Number(parts[2]) * 3600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
@ -47,6 +47,9 @@ function create_edit_game(game = null) {
|
|||||||
let show_game_file_upload_btn = document.getElementById("show_game_file_upload");
|
let show_game_file_upload_btn = document.getElementById("show_game_file_upload");
|
||||||
let cancel_game_file_upload_btn = document.getElementById("cancel_game_file_upload");
|
let cancel_game_file_upload_btn = document.getElementById("cancel_game_file_upload");
|
||||||
let groupF = document.getElementById("game_groups");
|
let groupF = document.getElementById("game_groups");
|
||||||
|
let time_limitedChk = document.getElementById("time_limited");
|
||||||
|
let time_limitF = document.getElementById("time_limit");
|
||||||
|
let repeatableChk = document.getElementById("repeatable");
|
||||||
|
|
||||||
if (!updating) { // creating a new game
|
if (!updating) { // creating a new game
|
||||||
nameF.value = "";
|
nameF.value = "";
|
||||||
@ -56,6 +59,8 @@ function create_edit_game(game = null) {
|
|||||||
ownerF.readOnly = true;
|
ownerF.readOnly = true;
|
||||||
contributorsF.value = "";
|
contributorsF.value = "";
|
||||||
groupF.value = "";
|
groupF.value = "";
|
||||||
|
time_limitedChk.checked = false;
|
||||||
|
repeatableChk.checked = true;
|
||||||
|
|
||||||
// hide additional controls
|
// hide additional controls
|
||||||
hide("additional_controls");
|
hide("additional_controls");
|
||||||
@ -68,8 +73,17 @@ function create_edit_game(game = null) {
|
|||||||
contributorsF.value = game["contributors"].join(", ");
|
contributorsF.value = game["contributors"].join(", ");
|
||||||
groupF.value = game["groups"].join(", ");
|
groupF.value = game["groups"].join(", ");
|
||||||
|
|
||||||
|
let props = game["properties"];
|
||||||
|
let time_limit = Math.max(Number(props["time_limit"]), 0);
|
||||||
|
time_limitF.value = seconds_to_time(time_limit);
|
||||||
|
time_limitedChk.checked = time_limit > 0;
|
||||||
|
handle_time_limit_chkbox();
|
||||||
|
|
||||||
|
repeatableChk.checked = props["repeatable"];
|
||||||
|
|
||||||
// show additional controls
|
// show additional controls
|
||||||
show("additional_controls");
|
show("additional_controls");
|
||||||
|
|
||||||
}
|
}
|
||||||
gameFileF.value = "";
|
gameFileF.value = "";
|
||||||
|
|
||||||
@ -87,7 +101,11 @@ function create_edit_game(game = null) {
|
|||||||
description: descriptionF.value.trim(),
|
description: descriptionF.value.trim(),
|
||||||
owner: updating ? ownerF.value.trim() : USERDATA["nickname"],
|
owner: updating ? ownerF.value.trim() : USERDATA["nickname"],
|
||||||
contributors: contributorsF.value.trim(),
|
contributors: contributorsF.value.trim(),
|
||||||
groups: groupF.value.trim()
|
groups: groupF.value.trim(),
|
||||||
|
properties: {
|
||||||
|
time_limit: updating ? (time_limitedChk.checked ? time_to_seconds(time_limitF.value): 0) : 0,
|
||||||
|
repeatable: updating ? repeatableChk.checked : false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if (updating) {
|
if (updating) {
|
||||||
reqData["_id"] = game["_id"];
|
reqData["_id"] = game["_id"];
|
||||||
@ -163,6 +181,12 @@ function delete_games() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_time_limit_chkbox() {
|
||||||
|
let time_limitedChk = document.getElementById("time_limited");
|
||||||
|
let time_limitF = document.getElementById("time_limit");
|
||||||
|
time_limitF.disabled = !time_limitedChk.checked;
|
||||||
|
}
|
||||||
|
|
||||||
// function hint_all_groups(target_element_id) {
|
// function hint_all_groups(target_element_id) {
|
||||||
// const hintbox_insert_fn = (record) => {
|
// const hintbox_insert_fn = (record) => {
|
||||||
// let targetF = document.getElementById(target_element_id);
|
// let targetF = document.getElementById(target_element_id);
|
||||||
|
@ -1,18 +1,6 @@
|
|||||||
let TEST_DATA = {}
|
let TEST_DATA = {}
|
||||||
let INTERVAL_HANDLE = null;
|
let INTERVAL_HANDLE = null;
|
||||||
|
|
||||||
function print_time_left(t) {
|
|
||||||
let timerS = document.getElementById("timer");
|
|
||||||
let hours = Math.floor(t / 3600);
|
|
||||||
t -= hours * 3600;
|
|
||||||
let minutes = Math.floor(t / 60);
|
|
||||||
t -= minutes * 60;
|
|
||||||
let seconds = t;
|
|
||||||
timerS.innerHTML = String(hours).padStart(2, "0") + ":"
|
|
||||||
+ String(minutes).padStart(2, "0") + ":"
|
|
||||||
+ String(seconds).padStart(2, "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
function populate_infobox(test_data) {
|
function populate_infobox(test_data) {
|
||||||
if (INTERVAL_HANDLE !== null) {
|
if (INTERVAL_HANDLE !== null) {
|
||||||
clearInterval(INTERVAL_HANDLE);
|
clearInterval(INTERVAL_HANDLE);
|
||||||
@ -41,11 +29,12 @@ function populate_infobox(test_data) {
|
|||||||
show("concluded-info");
|
show("concluded-info");
|
||||||
} else {
|
} else {
|
||||||
if (test_data["time_limited"]) {
|
if (test_data["time_limited"]) {
|
||||||
|
let timerS = document.getElementById("timer");
|
||||||
let time_left_s = Number(test_data["end_limit_time"]) - Number(test_data["current_time"]);
|
let time_left_s = Number(test_data["end_limit_time"]) - Number(test_data["current_time"]);
|
||||||
print_time_left(time_left_s);
|
seconds_to_time(time_left_s);
|
||||||
INTERVAL_HANDLE = setInterval(() => {
|
INTERVAL_HANDLE = setInterval(() => {
|
||||||
time_left_s--;
|
time_left_s--;
|
||||||
print_time_left(time_left_s);
|
timerS.innerHTML = seconds_to_time(time_left_s);
|
||||||
if (time_left_s <= 0) {
|
if (time_left_s <= 0) {
|
||||||
populate_all(test_data["_id"]);
|
populate_all(test_data["_id"]);
|
||||||
clearInterval(INTERVAL_HANDLE);
|
clearInterval(INTERVAL_HANDLE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user