action_admin 0.1.0 → 0.1.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/{admin/admin.js → action_admin/action-admin.js} +1 -0
  3. data/app/assets/javascripts/admin/application.js +1 -1
  4. data/app/assets/stylesheets/action_admin/action-admin.scss +12 -0
  5. data/app/assets/stylesheets/action_admin/action-admin/tinymce.scss +6 -0
  6. data/app/assets/stylesheets/admin/application.scss +1 -1
  7. data/app/assets/stylesheets/admin/tinymce-editor.scss +1 -0
  8. data/app/controllers/action_admin/devise/confirmations_controller.rb +10 -0
  9. data/app/controllers/action_admin/devise/omniauth_callbacks_controller.rb +7 -0
  10. data/app/controllers/action_admin/devise/passwords_controller.rb +10 -0
  11. data/app/controllers/action_admin/devise/registrations_controller.rb +10 -0
  12. data/app/controllers/action_admin/devise/sessions_controller.rb +9 -0
  13. data/app/controllers/action_admin/devise/unlocks_controller.rb +10 -0
  14. data/{lib → app/controllers/concerns}/action_admin/actionable.rb +1 -0
  15. data/{lib → app/controllers/concerns}/action_admin/controller.rb +0 -0
  16. data/{lib → app/controllers/concerns}/action_admin/crudable.rb +0 -0
  17. data/app/helpers/action_admin/admin_helper.rb +19 -3
  18. data/app/helpers/action_admin/form_helper.rb +4 -4
  19. data/app/helpers/action_admin/markup_helper.rb +6 -3
  20. data/app/inputs/action_admin/attachment_input.rb +51 -0
  21. data/app/inputs/action_admin/select_list_input.rb +14 -0
  22. data/app/inputs/action_admin/slug_input.rb +63 -0
  23. data/app/inputs/action_admin/tag_list_input.rb +10 -0
  24. data/app/inputs/action_admin/tinymce_input.rb +9 -0
  25. data/app/inputs/action_admin/title_input.rb +16 -0
  26. data/app/presenters/action_admin/presenter.rb +126 -0
  27. data/app/presenters/concerns/action_admin/presentable.rb +29 -0
  28. data/app/views/action_admin/devise/confirmations/new.html.slim +14 -0
  29. data/app/views/action_admin/devise/passwords/edit.html.slim +20 -0
  30. data/app/views/action_admin/devise/passwords/new.html.slim +13 -0
  31. data/app/views/action_admin/devise/registrations/edit.html.slim +22 -0
  32. data/app/views/action_admin/devise/registrations/new.html.slim +19 -0
  33. data/app/views/action_admin/devise/sessions/new.html.slim +14 -0
  34. data/app/views/action_admin/devise/shared/_links.html.slim +19 -0
  35. data/app/views/action_admin/devise/unlocks/new.html.slim +14 -0
  36. data/app/views/admin/common/_alerts.html.slim +17 -0
  37. data/app/views/admin/common/_header.html.slim +2 -0
  38. data/app/views/admin/panels/_default.html.slim +11 -0
  39. data/app/views/admin/panels/_expanded.html.slim +11 -0
  40. data/app/views/admin/panels/_group.html.slim +1 -0
  41. data/app/views/admin/panels/_plain.html.slim +1 -0
  42. data/app/views/admin/records/_form.html.slim +34 -24
  43. data/app/views/admin/records/index.html.slim +9 -19
  44. data/app/views/layouts/admin.html.slim +0 -2
  45. data/app/views/layouts/admin/devise.html.slim +16 -0
  46. data/lib/action_admin.rb +2 -4
  47. data/lib/action_admin/config.rb +2 -1
  48. data/lib/action_admin/engine.rb +7 -1
  49. data/lib/action_admin/{simple_form.rb → form.rb} +3 -3
  50. data/lib/action_admin/{simple_form/form_builder.rb → form/builder.rb} +14 -3
  51. data/lib/action_admin/{simple_form → form}/error_notification.rb +1 -1
  52. data/lib/action_admin/form/minimal_builder.rb +19 -0
  53. data/lib/action_admin/routes.rb +19 -0
  54. data/lib/action_admin/version.rb +1 -1
  55. metadata +42 -11
  56. data/app/assets/stylesheets/admin/admin.scss +0 -2
  57. data/lib/action_admin/simple_form/minimal_form_builder.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c44353e5b5e06876da3b17b14b94496deefefe8a
4
- data.tar.gz: eb1c8aadd4b44d7df9238dead846f7b1879d856d
3
+ metadata.gz: 8f5a65a3d49134131805423322fd40c7b66b7520
4
+ data.tar.gz: 6bbba84f33f86e1dfa1d4be12e663746b6ef95b2
5
5
  SHA512:
6
- metadata.gz: 2d044084dce29f51d7c387556fce4526918ec7f4a36a2023a98f84ffe5372cde307d85a849e4f1a57384e0832bd214d076d7ec7c29d7ca72b763aceef853ef93
7
- data.tar.gz: 351f37c12c9feba3d42a329c9a75c4cde3482dccf8682d1a5c80312851840c4bbc648a45c2078f08ef6d598c4c2e8feaf64bf19ac881239c06dec254f7070ff2
6
+ metadata.gz: fa326acf06c41b654146b5ff48c61d332c2dbda5a42e3273301c2244ca8a48cfec4f557d4459e90aa430bbc8cc922e7813eb2d1332fa361bd3a47357be61b254
7
+ data.tar.gz: ad25a999ffbd4129fda022e04b69f47c98ccce3b6153b5d233ce29804fc484da6d9ebb04b063ab6b5fb22d95d2fcde49209f91f41492d39009e0c3d3c9ed4a7a
@@ -11,4 +11,5 @@
11
11
  // about supported directives.
