1
0
mirror of https://github.com/moodle/moodle.git synced 2025-03-20 07:30:01 +01:00
This commit is contained in:
Huong Nguyen 2024-12-16 10:24:44 +07:00
commit adb94bf614
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
10 changed files with 194 additions and 3 deletions
lib/amd
build/datafilter/filtertypes
src/datafilter/filtertypes
question/bank/editquestion

@ -1,3 +1,3 @@
define("core/datafilter/filtertypes/binary",["exports","core/datafilter/filtertype","core/datafilter/selectors","core/templates","core/str"],(function(_exports,_filtertype,_selectors,_templates,_str){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_filtertype=_interopRequireDefault(_filtertype),_selectors=_interopRequireDefault(_selectors),_templates=_interopRequireDefault(_templates);class _default extends _filtertype.default{constructor(){super(...arguments),_defineProperty(this,"optionOne",void 0),_defineProperty(this,"optionTwo",void 0)}async addValueSelector(initialValues){return[this.optionOne,this.optionTwo]=await this.getTextValues(),this.displayBinarySelection(initialValues[0])}getTextValues(){return(0,_str.get_strings)([{key:"no"},{key:"yes"}])}async displayBinarySelection(){let initialValue=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const specificFilterSet=this.rootNode.querySelector(_selectors.default.filter.byName(this.filterType)),sourceDataNode=this.getSourceDataForFilter(),context={filtertype:this.filterType,title:sourceDataNode.getAttribute("data-field-title"),required:sourceDataNode.dataset.required,options:[{text:this.optionOne,value:0,selected:0===initialValue},{text:this.optionTwo,value:1,selected:1===initialValue}]};return _templates.default.render("core/datafilter/filtertypes/binary_selector",context).then(((binaryUi,js)=>_templates.default.replaceNodeContents(specificFilterSet.querySelector(_selectors.default.filter.regions.values),binaryUi,js)))}get values(){return[parseInt(this.filterRoot.querySelector('[data-filterfield="'.concat(this.name,'"]')).value)]}}return _exports.default=_default,_exports.default}));
define("core/datafilter/filtertypes/binary",["exports","core/datafilter/filtertype","core/datafilter/selectors","core/templates","core/str"],(function(_exports,_filtertype,_selectors,_templates,_str){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_filtertype=_interopRequireDefault(_filtertype),_selectors=_interopRequireDefault(_selectors),_templates=_interopRequireDefault(_templates);class _default extends _filtertype.default{constructor(){super(...arguments),_defineProperty(this,"optionOne",void 0),_defineProperty(this,"optionTwo",void 0)}async addValueSelector(initialValues){[this.optionOne,this.optionTwo]=await this.getTextValues();const initialValue=initialValues?initialValues[0]:0;return this.displayBinarySelection(initialValue)}getTextValues(){return(0,_str.get_strings)([{key:"no"},{key:"yes"}])}async displayBinarySelection(){let initialValue=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const specificFilterSet=this.rootNode.querySelector(_selectors.default.filter.byName(this.filterType)),sourceDataNode=this.getSourceDataForFilter(),context={filtertype:this.filterType,title:sourceDataNode.getAttribute("data-field-title"),required:sourceDataNode.dataset.required,options:[{text:this.optionOne,value:0,selected:0===initialValue},{text:this.optionTwo,value:1,selected:1===initialValue}]};return _templates.default.render("core/datafilter/filtertypes/binary_selector",context).then(((binaryUi,js)=>_templates.default.replaceNodeContents(specificFilterSet.querySelector(_selectors.default.filter.regions.values),binaryUi,js)))}get values(){return[parseInt(this.filterRoot.querySelector('[data-filterfield="'.concat(this.name,'"]')).value)]}}return _exports.default=_default,_exports.default}));
//# sourceMappingURL=binary.min.js.map

File diff suppressed because one or more lines are too long

