MDL-77038 core_courseformat: deprecate state action section_move
The logic behind section_move is ambiguous and unnecessary complex. The move modal uses section_move_after which presents a more predictable behaviour. This issue replace the drag&drop use of section_move by the new section_move_after and deprecate the old method.
This commit is contained in:
@@ -9,6 +9,6 @@ define("core_courseformat/local/courseeditor/dndsection",["exports","core/reacti
|
||||
* @class core_courseformat/local/courseeditor/dndsection
|
||||
* @copyright 2021 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj},(0,_prefetch.prefetchStrings)("core",["addfilehere"]);class _default extends _reactive.BaseComponent{configState(state){this.id=this.element.dataset.id,this.section=state.section.get(this.id),this.course=state.course}configDragDrop(sectionitem){this.reactive.isEditing&&this.reactive.supportComponents&&(this.sectionitem=sectionitem,this.dragdrop=new _reactive.DragDrop(this),this.classes=this.dragdrop.getClasses())}destroy(){void 0!==this.sectionitem&&this.sectionitem.unregister(),void 0!==this.dragdrop&&this.dragdrop.unregister()}getLastCm(){return null}dragStart(dropdata){this.reactive.dispatch("sectionDrag",[dropdata.id],!0)}dragEnd(dropdata){this.reactive.dispatch("sectionDrag",[dropdata.id],!1)}validateDropData(dropdata){if("files"===(null==dropdata?void 0:dropdata.type))return!0;if("cm"===(null==dropdata?void 0:dropdata.type))return!0;if("section"===(null==dropdata?void 0:dropdata.type)){const sectionzeroid=this.course.sectionlist[0];return(null==dropdata?void 0:dropdata.id)!=this.id&&(null==dropdata?void 0:dropdata.id)!=sectionzeroid&&this.id!=sectionzeroid}return!1}showDropZone(dropdata){var _this$getLastCm;("files"==dropdata.type&&this.addOverlay({content:(0,_str.getString)("addfilehere","core"),icon:_templates.default.renderPix("t/download","core")}).then((()=>{var _this$dragdrop;null!==(_this$dragdrop=this.dragdrop)&&void 0!==_this$dragdrop&&_this$dragdrop.isDropzoneVisible()||this.removeOverlay()})).catch((error=>{throw error})),"cm"==dropdata.type)&&(null===(_this$getLastCm=this.getLastCm())||void 0===_this$getLastCm||_this$getLastCm.classList.add(this.classes.DROPDOWN));"section"==dropdata.type&&(this.section.number>dropdata.number?(this.element.classList.remove(this.classes.DROPUP),this.element.classList.add(this.classes.DROPDOWN)):(this.element.classList.add(this.classes.DROPUP),this.element.classList.remove(this.classes.DROPDOWN)))}hideDropZone(){var _this$getLastCm2;null===(_this$getLastCm2=this.getLastCm())||void 0===_this$getLastCm2||_this$getLastCm2.classList.remove(this.classes.DROPDOWN),this.element.classList.remove(this.classes.DROPUP),this.element.classList.remove(this.classes.DROPDOWN),this.removeOverlay()}drop(dropdata,event){if("files"!=dropdata.type){if("cm"==dropdata.type){const mutation=event.altKey?"cmDuplicate":"cmMove";this.reactive.dispatch(mutation,[dropdata.id],this.id)}"section"==dropdata.type&&this.reactive.dispatch("sectionMove",[dropdata.id],this.id)}else this.reactive.uploadFiles(this.section.id,this.section.number,dropdata.files)}}return _exports.default=_default,_exports.default}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_templates=(obj=_templates)&&obj.__esModule?obj:{default:obj},(0,_prefetch.prefetchStrings)("core",["addfilehere"]);class _default extends _reactive.BaseComponent{configState(state){this.id=this.element.dataset.id,this.section=state.section.get(this.id),this.course=state.course}configDragDrop(sectionitem){this.reactive.isEditing&&this.reactive.supportComponents&&(this.sectionitem=sectionitem,this.dragdrop=new _reactive.DragDrop(this),this.classes=this.dragdrop.getClasses())}destroy(){void 0!==this.sectionitem&&this.sectionitem.unregister(),void 0!==this.dragdrop&&this.dragdrop.unregister()}getLastCm(){return null}dragStart(dropdata){this.reactive.dispatch("sectionDrag",[dropdata.id],!0)}dragEnd(dropdata){this.reactive.dispatch("sectionDrag",[dropdata.id],!1)}validateDropData(dropdata){return"files"===(null==dropdata?void 0:dropdata.type)||("cm"===(null==dropdata?void 0:dropdata.type)||"section"===(null==dropdata?void 0:dropdata.type)&&((null==dropdata?void 0:dropdata.id)!=this.id&&(null==dropdata?void 0:dropdata.number)!=this.section.number+1))}showDropZone(dropdata){var _this$getLastCm;("files"==dropdata.type&&this.addOverlay({content:(0,_str.getString)("addfilehere","core"),icon:_templates.default.renderPix("t/download","core")}).then((()=>{var _this$dragdrop;null!==(_this$dragdrop=this.dragdrop)&&void 0!==_this$dragdrop&&_this$dragdrop.isDropzoneVisible()||this.removeOverlay()})).catch((error=>{throw error})),"cm"==dropdata.type)&&(null===(_this$getLastCm=this.getLastCm())||void 0===_this$getLastCm||_this$getLastCm.classList.add(this.classes.DROPDOWN));"section"==dropdata.type&&(this.element.classList.remove(this.classes.DROPUP),this.element.classList.add(this.classes.DROPDOWN))}hideDropZone(){var _this$getLastCm2;null===(_this$getLastCm2=this.getLastCm())||void 0===_this$getLastCm2||_this$getLastCm2.classList.remove(this.classes.DROPDOWN),this.element.classList.remove(this.classes.DROPUP),this.element.classList.remove(this.classes.DROPDOWN),this.removeOverlay()}drop(dropdata,event){if("files"!=dropdata.type){if("cm"==dropdata.type){const mutation=event.altKey?"cmDuplicate":"cmMove";this.reactive.dispatch(mutation,[dropdata.id],this.id)}"section"==dropdata.type&&this.reactive.dispatch("sectionMoveAfter",[dropdata.id],this.id)}else this.reactive.uploadFiles(this.section.id,this.section.number,dropdata.files)}}return _exports.default=_default,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=dndsection.min.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -119,10 +119,9 @@ export default class extends BaseComponent {
|
||||
if (dropdata?.type === 'cm') {
|
||||
return true;
|
||||
}
|
||||
// We accept any section but the section 0 or ourself
|
||||
// We accept any section but yourself and the next one.
|
||||
if (dropdata?.type === 'section') {
|
||||
const sectionzeroid = this.course.sectionlist[0];
|
||||
return dropdata?.id != this.id && dropdata?.id != sectionzeroid && this.id != sectionzeroid;
|
||||
return dropdata?.id != this.id && dropdata?.number != this.section.number + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -151,14 +150,8 @@ export default class extends BaseComponent {
|
||||
this.getLastCm()?.classList.add(this.classes.DROPDOWN);
|
||||
}
|
||||
if (dropdata.type == 'section') {
|
||||
// The relative move of section depends on the section number.
|
||||
if (this.section.number > dropdata.number) {
|
||||
this.element.classList.remove(this.classes.DROPUP);
|
||||
this.element.classList.add(this.classes.DROPDOWN);
|
||||
} else {
|
||||
this.element.classList.add(this.classes.DROPUP);
|
||||
this.element.classList.remove(this.classes.DROPDOWN);
|
||||
}
|
||||
this.element.classList.remove(this.classes.DROPUP);
|
||||
this.element.classList.add(this.classes.DROPDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +187,7 @@ export default class extends BaseComponent {
|
||||
this.reactive.dispatch(mutation, [dropdata.id], this.id);
|
||||
}
|
||||
if (dropdata.type == 'section') {
|
||||
this.reactive.dispatch('sectionMove', [dropdata.id], this.id);
|
||||
this.reactive.dispatch('sectionMoveAfter', [dropdata.id], this.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ajax from 'core/ajax';
|
||||
import log from 'core/log';
|
||||
|
||||
/**
|
||||
* Default mutation manager
|
||||
@@ -235,11 +236,14 @@ export default class {
|
||||
/**
|
||||
* Move course modules to specific course location.
|
||||
*
|
||||
* @deprecated since Moodle 4.4 MDL-77038.
|
||||
* @todo MDL-80116 This will be deleted in Moodle 4.8.
|
||||
* @param {StateManager} stateManager the current state manager
|
||||
* @param {array} sectionIds the list of section ids to move
|
||||
* @param {number} targetSectionId the target section id
|
||||
*/
|
||||
async sectionMove(stateManager, sectionIds, targetSectionId) {
|
||||
log.debug('sectionMove() is deprecated. Use sectionMoveAfter() instead');
|
||||
if (!targetSectionId) {
|
||||
throw new Error(`Mutation sectionMove requires targetSectionId`);
|
||||
}
|
||||
|
||||
@@ -140,6 +140,8 @@ class stateactions {
|
||||
/**
|
||||
* Move course sections to another location in the same course.
|
||||
*
|
||||
* @deprecated since Moodle 4.4 MDL-77038.
|
||||
* @todo MDL-80116 This will be deleted in Moodle 4.8.
|
||||
* @param stateupdates $updates the affected course elements track
|
||||
* @param stdClass $course the course object
|
||||
* @param int[] $ids the list of affected course module ids
|
||||
@@ -153,6 +155,10 @@ class stateactions {
|
||||
?int $targetsectionid = null,
|
||||
?int $targetcmid = null
|
||||
): void {
|
||||
debugging(
|
||||
'The method stateactions::section_move() has been deprecated, please use stateactions::section_move_after() instead.',
|
||||
DEBUG_DEVELOPER
|
||||
);
|
||||
// Validate target elements.
|
||||
if (!$targetsectionid) {
|
||||
throw new moodle_exception("Action cm_move requires targetsectionid");
|
||||
|
||||
@@ -2,6 +2,12 @@ This files describes API changes for course formats
|
||||
|
||||
Overview of this plugin type at https://moodledev.io/docs/apis/plugintypes/format
|
||||
|
||||
=== 4.4 ===
|
||||
* The state mutations sectionMove is deprecated. From now on sectionMoveAfter is the only
|
||||
valid section move mutation.
|
||||
* The state action core_courseformat\stateactions::section_move is deprecated and
|
||||
replaced by core_courseformat\stateactions::section_move_after.
|
||||
|
||||
=== 4.3 ===
|
||||
* New core_courseformat\output\activitybadge class that can be extended by any module to display content near the activity name.
|
||||
The content of the afterlink feature has been moved to the end of the activity card so modules using it should check this new
|
||||
|
||||
Reference in New Issue
Block a user