express_admin 1.4.11 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5b5fd470148d183da2706152e9b7019eb2c6d9
4
- data.tar.gz: b39194d97af745e8e35873dd0a9e9e44bfb356f7
3
+ metadata.gz: 2ee970ef95e2385137a11fa6508edacd01faeae8
4
+ data.tar.gz: 9fb8fd28dacf2d2c4bfd81cfcdf603e6be99f678
5
5
  SHA512:
6
- metadata.gz: 1411b21129cb3d05ba04f7f83bb13428e6145cab8702897079d5cbcb9304486ca516f9076b60c9b71e8f6edc48abe880e21010404d1d9ccd0081a2fe8427e49b
7
- data.tar.gz: f0348de1c2da9faf4f5810c53449721a01c0f423d1af63e0048a80b01e4f5b9fa8cc226cc0a84b915a48bd60864231277edef22d7bea874f665a521740034be6
6
+ metadata.gz: c627d21e2cfdfed8d54317c2f05aa401614781431afa7aabcb98f8c8c0604075de1005ed1f070024ad3b18273d4035536fd81e9c61931a968a1f351ed2b3df7c
7
+ data.tar.gz: 7c6897243cc55e89e07c80eccd7089a051078b9602ad4918985dfe13657b6e4332d8c065edd7ecd4d7a9c1ead4bc279995e62b9b6255e98e778cfd5db637a73f
@@ -1,6 +1,6 @@
1
1
  //= require jquery
2
2
  //= require jquery_ujs
3
- //= require jquery-ui/sortable
3
+ //= require jquery-ui
4
4
  //= require jquery.loadingdotdotdot
5
5
  //= require tinymce-jquery
6
6
  //= require select2
@@ -11,3 +11,10 @@
11
11
  size: 1rem
12
12
  weight: normal
13
13
  padding: 0.5rem 0
14
+
15
+ .pane
16
+ @include breakpoint(medium)
17
+ max-height: 300px
18
+
19
+ @include breakpoint(large)
20
+ max-height: 500px
@@ -1,2 +1,2 @@
1
1
  .v-box
2
- @include grid-block($orientation: vertical)
2
+ @include grid-block($orientation: vertical)
@@ -4,6 +4,7 @@ $border-color: #dedede
4
4
  $light-gray: #f9f9f9
5
5
  $block-alt-bg-color: whitesmoke
6
6
  $dark: #444
7
+ $light: #fff
7
8
 
8
9
  $blue: #26ade4
9
10
  $light-blue: #94bde1
@@ -21,15 +21,16 @@
21
21
 
22
22
  // Still a bit hacky. Need to polish this more
23
23
  // This was done to contain the giant table in rbac's routes#index
24
- .large-table-container
25
- @include breakpoint(small)
26
- height: 300px
27
-
28
- @include breakpoint(medium)
29
- height: 500px
30
-
31
- @include breakpoint(large)
32
- height: 800px
24
+ // Might not need this anymore because of 77b7136
25
+ // .large-table-container
26
+ // @include breakpoint(small)
27
+ // height: 300px
28
+ //
29
+ // @include breakpoint(medium)
30
+ // height: 500px
31
+ //
32
+ // @include breakpoint(large)
33
+ // height: 800px
33
34
 
34
35
  .definition-table
35
36
  tbody
@@ -1,14 +1,17 @@
1
1
  module ExpressAdmin
2
2
  class PageHeader < ExpressTemplates::Components::Base
3
- ETC = ExpressTemplates::Components
4
3
 
5
4
  contains -> {
6
- h1 {
7
- content_for(:page_header) if content_for?(:page_header)
8
- }
9
- para(class: 'lead') {
10
- content_for(:page_header_lead) if content_for?(:page_header_lead)
11
- }
5
+ if content_for?(:page_header)
6
+ h1 {
7
+ content_for(:page_header)
8
+ }
9
+ end
10
+ if content_for?(:page_header_lead)
11
+ para(class: 'lead') {
12
+ content_for(:page_header_lead)
13
+ }
14
+ end
12
15
  }
13
16
  end
14
- end
17
+ end
@@ -0,0 +1,37 @@
1
+ module ExpressAdmin
2
+ class Commandable
3
+ def initialize(defaults = {})
4
+ @defaults = defaults
5
+ end
6
+
7
+ def call(mapper, options = {})
8
+ options = @defaults.merge(options)
9
+ controller_name = mapper.send(:parent_resource).controller
10
+ resource_class = "#{controller_name.classify.pluralize}Controller".constantize.resource_class
11
+ resource_class.commands.each do |action|
12
+ # post :foo, to: "module/controller#foo"
13
+ mapper.member do
14
+ mapper.post action, to: "#{controller_name}##{action}"
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ module ActionDispatch::Routing::Mapper::Resources
23
+ def resources_with_commandable(*resources, &block)
24
+ unless @concerns[:commandable]
25
+ concern :commandable, ExpressAdmin::Commandable.new
26
+ end
27
+
28
+ resources_without_commandable(*resources) do |resource|
29
+ block.call(resource) unless block.nil?
30
+ concerns :commandable
31
+ end
32
+ end
33
+
34
+ alias :resources_without_commandable :resources
35
+ alias :resources :resources_with_commandable
36
+
37
+ end
@@ -0,0 +1,46 @@
1
+ module ExpressAdmin
2
+ module Commands
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include InstanceMethods
6
+ extend ClassMethods
7
+
8
+ class_attribute :commands
9
+ self.commands = []
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ def exposes_command(command)
16
+ exposes_commands command
17
+ end
18
+
19
+ def exposes_commands(*commands)
20
+ self.commands += commands
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ # If not using, AASM, override this for disallowing commands
26
+ def unavailable_commands
27
+ []
28
+ end
29
+
30
+ def available_commands
31
+ if respond_to?(:aasm)
32
+ commands & aasm_event_triggers
33
+ else
34
+ commands - unavailable_commands
35
+ end
36
+ end
37
+
38
+ protected
39
+ def aasm_event_triggers
40
+ aasm.events.map(&:name).map(&:to_s).map {|s| "#{s}!"}.map(&:to_sym)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ ActiveRecord::Base.include(ExpressAdmin::Commands)
@@ -32,7 +32,7 @@ module ExpressAdmin
32
32
 
33
33
  if self.resource_class.respond_to?(:commands)
34
34
  self.resource_class.commands.each do |command|
35
- define_command_method(command)
35
+ define_command_method(command.to_s.gsub(/\!\Z/, ''), command)
36
36
  end
37
37
  end
38
38
  end
@@ -48,8 +48,8 @@ module ExpressAdmin
48
48
 
49
49
  protected
50
50
 
51
- def define_command_method(command)
52
- define_method(command) do
51
+ def define_command_method(action, command)
52
+ define_method(action) do
53
53
  load_resource
54
54
  begin
55
55
  resource.send(command)
@@ -246,10 +246,6 @@ module ExpressAdmin
246
246
  "@#{resource_name}".to_sym
247
247
  end
248
248
 
249
- # def resource_class
250
- # self.class.to_s.gsub(/Controller$/, '').singularize.classify.constantize
251
- # end
252
-
253
249
  # Foo::WidgetsController -> widget
254
250
  def resource_name
255
251
  self.class.resource_name
@@ -1,3 +1,3 @@
1
1
  module ExpressAdmin
2
- VERSION = "1.4.11"
2
+ VERSION = "1.5.0"
3
3
  end
data/lib/express_admin.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), "core_extensions/string_promptify")
2
2
  require "express_admin/engine"
3
3
  require "express_admin/routes"
4
+ require "express_admin/commands"
5
+ require "express_admin/commandable"
4
6
 
5
7
  module ExpressAdmin
6
8
  end
@@ -19,6 +19,7 @@ module ExpressAdmin
19
19
  eigenclass.send(:define_method, :params) do
