MDL-76850 core_courseformat: bulk duplicate activities

This commit is contained in:
Ferran Recio
2023-02-21 12:26:04 +01:00
parent e6802896f7
commit d43c14471b
11 changed files with 35 additions and 10 deletions
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
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
@@ -472,13 +472,13 @@ export default class extends BaseComponent {
* @param {Event} event the triggered event
*/
async _requestCmDuplicate(target, event) {
const cmId = target.dataset.id;
if (!cmId) {
const cmIds = this._getTargetIds(target);
if (cmIds.length == 0) {
return;
}
const sectionId = target.dataset.sectionid ?? null;
event.preventDefault();
this.reactive.dispatch('cmDuplicate', [cmId], sectionId);
this.reactive.dispatch('cmDuplicate', cmIds, sectionId);
}
/**
@@ -199,6 +199,7 @@ export default class {
this.sectionLock(stateManager, Array.from(sectionIds), true);
const updates = await this._callEditWebservice('cm_duplicate', course.id, cmIds, targetSectionId, targetCmId);
this.bulkReset(stateManager);
stateManager.processUpdates(updates);
this.sectionLock(stateManager, Array.from(sectionIds), false);
@@ -328,7 +328,7 @@ export default class Component extends BaseComponent {
container.append(item);
return;
}
if (currentitem !== item) {
if (currentitem !== item && item) {
container.insertBefore(item, currentitem);
}
});
@@ -99,6 +99,17 @@ class bulkedittools implements named_templatable, renderable {
];
}
$duplicatecapabilities = ['moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport'];
if (has_all_capabilities($duplicatecapabilities, $context, $user)) {
$controls['duplicate'] = [
'icon' => 't/copy',
'action' => 'cmDuplicate',
'name' => get_string('duplicate'),
'bulk' => 'cm',
];
}
return $controls;
}
@@ -97,3 +97,16 @@ Feature: Bulk course activity actions.
And I click on "Apply" "button" in the "Availability" "dialogue"
Then I should see "Available but not shown on course page" in the "Activity sample 1" "activity"
And I should see "Available but not shown on course page" in the "Activity sample 3" "activity"
Scenario: Bulk duplicate activities
Given I click on "Select activity Activity sample 1" "checkbox"
And I click on "Select activity Activity sample 3" "checkbox"
And I should see "2 selected" in the "sticky-footer" "region"
When I click on "Duplicate" "button" in the "sticky-footer" "region"
Then I should see "Activity sample 1" in the "Topic 1" "section"
And I should see "Activity sample 1 (copy)" in the "Topic 1" "section"
And "Activity sample 1 (copy)" "activity" should appear after "Activity sample 1" "activity"
And I should see "Activity sample 3" in the "Topic 2" "section"
And I should see "Activity sample 3 (copy)" in the "Topic 2" "section"
And "Activity sample 3 (copy)" "activity" should appear after "Activity sample 3" "activity"
And I should see "0 selected" in the "sticky-footer" "region"