Class: Bhf::Platform
- Inherits:
-
Object
- Object
- Bhf::Platform
- Defined in:
- lib/bhf/platform.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#page_name ⇒ Object
readonly
Returns the value of attribute page_name.
-
#pagination ⇒ Object
Returns the value of attribute pagination.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#title_singular ⇒ Object
readonly
Returns the value of attribute title_singular.
-
#title_zero ⇒ Object
readonly
Returns the value of attribute title_zero.
Instance Method Summary collapse
- #columns ⇒ Object
- #columns_count ⇒ Object
- #custom_columns? ⇒ Boolean
- #custom_link ⇒ Object
- #custom_partial ⇒ Object
- #custom_search ⇒ Object
- #definitions ⇒ Object
- #entries_per_page ⇒ Object
- #fields ⇒ Object
- #form ⇒ Object
- #has_file_upload? ⇒ Boolean
- #hide_create ⇒ Object
- #hide_delete ⇒ Object
- #hide_edit ⇒ Object
- #hooks(method) ⇒ Object
-
#initialize(options, page_name, user = nil) ⇒ Platform
constructor
A new instance of Platform.
- #model ⇒ Object
- #model_name ⇒ Object
- #prepare_objects(options, paginate_options = nil) ⇒ Object
- #return_to ⇒ Object
- #search? ⇒ Boolean
- #search_field? ⇒ Boolean
- #show ⇒ Object
- #show_duplicate ⇒ Object
- #show_extra_fields ⇒ Object
- #sortable ⇒ Object
- #sortable_property ⇒ Object
- #table ⇒ Object
- #table_hide? ⇒ Boolean
- #user_scope? ⇒ Boolean
Constructor Details
#initialize(options, page_name, user = nil) ⇒ Platform
Returns a new instance of Platform.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bhf/platform.rb', line 7 def initialize(, page_name, user = nil) @objects = [] if .is_a?(String) = { => nil} end @name = .keys[0] @data = .values[0] || {} @collection = get_collection t_model_path = "activerecord.models.#{model.model_name.to_s.downcase}" model_name = I18n.t(t_model_path, count: 2, default: @name.pluralize.capitalize) @title = I18n.t("bhf.platforms.#{@name}.title", count: 2, default: model_name) model_name = I18n.t(t_model_path, count: 1, default: @name.singularize.capitalize) @title_singular = I18n.t("bhf.platforms.#{@name}.title", count: 1, default: model_name) model_name = I18n.t(t_model_path, count: 0, default: @name.singularize.capitalize) @title_zero = I18n.t("bhf.platforms.#{@name}.title", count: 0, default: model_name) @model = model @page_name = page_name @user = user end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def name @name end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def objects @objects end |
#page_name ⇒ Object (readonly)
Returns the value of attribute page_name.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def page_name @page_name end |
#pagination ⇒ Object
Returns the value of attribute pagination.
4 5 6 |
# File 'lib/bhf/platform.rb', line 4 def pagination @pagination end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title @title end |
#title_singular ⇒ Object (readonly)
Returns the value of attribute title_singular.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title_singular @title_singular end |
#title_zero ⇒ Object (readonly)
Returns the value of attribute title_zero.
5 6 7 |
# File 'lib/bhf/platform.rb', line 5 def title_zero @title_zero end |
Instance Method Details
#columns ⇒ Object
94 95 96 97 98 99 |
# File 'lib/bhf/platform.rb', line 94 def columns default_attrs((:display) || (:columns), @collection[0..5]). each_with_object([]) do |field, obj| obj << Bhf::Data::Column.new(field) end end |
#columns_count ⇒ Object
143 144 145 |
# File 'lib/bhf/platform.rb', line 143 def columns_count columns.count + (sortable ? 2 : 1) end |
#custom_columns? ⇒ Boolean
46 47 48 |
# File 'lib/bhf/platform.rb', line 46 def custom_columns? (:columns).is_a?(Array) end |
#custom_link ⇒ Object
171 172 173 |
# File 'lib/bhf/platform.rb', line 171 def custom_link 'custom_link' end |
#custom_partial ⇒ Object
175 176 177 |
# File 'lib/bhf/platform.rb', line 175 def custom_partial 'partial' end |
#custom_search ⇒ Object
42 43 44 |
# File 'lib/bhf/platform.rb', line 42 def custom_search (:custom_search) end |
#definitions ⇒ Object
101 102 103 104 105 106 |
# File 'lib/bhf/platform.rb', line 101 def definitions default_attrs((:display) || (:definitions), @collection, false). each_with_object([]) do |field, obj| obj << Bhf::Data::Show.new(field) end end |
#entries_per_page ⇒ Object
112 113 114 |
# File 'lib/bhf/platform.rb', line 112 def entries_per_page (:per_page) end |
#fields ⇒ Object
90 91 92 |
# File 'lib/bhf/platform.rb', line 90 def fields default_attrs((:display), @collection, false) end |
#form ⇒ Object
133 134 135 |
# File 'lib/bhf/platform.rb', line 133 def form @data['form'] end |
#has_file_upload? ⇒ Boolean
116 117 118 119 120 121 122 123 |
# File 'lib/bhf/platform.rb', line 116 def has_file_upload? return true if (:multipart) == true fields.each do |field| return true if field.form_type.to_sym == :file end false end |
#hide_create ⇒ Object
159 160 161 |
# File 'lib/bhf/platform.rb', line 159 def hide_create ('hide_create') || ('hide_new') end |
#hide_delete ⇒ Object
167 168 169 |
# File 'lib/bhf/platform.rb', line 167 def hide_delete 'hide_delete' end |
#hide_edit ⇒ Object
155 156 157 |
# File 'lib/bhf/platform.rb', line 155 def hide_edit 'hide_edit' end |
#hooks(method) ⇒ Object
137 138 139 140 141 |
# File 'lib/bhf/platform.rb', line 137 def hooks(method) if @data['hooks'] && @data['hooks'][method.to_s] @data['hooks'][method.to_s].to_sym end end |
#model ⇒ Object
80 81 82 83 84 |
# File 'lib/bhf/platform.rb', line 80 def model return @model if @model return @data['model'].constantize if @data['model'] @name.singularize.camelize.constantize end |
#model_name ⇒ Object
86 87 88 |
# File 'lib/bhf/platform.rb', line 86 def model_name ActiveModel::Naming.singular(model) end |
#prepare_objects(options, paginate_options = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bhf/platform.rb', line 54 def prepare_objects(, = nil) if user_scope? chain = @user.send((:user_scope).to_sym) else chain = model chain = chain.send data_source if data_source end unless [:order].blank? chain = chain.reorder("#{[:order]} #{[:direction]}") end if search? && [:search].present? chain = do_search(chain, [:search]) end if && !sortable chain = chain.page([:page]).per([:per_page]) elsif chain == model chain = chain.all end @objects = chain end |
#return_to ⇒ Object
179 180 181 |
# File 'lib/bhf/platform.rb', line 179 def return_to 'return_to' end |
#search? ⇒ Boolean
30 31 32 |
# File 'lib/bhf/platform.rb', line 30 def search? (:search) != false end |
#search_field? ⇒ Boolean
38 39 40 |
# File 'lib/bhf/platform.rb', line 38 def search_field? (:search_field) != false end |
#show ⇒ Object
129 130 131 |
# File 'lib/bhf/platform.rb', line 129 def show @data['show'] end |
#show_duplicate ⇒ Object
163 164 165 |
# File 'lib/bhf/platform.rb', line 163 def show_duplicate 'show_duplicate' end |
#show_extra_fields ⇒ Object
108 109 110 |
# File 'lib/bhf/platform.rb', line 108 def show_extra_fields (:extra_fields) end |
#sortable ⇒ Object
147 148 149 |
# File 'lib/bhf/platform.rb', line 147 def sortable 'sortable' end |
#sortable_property ⇒ Object
151 152 153 |
# File 'lib/bhf/platform.rb', line 151 def sortable_property 'sortable_property' end |
#table ⇒ Object
125 126 127 |
# File 'lib/bhf/platform.rb', line 125 def table @data['table'] end |
#table_hide? ⇒ Boolean
34 35 36 |
# File 'lib/bhf/platform.rb', line 34 def table_hide? (:hide) == true || model. end |
#user_scope? ⇒ Boolean
50 51 52 |
# File 'lib/bhf/platform.rb', line 50 def user_scope? @user && (:user_scope) end |