12
12
  //
13
13
  //= require rails-ujs
14
+ //= require tinymce
14
15
  //= require bedrock
@@ -10,4 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require admin
13
+ //= require action-admin
@@ -0,0 +1,12 @@
1
+ @import "foundation-components";
2
+ @import "bedrock-components";
3
+
4
+ .panel {
5
+
6
+ .input:last-child {
7
+
8
+ input, textarea, select, .select2 {
9
+ margin-bottom: 0;
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ @import 'foundation';
2
+
3
+ @include foundation-global-styles;
4
+ @include foundation-typography;
5
+ @include foundation-button;
6
+ @include foundation-forms;
@@ -1 +1 @@
1
- @import "admin";
1
+ @import "action-admin";
@@ -0,0 +1 @@
1
+ @import "action-admin/tinymce";
@@ -0,0 +1,10 @@
1
+ module ActionAdmin
2
+ class Devise::ConfirmationsController < ::Devise::ConfirmationsController
3
+ include ActionAdmin::Actionable
4
+
5
+ action_title :new, 'Confirm Account'
6
+ action_title :show, 'Confirmed Account'
7
+
8
+ layout 'admin/devise'
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module ActionAdmin
2
+ class Devise::OmniauthCallbacksController < ::Devise::OmniauthCallbacksController
3
+ include ActionAdmin::Actionable
4
+
5
+ layout 'admin/devise'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module ActionAdmin
2
+ class Devise::PasswordsController < ::Devise::PasswordsController
3
+ include ActionAdmin::Actionable
4
+
5
+ action_title :new, 'Forgot Password'
6
+ action_title :edit, 'Reset Password'
7
+
8
+ layout 'admin/devise'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ActionAdmin
2
+ class Devise::RegistrationsController < ::Devise::RegistrationsController
3
+ include ActionAdmin::Actionable
4
+
5
+ action_title :new, 'Register'
6
+ action_title :edit, 'Edit Profile'
7
+
8
+ layout -> { action_name == 'edit' ? 'admin' : 'admin/devise' }
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module ActionAdmin
2
+ class Devise::SessionsController < ::Devise::SessionsController
3
+ include ActionAdmin::Actionable
4
+
5
+ action_title :new, 'Login'
6
+
7
+ layout 'admin/devise'
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module ActionAdmin
2
+ class Devise::UnlocksController < ::Devise::UnlocksController
3
+ include ActionAdmin::Actionable
4
+
5
+ action_title :new, 'Unlock Instructions'
6
+ action_title :show, 'Unlock Account'
7
+
8
+ layout 'admin/devise'
9
+ end
10
+ end
@@ -13,6 +13,7 @@ module ActionAdmin
13
13
  def action_title(action, title)
14
14
  self.action_header.action(action)
15
15
  self.action_header.title(title)
16
+ self.action_header.action(nil)
16
17
  end
17
18
 
18
19
  def header(action, &block)
@@ -5,8 +5,10 @@ module ActionAdmin
5
5
  end
6
6
 
7
7
  def admin_action_title(action=nil)
8
- name = action || action_name
9
- controller.action_header.action_title(name, self)
8
+ if controller.respond_to? :action_header
9
+ name = action || action_name
10
+ controller.action_header.action_title(name, self)
11
+ end
10
12
  end
11
13
 
12
14
  def admin_meta_tags
@@ -16,11 +18,25 @@ module ActionAdmin
16
18
  nofollow: true,
17
19
  reverse: true,
18
20
  title: admin_action_title || "#{action_name}".titleize,
19
- charset: 'utf-8'
21
+ charset: 'utf-8',
22
+ viewport: 'width=device-width, initial-scale=1.0'
20
23
  }
21
24
 
22
25
  set_meta_tags tags
23
26
  display_meta_tags
24
27
  end
28
+
29
+ def admin_present(record, presenter=nil)
30
+ record = record.new if record.respond_to? :new
31
+ class_name = record.class.name
32
+ presenter = presenter || "Admin::#{class_name}Presenter"
33
+ presenter = "#{presenter}".safe_constantize || 'ActionAdmin::Presenter'.constantize
34
+
35
+ presenter.new(record, self)
36
+ end
37
+
38
+ def admin_present_many(records, presenter=nil)
39
+ records.to_a.map { |r| admin_present(r, presenter) }
40
+ end
25
41
  end
26
42
  end
@@ -3,7 +3,7 @@ module ActionAdmin
3
3
  # Admin simple form
4
4
  def admin_form_for(object, *args, &block)
5
5
  options = args.extract_options!
6
- builder = { builder: ActionAdmin::SimpleForm::FormBuilder }
6
+ builder = { builder: ActionAdmin::Form::Builder }
7
7
  options = options.merge(builder) unless options[:builder]
8
8
 
9
9
  simple_form_for(object, *(args << options), &block)
@@ -12,7 +12,7 @@ module ActionAdmin
12
12
  # Admin simple form fields
13
13
  def admin_fields_for(*args, &block)
14
14
  options = args.extract_options!
15
- builder = { builder: ActionAdmin::SimpleForm::FormBuilder }
15
+ builder = { builder: ActionAdmin::Form::Builder }
16
16
  options = options.merge(builder) unless options[:builder]
17
17
 
18
18
  simple_form_for(*(args << options), &block)
@@ -21,7 +21,7 @@ module ActionAdmin
21
21
  # Admin simple form with placeholders
22
22
  def admin_minimal_form_for(object, *args, &block)
23
23
  options = args.extract_options!
24
- options = options.merge(builder: ActionAdmin::SimpleForm::MinimalFormBuilder)
24
+ options = options.merge(builder: ActionAdmin::Form::MinimalBuilder)
25
25
 
26
26
  admin_form_for(object, *(args << options), &block)
27
27
  end
@@ -29,7 +29,7 @@ module ActionAdmin
29
29
  # Admin simple form fields with placeholders
30
30
  def admin_minimal_fields_for(*args, &block)
31
31
  options = args.extract_options!
32
- options = options.merge(builder: ActionAdmin::SimpleForm::MinimalFormBuilder)
32
+ options = options.merge(builder: ActionAdmin::Form::MinimalBuilder)
33
33
 
34
34
  admin_fields_for(*(args << options), &block)
35
35
  end
@@ -68,17 +68,20 @@ module ActionAdmin
68
68
  }
69
69
 
70
70
  options = {
71
- menu_class: 'menu',
71
+ menu_class: 'menu icons icon-left',
72
72
  separator_class: 'is-separator',
73
73
  submenu_parent_class: 'has-children',
74
74
  submenu_class: 'vertical menu nested',
75
75
  active_class: 'is-current',
76
76
  active_submenu_class: 'is-current',
77
77
  icon_prefix: 'mdi mdi-',
78
- icon_position: 'right'
78
+ icon_position: 'left'
79
79
  }
80
80
 
81
- smart_navigation_for items[position], options
81
+ custom = ActionAdmin.config.menus.send(:"topbar_#{position}")
82
+ items = items[position].merge(Hash(custom).symbolize_keys)
83
+
84
+ smart_navigation_for items, options
82
85
  end
83
86
 
84
87
  def admin_action_links(action=nil)
@@ -0,0 +1,51 @@
1
+ module ActionAdmin
2
+ class AttachmentInput < SimpleForm::Inputs::StringInput
3
+ def input(wrapper_options)
4
+ modal = options.fetch :modal, 'media-modal'
5
+ html = content_tag :div, input_placeholder, id: input_html_id, data: { media_attach: modal }
6
+
7
+ html + input_template
8
+ end
9
+
10
+ def input_placeholder
11
+ span = content_tag :span, 'No thumbnail', class: 'margin-bottom-1'
12
+ icon = content_tag :i, nil, class: 'mdi mdi-camera-off'
13
+ button = content_tag :a, 'Add Thumbnail', data: { open: input_html_id }, class: 'button success small hollow margin-0'
14
+ content = content_tag :div, empty_input + icon + span + button, class: 'no-content hide', data: { empty_state: '' }
15
+ image = attachment(attachment_url) if attachment_url.present?
16
+
17
+ content + content_tag(:div, image, data: { list_remove: '' }, class: 'attachments')
18
+ end
19
+
20
+ def empty_input
21
+ @builder.hidden_field(:"#{attribute_name}_id", value: '', id: nil)
22
+ end
23
+
24
+ def hidden_input
25
+ @builder.hidden_field(:"#{attribute_name}_id", data: { value: :id })
26
+ end
27
+
28
+ def input_html_id
29
+ hidden_input[/id=\"(.*)\"/, 1].dasherize
30
+ end
31
+
32
+ def attachment_url
33
+ object.send(attribute_name).try(:file_url, :preview)
34
+ end
35
+
36
+ def attachment(image_url=nil)
37
+ image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: :id, url: "#{template.root_url.chomp('/')}[src]" }
38
+ button = content_tag :a, 'Remove Thumbnail', class: 'button alert small hollow margin-0', data: { remove: '' }
39
+
40
+ content_tag :div, hidden_input + image + button, class: 'attachment text-center', data: { list_item: '' }
41
+ end
42
+
43
+ def input_template
44
+ content_tag :script, attachment, id: "#{input_html_id}-item-template", type: 'text/template'
45
+ end
46
+
47
+ def label(wrapper_options)
48
+ ''
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ module ActionAdmin
2
+ class SelectListInput < SimpleForm::Inputs::CollectionSelectInput
3
+ def input(wrapper_options)
4
+ input_html_options[:data] ||= {}
5
+ input_html_options[:data].merge!({
6
+ select_box: '',
7
+ list: true,
8
+ placeholder: input_html_options[:placeholder]
9
+ })
10
+
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,63 @@
1
+ module ActionAdmin
2
+ class SlugInput < SimpleForm::Inputs::StringInput
3
+ def input(wrapper_options)
4
+ input_html_options[:placeholder] ||= raw_label_text
5
+ input_html_options[:type] ||= 'text'
6
+ input_html_options[:class] ||= []
7
+ input_html_options[:class] += ['small', 'edit-input']
8
+
9
+ opts = { class: 'inline-edit-box', data: { inline_edit_box: '' } }
10
+
11
+ template.content_tag(:div, opts) do
12
+ template.concat preview_link
13
+ template.concat super
14
+ template.concat edit_button
15
+ template.concat save_button
16
+ end
17
+ end
18
+
19
+ def url
20
+ method = options.fetch :url, ActionAdmin.config.app_urls
21
+ template.try(method, object) unless object.new_record?
22
+ end
23
+
24
+ def prefix(text)
25
+ "#{raw_label_text}: #{text}"
26
+ end
27
+
28
+ def input_value
29
+ object.try(attribute_name)
30
+ end
31
+
32
+ def empty_value
33
+ prefix('Not defined')
34
+ end
35
+
36
+ def value_pattern
37
+ prefix "#{url}".sub("#{input_value}", '[val]')
38
+ end
39
+
40
+ def preview_value
41
+ input_value.present? ? prefix(url) : empty_value
42
+ end
43
+
44
+ def preview_link
45
+ data = { preview: '', value: value_pattern, placeholder: empty_value }
46
+ template.content_tag :small, preview_value, class: 'edit-preview', data: data
47
+ end
48
+
49
+ def edit_button
50
+ opts = { class: 'edit-button mdi mdi-pencil', data: { edit: '' } }
51
+ template.content_tag :span, nil, opts
52
+ end
53
+
54
+ def save_button
55
+ opts = { class: 'save-button mdi mdi-check', data: { save: '' } }
56
+ template.content_tag :span, nil, opts
57
+ end
58
+
59
+ def label(wrapper_options)
60
+ ''
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ module ActionAdmin
2
+ class TagListInput < SelectListInput
3
+ def input(wrapper_options)
4
+ input_html_options[:data] ||= {}
5
+ input_html_options[:data].merge!({ tags: true })
6
+
7
+ super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module ActionAdmin
2
+ class TinymceInput < SimpleForm::Inputs::TextInput
3
+ def input(wrapper_options)
4
+ input_html_options[:data] ||= {}
5
+ input_html_options[:data].merge!({ tiny_mce_editor: '', content_css: template.asset_path('admin/tinymce-editor.css') })
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module ActionAdmin
2
+ class TitleInput < SimpleForm::Inputs::StringInput
3
+ def input(wrapper_options)
4
+ input_html_options[:placeholder] ||= raw_label_text
5
+ input_html_options[:type] ||= 'text'
6
+ input_html_options[:class] ||= []
7
+ input_html_options[:class] += ['large']
8
+
9
+ super
10
+ end
11
+
12
+ def label(wrapper_options)
13
+ ''
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,126 @@
1
+ module ActionAdmin
2
+ class Presenter
3
+ include ActionAdmin::Presentable
4
+
5
+ def initialize(record, context)
6
+ @model = record.class
7
+ @record = record
8
+ @context = context
9
+ end
10
+
11
+ def attributes
12
+ self.record_attributes
13
+ end
14
+
15
+ def attribute_names
16
+ if attributes.keys.any?
17
+ attributes.keys
18
+ else
19
+ items = ['title', 'name', 'email', 'id']
20
+ names = @record.class.attribute_names.select { |i| i.in? items }
21
+
22
+ names.sort_by { |i| items.index i }.first(1)
23
+ end
24
+ end
25
+
26
+ def attribute_labels
27
+ attribute_names.map { |i| @model.human_attribute_name(i) }
28
+ end
29
+
30
+ def render_attribute(name)
31
+ @context.simple_attribute_for(@record, name, Hash(attributes[name]))
32
+ end
33
+
34
+ def render_attributes(*args)
35
+ options = args.extract_options!
36
+ wrapper = args.first
37
+ attribs = attribute_names.map do |a|
38
+ @context.content_tag(wrapper, render_attribute(a), options)
39
+ end
40
+
41
+ attribs.join.html_safe
42
+ end
43
+
44
+ def render_attributes_labels(*args)
45
+ options = args.extract_options!
46
+ wrapper = args.first
47
+ attribs = attribute_labels.map do |a|
48
+ @context.content_tag(wrapper, a, options)
49
+ end
50
+
51
+ attribs.join.html_safe
52
+ end
53
+
54
+ def action_links(*args)
55
+ options = args.extract_options!
56
+ wrapper = args.first
57
+
58
+ @context.content_tag wrapper, options do
59
+ @context.admin_table_action_links(@record)
60
+ end
61
+ end
62
+
63
+ def fields
64
+ self.record_fields
65
+ end
66
+
67
+ def render_field(form, field, options={})
68
+ association = options[:association]
69
+
70
+ if association.present?
71
+ form.association field, Hash(options).except(:association)
72
+ else
73
+ form.input field, Hash(options)
74
+ end
75
+ end
76
+
77
+ def render_fields(form)
78
+ fields.map { |f, o| render_field(form, f, 0) }.join.html_safe
79
+ end
80
+
81
+ def panels
82
+ self.record_panels
83
+ end
84
+
85
+ def render_panel(form, options={})
86
+ template = "admin/panels/#{options.fetch :template, 'default'}"
87
+ content = Array(options[:fields]).map do |f|
88
+ opts = fields[f]
89
+
90
+ opts[:label] = false if options[:labels] == false
91
+ opts[:label] = true if Array(options[:labels]).include?(f)
92
+
93
+ render_field(form, f, opts)
94
+ end
95
+
96
+ options = {
97
+ layout: false,
98
+ content: content.join.html_safe,
99
+ title: options[:title],
100
+ footer: options[:footer]
101
+ }
102
+
103
+ @context.render template, options
104
+ end
105
+
106
+ def render_panels(options={})
107
+ form = options[:form]
108
+ context = options[:context]
109
+
110
+ panels_for_context(context).map { |_i, o| render_panel(form, o) }.join.html_safe
111
+ end
112
+
113
+ def sorted_panels
114
+ items = [:high, :medium, :low]
115
+ panels.sort_by { |_i, o| [items.index(o[:priority]).to_i, o[:order].to_i] }
116
+ end
117
+
118
+ def panels_for_context(context=nil)
119
+ if context.blank?
120
+ sorted_panels.select { |_i, o| o[:context].blank? }
121
+ else
122
+ sorted_panels.select { |_i, o| o[:context] == context }
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,29 @@
1
+ module ActionAdmin
2
+ module Presentable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_attribute :record_attributes
7
+ class_attribute :record_fields
8
+ class_attribute :record_panels
9
+
10
+ self.record_attributes = {}
11
+ self.record_fields = {}
12
+ self.record_panels = {}
13
+ end
14
+
15
+ class_methods do
16
+ def attribute(name, options={})
17
+ self.record_attributes = self.record_attributes.merge(name => options)
18
+ end
19
+
20
+ def field(name, options={})
21
+ self.record_fields = self.record_fields.merge(name => options)
22
+ end
23
+
24
+ def panel(name, options={})
25
+ self.record_panels = self.record_panels.merge(name => options)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.error_notification
8
+ = f.full_error :confirmation_token
9
+ = f.input :email, required: true, autofocus: true
10
+
11
+ .panel-footer
12
+ = f.button :submit, 'Resend confirmation instructions', class: 'expanded margin-0'
13
+
14
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,20 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.error_notification
8
+
9
+ - if @minimum_password_length
10
+ .callout.info = "Password: #{@minimum_password_length} characters minimum"
11
+
12
+ = f.input :reset_password_token, as: :hidden
13
+ = f.full_error :reset_password_token
14
+ = f.input :password, label: 'New password', required: true, autofocus: true
15
+ = f.input :password_confirmation, label: 'Confirm new password', required: true
16
+
17
+ .panel-footer
18
+ = f.button :submit, 'Change password', class: 'expanded margin-0'
19
+
20
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,13 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.error_notification
8
+ = f.input :email, required: true, autofocus: true
9
+
10
+ .panel-footer
11
+ = f.button :submit, 'Send me reset password instructions', class: 'expanded margin-0'
12
+
13
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,22 @@
1
+ = admin_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
2
+ = f.error_notification
3
+
4
+ - if devise_mapping.confirmable? && resource.pending_reconfirmation?
5
+ p.callout.primary = "Currently waiting confirmation for: #{resource.unconfirmed_email}"
6
+
7
+ .panel
8
+ .panel-header.border
9
+ = action_name.titleize
10
+
11
+ .panel-content.border
12
+ = f.input :email, required: true, autofocus: true
13
+ = f.input :password, autocomplete: 'off', hint: "leave it blank if you don't want to change it", required: false
14
+ = f.input :password_confirmation, required: false
15
+ = f.input :current_password, hint: 'we need your current password to confirm your changes', required: true
16
+
17
+ .panel-footer
18
+ .grid-x
19
+ .cell.auto
20
+ = f.button :submit, 'Update', class: 'margin-0'
21
+ .cell.shrink
22
+ = link_to 'Cancel my account', registration_path(resource_name), class: 'button alert hollow margin-0' data: { confirm: 'Are you sure?' }, method: :delete
@@ -0,0 +1,19 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.error_notification
8
+
9
+ - if @minimum_password_length
10
+ .callout.info = "Password: #{@minimum_password_length} characters minimum"
11
+
12
+ = f.input :email, required: true, autofocus: true
13
+ = f.input :password, required: true
14
+ = f.input :password_confirmation, required: true
15
+
16
+ .panel-footer
17
+ = f.button :submit, 'Sign up', class: 'expanded margin-0'
18
+
19
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,14 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.input :email, required: false, autofocus: true
8
+ = f.input :password, required: false
9
+ = f.input :remember_me, as: :boolean if devise_mapping.rememberable?
10
+
11
+ .panel-footer
12
+ = f.button :submit, 'Log in', class: 'expanded margin-0'
13
+
14
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,19 @@
1
+ .footer-links
2
+ - if controller_name != 'sessions'
3
+ = link_to "Log in", new_session_path(resource_name)
4
+
5
+ - if devise_mapping.registerable? && controller_name != 'registrations'
6
+ = link_to "Sign up", new_registration_path(resource_name)
7
+
8
+ - if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
9
+ = link_to "Forgot your password?", new_password_path(resource_name)
10
+
11
+ - if devise_mapping.confirmable? && controller_name != 'confirmations'
12
+ = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
13
+
14
+ - if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
15
+ = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
16
+
17
+ - if devise_mapping.omniauthable?
18
+ - resource_class.omniauth_providers.each do |provider|
19
+ = link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider)
@@ -0,0 +1,14 @@
1
+ = admin_minimal_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f|
2
+ .panel
3
+ .panel-header.border
4
+ = admin_action_title
5
+
6
+ .panel-content.border
7
+ = f.error_notification
8
+ = f.full_error :unlock_token
9
+ = f.input :email, required: true, autofocus: true
10
+
11
+ .panel-footer
12
+ = f.button :submit, 'Resend unlock instructions', class: 'expanded margin-0'
13
+
14
+ = render 'action_admin/devise/shared/links'
@@ -0,0 +1,17 @@
1
+ - if notice.present?
2
+ .callout.primary
3
+ - [notice].flatten.each do |msg|
4
+ = msg
5
+ br
6
+
7
+ - if alert.present?
8
+ .callout.warning
9
+ - [alert].flatten.each do |msg|
10
+ = msg
11
+ br
12
+
13
+ - if defined? record and record.errors.present?
14
+ .callout.warning
15
+ - record.errors.full_messages.each do |error|
16
+ = error
17
+ br
@@ -2,3 +2,5 @@
2
2
  .header
