Skip to content

Commit

Permalink
fix: resource index displays the correct name (#484)
Browse files Browse the repository at this point in the history
* fix: resource index displays the correct name

* fix: uppercased label
  • Loading branch information
adrianthedev committed Jul 29, 2021
1 parent b8fc392 commit 7d2f164
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/components/avo/index/resource_controls_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def edit_path

def singular_resource_name
if @reflection.present?
@reflection.name.to_s.downcase.singularize
::Avo::App.get_resource_by_model_name(@reflection.class_name).name
else
@resource.singular_name.present? ? @resource.singular_name : @resource.model_class.model_name.name.downcase
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/views/resource_index_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% if can_create? %>
<%= a_link create_path do %>
<%= svg 'plus' %> <%= t('avo.create_new_item', item: @resource.model_class.model_name.human.downcase ) %>
<%= svg 'plus' %> <%= t('avo.create_new_item', item: singular_resource_name.downcase ) %>
<% end %>
<% end %>
Expand Down
14 changes: 6 additions & 8 deletions app/components/avo/views/resource_index_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize(

def title
if @reflection.present?
@reflection.plural_name.capitalize
::Avo::App.get_resource_by_model_name(@reflection.class_name).plural_name
else
@resource.plural_name
end
Expand All @@ -52,11 +52,11 @@ def can_attach?
klass = @reflection
klass = @reflection.through_reflection if klass.is_a? ::ActiveRecord::Reflection::ThroughReflection

@reflection.present? && klass.is_a?(::ActiveRecord::Reflection::HasManyReflection) && !has_reflection_and_is_read_only && authorize_association_for('attach')
@reflection.present? && klass.is_a?(::ActiveRecord::Reflection::HasManyReflection) && !has_reflection_and_is_read_only && authorize_association_for("attach")
end

def can_detach?
@reflection.present? && @reflection.is_a?(::ActiveRecord::Reflection::HasOneReflection) && @models.present? && !has_reflection_and_is_read_only && authorize_association_for('detach')
@reflection.present? && @reflection.is_a?(::ActiveRecord::Reflection::HasOneReflection) && @models.present? && !has_reflection_and_is_read_only && authorize_association_for("detach")
end

def has_reflection_and_is_read_only
Expand All @@ -68,12 +68,10 @@ def has_reflection_and_is_read_only
end

if filtered_fields.present?
is_field_read_only = filtered_fields.filter{ |f| f.id == @reflection.name}[0].readonly
filtered_fields.find { |f| f.id == @reflection.name }.readonly
else
is_field_read_only = false
false
end

is_field_read_only
end

def create_path
Expand Down Expand Up @@ -103,7 +101,7 @@ def detach_path

def singular_resource_name
if @reflection.present?
@reflection.name.to_s.downcase.singularize
::Avo::App.get_resource_by_model_name(@reflection.class_name).name
else
@resource.singular_name.present? ? @resource.singular_name : @resource.model_class.model_name.name.downcase
end
Expand Down
1 change: 0 additions & 1 deletion app/components/avo/views/resource_show_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<% if resource_panel[:name] == @resource.default_panel_name %>
<%= render 'actions' %>
<% if @reflection.present? && @resource.model.present? %>
<% if can_detach? %>
<%= a_link detach_path, color: 'indigo', method: :delete, data: { confirm: "Are you sure you want to detach this #{@reflection.name.to_s}." } do %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Avo::Engine.routes.draw do
root "home#index"

get "resources", to: redirect("/avo")
get "resources", to: redirect("/admin")

scope "avo_api", as: "avo_api" do
get "/search", to: "search#index"
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def model_title
def name
return @name if @name.present?

return I18n.t(@translation_key, count: 1).capitalize if @translation_key
return I18n.t(self.class.translation_key, count: 1).capitalize if self.class.translation_key

self.class.name.demodulize.chomp("Resource").titlecase
end
Expand All @@ -218,7 +218,7 @@ def singular_name
end

def plural_name
return I18n.t(@translation_key, count: 2).capitalize if @translation_key
return I18n.t(self.class.translation_key, count: 2).capitalize if self.class.translation_key

name.pluralize
end
Expand Down

0 comments on commit 7d2f164

Please sign in to comment.