qm-acts-as-generic-controller 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/app/views/generic_controller/_index_table.erb +11 -0
- data/app/views/generic_controller/form.erb +2 -1
- data/app/views/generic_controller/index.erb +18 -1
- data/lib/qm-acts-as-generic-controller-controller.rb +15 -1
- data/lib/qm-acts-as-generic-controller-model.rb +23 -0
- metadata +17 -3
data/Rakefile
CHANGED
@@ -9,11 +9,12 @@ begin
|
|
9
9
|
gemspec.email = "marcin@saepia.net"
|
10
10
|
gemspec.homepage = "http://q.saepia.net"
|
11
11
|
gemspec.authors = ["Marcin Lewandowski"]
|
12
|
-
gemspec.version = "0.0.
|
12
|
+
gemspec.version = "0.0.11"
|
13
13
|
gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*", "app/views/generic_controller/*" ]
|
14
14
|
gemspec.add_dependency "qui-common-helpers", ">= 0.0.6"
|
15
15
|
gemspec.add_dependency "rfc822"
|
16
16
|
gemspec.add_dependency "sort_alphabetical"
|
17
|
+
gemspec.add_dependency "calendar_date_select"
|
17
18
|
end
|
18
19
|
rescue LoadError
|
19
20
|
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
@@ -6,6 +6,9 @@
|
|
6
6
|
<%- has_edit = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(controller_name, "edit") }.compact.size > 0 %>
|
7
7
|
<%- has_delete = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(controller_name, "destroy") }.compact.size > 0 %>
|
8
8
|
|
9
|
+
<%- if defined?(QM::ActsAsWorkflow) and class_name.is_workflow? -%>
|
10
|
+
<%- headers << :"#{section}.workflow.common.indexTableHeader" -%>
|
11
|
+
<%- end -%>
|
9
12
|
|
10
13
|
<%- if defined?(QUI::IndexTable) -%>
|
11
14
|
|
@@ -17,6 +20,14 @@
|
|
17
20
|
<td><%= render :partial => "generic_controller/data", :locals => { :record => r, :field => field } %></td>
|
18
21
|
<%- end -%>
|
19
22
|
|
23
|
+
<%- if defined?(QM::ActsAsWorkflow) and class_name.is_workflow? -%>
|
24
|
+
<td>
|
25
|
+
<%- unless r.current_workflow_node.nil? -%>
|
26
|
+
<%= strip_tags t(:"#{section}.workflow.#{class_name.to_s.tableize.singularize}.#{r.current_workflow_node}.header", :object => link_to_object(r)).gsub("<br />", " ") %><br /><%= link_to_object(r.current_workflow_actor) %> (<%= relative_time(r.current_workflow_pending_time) %>)
|
27
|
+
<%- end -%>
|
28
|
+
</td>
|
29
|
+
<%- end -%>
|
30
|
+
|
20
31
|
<%- if has_edit -%>
|
21
32
|
<td><%= link_to_edit r %></td>
|
22
33
|
<%- end -%>
|
@@ -14,7 +14,6 @@
|
|
14
14
|
<%- end -%>
|
15
15
|
|
16
16
|
<ol>
|
17
|
-
|
18
17
|
<%- klass.generic_fields.each do |field| -%>
|
19
18
|
<%- if field.is_a? Hash -%>
|
20
19
|
<%- attribute_name = field.keys.first.to_sym -%>
|
@@ -58,6 +57,8 @@
|
|
58
57
|
<%- else -%>
|
59
58
|
<%- if record.column_for_attribute(attribute_name).type == :text -%>
|
60
59
|
<%= f.text_area attribute_name, :rows => 5, :cols => 60 %>
|
60
|
+
<%- elsif record.column_for_attribute(attribute_name).type == :date -%>
|
61
|
+
<%= f.calendar_date_select attribute_name %>
|
61
62
|
<%- else -%>
|
62
63
|
<%= f.text_field attribute_name %>
|
63
64
|
<%- end -%>
|
@@ -1,3 +1,6 @@
|
|
1
|
+
<%- records ||= instance_variable_get("@#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize}") -%>
|
2
|
+
<%- class_name ||= @controller.class.to_s.demodulize.gsub("Controller", "").singularize.constantize -%>
|
3
|
+
|
1
4
|
<%- if defined?(QUI::Toolbar) -%>
|
2
5
|
<%- toolbar do |t| -%>
|
3
6
|
<%- begin -%>
|
@@ -10,4 +13,18 @@
|
|
10
13
|
<%- end -%>
|
11
14
|
<%- end -%>
|
12
15
|
|
13
|
-
|
16
|
+
<%- if class_name.has_generic_named_scopes? -%>
|
17
|
+
<%- content_tag(:div, :class => "index_scopes") do -%>
|
18
|
+
<%- form_tag params, :method => :get do -%>
|
19
|
+
<%- class_name.named_scopes.each do |identifier, options| -%>
|
20
|
+
<%- if options.has_key?(:generic) and options[:generic] == true -%>
|
21
|
+
<%= check_box_tag "scopes[]", identifier, params[:scopes] && params[:scopes].include?(identifier.to_s), :id => "scope_#{class_name}_#{identifier}" %>
|
22
|
+
<%= label_tag "scope_#{class_name}_#{identifier}", t(:"#{section}.scopes.#{class_name.to_s.tableize.singularize}.#{identifier}") %>
|
23
|
+
<%- end -%>
|
24
|
+
<%- end -%>
|
25
|
+
|
26
|
+
<%= submit_tag t(:changeScopeAsAction), :class => "submit" %>
|
27
|
+
<%- end -%>
|
28
|
+
<%- end -%>
|
29
|
+
<%- end -%>
|
30
|
+
<%= render :partial => "generic_controller/index_table", :locals => { :records => records, :class_name => class_name } %>
|
@@ -32,7 +32,21 @@ module QM
|
|
32
32
|
|
33
33
|
module InstanceMethods
|
34
34
|
def index
|
35
|
-
|
35
|
+
unless instance_variable_defined?(plural_variable)
|
36
|
+
|
37
|
+
if params[:scopes] and params[:scopes].is_a?(Array)
|
38
|
+
valid_scopes = params[:scopes].uniq.each{ |scope| scope if model.generic_named_scopes.has_key? scope.to_sym }.compact
|
39
|
+
if valid_scopes.size > 0
|
40
|
+
data = eval "model.#{valid_scopes.join(".")}"
|
41
|
+
else
|
42
|
+
data = model.all
|
43
|
+
end
|
44
|
+
else
|
45
|
+
data = model.all
|
46
|
+
end
|
47
|
+
|
48
|
+
instance_variable_set(plural_variable, data)
|
49
|
+
end
|
36
50
|
|
37
51
|
respond_to do |format|
|
38
52
|
format.html
|
@@ -32,6 +32,29 @@ module QM
|
|
32
32
|
|
33
33
|
super association_id, options
|
34
34
|
end
|
35
|
+
|
36
|
+
def named_scopes
|
37
|
+
@named_scopes || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def generic_named_scopes
|
41
|
+
scopes = {}
|
42
|
+
named_scopes.each{ |i, o| scopes[i] = o if o.has_key?(:generic) and o[:generic] }
|
43
|
+
scopes
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_generic_named_scopes?
|
47
|
+
generic_named_scopes.size != 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def named_scope(name, options = {}, &block)
|
51
|
+
@named_scopes ||= {}
|
52
|
+
@named_scopes[name.to_sym] = options.dup
|
53
|
+
|
54
|
+
options.delete(:generic) if options.is_a? Hash
|
55
|
+
|
56
|
+
super name, options, &block
|
57
|
+
end
|
35
58
|
|
36
59
|
|
37
60
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qm-acts-as-generic-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcin Lewandowski
|
@@ -62,6 +62,20 @@ dependencies:
|
|
62
62
|
version: "0"
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: calendar_date_select
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: *id004
|
65
79
|
description: "qM: generates generic controller actions and views"
|
66
80
|
email: marcin@saepia.net
|
67
81
|
executables: []
|