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

Updates translatable custom pages #2913

Conversation

papayalabs
Copy link
Contributor

@papayalabs papayalabs commented Sep 20, 2018

References

Issue #2741

Visual Changes

screen1jpg
Editing with many languages
screen2

Notes

In the migration of translation tables of custom pages ( 20180802221830_add_translate_pages.rb ) we add a change_column to allow null in title. Title is not used anymore as index in table and now is used in many languages title_en,title_es,title_fr, etc. Give NullConstraint from database if do not make this change.

class AddTranslatePages < ActiveRecord::Migration
  def self.up
    SiteCustomization::Page.create_translation_table!({
      title: :string,
      subtitle: :string,
      content: :text
    })
    change_column :site_customization_pages, :title, :string, :null => true
  end

  def self.down
    SiteCustomization::Page.drop_translation_table!
    change_column :site_customization_pages, :title, :string, :null => false
  end
end

@papayalabs
Copy link
Contributor Author

Hi @mlovic, all the functionality works fine, the only detail is when you click other translation tag in the Custom Page form the CKEDITOR goes down one line and keeps like that if you continue navigating. I try to fix this from the beginning but I could not find how.

Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

Thanks @papayalabs! I've made some comments; could you have a look? Feel free to disagree with any of the comments, of course 😉.

I haven't tested the functionality properly yet; I'll do it after I hear back from you. Thanks again!

@@ -30,19 +31,25 @@ def destroy
notice = t('admin.site_customization.pages.destroy.notice')
redirect_to admin_site_customization_pages_path, notice: notice
end

def resource
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this method should be private.

:title,
:subtitle,
:content,
:more_info_flag,
:print_content_flag,
:status,
:locale
:locale]

Copy link
Member

@javierm javierm Sep 21, 2018

Choose a reason for hiding this comment

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

Would you mind checking trailing whitespaces? We're currently in the process of adding a rubocop rule for trailing whitespaces. In the meantime, you might want to add it manually and check for trailing whitespaces using tools like rubocop-git or (even better IMHO) configure your text editor to highlight trailing whitespaces or (probably useful as well) add a pre-commit git hook which checks whitespace issues.


def url
"/#{slug}"
end
end

Copy link
Member

Choose a reason for hiding this comment

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

We're also about to add a newline character to rubocop rules. Would you mind checking for trailing blank lines as well, or configuring your editor so it automatically adds a newline character? This way we don't accidentally change files just to add/remove blank lines at the end.

data: { locale: locale },
style: display_translation?(locale) do %>
<%= f.cktext_area "content_#{locale.to_s.downcase.underscore.to_sym}",
class: "js-globalize-attribute",
Copy link
Member

Choose a reason for hiding this comment

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

I think there a few tabs in these lines. Could you check we use whitespaces for indentation instead of tabs? Again, configuring your text editor to highlight tab characters makes the job way easier.

expect(page).not_to have_link "Español"
end

context "Globalize javascript interface" do
Copy link
Member

Choose a reason for hiding this comment

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

It looks like some of these tests could be replaced by it_behaves_like "translatable". I'm not sure, though. @mlovic @papayalabs What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using it_behaves_like "translatable" will use test "Add a translation scenario" with "Français" and I think is important to test with "Português" because for this language has some particularities that may trigger some errors that will not trigger with other languages. But again is my perspective, if you guys prefer with "translatable" code I will changed ;)

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's important to test Brazilian Portuguese 👍! In the translatable shared examples there's a scenario for that case, called "Add a translation for a locale with non-underscored name". Would that be enough, or do we need something specific to custom pages? If we need something specific, we could add it_behaves_like "translatable" and then add tests for specific cases, like in collaborative legislation specs. What do you think?

Copy link
Contributor Author

@papayalabs papayalabs Sep 25, 2018

Choose a reason for hiding this comment

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

Sorry, I had not seen that scenario in the translatable shared. I think that would be enough, Thanks for the clarification @javierm! I am going to updated with translatable shared

Copy link
Contributor Author

@papayalabs papayalabs Sep 26, 2018

Choose a reason for hiding this comment

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

Hi @javierm! in the translatable shared class is there a way to pass some field that are not translatable? For example in cutom pages the default for status is draft and we need to pass status published for tests.

Copy link
Member

Choose a reason for hiding this comment

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

How about adding a new factory? In spec/factories/administration.rb:

  factory :site_customization_page, class: 'SiteCustomization::Page' do
    slug "example-page"
   # (...)

    trait :published do
      status "published"
    end
    
    # (...)

    factory :published_site_customization_page, traits: [:published] # <---- Add this line
  end

Maybe that way we could pass published_site_customization_page as the factory name to translatable.

You might run into issues using the translatable behaviour because (so far) some of the specs there don't work well with CKEditor. If that happens, it's OK to leave the tests where they are for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much for the tip!!

Copy link
Contributor Author

@papayalabs papayalabs Sep 26, 2018

Choose a reason for hiding this comment

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

