javy_tool 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/javy_tool/breadcrumb.rb +8 -5
- data/lib/javy_tool/construct_query.rb +8 -6
- data/lib/javy_tool/custom_error.rb +22 -0
- data/lib/javy_tool/version.rb +1 -1
- data/lib/javy_tool.rb +1 -0
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ac9cd0089059b9f4f8fd700234f22f459eaef30608b2e812c8bfb0fcf6941f5
|
4
|
+
data.tar.gz: 154e244838aa290c18219aa4edb0e356e2ac254ca8ce0402acae17a628d6e6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd3ff14eb1f6164dd6fda936655dac282bb5071a23e1fe1b959dbd5ec6ac27d571cf5a3656ed9148812581421e21ca0c7b88eefa6d16206b46906c34a2b4ec34
|
7
|
+
data.tar.gz: b5b10a02788385a9e24feb34f4bd387f827af666aa15fba49f67c82d2d8823a193766805df240294ef85f431df6833493f7c6520f6a94b3bfcbda0b340c536e8
|
data/lib/javy_tool/breadcrumb.rb
CHANGED
@@ -8,7 +8,8 @@ module JavyTool
|
|
8
8
|
protected
|
9
9
|
|
10
10
|
def set_breadcrumbs
|
11
|
-
|
11
|
+
#Rails.logger.info I18n.locale
|
12
|
+
@breadcrumbs = ["#{I18n.t('common.index_icon')}#{view_context.link_to(I18n.t('common.home'), root_path)}".html_safe]
|
12
13
|
end
|
13
14
|
|
14
15
|
def drop_breadcrumb(title=nil, url=nil)
|
@@ -52,12 +53,13 @@ module JavyTool
|
|
52
53
|
|
53
54
|
|
54
55
|
# display the flash messages using foundation
|
55
|
-
def notice_message
|
56
|
+
def notice_message(cls: 'alert-box')
|
56
57
|
flash_messages = []
|
57
58
|
flash.each do |type, message|
|
59
|
+
next if message.nil?
|
58
60
|
type = :info if type == :notice
|
59
61
|
type = :alert if type == :error
|
60
|
-
text = content_tag(:div, message.html_safe, class: "
|
62
|
+
text = content_tag(:div, message.html_safe, class: "#{cls} #{type}")
|
61
63
|
flash_messages << text if message
|
62
64
|
end
|
63
65
|
flash_messages.join("\n").html_safe
|
@@ -148,12 +150,13 @@ module JavyTool
|
|
148
150
|
# });
|
149
151
|
#
|
150
152
|
#
|
151
|
-
def link_to_add_fields(name, f, association,new_object=nil)
|
153
|
+
def link_to_add_fields(name, f, association,new_object=nil,options={})
|
152
154
|
new_object ||= f.object.class.reflect_on_association(association).klass.new()
|
153
155
|
fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder|
|
154
156
|
render(association.to_s.singularize + "_fields", :f => builder)
|
155
157
|
end
|
156
|
-
|
158
|
+
options.merge!(data: {association: association,content: escape_javascript(fields.html_safe)},class: "add_fields")
|
159
|
+
link_to(name,"#",options)
|
157
160
|
end
|
158
161
|
|
159
162
|
|
@@ -6,7 +6,7 @@ module JavyTool
|
|
6
6
|
#model_class: 查询的类名,字符串类型
|
7
7
|
#param: 查询参数,为空的话默认用model_class参数的underscore版本
|
8
8
|
#返回数组 [普通条件,like条件]
|
9
|
-
def construct_condition(model_class,like_ary: [],param: nil,gt:[],lt:[])
|
9
|
+
def construct_condition(model_class,like_ary: [],left_like:[],right_like:[],param: nil,gt:[],lt:[])
|
10
10
|
model_class = model_class.to_s
|
11
11
|
_class = model_class.classify.constantize
|
12
12
|
param = param || model_class.underscore
|
@@ -18,19 +18,21 @@ module JavyTool
|
|
18
18
|
con_hash = params[param].select{|_,value|value.present?}
|
19
19
|
if con_hash.present?
|
20
20
|
_like_con = con_hash.extract!(*(like_ary.collect{|item| item.to_s} & con_hash.keys)).map{|k,v| ["#{k} like ?","%#{v}%"] } if like_ary.present?
|
21
|
+
_left_like_con = con_hash.extract!(*(left_like.collect{|item| item.to_s} & con_hash.keys)).map{|k,v| ["#{k} like ?","#{v}%"] } if left_like.present?
|
22
|
+
_right_like_con = con_hash.extract!(*(right_like.collect{|item| item.to_s} & con_hash.keys)).map{|k,v| ["#{k} like ?","#{v}%"] } if right_like.present?
|
21
23
|
|
22
24
|
if gt.present?
|
23
|
-
gt.collect!
|
25
|
+
gt.collect!(&:to_s)
|
24
26
|
gt = (gt + gt.map{|item| "gt_#{item}"}) & con_hash.keys
|
25
|
-
_gt_con=con_hash.extract!(*gt).
|
27
|
+
_gt_con=con_hash.extract!(*gt).map{|k,v| ["#{k.sub(/^gt_/,'')} >= ?",v] }
|
26
28
|
end
|
27
29
|
if lt.present?
|
28
|
-
lt.collect!
|
30
|
+
lt.collect!(&:to_s)
|
29
31
|
lt = (lt + lt.map{|item| "lt_#{item}"}) & con_hash.keys
|
30
|
-
_lt_con= con_hash.extract!(*lt).
|
32
|
+
_lt_con= con_hash.extract!(*lt).map{|k,v| ["#{k.sub(/^lt_/,'')} <= ?",v] }
|
31
33
|
end
|
32
34
|
|
33
|
-
all_ary_con = ((_like_con || [])+(_gt_con||[])+(_lt_con||[])).transpose
|
35
|
+
all_ary_con = ((_left_like_con || [])+(_right_like_con || [])+(_like_con || [])+(_gt_con||[])+(_lt_con||[])).transpose
|
34
36
|
all_ary_con = [all_ary_con.first.join(" and "),all_ary_con.last].flatten if all_ary_con.present?
|
35
37
|
#适用于查询字段为空的情况
|
36
38
|
con_hash.each{|k,v|con_hash[k] = nil if v == 'null'}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module JavyTool
|
2
|
+
module CustomError
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class AccessDenied < Error
|
6
|
+
attr_reader :action, :subject
|
7
|
+
attr_writer :default_message
|
8
|
+
|
9
|
+
def initialize(message = nil, action = nil, subject = nil)
|
10
|
+
@message = message
|
11
|
+
@action = action
|
12
|
+
@subject = subject
|
13
|
+
@default_message = I18n.t(:"custom_error.default", :default => "Access this page error.")
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@message || @default_message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/lib/javy_tool/version.rb
CHANGED
data/lib/javy_tool.rb
CHANGED
@@ -5,6 +5,7 @@ module JavyTool
|
|
5
5
|
autoload :Breadcrumb, "javy_tool/breadcrumb"
|
6
6
|
autoload :Csv, "javy_tool/csv"
|
7
7
|
autoload :ConstructQuery, "javy_tool/construct_query"
|
8
|
+
autoload :CustomError, "javy_tool/custom_error"
|
8
9
|
mattr_accessor :tool_config
|
9
10
|
mattr_accessor :upload_path
|
10
11
|
@@upload_path = "/tmp"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: javy_tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javy_liu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: pack some used methods
|
14
14
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/javy_tool/breadcrumb.rb
|
28
28
|
- lib/javy_tool/construct_query.rb
|
29
29
|
- lib/javy_tool/csv.rb
|
30
|
+
- lib/javy_tool/custom_error.rb
|
30
31
|
- lib/javy_tool/utils.rb
|
31
32
|
- lib/javy_tool/version.rb
|
32
33
|
homepage: https://github.com/javyliu/javy_tool
|
@@ -48,10 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: '0'
|
50
51
|
requirements: []
|
51
|
-
|
52
|
-
rubygems_version: 2.4.6
|
52
|
+
rubygems_version: 3.0.2
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: some methods ofen used in my projects
|
56
56
|
test_files: []
|
57
|
-
has_rdoc:
|