Skip to content

Commit

Permalink
Issue #78: Add look ahead and look behind filters in quizzes in progr…
Browse files Browse the repository at this point in the history
…ess dashboard
  • Loading branch information
guillogo authored and Matt Porritt committed Mar 13, 2021
1 parent 147e971 commit b56fd21
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 7 deletions.
2 changes: 1 addition & 1 deletion amd/build/dashboard_quiz_inprogress.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/dashboard_quiz_inprogress.min.js.map

Large diffs are not rendered by default.

50 changes: 49 additions & 1 deletion amd/src/dashboard_quiz_inprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function(Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
var refreshPeriod = 60;
var counterid;
var tablesort = 'name_asc';
var hoursAhead = 1;
var hoursBehind = 1;

const cards = [
{cardId: 'local-assessfreq-quiz-summary-upcomming-graph', call: 'upcomming_quizzes', aspect: true},
Expand Down Expand Up @@ -290,7 +292,10 @@ function(Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
let sorton = sortarray[0];
let direction = sortarray[1];

let params = {'data': JSON.stringify({'search': search, 'page': page, 'sorton': sorton, 'direction': direction})};
let params = {'data': JSON.stringify(
{'search': search, 'page': page, 'sorton': sorton, 'direction': direction,
'hoursahead': hoursAhead, 'hoursbehind': hoursBehind}
)};

spinner.classList.remove('hide'); // Show sinner if not already shown.

Expand Down Expand Up @@ -384,6 +389,42 @@ function(Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
ZoomModal.zoomGraph(event, params, method);
};

/**
* Process the hours ahead event from the in progress quizzes table.
*/
const quizzesAheadSet = function(event) {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
let hours = event.target.dataset.metric;
setUserPreference('local_assessfreq_quizzes_inprogress_table_hoursahead_preference', hours)
.then(() => {
hoursAhead = hours;
processDashboard(); // Reload the table.
})
.fail(() => {
Notification.exception(new Error('Failed to update user preference: hours ahead'));
});
}
};

/**
* Process the hours behind event from the in progress quizzes table.
*/
const quizzesBehindSet = function(event) {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
let hours = event.target.dataset.metric;
setUserPreference('local_assessfreq_quizzes_inprogress_table_hoursbehind_preference', hours)
.then(() => {
hoursBehind = hours;
processDashboard(); // Reload the table.
})
.fail(() => {
Notification.exception(new Error('Failed to update user preference: hours behind'));
});
}
};

/**
* Initialise method for quizzes in progress dashboard rendering.
*/
Expand Down Expand Up @@ -418,6 +459,13 @@ function(Ajax, Templates, Fragment, ZoomModal, Str, Notification) {
let upcommingZoom = document.getElementById('local-assessfreq-quiz-summary-upcomming-graph-zoom');
upcommingZoom.addEventListener('click', triggerZoomGraph);

// Set up behind and ahead quizzes event listeners.
let quizzesAheadElement = document.getElementById('local-assessfreq-quiz-student-table-hoursahead');
quizzesAheadElement.addEventListener('click', quizzesAheadSet);

let quizzesBehindElement = document.getElementById('local-assessfreq-quiz-student-table-hoursbehind');
quizzesBehindElement.addEventListener('click', quizzesBehindSet);

processDashboard();

};
Expand Down
35 changes: 32 additions & 3 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,30 @@ public function render_student_search_table(
* @param string $direction The direction to sort the quizzes.
* @return string $output HTML for the table.
*/
public function render_quizzes_inprogress_table(string $search, int $page, string $sorton, string $direction): string {
public function render_quizzes_inprogress_table(string $search, int $page, string $sorton, string $direction, int $hoursahead = 0, int $hoursbehind = 0): string {
$context = \context_system::instance(); // TODO: pass the actual context in from the caller.
$now = time();
$quiz = new quiz();
$quiz = new quiz($hoursahead, $hoursbehind);
$quizzes = $quiz->get_quiz_summaries($now);
$pagesize = get_user_preferences('local_assessfreq_quiz_table_inprogress_preference', 5);

list($filtered, $totalrows) = $quiz->filter_quizzes($quizzes['inprogress'], $search, $page, $pagesize);
$inprogressquizzes = $quizzes['inprogress'];
$upcommingquizzes = $quizzes['upcomming'];
$finishedquizzes = $quizzes['finished'];

foreach ($upcommingquizzes as $key=>$upcommingquiz) {
foreach ($upcommingquiz as $keyupcomming=>$upcomming) {
$inprogressquizzes[$keyupcomming] = $upcomming;
}
}

foreach ($finishedquizzes as $key=>$finishedquiz) {
foreach ($finishedquiz as $keyfinished=>$finished) {
$inprogressquizzes[$keyfinished] = $finished;
}
}

list($filtered, $totalrows) = $quiz->filter_quizzes($inprogressquizzes, $search, $page, $pagesize);
$sortedquizzes = \local_assessfreq\utils::sort($filtered, $sorton, $direction);

$pagingbar = new \paging_bar($totalrows, $page, $pagesize, '/');
Expand Down Expand Up @@ -282,16 +298,28 @@ private function render_quiz_select_refresh_button(): string {
*/
private function render_quiz_refresh_button(): string {
$preferencerefresh = get_user_preferences('local_assessfreq_quiz_refresh_preference', 60);
$preferencehoursahead = get_user_preferences('local_assessfreq_quizzes_inprogress_table_hoursahead_preference', 0);
$preferencehoursbehind = get_user_preferences('local_assessfreq_quizzes_inprogress_table_hoursbehind_preference', 0);

$refreshminutes = array(
60 => 'minuteone',
120 => 'minutetwo',
300 => 'minutefive',
600 => 'minuteten',
);

$hours = array(
0 => 'hours0',
1 => 'hours1',
4 => 'hours4',
8 => 'hours8',
);

$context = array(
'refreshinitial' => get_string($refreshminutes[$preferencerefresh], 'local_assessfreq'),
'refresh' => array($refreshminutes[$preferencerefresh] => 'true'),
'hoursahead' => array($hours[$preferencehoursahead] => 'true'),
'hoursbehind' => array($hours[$preferencehoursbehind] => 'true'),
);

return $this->render_from_template('local_assessfreq/quiz-dashboard-inprogress-controls', $context);
Expand Down Expand Up @@ -364,6 +392,7 @@ private function render_student_table_cards(): string {
);

$hours = array(
0 => 'hours0',
1 => 'hours1',
4 => 'hours4',
8 => 'hours8',
Expand Down
Loading

0 comments on commit b56fd21

Please sign in to comment.