20
20
  ActionController::Parameters.new(params.with_indifferent_access)
21
21
  end
22
+ # hack so we can call the action without all controller stuff
22
23
  eigenclass.send(:define_method, :respond_to) do |&block|
23
24
  block.call(ActionController::MimeResponds::Collector.new([], 'text/html'))
24
25
  end
@@ -110,8 +111,14 @@ module ExpressAdmin
110
111
 
111
112
  test ".define_command_method defines a command action method on the controller" do
112
113
  refute widgets_controller.respond_to?(:foo)
113
- widgets_controller.class.send(:define_command_method, :foo)
114
+ widgets_controller.class.send(:define_command_method, :foo, :foo!)
114
115
  assert widgets_controller.respond_to?(:foo)
115
116
  end
117
+
118
+ test "if a resource exposes commands, the controllers should have an action for the command" do
119
+ assert widgets_controller.respond_to?(:twiddle), "widgets_controller#twiddle should be there"
120
+ widgets_controller(id: widgets(:one).id).twiddle
121
+ assert widgets(:one).reload.column2.eql?("twiddled"), "widgets_controller#twiddle didn't twiddle the widget"
122
+ end
116
123
  end
117
124
  end
@@ -0,0 +1,2 @@
1
+ class CategoriesController < ExpressAdmin::StandardController
2
+ end
@@ -0,0 +1,2 @@
1
+ class PartsController < ExpressAdmin::StandardController
2
+ end
@@ -0,0 +1,2 @@
1
+ class WidgetsController < ExpressAdmin::StandardController
2
+ end
@@ -7,4 +7,10 @@ class Widget < ActiveRecord::Base
7
7
 
8
8
  attr :password
9
9
 
10
+ exposes_command :twiddle
11
+
12
+ def twiddle
13
+ update_attributes(column2: "twiddled")
14
+ end
15
+
10
16
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.11
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
@@ -427,8 +427,11 @@ files:
427
427
  - config/initializers/request_store_current_user.rb
428
428
  - config/initializers/tinymce-rails.rb
429
429
  - config/tinymce.yml
430
+ - lib/core_extensions/active_record_base_commands.rb
430
431
  - lib/core_extensions/string_promptify.rb
431
432
  - lib/express_admin.rb
433
+ - lib/express_admin/commandable.rb
434
+ - lib/express_admin/commands.rb
432
435
  - lib/express_admin/engine.rb
433
436
  - lib/express_admin/menu.rb
434
437
  - lib/express_admin/routes.rb
@@ -461,7 +464,10 @@ files:
461
464
  - test/dummy/app/controllers/admin/parts_controller.rb
462
465
  - test/dummy/app/controllers/admin/widgets_controller.rb
463
466
  - test/dummy/app/controllers/application_controller.rb
467
+ - test/dummy/app/controllers/categories_controller.rb
464
468
  - test/dummy/app/controllers/demo_controller.rb
469
+ - test/dummy/app/controllers/parts_controller.rb
470
+ - test/dummy/app/controllers/widgets_controller.rb
465
471
  - test/dummy/app/helpers/application_helper.rb
466
472
  - test/dummy/app/helpers/demo_helper.rb
467
473
  - test/dummy/app/models/category.rb
@@ -797,7 +803,10 @@ test_files:
797
803
  - test/dummy/app/controllers/admin/parts_controller.rb
798
804
  - test/dummy/app/controllers/admin/widgets_controller.rb
799
805
  - test/dummy/app/controllers/application_controller.rb
806
+ - test/dummy/app/controllers/categories_controller.rb
800
807
  - test/dummy/app/controllers/demo_controller.rb
808
+ - test/dummy/app/controllers/parts_controller.rb
809
+ - test/dummy/app/controllers/widgets_controller.rb
801
810
  - test/dummy/app/helpers/application_helper.rb
802
811
  - test/dummy/app/helpers/demo_helper.rb
803
812
  - test/dummy/app/models/category.rb