3
3
  h1.h3.title = admin_action_title
4
4
  .actions = admin_action_links
5
+
6
+ = render 'admin/common/alerts'
@@ -0,0 +1,11 @@
1
+ .panel
2
+ - if title
3
+ .panel-header.border = title
4
+
5
+ - if content
6
+ .panel-content.border
7
+ = content
8
+
9
+ - if footer
10
+ .panel-footer
11
+ = footer
@@ -0,0 +1,11 @@
1
+ .panel
2
+ - if title
3
+ .panel-header = title
4
+
5
+ - if content
6
+ .panel-content.padding-0.border-none
7
+ = content
8
+
9
+ - if footer
10
+ .panel-footer
11
+ = footer
@@ -0,0 +1 @@
1
+ .panel.input-group-list = content
@@ -0,0 +1 @@
1
+ .panel.background-none = content
@@ -1,29 +1,39 @@
1
1
  = admin_form_for([:admin, current_record]) do |f|
2
2
  = f.error_notification
3
3
 
4
- .panel
5
- .panel-header.border = action_name.titleize
6
- .panel-content.border
7
- - (permitted_params - current_model.attribute_aliases.values.map(&:to_sym)).each do |parameter|
8
- - parameter = parameter.first if parameter.is_a? Array
9
- - parameter = parameter.keys.first if parameter.is_a? Hash
4
+ .page-content
5
+ .content
6
+ = admin_present(current_record).render_panels(form: f)
10
7
 
