Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] spinner as web component #22491

Closed
wants to merge 2 commits into from
Closed

[4.0] spinner as web component #22491

wants to merge 2 commits into from

Conversation

dgrammatiko
Copy link
Contributor

Pull Request for Issue # .

Summary of Changes

  • Drops the code from the core.js for the spinner (already deprecated in j3) and introduces a web component
  • Some minor changes in the build module for the web components. The settings.json will now allow custom paths in the media folder. So someone could do some PRs to move the fields custom elements to their appropriate place (/media/system/js/fields/)
  • Seperated the logic from the mark up for the category field (someone really needs to do this for all the mark up that is hidden in fields or some helpers!!!)
  • Reworked the custom fields part that injected some inline jQuery script. So now the script is part of the category field (that is the right place for the js to live) and the helper just passes some data to the field. The js is still inline so someone should just move it to a file...
  • Patched the custom fields to work with the new element
  • Patched the installation to work with the new element
  • Patched the com_associations to work with the new element

Testing Instructions

Install Joomla, spinner is ok
Make sure that you have custom fields assigned to one category. Edit an article and change its cat to the one that custom fields are attached. spinner is ok
Try a multilingual and check if the spinner works ok

Expected result

Actual result

Documentation Changes Required

In 4.0 in each page that a spinner is needed the following steps will need to be done:

  • Include the web component
HTMLHelper::_('webcomponent', 'system/webcomponents/joomla-core-loader.min.js', ['relative' => true, 'version' => 'auto']);
  • To show the spinner all we need to do is create an element:
spinner = document.createElement('joomla-core-loader');

// Assuming that the spinner is full screen
document.body.appendChild(spinner);

/*
if we need to append the spinner to some other container
all we have to do is replace document.body with the element 
that we want the spinner to appear
*/
  • To remove the spinner all we need to do is destroy the element:
spinner = document.querySelector('joomla-core-loader');

spinner.parentNode.removeChild(spinner);

if you want to use the same codebase for different versions (j3 and j4) here is a quick code:

if (Joomla.loadingLayer && typeof Joomla.loadingLayer === 'function') {
 // We are in J3 so use the old method
 Joomla.loadingLayer('show');
} else {
 // We are in the future
spinner = document.createElement('joomla-core-loader');
document.body.appendChild(spinner);
}

if (!jQuery(formControl).val() != '" . $assignedCatids . "'){jQuery(formControl).val('" . $assignedCatids . "');}
});"
);
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to get removed or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup this inline script cannot be overridden unless you create a plugin (which might not even possible to do in j4 due to name spacing). Asset loading should happen only in layouts

// Preload spindle-wheel when we need to submit form due to category selector changed
\Joomla\CMS\Factory::getDocument()->addScriptDeclaration(
<<<JS
document.addEventListener('DOMContentLoaded', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be added only when custom fields are involved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs a wrapper similar to the one one top

@@ -113,7 +110,7 @@ jQuery(document).ready(function($) {
target.setAttribute('data-language', selected.split(':')[0]);

// Iframe load start, show Joomla loading layer.
Joomla.loadingLayer('show');
document.body.appendChild(document.createElement('joomla-core-loader'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this file needs to be converted to es6 and vanilla js. The indentation won’t solve the real problems here

@@ -168,7 +165,8 @@ jQuery(document).ready(function($) {
});

// Iframe load finished, hide Joomla loading layer.
Joomla.loadingLayer('hide');
var spinner = document.querySelector('joomla-core-loader');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent


const template = document.createElement('template');
template.innerHTML = `<style>{{CSS_CONTENTS_PLACEHOLDER}}</style>
<div><span class="yellow"></span><span class="red"></span><span class="blue"></span><span class="green"></span><p>&reg;</p></div>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correctly indented, the contents are part of the template therefore they don’t obey the the cs of the js, something like `<<<JS

` in php world

@@ -12,7 +12,7 @@
Joomla.setlanguage = function(form) {
var data = Joomla.serialiseForm(form);

Joomla.loadingLayer("show");
document.body.appendChild(document.createElement('joomla-core-loader'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

} else {
Joomla.loadingLayer("hide");
var el = document.querySelector('joomla-core-loader')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

@brianteeman
Copy link
Contributor

There are multiple issues being addressed in this one pr and it really should be one issue per pr. It makes testing much more reliable and avoids parts of the pr not being tested etc

@dgrammatiko
Copy link
Contributor Author

It’s a take it or leave it...

@brianteeman
Copy link
Contributor

Thats a shame as its not the right thing to do (as you well know) and its the reason why whe in the past pr's with multiple issues were merged we are wasting time undoing all the mistakes.

@Fedik
Copy link
Member

Fedik commented Oct 4, 2018

maybe can you please skip the category field for now? it will have a huge conflict with #22263

@dgrammatiko
Copy link
Contributor Author

@Fedik unfortuanatelly this is a really poor implementation with so many anti patterns so at some point it needs to be done.

  • field markup is not overridable
  • field specific js is loaded in a helper file in com_fields

I know it’s a pain but at some point these needs to be done correctly...

@brianteeman
Copy link
Contributor

As I am currently wasting a lot of time redoing a lot of work that was committed in error because it was not tested properly because it was buried in a big pr with other things we must stop accepting any pr that addresses multiple issues at the same time. It is a waste of people's limited time to have to redo things that were not able to be tested!

@dgrammatiko dgrammatiko closed this Oct 4, 2018
@dgrammatiko
Copy link
Contributor Author

Ok good luck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants