Skip to content

Commit

Permalink
Fixes #25, adds icons showing translation status to docs and categori…
Browse files Browse the repository at this point in the history
…es admin views

Signed-off-by: Scott Miller <[email protected]>
  • Loading branch information
scott committed Dec 12, 2015
1 parent f56f820 commit f3c91a5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ ul.dropdown-menu li a.strong {
font-weight: bolder;
}

.badge-light {
background-color: #eee;
}

.locale-badges {
padding-right: 20px;
padding-top: 10px;
}

/* === LAYOUT === */

#breadcrumbs {
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,19 @@ def i18n_reply
select.html_safe
end

def i18n_icons(object)
output = '<div class="locale-badges pull-right hidden-xs hidden-sm">'
I18n.available_locales.each do |locale|
I18n.with_locale(locale) do
if object.translations.where(locale: locale).count > 0
output += "<span class='badge' title='#{I18n.t(:language_name)}'>#{locale.upcase}</span></a>"
else
output += "<span class='badge badge-light' title='#{I18n.t(:language_name)}'>#{locale.upcase}</span></a>"
end
end
end
output += '</div>'
output.html_safe
end

end
10 changes: 8 additions & 2 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ class Category < ActiveRecord::Base
scope :ranked, -> { order('rank ASC') }
scope :featured, -> {where(front_page: true) }

validates_presence_of :name
validates_uniqueness_of :name


def to_param
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}" unless name.nil?
end

validates_presence_of :name
validates_uniqueness_of :name
def read_translated_attribute(name)
globalize.stash.contains?(Globalize.locale, name) ? globalize.stash.read(Globalize.locale, name) : translation_for(Globalize.locale).send(name)
end


end
4 changes: 4 additions & 0 deletions app/models/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def to_param
"#{id}-#{title.gsub(/[^a-z0-9]+/i, '-')}"
end

def read_translated_attribute(name)
globalize.stash.contains?(Globalize.locale, name) ? globalize.stash.read(Globalize.locale, name) : translation_for(Globalize.locale).send(name)
end

def content
c = RDiscount.new(self.body)
return c.to_html
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/_cat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class="more-important">
<%= link_to cat.name, admin_articles_path(cat.id) %>
</span><span class="label label-count pull-right"><%= cat.docs.count %></span>

<%= i18n_icons(cat) if I18n.available_locales.count > 1 %>&nbsp;&nbsp;
<br/>
<%= cat.meta_description %>
</td>
Expand Down
5 changes: 3 additions & 2 deletions app/views/admin/articles.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<div class="row">
<div class="col-md-12">
<table id="forums">
<col width="85%">
<col width="15%">
<col>
<col width="5%">
<% @docs.each do |doc| %>
<tr id="doc-<%= doc.id %>">
<td>
<span class="more-important"><%= link_to doc.title, edit_category_doc_path(doc.category.id, doc.id, lang: I18n.locale) %> <%= " - #{I18n.t('featured_content', default: 'Featured')}" if doc.front_page == true %> <%= " - #{I18n.t('draft_content', default: 'Draft')}" if doc.active == false %></span>
<%= i18n_icons(doc) if I18n.available_locales.count > 1 %>
<br/>
<span class="less-important"><%= I18n.t('written_on', date_written: doc.created_at.strftime("%m/%d/%Y"), default: 'Written on') %> <%= doc.updated_at == doc.created_at ? "" : " | #{I18n.t("content_last_updated", date_updated: doc.updated_at.strftime("%m/%d/%Y"))}" %></span>
</td>
Expand Down
8 changes: 4 additions & 4 deletions app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= f.text_field :name, :label => I18n.translate("activerecord.attributes.category.name", locale: I18n.locale) %>
<%= f.text_field :name, label: I18n.translate("activerecord.attributes.category.name", locale: I18n.locale), value: @category.read_translated_attribute(:name) %>
<%= f.text_field :icon, class: 'icon-picker no-translate', placeholder: t(:select_icon_helptext, default: 'Select an icon to associate with this category (optional)'), :label => I18n.translate("activerecord.attributes.category.icon", locale: I18n.locale) %>
<%#= f.text_field :section %>
<%= f.text_field :keywords, :label => I18n.translate("activerecord.attributes.category.keywords", locale: I18n.locale) %>
<%= f.text_field :title_tag, :label => I18n.translate("activerecord.attributes.category.title_tag", locale: I18n.locale) %>
<%= f.text_field :meta_description, :label => I18n.translate("activerecord.attributes.category.meta_description", locale: I18n.locale) %>
<%= f.text_field :keywords, label: I18n.translate("activerecord.attributes.category.keywords", locale: I18n.locale), value: @category.read_translated_attribute(:keywords) %>
<%= f.text_field :title_tag, label: I18n.translate("activerecord.attributes.category.title_tag", locale: I18n.locale), value: @category.read_translated_attribute(:title_tag) %>
<%= f.text_field :meta_description, label: I18n.translate("activerecord.attributes.category.meta_description", locale: I18n.locale), value: @category.read_translated_attribute(:meta_description) %>
<% if params[:lang] == "#{I18n.locale}" %>
<%= f.check_box :front_page, class: 'no-translate', :label => I18n.translate("activerecord.attributes.category.front_page", locale: I18n.locale) %>
<%= f.check_box :active, class: 'no-translate', :label => I18n.translate("activerecord.attributes.category.active", locale: I18n.locale) %>
Expand Down
16 changes: 10 additions & 6 deletions app/views/docs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<%= f.text_field :title, :label => I18n.translate("activerecord.attributes.doc.title", locale: I18n.locale) %>
<%= f.text_field :title, label: I18n.translate("activerecord.attributes.doc.title", locale: I18n.locale), value: @doc.read_translated_attribute(:title) %>
<% if params[:lang] == "#{I18n.locale}" %>
<%= f.select("category_id", Category.all.collect {|c| [ c.name, c.id ] }, { include_blank: t(:select_category, default: 'Select Category'), :label => I18n.translate("activerecord.attributes.doc.category_id", locale: I18n.locale) }, { class: 'no-translate' }) %>
<% else %>
<%= f.hidden_field("category_id", value: @doc.category_id) %>
<% end %>
<%#= render 'admin/quill_editor' #uncomment this line if you prefer to use the quill editor %>
<%#= f.hidden_field :body #uncomment this line if you prefer to use the quill editor %>
<%= f.trix_editor :body %>
<%= f.trix_editor :body, value: @doc.read_translated_attribute(:body) %>
<% unless params[:lang] == "#{I18n.locale}" || @doc.translations.where(locale: locale).count > 0 %>
<script>
$('trix-editor').find('div').html('')
</script>
<% end %>
</body>
<hr/>
<% unless Cloudinary.config.cloud_name.nil? %>
<div class="doc-form-files">
<h4 class="form-subhead">Upload Images:</h4>
<%#= attachinary_file_field_tag 'doc[screenshots]', @doc, :screenshots %>
<%= cl_image_upload_tag(:image_id) %>
</div>
<% end %>
<hr/>
<h4 class="form-subhead">Additional Settings:</h4>
<%= f.text_field :meta_description, :label => I18n.translate("activerecord.attributes.doc.meta_description", locale: I18n.locale) %>
<%= f.text_field :title_tag, :label => I18n.translate("activerecord.attributes.doc.title_tag", locale: I18n.locale) %>
<%= f.text_field :keywords, :label => I18n.translate("activerecord.attributes.doc.keywords", locale: I18n.locale) %>
<%= f.text_field :meta_description, label: I18n.translate("activerecord.attributes.doc.meta_description", locale: I18n.locale), value: @doc.read_translated_attribute(:meta_description) %>
<%= f.text_field :title_tag, label: I18n.translate("activerecord.attributes.doc.title_tag", locale: I18n.locale), value: @doc.read_translated_attribute(:title_tag) %>
<%= f.text_field :keywords, label: I18n.translate("activerecord.attributes.doc.keywords", locale: I18n.locale), value: @doc.read_translated_attribute(:keywords) %>

<%#= f.text_field :rank %>
<%= f.check_box(:front_page, class:'no-translate', inline: true, :label => I18n.translate("activerecord.attributes.doc.front_page", locale: I18n.locale)) if params[:lang] == "#{I18n.locale}" %><br/><br/>
Expand Down

0 comments on commit f3c91a5

Please sign in to comment.