Skip to content

Commit

Permalink
Merge pull request #120 from KQMATH/bug/#63
Browse files Browse the repository at this point in the history
Yet to be solved: Make workflow file work again
  • Loading branch information
hgeorgsch committed Aug 16, 2023
2 parents e334a44 + 71bfc6f commit 9554c58
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

services:
postgres:
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0
run: moodle-plugin-ci codechecker

- name: Moodle PHPDoc Checker
if: ${{ always() }}
Expand All @@ -93,7 +93,7 @@ jobs:

- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0
run: moodle-plugin-ci grunt

- name: PHPUnit tests
if: ${{ always() }}
Expand Down
18 changes: 8 additions & 10 deletions amd/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod_jazzquiz
* @module mod_jazzquiz
* @author Sebastian S. Gundersen <sebastsg@stud.ntnu.no>
* @copyright 2014 University of Wisconsin - Madison
* @copyright 2018 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function ($, mConfig, mString, Y, mEvent) {
define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function($, mConfig, mString, Y, mEvent) {

// Contains the needed values for using the ajax script.
let session = {
Expand Down Expand Up @@ -56,10 +56,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function
url: url,
data: data,
dataType: 'json',
success: success,
error: function (xhr, status, error) {
//console.error('XHR Error: ' + error + '. Status: ' + status);
}
success: success
}).fail(() => setText(Quiz.info, 'error_with_request'));
}

