- 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>
|
||||
<script src="js/req.js"></script>
|
||||
<script src="js/spreadquiz.js"></script>
|
||||
<script src="js/common.js"></script>
|
||||
<script src="js/o.js"></script>
|
||||
<script src="js/hintbox.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="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>
|
||||
<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>
|
||||
<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 = [
|
||||
"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
|
||||
];
|
||||
|
||||
|
@ -161,6 +161,7 @@ switch ($action) {
|
||||
$contributors = explode_list($data["contributors"] ?: "");
|
||||
$owner = $update ? trim($data["owner"] ?: $nickname) : $nickname;
|
||||
$groups = explode_list($data["groups"] ?: "");
|
||||
$properties = $data["properties"] ?: [];
|
||||
|
||||
$groupids = get_groupids_by_compounds($groups); // convert group compounds to _ids
|
||||
|
||||
@ -200,6 +201,8 @@ switch ($action) {
|
||||
$game_data["owner"] = $owner;
|
||||
}
|
||||
$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 file if supplied
|
||||
|
28
js/common.js
28
js/common.js
@ -2,4 +2,32 @@ function unix_time_to_human_readable(tunix) {
|
||||
const date = new Date(Number(tunix) * 1000);
|
||||
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");
|
||||
}
|
||||
|
||||
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 cancel_game_file_upload_btn = document.getElementById("cancel_game_file_upload");
|
||||
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
|
||||
nameF.value = "";
|
||||
@ -56,6 +59,8 @@ function create_edit_game(game = null) {
|
||||
ownerF.readOnly = true;
|
||||
contributorsF.value = "";
|
||||
groupF.value = "";
|
||||
time_limitedChk.checked = false;
|
||||
repeatableChk.checked = true;
|
||||
|
||||
// hide additional controls
|
||||
hide("additional_controls");
|
||||
@ -68,8 +73,17 @@ function create_edit_game(game = null) {
|
||||
contributorsF.value = game["contributors"].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");
|
||||
|
||||
}
|
||||
gameFileF.value = "";
|
||||
|
||||
@ -87,7 +101,11 @@ function create_edit_game(game = null) {
|
||||
description: descriptionF.value.trim(),
|
||||
owner: updating ? ownerF.value.trim() : USERDATA["nickname"],
|
||||
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) {
|
||||
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) {
|
||||
// const hintbox_insert_fn = (record) => {
|
||||
// let targetF = document.getElementById(target_element_id);
|
||||
@ -178,4 +202,4 @@ function delete_games() {
|
||||
// }
|
||||
//
|
||||
// open_hintbox_at(target_element_id, req, print_group_name, hintbox_insert_fn);
|
||||
// }
|
||||
// }
|
||||
|
@ -1,18 +1,6 @@
|
||||
let TEST_DATA = {}
|
||||
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) {
|
||||
if (INTERVAL_HANDLE !== null) {
|
||||
clearInterval(INTERVAL_HANDLE);
|
||||
@ -41,11 +29,12 @@ function populate_infobox(test_data) {
|
||||
show("concluded-info");
|
||||
} else {
|
||||
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"]);
|
||||
print_time_left(time_left_s);
|
||||
seconds_to_time(time_left_s);
|
||||
INTERVAL_HANDLE = setInterval(() => {
|
||||
time_left_s--;
|
||||
print_time_left(time_left_s);
|
||||
timerS.innerHTML = seconds_to_time(time_left_s);
|
||||
if (time_left_s <= 0) {
|
||||
populate_all(test_data["_id"]);
|
||||
clearInterval(INTERVAL_HANDLE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user