Skip to content

Commit

Permalink
On tests, saves "Read words aloud" status, and allows to click the te…
Browse files Browse the repository at this point in the history
…xt to toggle the checkbox.
  • Loading branch information
HugoFara committed Jan 7, 2024
2 parents 12a90a3 + fde758d commit 4305299
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 41 deletions.
78 changes: 49 additions & 29 deletions do_test_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ function get_sql_test_data(&$title, &$p)
echo error_message_with_hide($message, true);
return '';
}
$title .= ' in ' . get_first_value(
'SELECT LgName AS value
FROM ' . $tbpref . 'languages, ' . $testsql . ' AND LgID = WoLgID
LIMIT 1'
$title .= ' IN ' . get_first_value(
"SELECT LgName AS value
FROM {$tbpref}languages, {$testsql} AND LgID = WoLgID
LIMIT 1"
);
return $testsql;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ function get_text_test_data(&$title, &$p): string
);
saveSetting('currenttext', $_REQUEST['text']);
$testsql =
' ' . $tbpref . 'words, ' . $tbpref . 'textitems2
' ' . $tbpref . 'words, ' . $tbpref . 'textitems2
WHERE Ti2LgID = WoLgID AND Ti2WoID = WoID AND Ti2TxID = ' . $textid . ' ';
return $testsql;
}
Expand All @@ -117,13 +117,13 @@ function get_text_test_data(&$title, &$p): string
function get_test_counts($testsql)
{
$totalcountdue = get_first_value(
"SELECT count(distinct WoID) AS value
FROM " . $testsql . " AND WoStatus BETWEEN 1 AND 5
"SELECT count(distinct WoID) AS value
FROM " . $testsql . " AND WoStatus BETWEEN 1 AND 5
AND WoTranslation != '' AND WoTranslation != '*' AND WoTodayScore < 0"
);
$totalcount = get_first_value(
"SELECT count(distinct WoID) AS value
FROM " . $testsql . " AND WoStatus BETWEEN 1 AND 5 AND WoTranslation != ''
"SELECT count(distinct WoID) AS value
FROM " . $testsql . " AND WoStatus BETWEEN 1 AND 5 AND WoTranslation != ''
AND WoTranslation != '*'"
);
return array($totalcountdue, $totalcount);
Expand Down Expand Up @@ -186,29 +186,48 @@ function do_test_header_js()
{
?>
<script type="text/javascript">

function setUtteranceSetting () {
const utterancechecked = JSON.parse(
localStorage.getItem('review-utterance-allowed')
);
const utterancecheckbox = document.getElementById('utterance-allowed');

utterancecheckbox.checked = utterancechecked;
utterancecheckbox.addEventListener('change', function () {
localStorage.setItem(
'review-utterance-allowed',
utterancecheckbox.checked
);
});
}


/**
* Reset frames location
*/
function resetFrames() {
parent.frames['ro'].location.href = 'empty.html';
parent.frames['ru'].location.href = 'empty.html';
parent.frames['ru'].location.href = 'empty.html';
}

/**
* Prepare frames for testing words
/**
* Prepare frames for testing words
*/
function startWordTest(type, property) {
resetFrames();
window.location.href = 'do_test.php?type=' + type + '&' + property;
}

/**
* Prepare frames for test table.
/**
* Prepare frames for test table.
*/
function startTestTable(property) {
resetFrames();
window.location.href = 'do_test.php?type=table&' + property;
}

$(setUtteranceSetting)
</script>
<?php
}
Expand All @@ -229,33 +248,34 @@ function do_test_header_content($title, $p, $totalcountdue, $totalcount, $langua
?>
<h1>TEST ▶ <?php echo tohtml($title) ?></h1>
<div style="margin: 5px;">
Word<?php echo intval($totalcount) > 1 ? 's' : ''; ?> due today:
<?php echo htmlspecialchars($totalcount); ?>,
Word<?php echo intval($totalcount) > 1 ? 's' : ''; ?> due today:
<?php echo htmlspecialchars($totalcount); ?>,
<span class="todosty" id="not-tested-header"><?php
echo htmlspecialchars($totalcountdue);
?></span> remaining.
</div>
<div class="flex-spaced">
<div>
<input type="button" value="..[<?php echo $language; ?>].."
<input type="button" value="..[<?php echo $language; ?>].."
onclick="startWordTest(1, '<?php echo $p; ?>')" />
<input type="button" value="..[L1].."
<input type="button" value="..[L1].."
onclick="startWordTest(2, '<?php echo $p; ?>')" />
<input type="button" value="..[••].."
onclick="startWordTest(3, '<?php echo $p; ?>')" />
<input type="button" value="..[••].."
onclick="startWordTest(3, '<?php echo $p; ?>')" />
</div>
<div>
<input type="button" value="[<?php echo $language; ?>]"
<div>
<input type="button" value="[<?php echo $language; ?>]"
onclick="startWordTest(4, '<?php echo $p; ?>')" />
<input type="button" value="[L1]"
onclick="startWordTest(5, '<?php echo $p; ?>')" />
<input type="button" value="[L1]"
onclick="startWordTest(5, '<?php echo $p; ?>')" />
</div>
<div>
<input type="button" value="Table"
onclick="startTestTable('<?php echo $p; ?>')" />
<div>
<input type="button" value="Table"
onclick="startTestTable('<?php echo $p; ?>')" />
</div>
<div>
<input type="checkbox" id="utterance-allowed">Read words aloud</input>
<div>
<input type="checkbox" id="utterance-allowed" />
<label for="utterance-allowed">Read words aloud</label>
</div>
</div>
<?php
Expand Down
24 changes: 12 additions & 12 deletions do_test_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,21 +837,21 @@ function do_test_footer($notyettested, $wrong, $correct)
title="Correct" alt="Correct" height="10" width="<?php echo $l_correct; ?>" />
</span>
<span style="margin-left: 15px; margin-right: 15px;">
<span title="Total number of tests" id="total_tests"><?php
echo $totaltests;
?></span>
<span title="Total number of tests" id="total_tests">
<?php echo $totaltests; ?>
</span>
=
<span class="todosty" title="Not yet tested" id="not-tested"><?php
echo $notyettested;
?></span>
<span class="todosty" title="Not yet tested" id="not-tested">
<?php echo $notyettested; ?>
</span>
+
<span class="donewrongsty" title="Wrong" id="wrong-tests"><?php
echo $wrong;
?></span>
<span class="donewrongsty" title="Wrong" id="wrong-tests">
<?php echo $wrong; ?>
</span>
+
<span class="doneoksty" title="Correct" id="correct-tests"><?php
echo $correct;
?></span>
<span class="doneoksty" title="Correct" id="correct-tests">
<?php echo $correct; ?>
</span>
</span>
</footer>
<?php
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ settings ([#119](https://github.com/HugoFara/lwt/issues/119)).
[#169](https://github.com/HugoFara/lwt/pull/169), closing discussion
[#141](https://github.com/HugoFara/lwt/discussions/141).
Many thanks to [@ProgramComputer](https://github.com/ProgramComputer)!
* On word review:
* The "Read words aloud" setting is now saved, PR [#185](https://github.com/HugoFara/lwt/pull/185).
* UX change: You can click on "Read words aloud" text to check the checkbox.

### Changed

Expand Down
6 changes: 6 additions & 0 deletions docs/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,12 @@ <h4>Added</h4>
<a href="https://github.com/HugoFara/lwt/pull/169">#169</a>, closing discussion
<a href="https://github.com/HugoFara/lwt/discussions/141">#141</a>.
Many thanks to <a href="https://github.com/ProgramComputer">@ProgramComputer</a>!</li>
<li>On word review:
<ul>
<li>The "Read words aloud" setting is now saved, PR <a href="https://github.com/HugoFara/lwt/pull/185">#185</a>.</li>
<li>UX change: You can click on "Read words aloud" text to check the checkbox.</li>
</ul>
</li>
</ul>
<h4>Changed</h4>
<ul>
Expand Down

0 comments on commit 4305299

Please sign in to comment.