erp_tech_svcs 4.0.0 → 4.2.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/README.md +0 -24
- data/app/controllers/api/v1/audit_log_items_controller.rb +33 -0
- data/app/controllers/api/v1/audit_logs_controller.rb +32 -0
- data/app/controllers/api/v1/capabilities_controller.rb +160 -0
- data/app/controllers/api/v1/file_assets_controller.rb +40 -0
- data/app/controllers/api/v1/groups_controller.rb +236 -0
- data/app/controllers/api/v1/security_roles_controller.rb +276 -0
- data/app/controllers/api/v1/users_controller.rb +262 -0
- data/app/controllers/erp_tech_svcs/session_controller.rb +8 -5
- data/app/controllers/erp_tech_svcs/user_controller.rb +14 -15
- data/app/mailers/user_mailer.rb +8 -5
- data/app/models/audit_log.rb +111 -36
- data/app/models/audit_log_item.rb +30 -0
- data/app/models/audit_log_item_type.rb +1 -0
- data/app/models/audit_log_type.rb +19 -0
- data/app/models/capability.rb +22 -6
- data/app/models/extensions/tracked_status_type.rb +3 -0
- data/app/models/file_asset.rb +245 -20
- data/app/models/file_asset_holder.rb +20 -0
- data/app/models/group.rb +38 -25
- data/app/models/notification.rb +32 -13
- data/app/models/notification_type.rb +13 -0
- data/app/models/security_role.rb +17 -4
- data/app/models/user.rb +116 -29
- data/app/validators/password_strength_validator.rb +1 -1
- data/app/views/user_mailer/activation_needed_email.html.erb +293 -15
- data/app/views/user_mailer/reset_password_email.html.erb +268 -13
- data/config/initializers/logger.rb +19 -0
- data/config/initializers/sorcery.rb +2 -0
- data/config/initializers/wickedpdf.rb +4 -0
- data/config/routes.rb +64 -0
- data/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb +1 -5
- data/db/data_migrations/20150819140550_create_job_tracker_for_notification.rb +14 -0
- data/db/migrate/20080805000010_base_tech_services.rb +99 -39
- data/db/migrate/20150414151421_add_nested_set_columns_to_security_role.rb +13 -0
- data/db/migrate/20150609003216_update_user_for_sorcery.rb +11 -0
- data/db/migrate/20150819135108_add_custom_fields_to_notifications.rb +5 -0
- data/db/migrate/20160122155402_add_description_to_file_asset.rb +13 -0
- data/db/migrate/20160310163060_add_created_by_updated_by_to_erp_tech_svcs.rb +35 -0
- data/db/migrate/20160313161611_add_tenant_id_to_audit_log.rb +16 -0
- data/lib/erp_tech_svcs.rb +6 -10
- data/lib/erp_tech_svcs/config.rb +7 -2
- data/lib/erp_tech_svcs/delayed_jobs/delete_expired_sessions_job.rb +49 -0
- data/lib/erp_tech_svcs/delayed_jobs/notification_job.rb +50 -0
- data/lib/erp_tech_svcs/engine.rb +0 -1
- data/lib/erp_tech_svcs/erp_tech_svcs_audit_log.rb +12 -6
- data/lib/erp_tech_svcs/extensions.rb +0 -1
- data/lib/erp_tech_svcs/extensions/active_record/has_capability_accessors.rb +57 -29
- data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +57 -31
- data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +12 -4
- data/lib/erp_tech_svcs/extensions/active_record/is_json.rb +22 -15
- data/lib/erp_tech_svcs/extensions/active_record/scoped_by.rb +16 -13
- data/lib/erp_tech_svcs/extensions/compass_ae/erp_base_erp_svcs/controllers/api/parties_controller.rb +15 -0
- data/lib/erp_tech_svcs/file_support.rb +1 -0
- data/lib/erp_tech_svcs/file_support/file_system_manager.rb +77 -44
- data/lib/erp_tech_svcs/file_support/manager.rb +12 -3
- data/lib/erp_tech_svcs/file_support/railties/compass_ae_resolver.rb +49 -0
- data/lib/erp_tech_svcs/file_support/s3_manager.rb +73 -51
- data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +11 -2
- data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +238 -46
- data/lib/erp_tech_svcs/version.rb +1 -1
- data/lib/tasks/erp_tech_svcs_tasks.rake +43 -5
- metadata +73 -42
- data/app/models/user_defined_data.rb +0 -6
- data/app/models/user_defined_field.rb +0 -8
- data/config/initializers/pdfkit.rb +0 -18
- data/db/data_migrations/20121130212146_note_capabilities.rb +0 -23
- data/db/migrate/20121116151510_create_groups.rb +0 -18
- data/db/migrate/20121126171612_upgrade_security.rb +0 -53
- data/db/migrate/20121126173506_upgrade_security2.rb +0 -274
- data/db/migrate/20130410135419_add_queue_to_delayed_jobs.rb +0 -13
- data/db/migrate/20130610163240_create_notifications.rb +0 -37
- data/db/migrate/20130725212647_add_party_id_idx_to_users.rb +0 -9
- data/db/migrate/20131113213843_add_audit_log_item_old_value.rb +0 -13
- data/db/migrate/20131113213844_add_erp_tech_svcs_missing_indexes.rb +0 -31
- data/db/migrate/20131129203603_add_user_defined_fields.rb +0 -43
- data/db/migrate/20141013060204_add_custom_fields_to_notifications.rb +0 -12
- data/db/migrate/20141108182427_add_scoped_by_to_file_assets.rb +0 -14
- data/lib/erp_tech_svcs/extensions/active_record/has_user_defined_data.rb +0 -147
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_job.rb +0 -47
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_service.rb +0 -15
- data/lib/erp_tech_svcs/utils/compass_logger.rb +0 -87
@@ -1,25 +1,40 @@
|
|
1
1
|
module ErpTechSvcs
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
2
|
+
module Extensions
|
3
|
+
module ActiveRecord
|
4
|
+
module HasFileAssets
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
# If set to auto destroy any files related to a model via this mixin will automatically be removed
|
11
|
+
# regardless of any other relationships they have. It defaults to true since most files
|
12
|
+
# should be removed when the model is removed.
|
13
|
+
module ClassMethods
|
14
|
+
def has_file_assets(auto_destroy=true)
|
15
|
+
extend HasFileAssets::SingletonMethods
|
16
|
+
include HasFileAssets::InstanceMethods
|
17
|
+
|
18
|
+
if auto_destroy
|
19
|
+
before_destroy :destroy_all_files
|
20
|
+
end
|
21
|
+
|
22
|
+
has_many :file_asset_holders,
|
23
|
+
:as => :file_asset_holder,
|
24
|
+
:dependent => :destroy
|
25
|
+
|
26
|
+
has_many :files,
|
27
|
+
:through => :file_asset_holders,
|
28
|
+
:class_name => 'FileAsset',
|
29
|
+
:source => :file_asset,
|
30
|
+
:include => :capabilities
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module SingletonMethods
|
35
|
+
end
|
36
|
+
|
37
|
+
module InstanceMethods
|
23
38
|
|
24
39
|
# Capabilites can be passed via a hash
|
25
40
|
# {
|
@@ -28,22 +43,25 @@ module ErpTechSvcs
|
|
28
43
|
# }
|
29
44
|
#
|
30
45
|
def add_file(data, path=nil, capabilities=nil)
|
31
|
-
|
46
|
+
file_asset = FileAsset.create!(:base_path => path, :data => data)
|
32
47
|
|
33
|
-
#set capabilites if they are passed
|
48
|
+
# set capabilites if they are passed
|
34
49
|
capabilities.each do |capability_type, roles|
|
35
50
|
file_asset.add_capability(capability_type, nil, roles)
|
36
51
|
end if capabilities
|
37
52
|
|
53
|
+
self.files << file_asset
|
54
|
+
self.save
|
55
|
+
|
38
56
|
file_asset
|
39
57
|
end
|
40
58
|
|
41
59
|
def images
|
42
|
-
|
60
|
+
self.files.where('type = ?', 'Image')
|
43
61
|
end
|
44
62
|
|
45
63
|
def templates
|
46
|
-
|
64
|
+
self.files.where('type = ?', 'Template')
|
47
65
|
end
|
48
66
|
|
49
67
|
def stylesheets
|
@@ -57,9 +75,17 @@ module ErpTechSvcs
|
|
57
75
|
def xmls
|
58
76
|
self.files.where('type = ?', 'XmlFile')
|
59
77
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
78
|
+
|
79
|
+
# destroy all files related to this model regardless of other relationships
|
80
|
+
def destroy_all_files
|
81
|
+
statement = "delete from file_assets where id in (select file_asset_id from file_asset_holders where (file_asset_holder_type = '#{self.class.to_s}' or file_asset_holder_type = '#{self.class.superclass.to_s}' ) and file_asset_holder_id = #{self.id} )"
|
82
|
+
|
83
|
+
::ActiveRecord::Base.connection.execute(statement)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end # HasFileAssets
|
89
|
+
end # ActiveRecord
|
90
|
+
end # Extensions
|
91
|
+
end # ErpTechSvcs
|
@@ -32,7 +32,7 @@ module ErpTechSvcs
|
|
32
32
|
|
33
33
|
def roles
|
34
34
|
self.security_roles
|
35
|
-
|
35
|
+
end
|
36
36
|
|
37
37
|
def add_role(role)
|
38
38
|
role = role.is_a?(SecurityRole) ? role : SecurityRole.find_by_internal_identifier(role.to_s)
|
@@ -40,7 +40,8 @@ module ErpTechSvcs
|
|
40
40
|
self.security_roles << role
|
41
41
|
self.save
|
42
42
|
end
|
43
|
-
|
43
|
+
end
|
44
|
+
alias :add_security_role :add_role
|
44
45
|
|
45
46
|
def add_roles(*passed_roles)
|
46
47
|
passed_roles.flatten!
|
@@ -49,23 +50,28 @@ module ErpTechSvcs
|
|
49
50
|
self.add_role(role)
|
50
51
|
end
|
51
52
|
end
|
53
|
+
alias :add_security_roles :add_roles
|
52
54
|
|
53
55
|
def remove_role(role)
|
54
56
|
role = role.is_a?(SecurityRole) ? role : SecurityRole.find_by_internal_identifier(role.to_s)
|
55
57
|
self.security_roles.delete(role) if has_role?(role)
|
56
|
-
|
58
|
+
end
|
59
|
+
alias :remove_security_role :remove_role
|
60
|
+
|
57
61
|
|
58
62
|
def remove_roles(*passed_roles)
|
59
63
|
passed_roles.flatten!
|
60
64
|
passed_roles.each do |role|
|
61
65
|
self.remove_role(role)
|
62
66
|
end
|
63
|
-
|
67
|
+
end
|
68
|
+
alias :remove_security_roles :remove_roles
|
64
69
|
|
65
70
|
def remove_all_roles
|
66
71
|
self.security_roles = []
|
67
72
|
self.save
|
68
73
|
end
|
74
|
+
alias :remove_all_security_roles :remove_all_roles
|
69
75
|
|
70
76
|
def has_role?(*passed_roles)
|
71
77
|
result = false
|
@@ -80,6 +86,8 @@ module ErpTechSvcs
|
|
80
86
|
end
|
81
87
|
result
|
82
88
|
end
|
89
|
+
alias :has_security_role? :has_role?
|
90
|
+
|
83
91
|
end
|
84
92
|
end #HasSecurityRoles
|
85
93
|
end #ActiveRecord
|
@@ -13,36 +13,43 @@ module ErpTechSvcs
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
15
|
|
16
|
-
def is_json(attr_name
|
17
|
-
|
18
|
-
class_name
|
19
|
-
else
|
20
|
-
case ::ActiveRecord::Base.connection.instance_values["config"][:adapter]
|
21
|
-
when 'postgresql'
|
22
|
-
::ActiveRecord::Coders::NestedHstore
|
23
|
-
else
|
24
|
-
JSON
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
serialize attr_name, class_name
|
16
|
+
def is_json(attr_name)
|
17
|
+
serialize attr_name, JSON
|
30
18
|
|
31
19
|
extend SingletonMethods
|
32
20
|
include InstanceMethods
|
33
21
|
|
34
22
|
# create method to initialize the json field with an empty hash
|
35
23
|
define_method("initialize_#{attr_name}_json") do
|
36
|
-
if
|
24
|
+
if attributes.keys.include?(attr_name.to_s) && send("#{attr_name}").nil?
|
37
25
|
send("#{attr_name}=", {})
|
38
26
|
end
|
39
27
|
end
|
40
28
|
after_initialize "initialize_#{attr_name}_json"
|
29
|
+
|
30
|
+
define_method("stringify_keys_for_#{attr_name}_json") do
|
31
|
+
if send(attr_name).is_a?(Hash)
|
32
|
+
send("#{attr_name}=", send(attr_name).stringify_keys)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
before_save "stringify_keys_for_#{attr_name}_json".to_sym
|
41
36
|
end
|
42
37
|
|
43
38
|
end
|
44
39
|
|
45
40
|
module SingletonMethods
|
41
|
+
def matches_is_json(attr_name, keyword, attr=nil)
|
42
|
+
if attr
|
43
|
+
arel_table[attr_name.to_sym].matches("%\"#{attr}\":\"#{keyword}\"%").
|
44
|
+
or(arel_table[attr_name.to_sym].matches("%\"#{attr}\":#{keyword}%"))
|
45
|
+
else
|
46
|
+
arel_table[attr_name.to_sym].matches("%#{keyword}%")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_json_attribute(attr_name, attr, keyword)
|
51
|
+
where(self.matches_is_json(attr_name, keyword, attr))
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
55
|
module InstanceMethods
|
@@ -10,15 +10,24 @@ module ErpTechSvcs
|
|
10
10
|
base.extend(ClassMethods)
|
11
11
|
end
|
12
12
|
|
13
|
+
def _config
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
13
17
|
module ClassMethods
|
14
18
|
|
15
|
-
def add_scoped_by(attr_name)
|
19
|
+
def add_scoped_by(attr_name=:scoped_by)
|
16
20
|
# serialize Scope attributes
|
17
21
|
is_json attr_name
|
18
22
|
|
19
23
|
extend SingletonMethods
|
20
24
|
include InstanceMethods
|
21
25
|
|
26
|
+
# create method to retrieve scoped_by attribute name
|
27
|
+
define_singleton_method("retrieve_scoped_by_name") do
|
28
|
+
attr_name
|
29
|
+
end
|
30
|
+
|
22
31
|
# create method to initialize the json field with an empty hash
|
23
32
|
define_method("initialize_#{attr_name}_scoped_by_json") do
|
24
33
|
if self.new_record?
|
@@ -32,28 +41,23 @@ module ErpTechSvcs
|
|
32
41
|
|
33
42
|
module SingletonMethods
|
34
43
|
def scoped_by(scope_name, scope_value)
|
35
|
-
|
36
|
-
where("(scoped_by @> '\"#{scope_name}\"=>\"#{scope_value}\"'::hstore )")
|
37
|
-
else
|
38
|
-
where(arel_table[:scoped_by].matches("%\"#{scope_name}\":\"#{scope_value}\"%")
|
39
|
-
.or(arel_table[:scoped_by].matches("%\"#{scope_name}\":#{scope_value}%")))
|
40
|
-
end
|
44
|
+
where(arel_table[retrieve_scoped_by_name].matches("%\"#{scope_name}\":\"#{scope_value}\"%").or(arel_table[retrieve_scoped_by_name].matches("%\"#{scope_name}\":#{scope_value}%")))
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
48
|
module InstanceMethods
|
45
49
|
def add_scope(scope_name, scope_value)
|
46
|
-
|
47
|
-
save
|
50
|
+
send(self.class.retrieve_scoped_by_name)[scope_name.to_s] = scope_value
|
51
|
+
save!
|
48
52
|
end
|
49
53
|
|
50
54
|
def remove_scope(scope_name)
|
51
|
-
|
52
|
-
save
|
55
|
+
send(self.class.retrieve_scoped_by_name)[scope_name.to_s] = nil
|
56
|
+
save!
|
53
57
|
end
|
54
58
|
|
55
59
|
def get_scope(scope_name)
|
56
|
-
|
60
|
+
send(self.class.retrieve_scoped_by_name)[scope_name.to_s]
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -61,4 +65,3 @@ module ErpTechSvcs
|
|
61
65
|
end # ActiveRecord
|
62
66
|
end # Extensions
|
63
67
|
end # ErpTechSvcs
|
64
|
-
|
data/lib/erp_tech_svcs/extensions/compass_ae/erp_base_erp_svcs/controllers/api/parties_controller.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Api::V1::PartiesController.class_eval do
|
2
|
+
|
3
|
+
def user
|
4
|
+
party = Party.find(params[:id])
|
5
|
+
|
6
|
+
user = party.user
|
7
|
+
|
8
|
+
if user
|
9
|
+
render json: {success: true, user: user.to_data_hash}
|
10
|
+
else
|
11
|
+
render json: {success: true, user: nil}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -6,6 +6,7 @@ require 'erp_tech_svcs/file_support/file_manipulator'
|
|
6
6
|
|
7
7
|
#path resolvers
|
8
8
|
require 'erp_tech_svcs/file_support/railties/s3_resolver'
|
9
|
+
require 'erp_tech_svcs/file_support/railties/compass_ae_resolver'
|
9
10
|
|
10
11
|
#paperclip
|
11
12
|
require 'erp_tech_svcs/file_support/paperclip_patch'
|
@@ -8,12 +8,12 @@ module ErpTechSvcs
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def update_file(path, content)
|
11
|
-
File.open(path, 'wb+') {|f| f.write(content) }
|
11
|
+
File.open(path, 'wb+') { |f| f.write(content) }
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_file(path, name, contents)
|
15
15
|
FileUtils.mkdir_p path unless File.exists? path
|
16
|
-
File.open(File.join(path,name), 'wb+') {|f| f.write(contents) }
|
16
|
+
File.open(File.join(path, name), 'wb+') { |f| f.write(contents) }
|
17
17
|
end
|
18
18
|
|
19
19
|
# copy a file
|
@@ -24,12 +24,14 @@ module ErpTechSvcs
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def create_folder(path, name)
|
27
|
-
|
27
|
+
unless File.directory? File.join(path, name)
|
28
|
+
FileUtils.mkdir_p File.join(path, name)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
def save_move(path, new_parent_path)
|
31
33
|
old_path = File.join(path)
|
32
|
-
new_path = File.join(Rails.root,new_parent_path)
|
34
|
+
new_path = File.join(Rails.root, new_parent_path)
|
33
35
|
result = false
|
34
36
|
unless File.exists? old_path
|
35
37
|
message = FILE_DOES_NOT_EXIST
|
@@ -37,7 +39,7 @@ module ErpTechSvcs
|
|
37
39
|
name = File.basename(path)
|
38
40
|
#make sure path is there.
|
39
41
|
FileUtils.mkdir_p new_path unless File.directory? new_path
|
40
|
-
FileUtils.mv(old_path, File.join(new_path,name))
|
42
|
+
FileUtils.mv(old_path, File.join(new_path, name))
|
41
43
|
message = "#{name} was moved to #{new_parent_path} successfully"
|
42
44
|
result = true
|
43
45
|
end
|
@@ -77,12 +79,18 @@ module ErpTechSvcs
|
|
77
79
|
if File.directory? path
|
78
80
|
is_directory = true
|
79
81
|
entries = Dir.entries(path)
|
80
|
-
entries.delete_if{|entry| entry =~ REMOVE_FILES_REGEX}
|
82
|
+
entries.delete_if { |entry| entry =~ REMOVE_FILES_REGEX }
|
81
83
|
if entries.count > 0 && !options[:force]
|
82
84
|
message = FOLDER_IS_NOT_EMPTY
|
83
85
|
result = false
|
84
86
|
else
|
85
87
|
FileUtils.rm_rf(path)
|
88
|
+
|
89
|
+
child_files = FileAsset.where(FileAsset.arel_table[:directory].matches("#{path.gsub(root, '')}%"))
|
90
|
+
child_files.each do |file|
|
91
|
+
file.destroy
|
92
|
+
end
|
93
|
+
|
86
94
|
message = "Folder #{name} was deleted #{name} successfully"
|
87
95
|
result = true
|
88
96
|
end
|
@@ -102,7 +110,7 @@ module ErpTechSvcs
|
|
102
110
|
unless File.exists? path
|
103
111
|
message = FILE_DOES_NOT_EXIST
|
104
112
|
else
|
105
|
-
contents = File.open(path, 'rb') {|file| file.read }
|
113
|
+
contents = File.open(path, 'rb') { |file| file.read }
|
106
114
|
end
|
107
115
|
return contents, message
|
108
116
|
end
|
@@ -112,65 +120,90 @@ module ErpTechSvcs
|
|
112
120
|
end
|
113
121
|
|
114
122
|
def find_node(path, options={})
|
115
|
-
|
123
|
+
if options[:file_asset_holder]
|
116
124
|
super
|
117
125
|
else
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
parent
|
126
|
-
|
126
|
+
if File.exists? path
|
127
|
+
if File.directory? path
|
128
|
+
path_pieces = path.split('/')
|
129
|
+
parent = build_tree_for_directory(path, options)
|
130
|
+
unless parent[:id] == path
|
131
|
+
path_pieces.each do |path_piece|
|
132
|
+
next if path_piece.blank?
|
133
|
+
parent[:children].each do |child_node|
|
134
|
+
if child_node[:text] == path_piece
|
135
|
+
parent = child_node
|
136
|
+
break
|
137
|
+
end
|
138
|
+
end
|
127
139
|
end
|
128
140
|
end
|
141
|
+
|
142
|
+
parent = nil if parent[:id] != path
|
143
|
+
parent
|
144
|
+
else
|
145
|
+
build_node(path, options)
|
129
146
|
end
|
147
|
+
else
|
148
|
+
nil
|
130
149
|
end
|
131
|
-
|
132
|
-
parent = nil if parent[:id] != path
|
133
|
-
parent
|
134
150
|
end
|
151
|
+
end
|
135
152
|
|
136
|
-
|
153
|
+
def build_node(path, options={})
|
154
|
+
if File.directory?(path)
|
155
|
+
if options[:preload]
|
156
|
+
build_tree_for_directory(path, options) if options[:preload]
|
157
|
+
else
|
158
|
+
path.gsub!(root, '') unless options[:keep_full_path]
|
159
|
+
|
160
|
+
{:text => path.split('/').last, :id => path, :iconCls => 'icon-content'}
|
161
|
+
end
|
162
|
+
else
|
163
|
+
path.gsub!(root, '') unless options[:keep_full_path]
|
164
|
+
|
165
|
+
parts = path.split('/')
|
166
|
+
parts.pop
|
167
|
+
download_path = parts.join('/')
|
168
|
+
|
169
|
+
if !options[:included_file_extensions_regex].nil? && entry =~ options[:included_file_extensions_regex]
|
170
|
+
{:text => path.split('/').last, :leaf => true, :iconCls => 'icon-document', :downloadPath => download_path, :id => path}
|
171
|
+
elsif options[:included_file_extensions_regex].nil?
|
172
|
+
{:text => path.split('/').last, :leaf => true, :iconCls => 'icon-document', :downloadPath => download_path, :id => path}
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
137
176
|
end
|
138
177
|
|
139
178
|
private
|
140
179
|
|
141
180
|
def build_tree_for_directory(directory, options)
|
142
|
-
keep_full_path
|
143
|
-
|
144
|
-
tree_data = {:text => directory.split('/').last, :id => directory, :leaf => false, :children => []}
|
145
|
-
else
|
146
|
-
keep_full_path = true
|
147
|
-
tree_data = {:text => directory.split('/').last, :id => directory, :leaf => false, :children => []}
|
181
|
+
if options[:keep_full_path] != false and !directory.index(root).nil?
|
182
|
+
options[:keep_full_path] = true
|
148
183
|
end
|
149
184
|
|
185
|
+
tree_data = {
|
186
|
+
:text => directory.split('/').last,
|
187
|
+
:iconCls => File.directory?(directory) ? 'icon-content' : 'icon-document',
|
188
|
+
:id => directory,
|
189
|
+
:leaf => !File.directory?(directory),
|
190
|
+
:children => []
|
191
|
+
}
|
192
|
+
|
193
|
+
tree_data[:id].gsub!(root, '') unless options[:keep_full_path]
|
194
|
+
|
150
195
|
Dir.entries(directory).each do |entry|
|
151
196
|
#ignore .svn folders and any other folders starting with .
|
152
197
|
next if entry =~ REMOVE_FILES_REGEX
|
153
198
|
|
154
|
-
|
155
|
-
path.gsub!(root,'') unless keep_full_path
|
199
|
+
tree_data[:children] << build_node(File.join(directory, entry), options)
|
156
200
|
|
157
|
-
if File.directory?(File.join(directory,entry))
|
158
|
-
tree_data[:children] << if options[:preload]
|
159
|
-
build_tree_for_directory(path, options) if options[:preload]
|
160
|
-
else
|
161
|
-
{:text => entry, :id => path, :iconCls => 'icon-content'}
|
162
|
-
end
|
163
|
-
elsif !options[:included_file_extensions_regex].nil? && entry =~ options[:included_file_extensions_regex]
|
164
|
-
tree_data[:children] << {:text => entry, :leaf => true, :iconCls => 'icon-document', :downloadPath => directory, :id => path}
|
165
|
-
elsif options[:included_file_extensions_regex].nil?
|
166
|
-
tree_data[:children] << {:text => entry, :leaf => true, :iconCls => 'icon-document', :downloadPath => directory, :id => path}
|
167
|
-
end
|
168
201
|
end if File.directory?(directory)
|
169
202
|
|
170
|
-
tree_data[:children].sort_by!{|item| [item[:text]]}
|
203
|
+
tree_data[:children].sort_by! { |item| [item[:text]] }
|
171
204
|
tree_data
|
172
205
|
end
|
173
206
|
|
174
|
-
end#FileSystemManager
|
175
|
-
end#FileSupport
|
176
|
-
end#ErpTechSvcs
|
207
|
+
end #FileSystemManager
|
208
|
+
end #FileSupport
|
209
|
+
end #ErpTechSvcs
|