Expand Down Expand Up @@ -126,6 +123,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function
return;
}
Quiz.show(Question.box.html(data.html));
// eslint-disable-next-line no-eval
eval(data.js);
data.css.forEach(cssUrl => {
let head = document.getElementsByTagName('head')[0];
Expand Down Expand Up @@ -265,7 +263,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function
changeQuizState(state, data) {
this.isNewState = (this.state !== state);
this.state = state;
this.role.onStateChange(state);
this.role.onStateChange();
const event = this.events[state];
this.role[event](data);
}
Expand Down Expand Up @@ -342,7 +340,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function
static renderMaximaEquation(input, targetId) {
const target = document.getElementById(targetId);
if (target === null) {
//console.error('Target element #' + targetId + ' not found.');
// Log error to console: 'Target element #' + targetId + ' not found.'.
return;
}
if (cache[input] !== undefined) {
Expand All @@ -359,10 +357,10 @@ define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function

/**
* Retrieve a language string that was sent along with the page.
* @param $element
* @param {*} $element
* @param {string} key Which string in the language file we want.
* @param {string} [from=jazzquiz] Which language file we want the string from. Default is jazzquiz.
* @param [args] This is {$a} in the string for the key.
* @param {array} args This is {$a} in the string for the key.
*/
function setText($element, key, from, args) {
from = (from !== undefined) ? from : 'jazzquiz';
Expand Down
29 changes: 20 additions & 9 deletions amd/src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


import Sortable from '../../js/sortable.min.js';

/**
* @package mod_jazzquiz
* @module mod_jazzquiz
* @author Sebastian S. Gundersen <sebastsg@stud.ntnu.no>
* @copyright 2015 University of Wisconsin - Madison
* @copyright 2018 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(['jquery'], function ($) {
define(['jquery'], function($) {

/**
* Submit the question order to the server. An empty array will delete all questions.
Expand All @@ -41,7 +44,7 @@ define(['jquery'], function ($) {
*/
function getQuestionOrder() {
let order = [];
$('.questionlist li').each(function () {
$('.questionlist li').each(function() {
order.push($(this).data('question-id'));
});
return order;
Expand Down Expand Up @@ -69,8 +72,12 @@ define(['jquery'], function ($) {
return order;
}

/**
* Add click-listener to a quiz by module id.
* @param {number} courseModuleId
*/
function listenAddToQuiz(courseModuleId) {
$('.jazzquiz-add-selected-questions').on('click', function () {
$('.jazzquiz-add-selected-questions').on('click', function() {
const $checkboxes = $('#categoryquestions td input[type=checkbox]:checked');
let questionIds = '';
for (const checkbox of $checkboxes) {
Expand All @@ -86,26 +93,30 @@ define(['jquery'], function ($) {

return {
initialize: courseModuleId => {
$('.edit-question-action').on('click', function () {
$('.edit-question-action').on('click', function() {
const action = $(this).data('action');
const questionId = $(this).data('question-id');
let order = [];
switch (action) {
case 'up':
case 'up': {
order = offsetQuestion(questionId, 1);
break;
case 'down':
}
case 'down': {
order = offsetQuestion(questionId, -1);
break;
case 'delete':
}
case 'delete': {
order = getQuestionOrder();
const index = order.indexOf(questionId);
if (index !== -1) {
order.splice(index, 1);
}
break;
default:
}
default: {
return;
}
}
submitQuestionOrder(order, courseModuleId);
});
Expand Down
30 changes: 16 additions & 14 deletions amd/src/instructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod_jazzquiz
* @module mod_jazzquiz
* @author Sebastian S. Gundersen <sebastsg@stud.ntnu.no>
* @copyright 2014 University of Wisconsin - Madison
* @copyright 2018 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
define(['jquery', 'mod_jazzquiz/core'], function($, Jazz) {

const Quiz = Jazz.Quiz;
const Question = Jazz.Question;
Expand Down Expand Up @@ -140,7 +140,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}
$row.addClass('merge-from');
let $table = $row.parent().parent();
$table.find('tr').each(function () {
$table.find('tr').each(function() {
const $cells = $(this).find('td');
if ($cells[1].id !== $barCell.attr('id')) {
$(this).addClass('merge-into');
Expand Down Expand Up @@ -233,7 +233,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {

// Add rows.
for (let i = 0; i < responses.length; i++) {
//const percent = (parseInt(responses[i].count) / total) * 100;
// Const percent = (parseInt(responses[i].count) / total) * 100;
const percent = (parseInt(responses[i].count) / highestResponseCount) * 100;

// Check if row with same response already exists.
Expand Down Expand Up @@ -262,7 +262,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {

const countHtml = '<span id="' + name + '_count_' + rowIndex + '">' + responses[i].count + '</span>';
let responseCell = row.insertCell(0);
responseCell.onclick = function () {
responseCell.onclick = function() {
$(this).parent().toggleClass('selected-vote-option');
};

Expand Down Expand Up @@ -299,7 +299,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}
}
}
};
}

/**
* Sort the responses in the graph by how many had the same response.
Expand Down Expand Up @@ -440,7 +440,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}

/**
* refresh() equivalent for votes.
* Method refresh() equivalent for votes.
*/
refreshVotes() {
// Should we show the results?
Expand Down Expand Up @@ -687,15 +687,15 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
this.quiz.question.isRunning = false;
}

onSessionClosed(data) {
onSessionClosed() {
Quiz.hide(Instructor.side);
Quiz.hide(Instructor.correctAnswer);
Instructor.enableControls([]);
this.responses.clear();
this.quiz.question.isRunning = false;
}

onVoting(data) {
onVoting() {
if (!this.responses.showResponses) {
this.responses.hide();
}
Expand All @@ -704,7 +704,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
this.responses.refreshVotes();
}

onStateChange(state) {
onStateChange() {
$('#region-main').find('ul.nav.nav-tabs').css('display', 'none');
$('#region-main-settings-menu').css('display', 'none');
$('.region_main_settings_menu_proxy').css('display', 'none');
Expand Down Expand Up @@ -776,7 +776,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
'jazzquiz-question-id': questions[i].jazzquizquestionid
});
$questionButton.data('test', 1);
$questionButton.on('click', function () {
$questionButton.on('click', function() {
const questionId = $(this).data('question-id');
const time = $(this).data('time');
const jazzQuestionId = $(this).data('jazzquiz-question-id');
Expand Down Expand Up @@ -810,6 +810,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
runVoting() {
const options = Instructor.getSelectedAnswersForVote();
const data = {questions: encodeURIComponent(JSON.stringify(options))};
// eslint-disable-next-line no-return-assign
Ajax.post('run_voting', data, () => {});
}

Expand Down Expand Up @@ -871,6 +872,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
Quiz.hide(Question.box);
Quiz.hide(Instructor.controls);
setText(Quiz.info, 'closing_session');
// eslint-disable-next-line no-return-assign
Ajax.post('close_session', {}, () => window.location = location.href.split('&')[0]);
}

Expand Down Expand Up @@ -947,7 +949,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}

static addReportEventHandlers() {
$(document).on('click', '#report_overview_controls button', function () {
$(document).on('click', '#report_overview_controls button', function() {
const action = $(this).data('action');
if (action === 'attendance') {
$('#report_overview_responded').fadeIn();
Expand All @@ -962,7 +964,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}

return {
initialize: function (totalQuestions, reportView, slots) {
initialize: function(totalQuestions, reportView, slots) {
let quiz = new Quiz(Instructor);
quiz.role.totalQuestions = totalQuestions;
if (reportView) {
Expand All @@ -978,6 +980,6 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
quiz.poll(500);
}
}
}
};

});
20 changes: 11 additions & 9 deletions amd/src/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod_jazzquiz
* @module mod_jazzquiz
* @author Sebastian S. Gundersen <sebastsg@stud.ntnu.no>
* @copyright 2014 University of Wisconsin - Madison
* @copyright 2018 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
define(['jquery', 'mod_jazzquiz/core'], function($, Jazz) {

const Quiz = Jazz.Quiz;
const Question = Jazz.Question;
Expand All @@ -47,11 +47,11 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
});
}

onNotRunning(data) {
onNotRunning() {
setText(Quiz.info, 'instructions_for_student');
}

onPreparing(data) {
onPreparing() {
setText(Quiz.info, 'wait_for_instructor');
}

Expand All @@ -65,15 +65,15 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
}
}

onReviewing(data) {
onReviewing() {
this.quiz.question.isVoteRunning = false;
this.quiz.question.isRunning = false;
this.quiz.question.hideTimer();
Quiz.hide(Question.box);
setText(Quiz.info, 'wait_for_instructor');
}

onSessionClosed(data) {
onSessionClosed() {
window.location = location.href.split('&')[0];
}

Expand All @@ -93,7 +93,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
this.quiz.question.isVoteRunning = true;
}

onStateChange(state) {
onStateChange() {

}

Expand All @@ -104,7 +104,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
onTimerTick(timeLeft) {
setText(Question.timer, 'question_will_end_in_x_seconds', 'jazzquiz', timeLeft);
}

// eslint-disable-next-line no-unused-vars
onQuestionRefreshed(data) {

}
Expand All @@ -118,7 +118,9 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
return;
}
this.quiz.question.isSaving = true;
// eslint-disable-next-line no-undef
if (typeof tinyMCE !== 'undefined') {
// eslint-disable-next-line no-undef
tinyMCE.triggerSave();
}
const serialized = Question.form.serializeArray();
Expand Down Expand Up @@ -165,6 +167,6 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
let quiz = new Quiz(Student);
quiz.poll(2000);
}
}
};

});

0 comments on commit 9554c58

Please sign in to comment.