11
- - if current_record.respond_to? parameter
12
- - if parameter.to_s == 'parent_id'
13
- - exclude = [current_record.id] + current_record.child_ids unless current_record.new_record?
14
- = f.input parameter, as: :select, collection: current_model.where.not(id: exclude), include_blank: 'No parent'
15
- - else
16
- - assoc = parameter.to_s.sub('_ids', '').sub('_id', '')
17
- - single = current_model.reflect_on_association(assoc)
18
- - plural = current_model.reflect_on_association(assoc.pluralize)
19
- - assoc = assoc.pluralize unless plural.nil?
8
+ .sidebar
9
+ = f.button :submit, class: 'large expanded'
10
+ = admin_present(current_record).render_panels(form: f, context: :sidebar)
20
11
 
21
- - if parameter.to_s.ends_with?('_id')
22
- = f.input parameter, collection: single.options[:class_name].classify.constantize.all, include_blank: 'None'
23
- - elsif parameter.to_s.ends_with?('_ids')
24
- = f.association assoc
25
- - else
26
- = f.input parameter, include_blank: 'Default', placeholder: "Enter #{parameter.to_s.humanize.downcase}..."
27
-
28
- .panel-footer
29
- = f.button :submit, class: 'margin-0'
12
+ / .panel
13
+ / .panel-header.border
14
+ / = action_name.titleize
15
+ /
16
+ / .panel-content.border
17
+ / - (permitted_params - current_model.attribute_aliases.values.map(&:to_sym)).each do |parameter|
18
+ / - parameter = parameter.first if parameter.is_a? Array
19
+ / - parameter = parameter.keys.first if parameter.is_a? Hash
20
+ /
21
+ / - if current_record.respond_to? parameter
22
+ / - if parameter.to_s == 'parent_id'
23
+ / - exclude = [current_record.id] + current_record.child_ids unless current_record.new_record?
24
+ / = f.input parameter, as: :select, collection: current_model.where.not(id: exclude), include_blank: 'No parent'
25
+ / - else
26
+ / - assoc = parameter.to_s.sub('_ids', '').sub('_id', '')
27
+ / - single = current_model.reflect_on_association(assoc)
28
+ / - plural = current_model.reflect_on_association(assoc.pluralize)
29
+ / - assoc = assoc.pluralize unless plural.nil?
30
+ /
31
+ / - if parameter.to_s.ends_with?('_id')
32
+ / = f.input parameter, collection: single.options[:class_name].classify.constantize.all, include_blank: 'None'
33
+ / - elsif parameter.to_s.ends_with?('_ids')
34
+ / = f.association assoc
35
+ / - else
36
+ / = f.input parameter, include_blank: 'Default', placeholder: "Enter #{parameter.to_s.humanize.downcase}..."
37
+ /
38
+ / .panel-footer
39
+ / = f.button :submit, class: 'margin-0'
@@ -3,31 +3,21 @@
3
3
 
