JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.0] Adding display of progress to installation #410

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/29376 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/installation/language/en-GB/joomla.ini b/installation/language/en-GB/joomla.ini index 04c5d7416d00e..07a4509346294 100644 --- a/installation/language/en-GB/joomla.ini +++ b/installation/language/en-GB/joomla.ini @@ -310,3 +310,9 @@ JLIB_FORM_CONTAINS_INVALID_FIELDS="The form cannot be submitted as it's missing JLIB_FORM_FIELD_INVALID_VALUE="This value is not valid." JLIB_FORM_FIELD_REQUIRED_CHECK="One of the options must be selected." JLIB_FORM_FIELD_REQUIRED_VALUE="Please fill in this field." + +; Installation progress screen +INSTL="Installation" +INSTL_FINISHED="Installation finished" +INSTL_IN_PROGRESS="Installation running" +INSTL_PROGRESS="Installation Progress" diff --git a/installation/src/Controller/InstallationController.php b/installation/src/Controller/InstallationController.php index 5ebb41bc6006f..5abe387ee2cf0 100644 --- a/installation/src/Controller/InstallationController.php +++ b/installation/src/Controller/InstallationController.php @@ -82,6 +82,7 @@ public function dbcheck() if ($data === false) { $this->app->enqueueMessage(Text::_('INSTL_DATABASE_VALIDATION_ERROR'), 'error'); $r->validated = false; + $r->error = true; $this->sendJsonResponse($r); return; @@ -89,7 +90,12 @@ public function dbcheck() $data = $model->storeOptions($data); - $r->validated = $model->validateDbConnection($data); + if (!$model->validateDbConnection($data)) { + $r->validated = false; + $r->error = true; + } else { + $r->validated = true; + } $this->sendJsonResponse($r); } @@ -121,10 +127,12 @@ public function create() } if (!$dbCreated) { - $r->view = 'setup'; + $r->view = 'setup'; + $r->error = true; } else { if (!$databaseModel->handleOldDatabase($options)) { - $r->view = 'setup'; + $r->view = 'setup'; + $r->error = true; } } @@ -168,12 +176,14 @@ public function populate() if (!isset($files[$step])) { $r->view = 'setup'; $this->app->enqueueMessage(Text::_('INSTL_SAMPLE_DATA_NOT_FOUND'), 'error'); + $r->error = true; $this->sendJsonResponse($r); } // Attempt to populate the database with the given file. if (!$model->createTables($schema, $options)) { - $r->view = 'setup'; + $r->view = 'setup'; + $r->error = true; } $this->sendJsonResponse($r); @@ -204,7 +214,8 @@ public function config() // Attempt to setup the configuration. if (!$configurationModel->setup($options)) { - $r->view = 'setup'; + $r->view = 'setup'; + $r->error = true; } $this->sendJsonResponse($r); diff --git a/installation/src/Response/JsonResponse.php b/installation/src/Response/JsonResponse.php index 89c0b93db3a07..17bac112db31b 100644 --- a/installation/src/Response/JsonResponse.php +++ b/installation/src/Response/JsonResponse.php @@ -122,6 +122,11 @@ public function __construct($data) } else { // Prepare the response data. $this->error = false; + + if (isset($data->error) && $data->error) { + $this->error = true; + } + $this->data = $data; } } diff --git a/installation/template/index.php b/installation/template/index.php index ef31a13f5691f..7ac31f5e4b876 100644 --- a/installation/template/index.php +++ b/installation/template/index.php @@ -53,6 +53,11 @@ Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT'); Text::script('INSTL_DATABASE_RESPONSE_ERROR'); +// Add strings for installation progress +Text::script('INSTL'); +Text::script('INSTL_FINISHED'); +Text::script('INSTL_IN_PROGRESS'); + // Load the JavaScript translated messages Text::script('INSTL_PROCESS_BUSY'); diff --git a/installation/template/js/setup.js b/installation/template/js/setup.js index 9df8d99a143a0..e52141385bdd4 100644 --- a/installation/template/js/setup.js +++ b/installation/template/js/setup.js @@ -58,24 +58,37 @@ Joomla.checkInputs = function() { inputs.forEach(function(item) { if (!item.valid) state = false; }); + document.getElementById('progress-text').classList.remove('error'); + document.getElementById('progress-text').setAttribute('role', 'status'); + document.getElementById('progress-text').innerText = Joomla.Text._('INSTL_IN_PROGRESS'); + document.getElementById('progressbar').setAttribute('value', 0); // Reveal everything document.getElementById('installStep1').classList.add('active'); document.getElementById('installStep2').classList.add('active'); document.getElementById('installStep3').classList.add('active'); - if (Joomla.checkFormField(['#jform_site_name', '#jform_admin_user', '#jform_admin_email', '#jform_admin_password', '#jform_db_type', '#jform_db_host', '#jform_db_user', '#jform_db_name'])) { Joomla.checkDbCredentials(); } }; - Joomla.checkDbCredentials = function() { - document.body.appendChild(document.createElement('joomla-core-loader')); + const progress = document.getElementById('progressbar'); + const progress_text = document.getElementById('progress-text'); var form = document.getElementById('adminForm'), data = Joomla.serialiseForm(form); + // Remove potential messages + Joomla.removeMessages(); + + // Hide form and show progress bar + document.getElementById('installStep1').classList.remove('active'); + document.getElementById('installStep2').classList.remove('active'); + document.getElementById('installStep3').classList.remove('active'); + document.getElementById('installStep4').classList.add('active'); + progress_text.innerText = Joomla.Text._('INSTL_IN_PROGRESS'); + Joomla.request({ method: "POST", url : Joomla.installationBaseUrl + '?task=installation.dbcheck&format=json', @@ -83,11 +96,12 @@ Joomla.checkDbCredentials = function() { perform: true, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, onSuccess: function(response, xhr){ - var loaderElement = document.querySelector('joomla-core-loader'); try { response = JSON.parse(response); } catch (e) { - loaderElement.parentNode.removeChild(loaderElement); + progress_text.setAttribute('role', 'alert'); + progress_text.classList.add('error'); + progress_text.innerText = response; console.error('Error in DB Check Endpoint'); console.error(response); Joomla.renderMessages({'error': [Joomla.Text._('INSTL_DATABASE_RESPONSE_ERROR')]}); @@ -100,21 +114,27 @@ Joomla.checkDbCredentials = function() { } Joomla.replaceTokens(response.token); - loaderElement.parentNode.removeChild(loaderElement); if (response.error) { - Joomla.renderMessages({'error': [response.message]}); + document.getElementById('installStep1').classList.add('active'); + document.getElementById('installStep2').classList.add('active'); + document.getElementById('installStep3').classList.add('active'); + document.getElementById('installStep4').classList.remove('active'); + progress_text.innerText = Joomla.Text._('INSTL'); } else if (response.data && response.data.validated === true) { // Run the installer - we let this handle the redirect for now // @todo: Convert to promises + progress.setAttribute('value', parseInt(progress.getAttribute('value')) + 1); + progress_text.innerText = Joomla.Text._('INSTL_IN_PROGRESS'); Joomla.install(['create', 'populate1', 'populate2', 'populate3', 'custom1', 'custom2', 'config'], form); } }, onError: function(xhr){ Joomla.renderMessages([['', Joomla.Text._('JLIB_DATABASE_ERROR_DATABASE_CONNECT', 'A Database error occurred.')]]); + progress_text.setAttribute('role', 'alert'); + progress_text.classList.add('error'); + progress_text.innerText = response.message; //Install.goToPage('summary'); - var loaderElement = document.querySelector('joomla-core-loader'); - loaderElement.parentNode.removeChild(loaderElement); try { var r = JSON.parse(xhr.responseText); @@ -199,5 +219,4 @@ Joomla.checkDbCredentials = function() { Joomla.checkInputs(); }) } - })(); diff --git a/installation/template/js/template.js b/installation/template/js/template.js index 963c8b8c36f44..b78b5aaaaed2f 100644 --- a/installation/template/js/template.js +++ b/installation/template/js/template.js @@ -154,17 +154,21 @@ * @param tasks An array of install tasks to execute */ Joomla.install = function(tasks, form) { + const progress = document.getElementById('progressbar'); + const progress_text = document.getElementById('progress-text'); if (!form) { throw new Error('No form provided') } if (!tasks.length) { - Joomla.goToPage('remove'); + if (progress_text) { + progress_text.innerText = Joomla.Text._('INSTL_FINISHED'); + } + setTimeout(Joomla.goToPage, 2000, 'remove'); return; } var task = tasks.shift(); var data = Joomla.serialiseForm(form); - document.body.appendChild(document.createElement('joomla-core-loader')); Joomla.request({ method: "POST", @@ -172,12 +176,14 @@ data: data, perform: true, onSuccess: function(response, xhr){ - var spinnerElement = document.querySelector('joomla-core-loader'); - try { response = JSON.parse(response); } catch (e) { - spinnerElement.parentNode.removeChild(spinnerElement); + if (progress_text) { + progress_text.setAttribute('role', 'alert'); + progress_text.classList.add('error'); + progress_text.innerText = response; + } console.error('Error in ' + task + ' Endpoint'); console.error(response); Joomla.renderMessages({'error': [Joomla.Text._('INSTL_DATABASE_RESPONSE_ERROR')]}); @@ -189,21 +195,30 @@ if (response.error === true) { - spinnerElement.parentNode.removeChild(spinnerElement); + progress_text.setAttribute('role', 'alert'); + progress_text.classList.add('error'); + progress_text.innerText = response.message; Joomla.renderMessages({"error": [response.message]}); return false; } if (response.messages) { - spinnerElement.parentNode.removeChild(spinnerElement); Joomla.renderMessages(response.messages); return false; } - spinnerElement.parentNode.removeChild(spinnerElement); + if (progress) { + progress.setAttribute('value', parseInt(progress.getAttribute('value')) + 1); + progress_text.innerText = Joomla.Text._('INSTL_IN_PROGRESS'); + } Joomla.install(tasks, form); }, onError: function(xhr){ + if (progress_text) { + progress_text.setAttribute('role', 'alert'); + progress_text.classList.add('error'); + progress_text.innerText = xhr.responseText; + } Joomla.renderMessages([['', Joomla.Text._('JLIB_DATABASE_ERROR_DATABASE_CONNECT', 'A Database error occurred.')]]); Joomla.goToPage('remove'); diff --git a/installation/template/scss/template.scss b/installation/template/scss/template.scss index eac37879de350..e7ea1cd4d12bb 100644 --- a/installation/template/scss/template.scss +++ b/installation/template/scss/template.scss @@ -395,3 +395,16 @@ caption { .table > :not(:last-child) > :last-child > * { border-bottom-color: $table-border-color; } + +// Installation progress +.progresslabel {width: 100%;} + +progress { + display: block; + width: 100%; + height: 25px; + margin: 1rem auto; + background: linear-gradient(#ccc 0%, #eee 50%, #eee 50%, #ccc 100%); + border: 0 none; + border-radius: 4px; +} diff --git a/installation/tmpl/setup/default.php b/installation/tmpl/setup/default.php index 39737eeffb78c..9b6978d193017 100644 --- a/installation/tmpl/setup/default.php +++ b/installation/tmpl/setup/default.php @@ -120,7 +120,17 @@
- +
+ + + +
+ +
+
```