effective_resources 0.3.13 → 0.4.0
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 +4 -4
- data/app/models/effective/resource.rb +1 -0
- data/app/models/effective/resources/actions.rb +55 -0
- data/app/models/effective/resources/paths.rb +6 -1
- data/app/models/effective/resources/relation.rb +1 -1
- data/app/views/application/edit.html.haml +20 -0
- data/app/views/application/index.html.haml +23 -0
- data/app/views/application/new.html.haml +5 -0
- data/app/views/application/show.html.haml +20 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710060a4d1418f907cd8ffb119036b6b641e58f5
|
4
|
+
data.tar.gz: 4c702a563c7bede6b1f415fd94f73e8eebf290c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58b4be5357a4f631ff7ef3c7a599fa16c5da4c7a990e5bf6ccfd7531af9f95d772a35b7115fda179215d3cff8133976f1b866f09c138de05009ec43b5d33a29
|
7
|
+
data.tar.gz: 2b3bd0c219550a21fefc27cbe3f2c4d1b25226b5f34c0bc2335d4ef99084d5b0643d66eb7945130b193e8a94b532f1a9e6b4ac57c75d1fa8b7d8fb6b2af3ffd9
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Effective
|
2
|
+
module Resources
|
3
|
+
module Actions
|
4
|
+
|
5
|
+
# This was written for the Edit actions fallback templates
|
6
|
+
|
7
|
+
def controller_routes
|
8
|
+
@controller_routes ||= (
|
9
|
+
path = controller_path
|
10
|
+
|
11
|
+
Rails.application.routes.routes.select do |route|
|
12
|
+
(route.defaults[:controller] == path) && route.defaults[:action].present?
|
13
|
+
end
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def controller_actions
|
18
|
+
controller_routes.map { |route| route.defaults[:action] }
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET actions
|
22
|
+
def member_actions
|
23
|
+
controller_routes.map { |route| route.defaults[:action] if is_get_member?(route) }.compact - crud_actions
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET actions
|
27
|
+
def member_post_actions
|
28
|
+
controller_routes.map { |route| route.defaults[:action] if is_post_member?(route) }.compact - crud_actions
|
29
|
+
end
|
30
|
+
|
31
|
+
# Same as controller_path in the view
|
32
|
+
def controller_path
|
33
|
+
[namespace, plural_name].compact * '/'
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def crud_actions
|
39
|
+
%w(index new create show edit update destroy)
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_get_member?(route)
|
43
|
+
route.verb.to_s.include?('GET') && route.path.required_names == ['id']
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_post_member?(route)
|
47
|
+
['POST', 'PUT', 'PATCH'].any? { |verb| route.verb == verb } && route.path.required_names == ['id']
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
@@ -30,7 +30,12 @@ module Effective
|
|
30
30
|
|
31
31
|
def action_path(action, check: false)
|
32
32
|
path = [action, namespace, name, 'path'].compact * '_'
|
33
|
-
path if (!check || path_exists?(path, 1))
|
33
|
+
path if (!check || path_exists?(path, 1, :any))
|
34
|
+
end
|
35
|
+
|
36
|
+
def action_post_path(action, check: false)
|
37
|
+
path = [action, namespace, name, 'path'].compact * '_'
|
38
|
+
path if (!check || path_exists?(path, 1, :post) || path_exists?(path, 1, :put) || path_exists?(path, 1, :patch))
|
34
39
|
end
|
35
40
|
|
36
41
|
def path_exists?(path, param = nil, verb = :get)
|
@@ -111,7 +111,7 @@ module Effective
|
|
111
111
|
relation.where("#{sql_column} = ?", term)
|
112
112
|
end
|
113
113
|
when :duration
|
114
|
-
if fuzzy && (term % 60
|
114
|
+
if fuzzy && (term % 60 == 0) && value.to_s.include?('m') == false
|
115
115
|
if term < 0
|
116
116
|
relation.where("#{sql_column} <= ? AND #{sql_column} > ?", term, term-60)
|
117
117
|
else
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name)
|
3
|
+
|
4
|
+
.row
|
5
|
+
.col-sm-6
|
6
|
+
%h1= @page_title
|
7
|
+
.col-sm-6
|
8
|
+
%p.text-right
|
9
|
+
- resource.member_post_actions.each do |action|
|
10
|
+
- if EffectiveResources.authorized?(controller, action.to_sym, @resource)
|
11
|
+
- if resource.action_post_path(action, check: true).present?
|
12
|
+
= link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
|
13
|
+
data: { confirm: "Really #{action} #{@resource}?", method: :post }
|
14
|
+
|
15
|
+
- if EffectiveResources.authorized?(controller, :destroy, @resource)
|
16
|
+
- if resource.destroy_path(check: true).present?
|
17
|
+
= link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
|
18
|
+
data: { confirm: "Really delete #{@resource}?", method: :delete }
|
19
|
+
|
20
|
+
= render 'form', resource.name.to_sym => @resource
|
@@ -0,0 +1,23 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
|
3
|
+
.row
|
4
|
+
.col-sm-6
|
5
|
+
%h1= @page_title
|
6
|
+
.col-sm-6
|
7
|
+
%p.text-right
|
8
|
+
- if can?(:new, resource.klass) && resource.new_path(check: true).present?
|
9
|
+
= link_to "New #{resource.human_name.titleize}", send(resource.new_path), class: 'btn btn-primary'
|
10
|
+
|
11
|
+
- if @datatable
|
12
|
+
= render_datatable(@datatable)
|
13
|
+
|
14
|
+
- elsif instance_variable_get('@' + resource.plural_name)
|
15
|
+
= render instance_variable_get('@' + resource.plural_name)
|
16
|
+
|
17
|
+
- elsif instance_variable_get('@' + resource.name)
|
18
|
+
= render instance_variable_get('@' + resource.name)
|
19
|
+
|
20
|
+
- elsif Rails.env.development?
|
21
|
+
%p effective_resources index view is not sure what to render.
|
22
|
+
%p Define an @datatable, @#{resource.plural_name}, or @#{resource.name}.
|
23
|
+
%p or include Effective::CrudController in your controller
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name)
|
3
|
+
|
4
|
+
.row
|
5
|
+
.col-sm-6
|
6
|
+
%h1= @page_title
|
7
|
+
.col-sm-6
|
8
|
+
%p.text-right
|
9
|
+
- resource.member_post_actions.each do |action|
|
10
|
+
- if EffectiveResources.authorized?(controller, action.to_sym, @resource)
|
11
|
+
- if resource.action_post_path(action, check: true).present?
|
12
|
+
= link_to action.titleize, send(resource.action_post_path(action), @resource), class: 'btn btn-primary',
|
13
|
+
data: { confirm: "Really #{action} #{@resource}?", method: :post }
|
14
|
+
|
15
|
+
- if EffectiveResources.authorized?(controller, :destroy, @resource)
|
16
|
+
- if resource.destroy_path(check: true).present?
|
17
|
+
= link_to 'Delete', send(resource.destroy_path, @resource), class: 'btn btn-danger',
|
18
|
+
data: { confirm: "Really delete #{@resource}?", method: :delete }
|
19
|
+
|
20
|
+
= render @resource
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- app/models/effective/attribute.rb
|
42
42
|
- app/models/effective/code_reader.rb
|
43
43
|
- app/models/effective/resource.rb
|
44
|
+
- app/models/effective/resources/actions.rb
|
44
45
|
- app/models/effective/resources/associations.rb
|
45
46
|
- app/models/effective/resources/attributes.rb
|
46
47
|
- app/models/effective/resources/forms.rb
|
@@ -51,6 +52,10 @@ files:
|
|
51
52
|
- app/models/effective/resources/paths.rb
|
52
53
|
- app/models/effective/resources/relation.rb
|
53
54
|
- app/models/effective/resources/sql.rb
|
55
|
+
- app/views/application/edit.html.haml
|
56
|
+
- app/views/application/index.html.haml
|
57
|
+
- app/views/application/new.html.haml
|
58
|
+
- app/views/application/show.html.haml
|
54
59
|
- config/effective_resources.rb
|
55
60
|
- lib/effective_resources.rb
|
56
61
|
- lib/effective_resources/engine.rb
|