4
4
  - else
5
5
  .panel
6
- .panel-header = action_name.titleize
6
+ .panel-header
7
+ = action_name.titleize
8
+
7
9
  .panel-content.padding-0.border-none
8
- table.unstriped.margin-0 data-table-checkbox=""
10
+ table.unstriped.margin-0
9
11
  thead
10
12
  tr
11
- - permitted_params.first(1).each do |parameter|
12
- - if current_record.respond_to? parameter
13
- - parameter = parameter.first if parameter.is_a? Array
14
- - parameter = parameter.keys.first if parameter.is_a? Hash
15
- th.expand = parameter.to_s.titleize
16
-
17
- th.shrink.actions Actions
13
+ = admin_present(current_model).render_attributes_labels(:th)
14
+ th = 'Actions'
18
15
 
19
16
  tbody
20
- - current_records.each do |record|
17
+ - admin_present_many(current_records).each do |record|
21
18
  tr
22
- - permitted_params.first(1).each do |parameter|
23
- - parameter = parameter.first if parameter.is_a? Array
24
- - parameter = parameter.keys.first if parameter.is_a? Hash
25
-
26
- - if record.respond_to? parameter
27
- td.expand = attribute_for record, parameter
28
-
29
- td.shrink.actions
30
- = admin_table_action_links record
19
+ = record.render_attributes(:td, class: 'expand')
20
+ = record.action_links(:td, class: 'shrink actions')
31
21
 