I get confused, was not necessary to create published_site_customization_page, the thing was that in translatable class it uses a update_button_text and for default uses the name Save changesbut the button in Custom Pages is Update Custom pageand I thought that the page was not published. I already add Update Custom page name in translatable class. But you are right does not recognize CKEditor fields nevertheless it works fine with the others fields and the tests now does not check CKEditor fields either. So how I proceed? Leave tests as they are or use translatable with (title,subtitle) only? Thanks!!

Copy link
Member

Choose a reason for hiding this comment

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

Leaving tests as they are is fine 👌. We'll try to better integrate CKEditor with Capybara in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok @javierm! So I thing all the requested changes are ready. I unified everything in one commit. Thanks!

db/schema.rb Outdated
@@ -116,6 +116,8 @@
t.datetime "updated_at", null: false
t.text "background_color"
t.text "font_color"
t.string "banner_position"
t.text "headings"
Copy link
Member

Choose a reason for hiding this comment

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

I think these lines aren't related to this pull request.

db/schema.rb Outdated
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180813141443) do
ActiveRecord::Schema.define(version: 20180831000000) do
Copy link
Member

Choose a reason for hiding this comment

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

This schema version doesn't seem to be related to any migration files. I wonder how it got there 😕.

db/schema.rb Outdated
t.string "subtitle"
t.text "content"
t.boolean "more_info_flag"
t.boolean "print_content_flag"
t.string "status", default: "draft"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "locale"
Copy link
Member

Choose a reason for hiding this comment

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

I didn't find a migration file where this column was dropped. Did I miss it?

@papayalabs
Copy link
Contributor Author

Hi @javierm! Yes you are right that I need to setup everything to be more aware of indentation and other rubocop rules. I fix all you tell me about this. I also change schema.rb ( hope I do it right). I only comment the changes in "spec/features/site_customization/custom_pages_spec.rb" with my perspective but is not fixed. Please tell me if you need more changes.

@papayalabs papayalabs force-pushed the 2741-updates-translatable-custom-pages-reloaded branch from 57e0971 to 110549d Compare September 24, 2018 06:32
@papayalabs
Copy link
Contributor Author

@javierm almost all the changes you request were made but I unified everything in one commit ( first one ) so it looks that were not made

Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

This is looking good. Thank you so much! I've just left a couple of comments, and since I'm not sure about the slug usage I've mentioned @decabeza who will probably know better.

class: "js-globalize-attribute",
ckeditor: { language: locale },
data: { locale: locale },
label: false %>
Copy link
Member

Choose a reason for hiding this comment

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

I think we need (somehow) a label here. Maybe you could use the code @microweb10 hast just implemented (still not merged, though): https://github.com/consul/consul/pull/2914/files#diff-4d169e27f1a8740fdcd328f352bf82d2R38

Copy link
Contributor Author

@papayalabs papayalabs Sep 25, 2018

Choose a reason for hiding this comment

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

Yes, our functionality with ckeditor is similar. Will work just fine anything that @microweb10 implement. 👍

@@ -1,11 +1,11 @@
<% provide :title do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.pages") %> - <%= @page.title %>
<% provide :slug do %>
Copy link
Member

Choose a reason for hiding this comment

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

Actually, we need to use provide :title 😉, since the parameter here is used to generate the HTML <title> tag (see app/views/layouts/_common_head.html.erb, the line saying <title><%= content_for?(:title) ? yield(:title) : default_title %></title>).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I will check this. I took the daring to replace slugwith titlebut I am not sure is the best way to go. 😉 I take this way because slug like status and created,updated at are not translatable in many languages but I could change everything to use titleagain. Just confirm me!

<% provide :title do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.pages") %> - <%= @page.title %>
<% provide :slug do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.pages") %> - <%= @page.slug %>
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong preference about which title the browser should show, which is what we're changing here. Which one do you think it's better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don´t have preference either 😉. Just confirm me what to use. :)

<% end %>

<%= back_link_to admin_site_customization_pages_path %>

<div class="small-12 column">
<h2 class="inline-block"><%= t("admin.site_customization.pages.edit.title", page_title: @page.title) %></h2>
<h2 class="inline-block"><%= t("admin.site_customization.pages.edit.title", page_title: @page.slug) %></h2>
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment as the previous one. Should admins see "Editing My Page" or "Editing my-page"? Maybe @decabeza can tell better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi, @papayalabs and @javierm! I think it's better always to use the page title. Usually, the slugs will have a dash or underscore and it'll a little more uncomprehensive. 😌

I think is easier to read
Administration - Editing My custom page
instead of
Administration - Editing my-custom-page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @decabeza! Ok clear! I will return everything with title instead slug. 👍

<th class="small-4"><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr id="<%= dom_id(page) %>">
<td>
<%= link_to page.title, edit_admin_site_customization_page_path(page) %>
<%= link_to page.slug, edit_admin_site_customization_page_path(page) %>
Copy link
Member

Choose a reason for hiding this comment

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

In all other translatable sections we show the title. @decabeza @papayalabs Which one do you guys think is more convenient here?

Copy link
Collaborator

@decabeza decabeza Sep 25, 2018

Choose a reason for hiding this comment

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

@papayalabs, @javierm, in this case, I think it would a good idea show the both, something like

