Skip to content

Commit

Permalink
Merge pull request #8 from cluebotng/add-keyboard-shortcuts
Browse files Browse the repository at this point in the history
Add keyboard shortcuts for reviewing
  • Loading branch information
DamianZaremba authored Nov 30, 2021
2 parents 7b28a49 + 1d8c1bb commit 55045a8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
15 changes: 14 additions & 1 deletion pages/Options.page.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ public function __construct()
$next_on_review = 0;
}

$query = "UPDATE `users` SET `next_on_review` = '" . mysqli_real_escape_string($mysql, $next_on_review) . "'";
if (isset($_POST['keyboard_shortcuts']) && $_POST['keyboard_shortcuts'] === "Yes") {
$keyboard_shortcuts = 1;
} else {
$keyboard_shortcuts = 0;
}

$_SESSION['next_on_review'] = ($next_on_review) ? true : false;
$_SESSION['keyboard_shortcuts'] = ($keyboard_shortcuts) ? true : false;

$query = "UPDATE `users` SET";
$query .= " `next_on_review` = '" . mysqli_real_escape_string($mysql, $next_on_review) . "',";
$query .= " `keyboard_shortcuts` = '" . mysqli_real_escape_string($mysql, $keyboard_shortcuts) . "'";
$query .= " WHERE `userid` = '" . mysqli_real_escape_string($mysql, $_SESSION['userid']) . "'";
mysqli_query($mysql, $query);

Expand All @@ -42,6 +51,10 @@ public function writeContent()
echo ($_SESSION['next_on_review']) ? ' checked=checked' : '';
echo ' /></p>';

echo '<p>Review keyboard shortcuts: <input type="checkbox" id="keyboard_shortcuts" name="keyboard_shortcuts" value="Yes"';
echo ($_SESSION['keyboard_shortcuts']) ? ' checked=checked' : '';
echo ' /></p>';

echo '<p><input id="submit" name="submit" type="submit" value="Save" /></p>';
echo '</form>';
}
Expand Down
32 changes: 28 additions & 4 deletions pages/View.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@
?>
(
<a href="?page=View&id=<?PHP echo $this->row['id'];
?>&status=0">Reported</a> &middot;
?>&status=0">Reported<?PHP if (isset($_SESSION['keyboard_shortcuts']) && $_SESSION['keyboard_shortcuts'] === true) {
?> (r)<?PHP
} ?></a> &middot;
<a href="?page=View&id=<?PHP echo $this->row['id'];
?>&status=1">Invalid</a> &middot;
?>&status=1">Invalid<?PHP if (isset($_SESSION['keyboard_shortcuts']) && $_SESSION['keyboard_shortcuts'] === true) {
?> (i)<?PHP
} ?></a> &middot;
<a href="?page=View&id=<?PHP echo $this->row['id'];
?>&status=2">Defer to Review Interface</a> &middot;
?>&status=2">Defer to Review Interface<?PHP if (isset($_SESSION['keyboard_shortcuts']) && $_SESSION['keyboard_shortcuts'] === true) {
?> (d)<?PHP
} ?></a> &middot;
<a href="?page=View&id=<?PHP echo $this->row['id'];
?>&status=3">Bug</a> &middot;
?>&status=3">Bug<?PHP if (isset($_SESSION['keyboard_shortcuts']) && $_SESSION['keyboard_shortcuts'] === true) {
?> (b)<?PHP
} ?></a> &middot;
<a href="?page=View&id=<?PHP echo $this->row['id'];
?>&status=4">Resolved</a>
)
Expand Down Expand Up @@ -142,3 +150,19 @@
<?PHP
}
?>

<?PHP if (isAdmin() && (isset($_SESSION['keyboard_shortcuts']) && $_SESSION['keyboard_shortcuts'] === true)) { ?>
<script type="text/javascript">
document.addEventListener('keydown', function (event) {
if (event.key === 'r') {
window.location = '?page=View&id=<?PHP echo $this->row['id']; ?>&status=0';
} else if (event.key === 'i') {
window.location = '?page=View&id=<?PHP echo $this->row['id']; ?>&status=1';
} else if (event.key === 'd') {
window.location = '?page=View&id=<?PHP echo $this->row['id']; ?>&status=2';
} else if (event.key === 'b') {
window.location = '?page=View&id=<?PHP echo $this->row['id']; ?>&status=3';
}
});
</script>
<?PHP } ?>

0 comments on commit 55045a8

Please sign in to comment.