abstracted 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/abstract_resources_controller.rb +2 -1
- data/app/controllers/concerns/print_control.rb +3 -2
- data/app/controllers/concerns/resource_control.rb +14 -1
- data/app/helpers/abstract_resources_helper.rb +1 -0
- data/app/models/abstract_resource.rb +50 -0
- data/lib/abstracted/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6732f8f5b0d977b55623928fd4c597835d84b2
|
4
|
+
data.tar.gz: cb180722ccb44e23296b3f67eb0fc8e6f7d6871a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f255f1c62b45a3ebf1089d23aaf53d977c8216930b017737140a7965539f040db7f821aa030dab57efc336f8aac7fa4978e19e83cf32762b49b1891bc38c69d
|
7
|
+
data.tar.gz: d6c6aae54640fd64f6b4a15514b02390e7c10c091fec8dfb56a830ea4264f51cf86b1d767eecf8572bb8bf4199e72d29c285fc347b34313bc012e9c010eebbef
|
@@ -7,11 +7,12 @@ class AbstractResourcesController < ApplicationController
|
|
7
7
|
self.responder = ::AbstractedResponder
|
8
8
|
respond_to :html, :xml, :js, :json
|
9
9
|
|
10
|
+
before_action :authenticate_user!
|
11
|
+
|
10
12
|
include PrintControl
|
11
13
|
include ResourceControl
|
12
14
|
include ParentControl
|
13
15
|
|
14
|
-
before_filter :authenticate_user!
|
15
16
|
before_action :set_fab_button_options
|
16
17
|
before_action :set_variant_template
|
17
18
|
after_action :verify_authorized
|
@@ -107,8 +107,9 @@ module PrintControl
|
|
107
107
|
def display_print_result
|
108
108
|
params[:print][:output_type] ||= 'html'
|
109
109
|
case params[:print][:output_type].downcase
|
110
|
-
|
111
|
-
when '
|
110
|
+
# when 'html'; render params[:print][:view_template_path], layout: 'print'
|
111
|
+
when 'html'; render "stock_items/print/_stock_items_list", layout: 'print'
|
112
|
+
when 'pdf'; render action: :new, status: :unprocessable_entity
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -107,7 +107,7 @@ module ResourceControl
|
|
107
107
|
def resources_url options={}
|
108
108
|
r=request.path
|
109
109
|
options = case params[:action]
|
110
|
-
when 'create','update','delete','destroy';
|
110
|
+
when 'create','update','delete','destroy'; {}
|
111
111
|
else resource_options(options)
|
112
112
|
end
|
113
113
|
return "%s%s" % [r,options] if r.match "#{resource.class.to_s.tableize}$"
|
@@ -134,6 +134,10 @@ module ResourceControl
|
|
134
134
|
else
|
135
135
|
# search
|
136
136
|
r = _search options
|
137
|
+
|
138
|
+
# filter
|
139
|
+
r = _filter r, options
|
140
|
+
|
137
141
|
# sort
|
138
142
|
r = _sort r, options
|
139
143
|
|
@@ -155,6 +159,15 @@ module ResourceControl
|
|
155
159
|
end
|
156
160
|
end
|
157
161
|
|
162
|
+
#
|
163
|
+
# filter - it at all
|
164
|
+
#
|
165
|
+
def _filter r, options
|
166
|
+
return r if params[:f].blank?
|
167
|
+
return resource_class.filter r, params[:f], options if resource_class.respond_to? :filter
|
168
|
+
r
|
169
|
+
end
|
170
|
+
|
158
171
|
#
|
159
172
|
# sort - it at all
|
160
173
|
#
|
@@ -123,6 +123,7 @@ module AbstractResourcesHelper
|
|
123
123
|
#
|
124
124
|
# lnk = parent? ? (parent_url + "/#{resource_name}") : "/#{resource_name}"
|
125
125
|
# lnk += options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&")
|
126
|
+
options = resources if resources.class == Hash
|
126
127
|
opt = {}
|
127
128
|
opt.merge!(options) if options.class==Hash
|
128
129
|
opt[:controller] ||= resource_class.table_name
|
@@ -36,6 +36,56 @@ class AbstractResource < ActiveRecord::Base
|
|
36
36
|
lot.where id: population
|
37
37
|
end
|
38
38
|
|
39
|
+
|
40
|
+
#
|
41
|
+
# filter the lot on filter
|
42
|
+
#
|
43
|
+
# filter => { updated_at: [ '<', '11-11-2011'], material: { eq: 'alu%'}}
|
44
|
+
#
|
45
|
+
def self.filter(lot, filter, options={})
|
46
|
+
filter.clone.each do |fld,v|
|
47
|
+
if v.is_a? Array
|
48
|
+
k = v.shift
|
49
|
+
lot = filter_proc lot, fld, k, v
|
50
|
+
elsif v.is_a? Hash
|
51
|
+
v.each do |k,val|
|
52
|
+
lot = filter_proc lot, fld, k, val
|
53
|
+
end
|
54
|
+
elsif v.is_a? String
|
55
|
+
lot = lot.where( "? = ?", fld, v )
|
56
|
+
else
|
57
|
+
raise "filter valueset '#{v}' not recognised?!"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
lot
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.filter_proc lot, fld, k, v
|
64
|
+
tbl = self.arel_table
|
65
|
+
case k.to_sym
|
66
|
+
when :lt, :lteq, :eq, :gteq, :gt, :matches
|
67
|
+
raise "Exactly one value allowed in filter [lt|eq|gt][|eq]!" if [v].flatten.size > 1
|
68
|
+
lot = lot.where tbl[fld].send k.to_sym, [v].flatten.shift
|
69
|
+
when :not_eq_any, :not_eq_all, :eq_any, :eq_all, :gteq_any, :gteq_all, :gt_any, :gt_all, :lt_any, :lt_all, :lteq_any, :lteq_all
|
70
|
+
raise "At least one value required in filter [|not][lt|eq|gt][_any|_all]!" if [v].flatten.size < 1
|
71
|
+
lot = lot.where tbl[fld].send k, [v].flatten
|
72
|
+
when :between, :not_between
|
73
|
+
raise "Exactly two values allowed in filter [not_]between!" if [v].flatten.size != 2
|
74
|
+
lot = lot.where tbl[fld].send k, [v].flatten
|
75
|
+
when :in, :in_any, :in_all, :not_in, :not_in_any, :not_in_all
|
76
|
+
lot = lot.where tbl[fld].send k, [v].flatten
|
77
|
+
when :matches_any, :matches_all, :does_not_match, :does_not_match_any, :does_not_match_all
|
78
|
+
lot = lot.where tbl[fld].send k, [v].flatten
|
79
|
+
when :matches_regexp, :does_not_match_regexp
|
80
|
+
raise "filter [does_not_]match[es]_regexp is not supported"
|
81
|
+
when :when, :concat
|
82
|
+
raise "filter [when|concat] is not supported"
|
83
|
+
else
|
84
|
+
raise "filter key '#{k}' not recognised?!"
|
85
|
+
end
|
86
|
+
lot
|
87
|
+
end
|
88
|
+
|
39
89
|
# depreciated ------------ 12/3/2016
|
40
90
|
#
|
41
91
|
# ancestry related methods - find them on AncestryAbstractResource
|
data/lib/abstracted/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstracted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Walther H Diechmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|