forest_admin_agent 1.0.0.pre.beta.47 → 1.0.0.pre.beta.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/forest_admin_agent.gemspec +1 -1
- data/lib/forest_admin_agent/http/router.rb +2 -0
- data/lib/forest_admin_agent/routes/abstract_route.rb +2 -2
- data/lib/forest_admin_agent/routes/resources/csv.rb +51 -0
- data/lib/forest_admin_agent/routes/resources/list.rb +0 -1
- data/lib/forest_admin_agent/routes/resources/related/csv_related.rb +60 -0
- data/lib/forest_admin_agent/routes/resources/related/list_related.rb +0 -1
- data/lib/forest_admin_agent/utils/csv_generator.rb +44 -0
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/version.rb +1 -1
- metadata +6 -4
- data/README.md +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40e4df2d99083f936e9cf9a4693f20d69cc6d3b2b86d8ef8c66abafdbd554d2b
|
4
|
+
data.tar.gz: 732d5c6d7c20f67558d609c1a8e28d834bbb1b01bd0880988721409e4bc564d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '009c1d66c244400c79b66dc66fa1acd0bcdd80de1c7cea811050352bdc1dc6ec494025a732f2a52b9368319db782da1fb720aa0cef1bc2d427c98a145da5614d'
|
7
|
+
data.tar.gz: a349fd075afbc6ed33fd44aba00dcd71f79b2d8ec767b4877f7756c41540368f25827a2501b825b92af08e7db9ce426a8009972a0af44f5a2334acc75fc5ac29
|
data/forest_admin_agent.gemspec
CHANGED
@@ -17,7 +17,7 @@ admin work on any Ruby application."
|
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/ForestAdmin/agent-ruby"
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/ForestAdmin/agent-ruby/CHANGELOG.md"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/ForestAdmin/agent-ruby/blob/main/CHANGELOG.md"
|
21
21
|
spec.metadata["rubygems_mfa_required"] = "false"
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
@@ -12,10 +12,12 @@ module ForestAdminAgent
|
|
12
12
|
Charts::Charts.new.routes,
|
13
13
|
Resources::Count.new.routes,
|
14
14
|
Resources::Delete.new.routes,
|
15
|
+
Resources::Csv.new.routes,
|
15
16
|
Resources::List.new.routes,
|
16
17
|
Resources::Show.new.routes,
|
17
18
|
Resources::Store.new.routes,
|
18
19
|
Resources::Update.new.routes,
|
20
|
+
Resources::Related::CsvRelated.new.routes,
|
19
21
|
Resources::Related::ListRelated.new.routes,
|
20
22
|
Resources::Related::CountRelated.new.routes,
|
21
23
|
Resources::Related::AssociateRelated.new.routes,
|
@@ -15,8 +15,8 @@ module ForestAdminAgent
|
|
15
15
|
@routes ||= {}
|
16
16
|
end
|
17
17
|
|
18
|
-
def add_route(name, method, uri, closure)
|
19
|
-
@routes[name] = { method: method, uri: uri, closure: closure }
|
18
|
+
def add_route(name, method, uri, closure, format = 'json')
|
19
|
+
@routes[name] = { method: method, uri: uri, closure: closure, format: format }
|
20
20
|
end
|
21
21
|
|
22
22
|
def setup_routes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ForestAdminAgent
|
2
|
+
module Routes
|
3
|
+
module Resources
|
4
|
+
class Csv < AbstractAuthenticatedRoute
|
5
|
+
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
6
|
+
include ForestAdminAgent::Utils
|
7
|
+
|
8
|
+
def setup_routes
|
9
|
+
add_route(
|
10
|
+
'forest_list_csv',
|
11
|
+
'get',
|
12
|
+
'/:collection_name.:format',
|
13
|
+
->(args) { handle_request(args) },
|
14
|
+
'csv'
|
15
|
+
)
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_request(args = {})
|
21
|
+
build(args)
|
22
|
+
@permissions.can?(:browse, @collection)
|
23
|
+
@permissions.can?(:export, @collection)
|
24
|
+
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
25
|
+
condition_tree: ConditionTreeFactory.intersect(
|
26
|
+
[
|
27
|
+
@permissions.get_scope(@collection),
|
28
|
+
ForestAdminAgent::Utils::QueryStringParser.parse_condition_tree(
|
29
|
+
@collection, args
|
30
|
+
)
|
31
|
+
]
|
32
|
+
),
|
33
|
+
search: ForestAdminAgent::Utils::QueryStringParser.parse_search(@collection, args),
|
34
|
+
search_extended: ForestAdminAgent::Utils::QueryStringParser.parse_search_extended(args)
|
35
|
+
)
|
36
|
+
projection = ForestAdminAgent::Utils::QueryStringParser.parse_projection(@collection, args)
|
37
|
+
records = @collection.list(@caller, filter, projection)
|
38
|
+
filename = args[:params][:filename] || "#{args[:params]["collection_name"]}.csv"
|
39
|
+
filename += '.csv' unless /\.csv$/i.match?(filename)
|
40
|
+
|
41
|
+
{
|
42
|
+
content: {
|
43
|
+
export: CsvGenerator.generate(records, projection)
|
44
|
+
},
|
45
|
+
filename: filename
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -4,7 +4,6 @@ module ForestAdminAgent
|
|
4
4
|
module Routes
|
5
5
|
module Resources
|
6
6
|
class List < AbstractAuthenticatedRoute
|
7
|
-
include ForestAdminAgent::Builder
|
8
7
|
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
9
8
|
def setup_routes
|
10
9
|
add_route('forest_list', 'get', '/:collection_name', ->(args) { handle_request(args) })
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ForestAdminAgent
|
2
|
+
module Routes
|
3
|
+
module Resources
|
4
|
+
module Related
|
5
|
+
class CsvRelated < AbstractRelatedRoute
|
6
|
+
include ForestAdminAgent::Utils
|
7
|
+
include ForestAdminDatasourceToolkit::Utils
|
8
|
+
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
9
|
+
|
10
|
+
def setup_routes
|
11
|
+
add_route(
|
12
|
+
'forest_related_list_csv',
|
13
|
+
'get',
|
14
|
+
'/:collection_name/:id/relationships/:relation_name.:format',
|
15
|
+
->(args) { handle_request(args) },
|
16
|
+
'csv'
|
17
|
+
)
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_request(args = {})
|
23
|
+
build(args)
|
24
|
+
@permissions.can?(:browse, @collection)
|
25
|
+
@permissions.can?(:export, @collection)
|
26
|
+
|
27
|
+
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
28
|
+
condition_tree: ConditionTreeFactory.intersect(
|
29
|
+
[
|
30
|
+
@permissions.get_scope(@collection),
|
31
|
+
ForestAdminAgent::Utils::QueryStringParser.parse_condition_tree(@child_collection, args)
|
32
|
+
]
|
33
|
+
)
|
34
|
+
)
|
35
|
+
projection = ForestAdminAgent::Utils::QueryStringParser.parse_projection_with_pks(@child_collection, args)
|
36
|
+
id = Utils::Id.unpack_id(@collection, args[:params]['id'], with_key: true)
|
37
|
+
records = Collection.list_relation(
|
38
|
+
@collection,
|
39
|
+
id,
|
40
|
+
args[:params]['relation_name'],
|
41
|
+
@caller,
|
42
|
+
filter,
|
43
|
+
projection
|
44
|
+
)
|
45
|
+
|
46
|
+
filename = args[:params][:filename] || "#{args[:params]["relation_name"]}.csv"
|
47
|
+
filename += '.csv' unless /\.csv$/i.match?(filename)
|
48
|
+
|
49
|
+
{
|
50
|
+
content: {
|
51
|
+
export: CsvGenerator.generate(records, projection)
|
52
|
+
},
|
53
|
+
filename: filename
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -23,7 +23,6 @@ module ForestAdminAgent
|
|
23
23
|
def handle_request(args = {})
|
24
24
|
build(args)
|
25
25
|
@permissions.can?(:browse, @collection)
|
26
|
-
# TODO: add csv behaviour
|
27
26
|
|
28
27
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
29
28
|
condition_tree: ConditionTreeFactory.intersect(
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module ForestAdminAgent
|
4
|
+
module Utils
|
5
|
+
class CsvGenerator
|
6
|
+
def self.generate(records, projection)
|
7
|
+
data = {}
|
8
|
+
projection.each do |schema_field|
|
9
|
+
is_relation = schema_field.include?(':') && projection.relations.key?(schema_field.split(':').first)
|
10
|
+
col_name = (is_relation ? schema_field.split(':').first : schema_field)
|
11
|
+
|
12
|
+
data[col_name] = []
|
13
|
+
records.each do |row|
|
14
|
+
data[col_name] << if is_relation
|
15
|
+
row[col_name][schema_field.split(':').last]
|
16
|
+
else
|
17
|
+
row[col_name]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
generate_csv_string(data)
|
23
|
+
end
|
24
|
+
|
25
|
+
# data = {
|
26
|
+
# "id" => [1, 2],
|
27
|
+
# "email" => ["mv@test.com", "na@test.com"],
|
28
|
+
# "name" => ["Matthieu", "Nicolas"],
|
29
|
+
# }
|
30
|
+
def self.generate_csv_string(data)
|
31
|
+
CSV.generate do |csv|
|
32
|
+
# headers
|
33
|
+
csv << data.keys
|
34
|
+
|
35
|
+
num_rows = data.values.first.size
|
36
|
+
num_rows.times do |i|
|
37
|
+
row = data.keys.map { |key| data[key][i] }
|
38
|
+
csv << row
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.48
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-05-
|
12
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -218,7 +218,6 @@ extensions: []
|
|
218
218
|
extra_rdoc_files: []
|
219
219
|
files:
|
220
220
|
- ".rspec"
|
221
|
-
- README.md
|
222
221
|
- Rakefile
|
223
222
|
- forest_admin
|
224
223
|
- forest_admin_agent.gemspec
|
@@ -249,10 +248,12 @@ files:
|
|
249
248
|
- lib/forest_admin_agent/routes/charts/api_chart_datasource.rb
|
250
249
|
- lib/forest_admin_agent/routes/charts/charts.rb
|
251
250
|
- lib/forest_admin_agent/routes/resources/count.rb
|
251
|
+
- lib/forest_admin_agent/routes/resources/csv.rb
|
252
252
|
- lib/forest_admin_agent/routes/resources/delete.rb
|
253
253
|
- lib/forest_admin_agent/routes/resources/list.rb
|
254
254
|
- lib/forest_admin_agent/routes/resources/related/associate_related.rb
|
255
255
|
- lib/forest_admin_agent/routes/resources/related/count_related.rb
|
256
|
+
- lib/forest_admin_agent/routes/resources/related/csv_related.rb
|
256
257
|
- lib/forest_admin_agent/routes/resources/related/dissociate_related.rb
|
257
258
|
- lib/forest_admin_agent/routes/resources/related/list_related.rb
|
258
259
|
- lib/forest_admin_agent/routes/resources/related/update_related.rb
|
@@ -272,6 +273,7 @@ files:
|
|
272
273
|
- lib/forest_admin_agent/utils/condition_tree_parser.rb
|
273
274
|
- lib/forest_admin_agent/utils/context_variables.rb
|
274
275
|
- lib/forest_admin_agent/utils/context_variables_injector.rb
|
276
|
+
- lib/forest_admin_agent/utils/csv_generator.rb
|
275
277
|
- lib/forest_admin_agent/utils/error_messages.rb
|
276
278
|
- lib/forest_admin_agent/utils/id.rb
|
277
279
|
- lib/forest_admin_agent/utils/query_string_parser.rb
|
@@ -300,7 +302,7 @@ licenses:
|
|
300
302
|
metadata:
|
301
303
|
homepage_uri: https://www.forestadmin.com
|
302
304
|
source_code_uri: https://github.com/ForestAdmin/agent-ruby
|
303
|
-
changelog_uri: https://github.com/ForestAdmin/agent-ruby/CHANGELOG.md
|
305
|
+
changelog_uri: https://github.com/ForestAdmin/agent-ruby/blob/main/CHANGELOG.md
|
304
306
|
rubygems_mfa_required: 'false'
|
305
307
|
post_install_message:
|
306
308
|
rdoc_options: []
|
data/README.md
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# Agent
|
2
|
-
|
3
|
-
TODO: Delete this and the text below, and describe your gem
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/agent_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Development
|
24
|
-
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
-
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/agent_ruby.
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [GPL-3.0 License](https://www.gnu.org/licenses/gpl-3.0.en.html).
|