app/admin/c80_estate/areas.rb in c80_estate-0.1.0.33 vs app/admin/c80_estate/areas.rb in c80_estate-0.1.0.34
- old
+ new
@@ -44,10 +44,33 @@
redirect_to collection_path, notice: [ids, inputs].to_s
end
config.clear_action_items!
+ controller do
+
+ def scoped_collection
+
+ # [X] 1. оптимизируем выдачу на index, согласно
+ # http://activeadmin.info/docs/2-resource-customization.html#customizing-resource-retrieval
+ # https://github.com/activeadmin/activeadmin/commit/f8ef8ca7f9ce6dc70a4761d6269477f0dff448ec
+ # http://www.rubydoc.info/gems/activeadmin/file/docs/2-resource-customization.md
+
+ # [ ]2. решаем задачу с "чужими незанятыми" и "чужими занятыми".
+ # * http://stackoverflow.com/a/23788089
+ # способ реализации с дописанным кастомным where
+ # super.where(account_id: account.id).order(:date_sent)
+
+ # включаем atypes и properties.logos: http://stackoverflow.com/a/24397716
+ C80Estate::Area
+ .includes(:astatuses, :atype, property: :plogos) ##[1]
+ .all_except_busy_alien(current_admin_user)
+
+ end
+
+ end
+
action_item :new_model, :only => :index do
if current_admin_user.can_create_areas?
link_to I18n.t("active_admin.new_model"), '/admin/areas/new', method: :get
end
end
@@ -70,10 +93,12 @@
end
end
config.sort_order = 'id_asc'
+ # before_filter :skip_sidebar!, :only => :index
+
filter :atype_id,
:label => 'Тип площади',
:as => :select,
:collection => -> { C80Estate::Atype.all.map { |p| ["#{p.title}", p.id] } },
:input_html => {:class => 'selectpicker', 'data-size' => "10", 'data-width' => '100%'}
@@ -139,18 +164,19 @@
filter :updated_at
scope "All", :all_areas
scope "Free", :free_areas
scope "Busy", :busy_areas
+ # scope 'My', :my_areas
index do
- selectable_column
+ # selectable_column
column :title do |area|
link_to area.title, "/admin/areas/#{area.id}", title: I18n.t("active_admin.view")
end
column :atype do |area|
- area.atype_title
+ area.atype.title
end
column '<abbr title="За м.кв. в месяц">Цена м.кв.</abbr>'.html_safe do |area|
"#{area.price_value.to_s(:rounded, :precision => 2)} руб"
end
column '<abbr title="Стоимость всей площади в месяц. Число PxS, где P - цена за м.кв. в месяц, S - метраж площади в м.кв.">Цена площади</abbr>'.html_safe do |area|
@@ -166,22 +192,17 @@
"#{area.square_value.to_s(:rounded, :precision => 2)} м<sup>2</sup>".html_safe
end
column :property do |area|
"<div class='image_vertical properties_index_logo'>
<span></span><a href='/admin/areas?utf8=✓&q%5Bproperty_id_eq%5D=#{area.property.id}&commit=Фильтровать&order=id_asc'><img src='#{image_path(area.property.logo_path)}'>
- </div><span class='properties_index_logo_title'>#{area.property_title}</span></a>".html_safe
-
+ </div><span class='properties_index_logo_title'>#{area.property.title}</span></a>".html_safe
end
column :astatuses do |area|
"<span class='status_#{area.astatus_tag}'>#{area.astatus_title}</span>".html_safe
end
column :assigned_person do |area|
area.property.assigned_person_title
end
- # actions
- # column '' do |area|
- # link_to I18n.t("active_admin.view"), "/admin/areas/#{area.id}", class: 'member_link'
- # end
column '' do |area|
if current_admin_user.can_edit_area?(area)
link_to I18n.t("active_admin.edit"), "/admin/areas/#{area.id}/edit", class: 'member_link'
end
end
\ No newline at end of file