-
Notifications
You must be signed in to change notification settings - Fork 297
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
Refs #37104 - fix sync_management #10873
Conversation
Hmm, trying the packit build, it now fails to load common/index.js:
Edit: https://centos8-stream-katello-nightly.tanso.example.com/assets/katello/common/index-41006bb366e1429ef7397de66336e76035be453bc9bac600cd845b9571266232.js would exist. Something is missing to add the hash? |
<script src="/assets/katello/common/index.js"></script> | ||
<script src="/assets/katello/sync_management.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<script src="/assets/katello/common/index.js"></script> | |
<script src="/assets/katello/sync_management.js"></script> | |
<%= javascript 'katello/common/index' %> | |
<%= javascript 'katello/sync_management' %> |
this makes things load the right files but in the wrong order:
<script type="text/javascript">
const html = " \n \n <script>\n localize({\n \"cancel\": \"Cancel\",\n \"cancelled\": \"Sync Canceled\",\n \"error\": \"Error\",\n \"complete\": \"Sync complete.\",\n \"no_start_time\": \"No start time currently available.\"\n });\n\n KT.repo_status = \$.parseJSON(\'{}\');\n KT.permissions = { \"syncable\" : false };\n <\/script>\n <script src=\"/assets/katello/common/vendor-9f3c77c20de190d174986979ad7d0d5cee9362a9a280adabf643e57ee4259155.js\"><\/script>\n <script src=\"/assets/katello/common-41006bb366e1429ef7397de66336e76035be453bc9bac600cd845b9571266232.js\"><\/script>\n <script src=\"/assets/katello/common/index-41006bb366e1429ef7397de66336e76035be453bc9bac600cd845b9571266232.js\"><\/script><script src=\"/assets/katello/sync_management-db168612191a6dc850c8d5cd28375ee6af25d8fd011e62638f11f7fd903f5025.js\"><\/script>\n"
load_dynamic_javascripts(html);
</script>
and well, this gives the localize error again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<script src="/assets/katello/common/index.js"></script> | |
<script src="/assets/katello/sync_management.js"></script> | |
<%= javascript_include_tag 'katello/common/index' %> | |
<%= javascript_include_tag 'katello/sync_management' %> |
This works.
Now, wth is the difference between javascript
and javascript_include_tag
?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's already wrapping it in content_for
… Weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more, this makes sense!
- Your original intent was "have the script load tags and the following embedded code in one block, so that it gets executed in the right order", but had the bug that it ignored asset pipeline paths.
- Using
javascript
creates acontent_for(:javascripts…)
block, which gets yielded into the:javascripts
section individually (so the=
of<%=
didn't really do anything) and thus the order is fucked up - Using
javascript_include_tag
creates script tags that honor the asset pipeline AND prints them directly where the code is, thus resulting in the correct order as one block, which then gets yielded into:javascripts
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh. Clicking the "active only" checkbox still gives me
Uncaught TypeError: KT.content is undefined
<anonymous> sync_management-db168612191a6dc850c8d5cd28375ee6af25d8fd011e62638f11f7fd903f5025.js:1
jQuery 2
dispatch
handle
and spinner.gif
is 404 (but that's already a problem in 4.9, and probably older: https://projects.theforeman.org/issues/37133)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> KT
<<< Object { utils: $(n), common: {…}, widget: {}, getData: getData(n), orgswitcher: {…}, menu: {…}, object: {…} }
>>> load_dynamic_javascripts("<script src=\"/assets/katello/sync_management-db168612191a6dc850c8d5cd28375ee6af25d8fd011e62638f11f7fd903f5025.js\"><\/script>")
<<< undefined
>>> KT
<<< Object { utils: $(n), common: {…}, widget: {}, getData: getData(n), orgswitcher: {…}, menu: {…}, object: {…}, content: {…}, content_actions: {…} }
So reloading that sync management script works. WTH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be something re-initializes KT
, thus overwriting what this code did?
<%= javascript "katello/hosts/host_and_hostgroup_edit" %> | ||
<% content_for(:javascripts) do -%> | ||
<%= javascript "katello/hosts/host_and_hostgroup_edit" %> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant, <%= javacript …
already does content_for(:javascripts)
: https://github.com/theforeman/foreman/blob/262b5caceab9c3f71d0b80f189cc724389593fb0/app/helpers/layout_helper.rb#L98-L100
<%= javascript "katello/hosts/activation_key_edit" %> | ||
<% content_for(:javascripts) do -%> | ||
<%= javascript "katello/hosts/activation_key_edit" %> | ||
<% end %> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant, <%= javacript …
already does content_for(:javascripts)
: https://github.com/theforeman/foreman/blob/262b5caceab9c3f71d0b80f189cc724389593fb0/app/helpers/layout_helper.rb#L98-L100
|
||
<%= javascript_include_tag 'katello/organizations/download_certificate' %> | ||
|
||
<% content_for(:javascripts) do -%> | ||
<%= javascript_include_tag 'katello/organizations/download_certificate' %> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we standardize on either
<%= javascript … %>
OR
<% content_for(:javascripts) do -%>
<%= javascript_include_tag … %>
<% end %>
using both seems odd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather use
<% content_for(:javascripts) do -%>
<%= javascript_include_tag … %>
<% end %>
just because when I see <%= javascript … %>
I assumed it was something default from ruby and not a custom thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree that ths makes it more explicit.
@@ -1,17 +1,19 @@ | |||
<%= javascript 'katello/sync_management' %> | |||
<% content_for(:javascripts) do -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<% content_for(:javascripts) do -%> | |
<% content_for(:katello_javascripts) do -%> |
THIS fixes it.
the reset happens here:
katello/app/views/katello/layouts/katello.html.erb
Lines 9 to 13 in 136a73e
<% content_for(:javascripts) do %> | |
<%= javascript_include_tag "katello/common/vendor" %> | |
<%= javascript_include_tag "katello/common" %> | |
<%= yield(:katello_javascripts) %> | |
<% end %> |
and once done like this, we don't have to reference katello/common/index
ourself at all, as that is now loaded in the right order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<% content_for(:katello_javascripts) do -%>
<%= javascript_include_tag 'katello/sync_management' %>
<script>
localize({
"cancel": "<%= escape_javascript(_('Cancel')) %>",
"cancelled": "<%= escape_javascript(_('Sync Canceled')) %>",
"error": "<%= escape_javascript(_('Error')) %>",
"complete": "<%= escape_javascript(_('Sync complete.')) %>",
"no_start_time": "<%= escape_javascript(_('No start time currently available.')) %>"
});
KT.repo_status = $.parseJSON('<%= escape_javascript(@repo_status.to_json.html_safe) %>');
KT.permissions = { "syncable" : <%= any_syncable? %> };
</script>
<% end -%>
this is how it looks in full on my box now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still get "Uncaught TypeError: Cannot read properties of undefined (reading 'select_repo')" on select none with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me (on a prod install, don't have a devel katello right now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code generated for loading (I added line breaks for readability):
<script type="text/javascript">
const html = "
<script src=\"/assets/katello/common/vendor-9f3c77c20de190d174986979ad7d0d5cee9362a9a280adabf643e57ee4259155.js\"><\/script>\n
<script src=\"/assets/katello/common-41006bb366e1429ef7397de66336e76035be453bc9bac600cd845b9571266232.js\"><\/script>\n
<script src=\"/assets/katello/sync_management-db168612191a6dc850c8d5cd28375ee6af25d8fd011e62638f11f7fd903f5025.js\"><\/script>\n
<script>\n localize({\n \"cancel\": \"Cancel\",\n \"cancelled\": \"Sync Canceled\",\n \"error\": \"Error\",\n \"complete\": \"Sync complete.\",\n \"no_start_time\": \"No start time currently available.\"\n });\n\n KT.repo_status = \$.parseJSON(\'{\\\"1\\\":{\\\"id\\\":1,\\\"product_id\\\":1,\\\"progress\\\":{},\\\"state\\\":\\\"Never Synced\\\",\\\"raw_state\\\":\\\"never_synced\\\"}}\');\n KT.permissions = { \"syncable\" : true };\n <\/script>\n\n"
load_dynamic_javascripts(html);
</script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah… but that still means that the code gets executed twice, which seems wrong :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean… It's probably still a good idea to have such a safety guard, but it should not be the "real" fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which code gets executed twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
katello/common
gets executed twice if we use content_for(:javascripts)
(and not :katello_javascripts
), as that generates:
- katello/common (from sync_management/index.html)
- katello/sync_management
- katello/common (from layouts/katello)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean… It's probably still a good idea to have such a safety guard, but it should not be the "real" fix
Yeah, I thought you meant adding it will cause the double execution.
Added it to the pr and used your solution, thanks!
FWIW, I'd omit the "Refs #37104 - wrap scripts in content_for(:javascripts)" commit from this PR and only have the "fix sync_management" changes (but I am neither author, nor reviewer, so just stating my thoughts ;) ) |
a1fd6f4
to
8f5136e
Compare
app/assets/javascripts/katello/sync_management/sync_management.js
the real change is to move
KT.content =
andKT.content_actions =
to be at the top, and remove$(document).ready(function() {
as it will only run the script when the document is ready because of thecontent_for
katello.common.js
fromsync_management/index.js
tosync_management/index.html.erb
to make sure its fully loaded in timecontent_for
so they wont run too early