<th><%= t("admin.site_customization.pages.page.title") %></th>
<th><%= t("admin.site_customization.pages.page.slug") %></th>

<td><%= link_to page.title, edit_admin_site_customization_page_path(page) %></td>
<td><%= page.slug %></td>

So... the admin can see the slug info in the index table without have to edit the page:

Title                        Slug
My custom page               my-custom-page

Moreover, in other sections we always use the title as a link, consistency is the key! 😌 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok @decabeza, show both and title as the key link 😉👍

expect(page).not_to have_link "Español"
end

context "Globalize javascript interface" do
Copy link
Member

Choose a reason for hiding this comment

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

I agree it's important to test Brazilian Portuguese 👍! In the translatable shared examples there's a scenario for that case, called "Add a translation for a locale with non-underscored name". Would that be enough, or do we need something specific to custom pages? If we need something specific, we could add it_behaves_like "translatable" and then add tests for specific cases, like in collaborative legislation specs. What do you think?

@@ -3,7 +3,7 @@
<ul class="features">
<li><%= link_to t("pages.help.other.how_to_use", org_name: setting['org_name']), how_to_use_path %></li>

<% SiteCustomization::Page.with_more_info_flag.with_same_locale.each do |custom_page| %>
<% SiteCustomization::Page.with_more_info_flag.each do |custom_page| %>
Copy link
Member

Choose a reason for hiding this comment

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

This one is tricky. IMHO we should only show pages which have a translation for the current locale. How about keeping this line the way it was and changing the scope to:

   scope :with_same_locale, -> { joins(:translations).where("site_customization_page_translations.locale": I18n.locale) }

Feel free to simplify the condition! This is only an example.

Copy link
Contributor Author

@papayalabs papayalabs Sep 25, 2018

Choose a reason for hiding this comment

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

I am agree. Will add again with_same_local scope and check to simplify the condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. But I dont find how simplified more.

SiteCustomization::Page.drop_translation_table!
change_column :site_customization_pages, :title, :string, :null => false
end
end
Copy link
Member

Choose a reason for hiding this comment

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

I think this missing newline character is the only spacing issue left.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry. Updated.

data: { locale: locale }
else
@template.concat send(field_type, localized_attr_name, final_options)
end
Copy link
Member

Choose a reason for hiding this comment

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

We've already merged #2914 which incorporated these changes, in case you'd like to rebase against master.

@papayalabs papayalabs force-pushed the 2741-updates-translatable-custom-pages-reloaded branch from f8e592c to db79982 Compare September 26, 2018 14:40
<%= f.submit class: "button success expanded" %>
</div>
<div class="small-12 column">
<hr>
Copy link
Member

Choose a reason for hiding this comment

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

Could you remove the trailing whitespaces in this line? By the way, IMHO this line should be either indented or before the previous line (I'm not sure which one is right; you probably know it better).

<div class="small-12 medium-6 large-3">
<%= f.submit class: "button success expanded" %>
</div>
</div>
Copy link
Member

@javierm javierm Sep 27, 2018

Choose a reason for hiding this comment

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

Could you move this line one space to the left 😉? Sorry if I'm being a bit annoying about whitespace issues. Hope you understand we've got many contributors and sometimes we need to try to keep the codebase as consistent as possible.

@papayalabs papayalabs force-pushed the 2741-updates-translatable-custom-pages-reloaded branch from 18c340c to 914bfa6 Compare September 27, 2018 11:46
<%= f.submit class: "button success expanded" %>
</div>
<div class="small-12 column">
<hr>
Copy link
Member

@javierm javierm Sep 27, 2018

Choose a reason for hiding this comment

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

Thanks for the indentation fix! Would you mind removing the trailing whitespaces here 🙏? Thank you so much!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! No problem. I revised with an option of the editor the trailing whitespaces but I think I am doing something wrong. I am going to checked again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready! Thanks @javierm for your patience 🙏

Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

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

Thank you for this one @papayalabs 🎉!

@@ -11,7 +11,7 @@
custom_page = create(:site_customization_page)
visit admin_site_customization_pages_path

expect(page).to have_content(custom_page.title)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we decided to keep the title and the slug on /admin/site_customization/pages/index.html.erb could you keep both also in the spec? 🙏 😌

Thanks!

Copy link
Contributor Author

@papayalabs papayalabs Sep 28, 2018

Choose a reason for hiding this comment

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

Of course @decabeza! I forgot to update the spec🐰I already added in all scenarios the changes. Thanks!!

@@ -22,19 +22,18 @@
click_link "Custom pages"
end

expect(page).not_to have_content "An example custom page"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same the previous 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready ✌️


click_button "Create Custom page"

expect(page).to have_content "An example custom page"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same the previous 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready ✌️

@javierm javierm merged commit 132fea9 into consuldemocracy:master Oct 3, 2018
@javierm
Copy link
Member

javierm commented Oct 3, 2018

Thank you so much @papayalabs 😉.

@papayalabs
Copy link
Contributor Author

My pleasure! Thank you guys to make so nice to contribute in this project!

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

4 participants