32
22
  - if current_records.respond_to? :current_page
33
23
  .panel-footer
@@ -2,8 +2,6 @@ doctype html
2
2
 
3
3
  html
4
4
  head
5
- meta name="viewport" content="width=device-width, initial-scale=1.0"
6
- meta http-equiv="X-UA-Compatible" content="IE=edge"
7
5
  = admin_meta_tags
8
6
  = csrf_meta_tags
9
7
  = favicon_link_tag 'admin/favicon.png'
@@ -0,0 +1,16 @@
1
+ doctype html
2
+
3
+ html
4
+ head
5
+ = admin_meta_tags
6
+ = csrf_meta_tags
7
+ = favicon_link_tag 'admin/favicon.png'
8
+ = stylesheet_link_tag 'admin/application', media: 'all'
9
+
10
+ body
11
+ .login-box
12
+ .logo-image = image_tag 'admin/logo-login.svg'
13
+ = render 'admin/common/alerts'
14
+ = yield
15
+
16
+ = javascript_include_tag 'admin/application'
data/lib/action_admin.rb CHANGED
@@ -5,6 +5,7 @@ require 'action_crud'
5
5
  require 'smart_pagination'
6
6
  require 'smart_navigation'
7
7
  require 'simple_attribute'
8
+ require 'action_admin/routes'
8
9
  require 'action_admin/engine'
