MDL-41958 import: Constistently showing progress steps.

This commit is contained in:
Luca Bösch 2019-02-21 18:08:59 +01:00
parent 800563e415
commit 292b987c5c
4 changed files with 79 additions and 7 deletions

View File

@ -69,7 +69,10 @@ if ($importcourseid === false || $searchcourses) {
// show the course selector
echo $OUTPUT->header();
echo $renderer->import_course_selector($url, $search);
$backup = new import_ui(false, array());
echo $renderer->progress_bar($backup->get_progress_bar());
$html = $renderer->import_course_selector($url, $search);
echo $html;
echo $OUTPUT->footer();
die();
}
@ -131,6 +134,8 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
// First execute the backup
$backup->execute();
// Before destroying the backup object, we still need to generate the progress bar.
$progressbar = $renderer->progress_bar($backup->get_progress_bar());
$backup->destroy();
unset($backup);
@ -209,6 +214,7 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
echo html_writer::end_tag('ul');
echo $OUTPUT->box_end();
}
echo $progressbar;
echo $OUTPUT->notification(get_string('importsuccess', 'backup'), 'notifysuccess');
echo $OUTPUT->continue_button(new moodle_url('/course/view.php', array('id'=>$course->id)));

View File

@ -90,8 +90,10 @@ abstract class base_ui {
$this->controller = $controller;
$this->progress = self::PROGRESS_INTIAL;
$this->stage = $this->initialise_stage(null, $params);
// Process UI event before to be safe.
$this->controller->process_ui_event();
if ($this->controller) {
// Process UI event before to be safe.
$this->controller->process_ui_event();
}
}
/**

View File

@ -33,6 +33,12 @@
*/
class import_ui extends backup_ui {
/**
* The stages of the backup user interface
* The precheck/selection stage of the backup - here you choose the initial settings.
*/
const STAGE_PRECHECK = 0;
/**
* Customises the backup progress bar
*
@ -68,6 +74,11 @@ class import_ui extends backup_ui {
}
$selectorlink = new moodle_url($PAGE->url, $this->stage->get_params());
$selectorlink->remove_params('importid');
$classes = ["backup_stage"];
if ($currentstage == 0) {
$classes[] = "backup_stage_current";
}
array_unshift($items, array(
'text' => '1. '.get_string('importcurrentstage0', 'backup'),
'class' => join(' ', $classes),
@ -85,7 +96,7 @@ class import_ui extends backup_ui {
*/
protected function initialise_stage($stage = null, array $params = null) {
if ($stage == null) {
$stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT);
$stage = optional_param('stage', self::STAGE_PRECHECK, PARAM_INT);
}
if (self::$skipcurrentstage) {
$stage *= 2;
@ -103,6 +114,9 @@ class import_ui extends backup_ui {
case backup_ui::STAGE_FINAL:
$stage = new import_ui_stage_final($this, $params);
break;
case self::STAGE_PRECHECK:
$stage = new import_ui_stage_precheck($this, $params);
break;
default:
$stage = false;
break;
@ -120,6 +134,56 @@ class import_ui extends backup_ui {
*/
class import_ui_stage_inital extends backup_ui_stage_initial {}
/**
* Class representing the precheck/selection stage of a import.
*
* In this stage the user is required to perform initial selections.
* That is a choice of which course to import from.
*
* @package core_backup
* @copyright 2019 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class import_ui_stage_precheck extends backup_ui_stage {
/**
* Precheck/selection import stage constructor
* @param backup_ui $ui
* @param array $params
*/
public function __construct(backup_ui $ui, array $params = null) {
$this->stage = import_ui::STAGE_PRECHECK;
parent::__construct($ui, $params);
}
/**
* Processes the precheck/selection import stage
*
* @param base_moodleform|null $form
*/
public function process(base_moodleform $form = null) {
// Dummy functions. We don't have to do anything here.
return;
}
/**
* Gets the next stage for the import.
*
* @return int
*/
public function get_next_stage() {
return backup_ui::STAGE_INITIAL;
}
/**
* Initialises the backup_moodleform instance for this stage
*
* @return backup_moodleform|void
*/
public function initialise_stage_form() {
// Dummy functions. We don't have to do anything here.
}
}
/**
* Extends the schema stage
*

View File

@ -216,7 +216,7 @@ class core_backup_renderer extends plugin_renderer_base {
$html .= html_writer::end_tag('div');
}
$html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
$html .= $this->continue_button($nextstageurl, 'post');
$html .= html_writer::end_tag('div');
return $html;
@ -242,7 +242,7 @@ class core_backup_renderer extends plugin_renderer_base {
get_string('backuptype', 'backup'),
get_string('backuptype'.$details['type'], 'backup'));
$html .= html_writer::end_tag('div');
$html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
$html .= $this->continue_button($nextstageurl, 'post');
$html .= html_writer::end_tag('div');
return $html;
@ -259,7 +259,7 @@ class core_backup_renderer extends plugin_renderer_base {
$html = html_writer::start_div('unknownformat');
$html .= $this->output->heading(get_string('errorinvalidformat', 'backup'), 2);
$html .= $this->output->notification(get_string('errorinvalidformatinfo', 'backup'), 'notifyproblem');
$html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
$html .= $this->continue_button($nextstageurl, 'post');
$html .= html_writer::end_div();
return $html;