Skip to content

Commit

Permalink
MDL-75492 mod_data: Remove redirection messages on preset apply process
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Nov 16, 2022
1 parent 9b34375 commit 1c96810
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 55 deletions.
15 changes: 7 additions & 8 deletions mod/data/classes/local/importer/preset_importer.php
Expand Up @@ -16,6 +16,7 @@

namespace mod_data\local\importer;

use core\notification;
use mod_data\manager;
use mod_data\preset;
use stdClass;
Expand Down Expand Up @@ -428,16 +429,14 @@ public function get_preset_selector(): array {
* @return void
*/
public function finish_import_process(bool $overwritesettings, stdClass $instance): void {
global $DB;
$this->import($overwritesettings);
$strimportsuccess = get_string('importsuccess', 'data');
$straddentries = get_string('addentries', 'data');
$strtodatabase = get_string('todatabase', 'data');
if (!$DB->get_records('data_records', ['dataid' => $instance->id])) {
\core\notification::success("$strimportsuccess <a href='edit.php?d=$instance->id'>$straddentries</a> $strtodatabase");
$result = $this->import($overwritesettings);
if ($result) {
notification::success(get_string('importsuccess', 'mod_data'));
} else {
\core\notification::success($strimportsuccess);
notification::error(get_string('cannotapplypreset', 'mod_data'));
}
$backurl = new \moodle_url('/mod/data/field.php', ['d' => $instance->id]);
redirect($backurl);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions mod/data/field.php
Expand Up @@ -108,13 +108,9 @@
$renderer = $manager->get_renderer();

if ($action == 'finishimport' && confirm_sesskey()) {
data_print_header($course, $cm, $data, false);
$overwritesettings = optional_param('overwritesettings', false, PARAM_BOOL);
$importer = preset_importer::create_from_parameters($manager);
$importer->finish_import_process($overwritesettings, $data);
echo $OUTPUT->continue_button(new moodle_url('/mod/data/field.php', ['d' => $data->id]));
echo $OUTPUT->footer();
exit;
}

switch ($mode) {
Expand Down Expand Up @@ -260,7 +256,7 @@
if ($importer->import(false)) {
notification::success(get_string('importsuccess', 'mod_data'));
} else {
notification::error(get_string('presetapplied', 'mod_data'));
notification::error(get_string('cannotapplypreset', 'mod_data'));
}
redirect($backurl);
}
Expand Down
7 changes: 4 additions & 3 deletions mod/data/lang/en/data.php
Expand Up @@ -27,7 +27,6 @@
$string['actionsmenu'] = 'Actions menu';
$string['add'] = 'Add entry';
$string['addcomment'] = 'Add comment';
$string['addentries'] = 'Add entries';
$string['addtemplate'] = 'Add entry template';
$string['advancedsearch'] = 'Advanced search';
$string['allowcomments'] = 'Allow comments on entries';
Expand Down Expand Up @@ -61,6 +60,7 @@
$string['cannotdeletepreset'] = 'Error deleting a preset!';
$string['cannotoverwritepreset'] = 'Error overwriting preset';
$string['cannotunziptopreset'] = 'Cannot unzip to the preset directory';
$string['cannotapplypreset'] = 'Error applying the preset.';
$string['closebeforeopen'] = 'You have specified an end date before the start date.';
$string['columns'] = 'columns';
$string['comment'] = 'Comment';
Expand Down Expand Up @@ -221,7 +221,7 @@
$string['importentries'] = 'Import entries';
$string['importpreset'] = 'Import preset';
$string['importapreset'] = 'Import a preset';
$string['importsuccess'] = 'The preset has been successfully applied.';
$string['importsuccess'] = 'Preset applied.';
$string['importpresetmissingcapability'] = 'You don\'t have permission to import a preset.';
$string['includeapproval'] = 'Include approval status';
$string['includetags'] = 'Include tags';
Expand Down Expand Up @@ -439,7 +439,6 @@
$string['textarea'] = 'Text area';
$string['timeadded'] = 'Time added';
$string['timemodified'] = 'Time modified';
$string['todatabase'] = 'to this database.';
$string['type'] = 'Field type';
$string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".';
$string['unsupportedfields'] = 'Unsupported fields';
Expand Down Expand Up @@ -479,3 +478,5 @@
$string['blank'] = 'Blank';
$string['savetemplate'] = 'Save template';
$string['addedby'] = 'Added by';
$string['addentries'] = 'Add entries';
$string['todatabase'] = 'to this database.';
2 changes: 2 additions & 0 deletions mod/data/lang/en/deprecated.txt
Expand Up @@ -6,4 +6,6 @@ pleaseaddsome,mod_data
blank,mod_data
savetemplate,mod_data
addedby,mod_data
addentries,mod_data
todatabase,mod_data

8 changes: 2 additions & 6 deletions mod/data/preset.php
Expand Up @@ -151,21 +151,17 @@
exit(0);
}

echo $OUTPUT->header();

if ($action === 'finishimport') {
if (!confirm_sesskey()) {
throw new moodle_exception('invalidsesskey');
}
$overwritesettings = optional_param('overwritesettings', false, PARAM_BOOL);
$importer = preset_importer::create_from_parameters($manager);
$importer->finish_import_process($overwritesettings, $data);

echo $OUTPUT->continue_button(new moodle_url('/mod/data/preset.php', ['d' => $data->id]));
echo $OUTPUT->footer();
exit(0);
}

echo $OUTPUT->header();

$actionbar = new \mod_data\output\action_bar($data->id, $url);
echo $actionbar->get_presets_action_bar();
$presets = new \mod_data\output\presets($manager, $presets, new \moodle_url('/mod/data/field.php'), true);
Expand Down
2 changes: 1 addition & 1 deletion mod/data/renderer.php
Expand Up @@ -128,7 +128,7 @@ public function importing_preset(stdClass $datamodule, \mod_data\local\importer\
$html .= html_writer::end_tag('div');

$actionbuttons = html_writer::start_div();
$cancelurl = new moodle_url('/mod/data/preset.php', ['d' => $datamodule->id]);
$cancelurl = new moodle_url('/mod/data/field.php', ['d' => $datamodule->id]);
$actionbuttons .= html_writer::tag('a', get_string('cancel') , [
'href' => $cancelurl->out(false),
'class' => 'btn btn-secondary mr-2',
Expand Down
4 changes: 2 additions & 2 deletions mod/data/tests/behat/data_presets.feature
Expand Up @@ -313,10 +313,10 @@ Feature: Users can view and manage data presets
And I choose "Import preset" in the open action menu
And I upload "mod/data/tests/fixtures/image_gallery_preset.zip" file to "Preset file" filemanager
Then I click on "Import preset and apply" "button" in the ".modal-dialog" "css_element"
Then I should see "The preset has been successfully applied."
Then I should see "Preset applied"
# I am on the field page.
And I should see "Manage fields"
Then I should see "The preset has been successfully applied."
Then I should see "Preset applied"

Examples:
| user |
Expand Down
14 changes: 4 additions & 10 deletions mod/data/tests/behat/import_presets.feature
Expand Up @@ -113,9 +113,7 @@ Feature: Users can import presets
And I upload "mod/data/tests/fixtures/image_gallery_preset.zip" file to "Preset file" filemanager
When I click on "Import preset and apply" "button"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I follow "Fields"
And I should see "Preset applied"
Then I should see "title"
And I should see "description" in the "description" "table_row"
And I should see "image" in the "image" "table_row"
Expand All @@ -137,9 +135,7 @@ Feature: Users can import presets
And I should see "Create a new field" in the "oldtitle" "table_row"
And I set the field "id_title" to "Map to oldtitle"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I follow "Fields"
And I should see "Preset applied"
Then I should not see "oldtitle"
And I should see "title"
And I should see "description" in the "description" "table_row"
Expand All @@ -158,12 +154,10 @@ Feature: Users can import presets
When I click on "Import preset and apply" "button"
And I should see "Fields mappings"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I follow "Fields"
And I should see "Preset applied"
And I follow "Presets"
And I choose the "Import preset" item in the "Action" action menu
And I upload "mod/data/tests/fixtures/image_gallery_preset.zip" file to "Preset file" filemanager
And I click on "Import preset and apply" "button"
Then I should not see "Fields mappings"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"
2 changes: 1 addition & 1 deletion mod/data/tests/behat/preview_preset.feature
Expand Up @@ -161,5 +161,5 @@ Feature: Users can preview presets
When I follow "Presets"
And I click on "Saved preset by teacher1" "link"
And I click on "Use this preset" "button"
Then I should see "The preset has been successfully applied"
Then I should see "Preset applied"
And I should see "My URL field"
29 changes: 11 additions & 18 deletions mod/data/tests/behat/use_presets.feature
Expand Up @@ -36,10 +36,8 @@ Feature: Users can use predefined presets
And I should see "Apply preset Image gallery"
And I click on "Map fields" "button"
And I should see "Fields mappings"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
When I follow "Fields"
When I click on "Continue" "button"
And I should see "Preset applied"
Then I should see "title"
And I should see "description" in the "description" "table_row"
And I should see "image" in the "image" "table_row"
Expand All @@ -64,9 +62,7 @@ Feature: Users can use predefined presets
And I should see "Create a new field" in the "oldtitle" "table_row"
And I set the field "id_title" to "Map to oldtitle"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I follow "Fields"
And I should see "Preset applied"
Then I should not see "oldtitle"
And I should see "title"
And I should see "description" in the "description" "table_row"
Expand All @@ -90,7 +86,7 @@ Feature: Users can use predefined presets
# We map existing field to keep the entry data
And I set the field "id_title" to "Map to Test field name"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"
And I follow "Fields"
And I should see "title"
And I follow "Database"
Expand All @@ -105,12 +101,12 @@ Feature: Users can use predefined presets
And I click on "Map fields" "button"
And I set the field "id_title" to "Map to Test field name"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"
And I follow "Presets"
And I click on "fullname" "radio" in the "Image gallery" "table_row"
And I click on "Use this preset" "button"
Then I should not see "Apply preset Image gallery"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"

Scenario: Using a preset from preset preview page on a non empty database could create new fields
Given the following "mod_data > fields" exist:
Expand All @@ -126,7 +122,7 @@ Feature: Users can use predefined presets
And I click on "Use this preset" "button"
And I should see "Apply preset Image gallery"
When I click on "Apply preset" "button"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"
And I follow "Fields"
Then I should see "title"
And I should see "description" in the "description" "table_row"
Expand All @@ -152,9 +148,7 @@ Feature: Users can use predefined presets
And I should see "Create a new field" in the "oldtitle" "table_row"
And I set the field "id_title" to "Map to oldtitle"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I follow "Fields"
And I should see "Preset applied"
Then I should not see "oldtitle"
And I should see "title"
And I should see "description" in the "description" "table_row"
Expand All @@ -178,7 +172,7 @@ Feature: Users can use predefined presets
# We map existing field to keep the entry data
And I set the field "id_title" to "Map to Test field name"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"
And I follow "Fields"
And I should see "title"
And I follow "Database"
Expand All @@ -195,13 +189,12 @@ Feature: Users can use predefined presets
And I should see "Fields mappings"
And I set the field "id_title" to "Map to Test field name"
And I click on "Continue" "button"
And I should see "The preset has been successfully applied"
And I click on "Continue" "button"
And I should see "Preset applied"
And I follow "Presets"
And I click on "Image gallery" "link"
And I click on "Use this preset" "button"
Then I should not see "Fields mappings"
And I should see "The preset has been successfully applied"
And I should see "Preset applied"

Scenario: Apply preset dialogue should show helpful information to the user
Given the following "activities" exist:
Expand Down
2 changes: 1 addition & 1 deletion mod/data/tests/behat/zero_state.feature
Expand Up @@ -54,7 +54,7 @@ Feature: Zero state page (no fields created)
And I upload "mod/data/tests/fixtures/image_gallery_preset.zip" file to "Preset file" filemanager
Then I click on "Import preset and apply" "button" in the ".modal-dialog" "css_element"
And I should see "Manage fields"
Then I should see "The preset has been successfully applied."
Then I should see "Preset applied"

@javascript
Scenario: Teacher can use a preset from zero state page on an empty database
Expand Down

0 comments on commit 1c96810

Please sign in to comment.