action_admin 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 982edc1021b2a77531f490363c7bd03ccd771dc6
4
- data.tar.gz: d31e4dd9c6d0a407a1484ca3fbc4e303f1ab5299
3
+ metadata.gz: e8c1c4bce91ccdc0e91b160a64bb2d33c4813b5a
4
+ data.tar.gz: b4a4abebea3d0b3db713543c4a80600849ffb163
5
5
  SHA512:
6
- metadata.gz: dbc141a4e4a8da89026d6d74f925a6408723cdbd7fb99aad16311e6c4d9e1741077170adebfe74b1eef46ac20f2060c0a31b0eeb4851559c5e151effd3683625
7
- data.tar.gz: 18fd1ac7ffa3a656ed76982930ca505222c24d5f0f6bd6dce7ca750ce7a830f5b7c8d790e698308514fdfe0131e8c5ba023c728db53db3c73b4bfa04113fb702
6
+ metadata.gz: a3d44fb6749ae4bc557f5d04d906427c5295073466633c6d8317bc67818d67d383943a57d66e4e4f7bd3e11a9340f3210a26bd4944538dad971cd7bbea73a55c
7
+ data.tar.gz: 1ab6296221e9377178c6fbf56f18cece1af8a5c9dc908140b75e83cf06bdd50537ec1a838e36b9fb8d640b3db3b951125ef4e9fb2ebd79ec7ad5da7d2256b1d4
@@ -68,3 +68,25 @@
68
68
  }
69
69
  }
70
70
  }
71
+
72
+
73
+ // Table elements
74
+
75
+ table {
76
+
77
+ .avatar:not(:only-child) {
78
+ margin-right: 5px;
79
+ }
80
+
81
+ .thumbnail {
82
+ margin: 0;
83
+ }
84
+
85
+ .label {
86
+ margin-right: 5px;
87
+
88
+ a {
89
+ color: inherit;
90
+ }
91
+ }
92
+ }
@@ -27,8 +27,8 @@ module ActionAdmin
27
27
  attribute_names.map { |i| @model.human_attribute_name(i) }
28
28
  end
29
29
 
30
- def render_attribute(name)
31
- @context.simple_attribute_for(@record, name, Hash(attributes[name]))
30
+ def render_attribute(name, options={})
31
+ @context.simple_attribute_for(@record, name, options)
32
32
  end
33
33
 
34
34
  def render_attributes(*args)
@@ -135,5 +135,32 @@ module ActionAdmin
135
135
  sorted_panels.select { |_i, o| o[:context] == context }
136
136
  end
137
137
  end
138
+
139
+ # def render_table(table)
140
+ # table = self.record_tables[table]
141
+ # end
142
+
143
+ def render_table_header(table)
144
+ table = self.record_tables[table]
145
+ cells = []
146
+
147
+ table.header.each do |_k, v|
148
+ cells << @context.content_tag(:th, v[:label], v[:html])
149
+ end
150
+
151
+ cells.join.html_safe
152
+ end
153
+
154
+ def render_table_columns(table)
155
+ table = self.record_tables[table]
156
+ cells = []
157
+
158
+ table.columns.each do |k, v|
159
+ options = v.fetch(:attribute, {})
160
+ cells << @context.content_tag(:td, render_attribute(k, options), v[:html])
161
+ end
162
+
163
+ cells.join.html_safe
164
+ end
138
165
  end
139
166
  end
@@ -6,10 +6,12 @@ module ActionAdmin
6
6
  class_attribute :record_attributes
7
7
  class_attribute :record_fields
8
8
  class_attribute :record_panels
9
+ class_attribute :record_tables
9
10
 
10
11
  self.record_attributes = {}
11
12
  self.record_fields = {}
12
13
  self.record_panels = {}
14
+ self.record_tables = {}
13
15
  end
14
16
 
15
17
  class_methods do
@@ -24,6 +26,15 @@ module ActionAdmin
24
26
  def panel(name, options={})
25
27
  self.record_panels = self.record_panels.merge(name => options)
26
28
  end
29
+
30
+ def table(name, options={}, &block)
31
+ new_table = ActionAdmin::Table.new(name, options)
32
+ new_table.merge(self.record_tables[name])
33
+
34
+ yield new_table if block_given?
35
+
36
+ self.record_tables = self.record_tables.merge(name => new_table)
37
+ end
27
38
  end
28
39
  end
29
40
  end
@@ -10,13 +10,13 @@
10
10
  table.unstriped.margin-0
11
11
  thead
12
12
  tr
13
- = admin_present(current_model).render_attributes_labels(:th)
14
- th = 'Actions'
13
+ = admin_present(current_model).render_table_header(:index)
14
+ th.shrink.actions.text-right = 'Actions'
15
15
 
16
16
  tbody
17
17
  - admin_present_many(current_records).each do |record|
18
18
  tr
19
- = record.render_attributes(:td, class: 'expand')
19
+ = record.render_table_columns(:index)
20
20
  = record.action_links(:td, class: 'shrink actions')
21
21
 
22
22
  - if current_records.respond_to? :current_page
@@ -0,0 +1,24 @@
1
+ SimpleAttribute.setup do |config|
2
+ config.avatar = { html: { class: 'rounded bordered' } }
3
+ config.image = { html: { class: 'thumbnail' }, default_value: 'upload-preview.svg' }
4
+ config.boolean = { true: 'success', false: 'alert', wrapper: { class: 'label' } }
5
+ config.wrappers = { badge: { class: 'badge' } }
6
+
7
+ config.wrappers do |wrapper|
8
+ wrapper.label_default = { class: 'label default' }
9
+ wrapper.label_primary = { class: 'label primary' }
10
+ wrapper.label_secondary = { class: 'label secondary' }
11
+ wrapper.label_info = { class: 'label info' }
12
+ wrapper.label_success = { class: 'label success' }
13
+ wrapper.label_warning = { class: 'label warning' }
14
+ wrapper.label_alert = { class: 'label alert' }
15
+
16
+ wrapper.badge_default = { class: 'badge default' }
17
+ wrapper.badge_primary = { class: 'badge primary' }
18
+ wrapper.badge_secondary = { class: 'badge secondary' }
19
+ wrapper.badge_info = { class: 'badge info' }
20
+ wrapper.badge_success = { class: 'badge success' }
21
+ wrapper.badge_warning = { class: 'badge warning' }
22
+ wrapper.badge_alert = { class: 'badge alert' }
23
+ end
24
+ end
@@ -15,6 +15,7 @@ module ActionAdmin
15
15
  autoload :Config
16
16
  autoload :Form
17
17
  autoload :Header
18
+ autoload :Table
18
19
 
19
20
  # Set attr accessors
20
21
  mattr_accessor :config
@@ -42,10 +42,13 @@ module ActionAdmin
42
42
  end
43
43
 
44
44
  def default_title(context)
45
+ singular = context.controller.try(:instance_name)
46
+ plural = context.controller.try(:collection_name)
47
+
45
48
  if context.action_name == 'index'
46
- context.controller_name.titleize
49
+ "#{plural || context.controller_name}".strip.titleize
47
50
  else
48
- context.action_name.titleize
51
+ "#{context.action_name} #{singular}".strip.titleize
49
52
  end
50
53
  end
51
54
 
@@ -0,0 +1,37 @@
1
+ module ActionAdmin
2
+ class Table
3
+ class_attribute :name
4
+ class_attribute :options
5
+ class_attribute :columns
6
+ class_attribute :header
7
+
8
+ def initialize(name, options)
9
+ self.name = name
10
+ self.options = options
11
+ self.columns = {}
12
+ self.header = {}
13
+ end
14
+
15
+ def column(name, options={})
16
+ self.columns = self.columns.merge(name => options)
17
+ self.header = self.header.merge(name => set_column_header(name, options))
18
+ end
19
+
20
+ def merge(table)
21
+ if table.is_a? ActionAdmin::Table
22
+ self.options = table.options.deep_merge(self.options)
23
+ self.columns = table.columns.merge(self.columns)
24
+ self.header = table.header.merge(self.header)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def set_column_header(name, options={})
31
+ label = options.fetch(:label, name.to_s.titleize)
32
+ html = options.fetch(:html, {})
33
+
34
+ { label: label, html: html }
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module ActionAdmin
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-18 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -242,6 +242,7 @@ files:
242
242
  - app/views/layouts/admin.html.slim
243
243
  - app/views/layouts/admin/devise.html.slim
244
244
  - config/initializers/admin_simple_form.rb
245
+ - config/initializers/simple_attribute.rb
245
246
  - config/routes.rb
246
247
  - lib/action_admin.rb
247
248
  - lib/action_admin/config.rb
@@ -252,6 +253,7 @@ files:
252
253
  - lib/action_admin/form/minimal_builder.rb
253
254
  - lib/action_admin/header.rb
254
255
  - lib/action_admin/routes.rb
256
+ - lib/action_admin/table.rb
255
257
  - lib/action_admin/version.rb
256
258
  - lib/tasks/action_admin_tasks.rake
257
259
  homepage: https://github.com/hardpixel/action-admin
@@ -274,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
276
  version: '0'
275
277
  requirements: []
276
278
  rubyforge_project:
277
- rubygems_version: 2.6.13
279
+ rubygems_version: 2.6.14
278
280
  signing_key:
279
281
  specification_version: 4
280
282
  summary: Ruby on Rails mountable engine to create admin interfaces