9
10
 
10
11
  module ActionAdmin
@@ -12,10 +13,7 @@ module ActionAdmin
12
13
 
13
14
  # Autoload modules
14
15
  autoload :Config
15
- autoload :SimpleForm
16
- autoload :Controller
17
- autoload :Actionable
18
- autoload :Crudable
16
+ autoload :Form
19
17
  autoload :Header
20
18
 
21
19
  # Set attr accessors
@@ -1,7 +1,8 @@
1
1
  module ActionAdmin
2
2
  class Config < Hashie::Dash
3
3
  property :app_name, default: 'Action Admin'
4
- property :menus, default: Hashie::Mash.new
4
+ property :app_urls, default: :web_url
5
+ property :menus, default: Hashie::Mash.new
5
6
 
6
7
  def menu(name, &block)
7
8
  if self.menus.send(:"#{name}").nil?
@@ -5,7 +5,13 @@ module ActionAdmin
5
5
  end
6
6
 
7
7
  initializer 'action_admin.assets.precompile' do |app|
8
- app.config.assets.precompile += %w(admin/*)
8
+ %w(action_admin admin).each do |sf|
9
+ app.config.assets.paths << root.join('app', 'assets', 'javascripts', sf).to_s
10
+ app.config.assets.paths << root.join('app', 'assets', 'stylesheets', sf).to_s
11
+ app.config.assets.paths << root.join('app', 'assets', 'images', sf).to_s
12
+ end
13
+
14
+ app.config.assets.precompile += %w(admin/application.js admin/application.css admin/tinymce-editor.css images/admin/*.*)
9
15
  end
10
16
 
11
17
  initializer 'action_admin', before: :load_config_initializers do
@@ -1,9 +1,9 @@
1
1
  module ActionAdmin
2
- module SimpleForm
2
+ module Form
3
3
  extend ActiveSupport::Autoload
4
4
 
5
- autoload :FormBuilder
6
- autoload :MinimalFormBuilder
5
+ autoload :Builder
6
+ autoload :MinimalBuilder
7
7
  autoload :ErrorNotification
8
8
  end
9
9
  end
@@ -1,6 +1,6 @@
1
1
  module ActionAdmin
2
- module SimpleForm
3
- class FormBuilder < ::SimpleForm::FormBuilder
2
+ module Form
3
+ class Builder < ::SimpleForm::FormBuilder
4
4
  # Initialize form builder
5
5
  def initialize(*)
6
6
  super
@@ -37,7 +37,7 @@ module ActionAdmin
37
37
 
38
38
  # Create error notification
39
39
  def error_notification(options={})
40
- SimpleForm::ErrorNotification.new(self, options).render
40
+ Form::ErrorNotification.new(self, options).render
41
41
  end
42
42
 
43
43
  # Find field wrapper
@@ -48,6 +48,17 @@ module ActionAdmin
48
48
  @admin[:wrapper_mappings] && @admin[:wrapper_mappings][input_type]
49
49
  end
50
50
  end
51
+
52
+ # Find namespaced input
53
+ def attempt_mapping_with_custom_namespace(input_name)
54
+ ['ActionAdmin', 'Admin'].each do |namespace|
55
+ if (mapping = attempt_mapping(input_name, namespace.constantize))
56
+ return mapping
57
+ end
58
+ end
59
+
60
+ nil
61
+ end
51
62
  end
52
63
  end
53
64
  end
@@ -1,5 +1,5 @@
1
1
  module ActionAdmin
2
- module SimpleForm
2
+ module Form
3
3
  class ErrorNotification < ::SimpleForm::ErrorNotification
4
4
  def html_options
5
5
  @options[:class] = "callout alert #{@options[:class]}".strip
@@ -0,0 +1,19 @@
1
+ module ActionAdmin
2
+ module Form
3
+ class MinimalBuilder < Builder
4
+ # Form builder input
5
+ def input(attribute_name, options = {}, &block)
6
+ options = @defaults.deep_dup.deep_merge(options) if @defaults
7
+ input = find_input(attribute_name, options, &block)
8
+ excluded = [:radio, :checkbox, :boolean, :check_boxes, :radio_buttons]
9
+
10
+ if !input.input_type.in?(excluded) and options[:placeholder].nil?
11
+ options[:placeholder] ||= input.send(:raw_label_text)
12
+ options[:label] ||= false
13
+ end
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ def authenticate_admin(resource, options={})
4
+ space = options.fetch :namespace, :admin
5
+ path = options.fetch :path, "#{space}/#{resource}"
6
+ model = "#{resource}".pluralize
7
+ names = { sign_in: 'login', sign_out: 'logout', sign_up: 'signup', edit: 'profile' }
8
+ options = { path: path, path_names: names, module: 'action_admin/devise' }.merge(options)
9
+
10
+ devise_for :"#{model}", options
11
+
12
+ authenticate resource do
13
+ namespace space do
14
+ yield
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ActionAdmin
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
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.0
4
+ version: 0.1.1
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-07 00:00:00.000000000 Z
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -175,17 +175,45 @@ files:
175
175
  - README.md
176
176
  - Rakefile
177
177
  - app/assets/images/admin/logo.svg
178
- - app/assets/javascripts/admin/admin.js
178
+ - app/assets/javascripts/action_admin/action-admin.js
179
179
  - app/assets/javascripts/admin/application.js
180
- - app/assets/stylesheets/admin/admin.scss
180
+ - app/assets/stylesheets/action_admin/action-admin.scss
181
+ - app/assets/stylesheets/action_admin/action-admin/tinymce.scss
181
182
  - app/assets/stylesheets/admin/application.scss
183
+ - app/assets/stylesheets/admin/tinymce-editor.scss
182
184
  - app/controllers/action_admin/base_controller.rb
183
185
  - app/controllers/action_admin/crud_controller.rb
186
+ - app/controllers/action_admin/devise/confirmations_controller.rb
187
+ - app/controllers/action_admin/devise/omniauth_callbacks_controller.rb
188
+ - app/controllers/action_admin/devise/passwords_controller.rb
189
+ - app/controllers/action_admin/devise/registrations_controller.rb
190
+ - app/controllers/action_admin/devise/sessions_controller.rb
191
+ - app/controllers/action_admin/devise/unlocks_controller.rb
184
192
  - app/controllers/action_admin/welcome_controller.rb
193
+ - app/controllers/concerns/action_admin/actionable.rb
194
+ - app/controllers/concerns/action_admin/controller.rb
195
+ - app/controllers/concerns/action_admin/crudable.rb
185
196
  - app/helpers/action_admin/admin_helper.rb
186
197
  - app/helpers/action_admin/form_helper.rb
187
198
  - app/helpers/action_admin/markup_helper.rb
199
+ - app/inputs/action_admin/attachment_input.rb
200
+ - app/inputs/action_admin/select_list_input.rb
201
+ - app/inputs/action_admin/slug_input.rb
202
+ - app/inputs/action_admin/tag_list_input.rb
203
+ - app/inputs/action_admin/tinymce_input.rb
204
+ - app/inputs/action_admin/title_input.rb
205
+ - app/presenters/action_admin/presenter.rb
206
+ - app/presenters/concerns/action_admin/presentable.rb
207
+ - app/views/action_admin/devise/confirmations/new.html.slim
208
+ - app/views/action_admin/devise/passwords/edit.html.slim
209
+ - app/views/action_admin/devise/passwords/new.html.slim
210
+ - app/views/action_admin/devise/registrations/edit.html.slim
211
+ - app/views/action_admin/devise/registrations/new.html.slim
212
+ - app/views/action_admin/devise/sessions/new.html.slim
213
+ - app/views/action_admin/devise/shared/_links.html.slim
214
+ - app/views/action_admin/devise/unlocks/new.html.slim
188
215
  - app/views/action_admin/welcome/index.html.slim
216
+ - app/views/admin/common/_alerts.html.slim
189
217
  - app/views/admin/common/_footer.html.slim
190
218
  - app/views/admin/common/_header.html.slim
191
219
  - app/views/admin/common/_logobar.html.slim
@@ -194,25 +222,28 @@ files:
194
222
  - app/views/admin/common/_sidebar.html.slim
195
223
  - app/views/admin/common/_topbar.html.slim
196
224
  - app/views/admin/common/action.html.slim
225
+ - app/views/admin/panels/_default.html.slim
226
+ - app/views/admin/panels/_expanded.html.slim
227
+ - app/views/admin/panels/_group.html.slim
228
+ - app/views/admin/panels/_plain.html.slim
197
229
  - app/views/admin/records/_form.html.slim
198
230
  - app/views/admin/records/edit.html.slim
199
231
  - app/views/admin/records/index.html.slim
200
232
  - app/views/admin/records/new.html.slim
201
233
  - app/views/admin/records/show.html.slim
202
234
  - app/views/layouts/admin.html.slim
235
+ - app/views/layouts/admin/devise.html.slim
203
236
  - config/initializers/admin_simple_form.rb
204
237
  - config/routes.rb
205
238
  - lib/action_admin.rb
206
- - lib/action_admin/actionable.rb
207
239
  - lib/action_admin/config.rb
208
- - lib/action_admin/controller.rb
209
- - lib/action_admin/crudable.rb
210
240
  - lib/action_admin/engine.rb
241
+ - lib/action_admin/form.rb
242
+ - lib/action_admin/form/builder.rb
243
+ - lib/action_admin/form/error_notification.rb
244
+ - lib/action_admin/form/minimal_builder.rb
211
245
  - lib/action_admin/header.rb
212
- - lib/action_admin/simple_form.rb
213
- - lib/action_admin/simple_form/error_notification.rb
214
- - lib/action_admin/simple_form/form_builder.rb
215
- - lib/action_admin/simple_form/minimal_form_builder.rb
246
+ - lib/action_admin/routes.rb
216
247
  - lib/action_admin/version.rb
217
248
  - lib/tasks/action_admin_tasks.rake
218
249
  homepage: https://github.com/hardpixel/action-admin
@@ -1,2 +0,0 @@
1
- @import "foundation-components";
2
- @import "bedrock-components";
@@ -1,20 +0,0 @@
1
- module ActionAdmin
2
- module SimpleForm
3
- class MinimalFormBuilder < FormBuilder
4
- # Form builder input
5
- def input(attribute_name, options = {}, &block)
6
- if options[:placeholder].nil?
7
- options[:placeholder] ||= if object.class.respond_to?(:human_attribute_name)
8
- object.class.human_attribute_name(attribute_name.to_s)
9
- else
10
- attribute_name.to_s.humanize
11
- end
12
-
13
- options[:label] = false if options[:label].nil?
14
- end
15
-
16
- super
17
- end
18
- end
19
- end
20
- end