@ -53,7 +53,8 @@ export default class extends Filter {
*/
async addValueSelector(initialValues) {
[this.optionOne, this.optionTwo] = await this.getTextValues();
return this.displayBinarySelection(initialValues[0]);
const initialValue = initialValues ? initialValues[0] : 0;
return this.displayBinarySelection(initialValue);
}
/**

@ -0,0 +1,11 @@
define("qbank_editquestion/datafilter/filtertypes/status",["exports","core/datafilter/filtertypes/binary","core/str"],(function(_exports,_binary,_str){var obj;
/**
* Filter for Status - Ready/Draft
*
* @module qbank_editquestion/datafilter/filtertypes/status
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @copyright 2024 Catalyst IT Europe Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_binary=(obj=_binary)&&obj.__esModule?obj:{default:obj};class _default extends _binary.default{getTextValues(){return(0,_str.get_strings)([{key:"questionstatusready",component:"qbank_editquestion"},{key:"questionstatusdraft",component:"qbank_editquestion"}])}}return _exports.default=_default,_exports.default}));
//# sourceMappingURL=status.min.js.map

@ -0,0 +1 @@
{"version":3,"file":"status.min.js","sources":["../../../src/datafilter/filtertypes/status.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Filter for Status - Ready/Draft\n *\n * @module qbank_editquestion/datafilter/filtertypes/status\n * @author Mark Johnson <mark.johnson@catalyst-eu.net>\n * @copyright 2024 Catalyst IT Europe Ltd\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Binary from 'core/datafilter/filtertypes/binary';\nimport {get_strings as getStrings} from 'core/str';\n\nexport default class extends Binary {\n /**\n * Return strings for Draft/Ready statuses.\n *\n * @returns {Promise}\n */\n getTextValues() {\n return getStrings([\n {key: 'questionstatusready', component: 'qbank_editquestion'},\n {key: 'questionstatusdraft', component: 'qbank_editquestion'}\n ]);\n }\n}\n"],"names":["Binary","getTextValues","key","component"],"mappings":";;;;;;;;oKA2B6BA,gBAMzBC,uBACW,oBAAW,CACd,CAACC,IAAK,sBAAuBC,UAAW,sBACxC,CAACD,IAAK,sBAAuBC,UAAW"}

@ -0,0 +1,40 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Filter for Status - Ready/Draft
*
* @module qbank_editquestion/datafilter/filtertypes/status
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @copyright 2024 Catalyst IT Europe Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Binary from 'core/datafilter/filtertypes/binary';
import {get_strings as getStrings} from 'core/str';
export default class extends Binary {
/**
* Return strings for Draft/Ready statuses.
*
* @returns {Promise}
*/
getTextValues() {
return getStrings([
{key: 'questionstatusready', component: 'qbank_editquestion'},
{key: 'questionstatusdraft', component: 'qbank_editquestion'}
]);
}
}

@ -71,4 +71,10 @@ class plugin_feature extends \core_question\local\bank\plugin_features_base {
];
}
#[\Override]
public function get_question_filters(?view $qbank = null): array {
return [
new status_condition($qbank),
];
}
}

@ -0,0 +1,88 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_editquestion;
use core_question\local\bank\condition;
use core_question\local\bank\question_version_status;
/**
* Filter condition for the status column
*
* @package qbank_editquestion
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class status_condition extends condition {
#[\Override]
public function get_title() {
return get_string('filter:status', 'qbank_editquestion');
}
#[\Override]
public static function get_condition_key() {
return 'status';
}
#[\Override]
public function get_filter_class() {
return 'qbank_editquestion/datafilter/filtertypes/status';
}
/**
* Return a single join type, we don't want a join type selector for this condition.
*
* @return array
*/
public function get_join_list(): array {
return [
self::JOINTYPE_DEFAULT,
];
}
/**
* Return an array mapping the values returned from the filter to the values required for the query.
*
* @return array
*/
protected static function get_status_list() {
return [
0 => question_version_status::QUESTION_STATUS_READY,
1 => question_version_status::QUESTION_STATUS_DRAFT,
];
}
/**
* Return an SQL condition to filter qv.status on the selected status.
*
* @param array $filter
* @return array
*/
public static function build_query_from_filter(array $filter): array {
if (!isset($filter['values'][0])) {
return ['', []];
}
$statuses = self::get_status_list();
if (!array_key_exists($filter['values'][0], $statuses)) {
throw new \moodle_exception('filter:invalidstatus', 'qbank_editquestion', '', $filter['values'][0]);
}
return [
'qv.status = :status',
['status' => $statuses[$filter['values'][0]]],
];
}
}

@ -23,6 +23,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['filter:status'] = 'Status of latest version';
$string['filter:invalidstatus'] = 'Invalid value "{$a}" for status filter.';
$string['pluginname'] = 'Edit questions';
$string['privacy:metadata'] = 'The Edit questions question bank plugin does not store any personal data.';

@ -0,0 +1,41 @@
@qbank @qbank_editquestion @javascript
Feature: Filter questions by status
As a teacher
In order to quickly find questions in Draft or Ready status
I want to filter the list of questions by status
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| qbank | Qbank 1 | Question bank 1 | C1 | qbank1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Activity module | qbank1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext | status |
| Test questions | truefalse | First question | Answer the first question | ready |
| Test questions | numerical | Second question | Answer the second question | draft |
| Test questions | essay | Third question | Answer the third question | ready |
Scenario: Filter by ready status
Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin"
And I should see "First question"
And I should see "Second question"
And I should see "Third question"
When I apply question bank filter "Status of latest version" with value "Ready"
Then I should see "First question"
And I should not see "Second question"
And I should see "Third question"
Scenario: Filter by draft status
Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin"
And I should see "First question"
And I should see "Second question"
And I should see "Third question"
When I apply question bank filter "Status of latest version" with value "Draft"
Then I should not see "First question"
And I should see "Second question"
And I should not see "Third question"