forest_admin_agent 1.0.0.pre.beta.40 → 1.0.0.pre.beta.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80b8857f137e139961cff4046676b1aae0e23361da856fcbec2893ec4015062d
4
- data.tar.gz: 390f9b579d38542751372cbd0044c72b6aac9c1878267b1c0adfc4263ebd00e4
3
+ metadata.gz: 4cf2cf28452f96556dff2a234ba9583c9ee7dfd737e7a5b9950dc173e8806c40
4
+ data.tar.gz: 99e9e3c1c7f3a490a6c92048951d698a6bf39401728db22caf4aec7a6020438c
5
5
  SHA512:
6
- metadata.gz: a31465607de88738292b710c8c13fc4188c63f7533f4c80149cd140caaaf7e6d33d7f5f1b66379342cd72c8d5303908c0d6b184656613b0d0bda3aebe1caedf6
7
- data.tar.gz: db279dd8cca208a0de6af1469f03a1cf634a3c4c3978d33fc40b1795e4a206d693b653a136bda0001062b0ea14fdf7a89197a4ba8b90faa32e80d37a7914844b
6
+ metadata.gz: fb7093defaccc0c4e7cf6424a5605687501e763fd6b0fa74cfa931685084f344522c16d04797b0c59c448bf1bdbb5d8b80ba6215d52f585216f007c235f6e5ec
7
+ data.tar.gz: dfeb108f3cf907718032c1817011805366ddc406f95f8b36485eb4871edc68549ab2e05100de4f27dc3a7caa418ed418236ec98fedfe531fc304fe19e697fde8
@@ -26,6 +26,12 @@ module ForestAdminAgent
26
26
  self
27
27
  end
28
28
 
29
+ def add_chart(name, &definition)
30
+ @customizer.add_chart(name, &definition)
31
+
32
+ self
33
+ end
34
+
29
35
  def customize_collection(name, &handle)
30
36
  @customizer.customize_collection(name, handle)
31
37
  end
@@ -9,6 +9,10 @@ module ForestAdminAgent
9
9
  instance.resolve(:datasource)
10
10
  end
11
11
 
12
+ def self.logger
13
+ instance.resolve(:logger)
14
+ end
15
+
12
16
  def self.config_from_cache
13
17
  instance.resolve(:cache).get('config')
14
18
  end
@@ -6,7 +6,7 @@ module ForestAdminAgent
6
6
  def self.routes
7
7
  [
8
8
  actions_routes,
9
- # api_charts_routes,
9
+ api_charts_routes,
10
10
  System::HealthCheck.new.routes,
11
11
  Security::Authentication.new.routes,
12
12
  Charts::Charts.new.routes,
@@ -36,17 +36,18 @@ module ForestAdminAgent
36
36
  end
37
37
 
38
38
  def self.api_charts_routes
39
- routes = []
40
- # TODO
41
- # AgentFactory.get('datasource').charts.each do |chart|
42
- # routes << ApiChartDatasource.new(chart).routes
43
- # end
44
- # AgentFactory.get('datasource').collections.each do |collection|
45
- # collection.charts.each do |chart|
46
- # routes << ApiChartCollection.new(collection, chart).routes
47
- # end
48
- # end
49
- routes.flatten
39
+ routes = {}
40
+ Facades::Container.datasource.collections.each_value do |collection|
41
+ collection.schema[:charts].each do |chart_name|
42
+ routes.merge!(Charts::ApiChartCollection.new(collection, chart_name).routes)
43
+ end
44
+ end
45
+
46
+ Facades::Container.datasource.schema[:charts].each do |chart_name|
47
+ routes.merge!(Charts::ApiChartDatasource.new(chart_name).routes)
48
+ end
49
+
50
+ routes
50
51
  end
51
52
  end
52
53
  end
@@ -0,0 +1,70 @@
1
+ require 'jsonapi-serializers'
2
+ require 'active_support/inflector'
3
+
4
+ module ForestAdminAgent
5
+ module Routes
6
+ module Charts
7
+ class ApiChartCollection < AbstractAuthenticatedRoute
8
+ include ForestAdminAgent::Utils
9
+
10
+ def initialize(collection, chart_name)
11
+ @chart_name = chart_name
12
+ @collection = collection
13
+
14
+ super()
15
+ end
16
+
17
+ def setup_routes
18
+ # Mount both GET and POST, respectively for smart and api charts.
19
+ collection_name = @collection.name
20
+ slug = @chart_name.parameterize
21
+
22
+ add_route(
23
+ "forest_chart_#{collection_name}_get_#{slug}",
24
+ 'get',
25
+ "/_charts/:collection_name/#{slug}",
26
+ proc { |args| handle_smart_chart(args) }
27
+ )
28
+
29
+ add_route(
30
+ "forest_chart_#{collection_name}_post_#{slug}",
31
+ 'post',
32
+ "/_charts/:collection_name/#{slug}",
33
+ proc { |args| handle_api_chart(args) }
34
+ )
35
+
36
+ unless Facades::Container.cache(:is_production)
37
+ Facades::Container.logger.log(
38
+ 'Info',
39
+ "Chart #{@chart_name} was mounted at /forest/_charts/#{collection_name}/#{slug}"
40
+ )
41
+ end
42
+
43
+ self
44
+ end
45
+
46
+ def handle_api_chart(args)
47
+ {
48
+ content: Serializer::ForestChartSerializer.serialize(
49
+ @collection.render_chart(
50
+ @caller,
51
+ @chart_name,
52
+ Id.unpack_id(@collection, args[:params]['record_id'])
53
+ )
54
+ )
55
+ }
56
+ end
57
+
58
+ def handle_smart_chart(args)
59
+ {
60
+ content: @collection.render_chart(
61
+ @caller,
62
+ @chart_name,
63
+ Id.unpack_id(@collection, args[:params]['record_id'])
64
+ )
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,62 @@
1
+ require 'jsonapi-serializers'
2
+ require 'active_support/inflector'
3
+
4
+ module ForestAdminAgent
5
+ module Routes
6
+ module Charts
7
+ class ApiChartDatasource < AbstractAuthenticatedRoute
8
+ def initialize(chart_name)
9
+ @chart_name = chart_name
10
+ @datasource = ForestAdminAgent::Facades::Container.datasource
11
+
12
+ super()
13
+ end
14
+
15
+ def setup_routes
16
+ # Mount both GET and POST, respectively for smart and api charts.
17
+ slug = @chart_name.parameterize
18
+
19
+ add_route(
20
+ "forest_chart_get_#{slug}",
21
+ 'get',
22
+ "/_charts/#{slug}",
23
+ proc { handle_smart_chart }
24
+ )
25
+
26
+ add_route(
27
+ "forest_chart_post_#{slug}",
28
+ 'post',
29
+ "/_charts/#{slug}",
30
+ proc { handle_api_chart }
31
+ )
32
+
33
+ unless Facades::Container.cache(:is_production)
34
+ Facades::Container.logger.log('Info', "/forest/_charts/#{slug}")
35
+ end
36
+
37
+ self
38
+ end
39
+
40
+ def handle_api_chart
41
+ {
42
+ content: Serializer::ForestChartSerializer.serialize(
43
+ @datasource.render_chart(
44
+ @caller,
45
+ @chart_name
46
+ )
47
+ )
48
+ }
49
+ end
50
+
51
+ def handle_smart_chart
52
+ {
53
+ content: @datasource.render_chart(
54
+ @caller,
55
+ @chart_name
56
+ )
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -82,11 +82,11 @@ module ForestAdminAgent
82
82
  previous_value = compute_value(FilterFactory.get_previous_period_filter(@filter, @caller.timezone))
83
83
  end
84
84
 
85
- ValueChart.new(value, previous_value)
85
+ ValueChart.new(value, previous_value).serialize
86
86
  end
87
87
 
88
88
  def make_objective
89
- ObjectiveChart.new(compute_value(@filter))
89
+ ObjectiveChart.new(compute_value(@filter)).serialize
90
90
  end
91
91
 
92
92
  def make_pie
@@ -99,7 +99,7 @@ module ForestAdminAgent
99
99
 
100
100
  result = @collection.aggregate(@caller, @filter, aggregation)
101
101
 
102
- PieChart.new(result.map { |row| { key: row[:group][group_field], value: row[:value] } })
102
+ PieChart.new(result.map { |row| { key: row[:group][group_field], value: row[:value] } }).serialize
103
103
  end
104
104
 
105
105
  def make_line
@@ -137,7 +137,7 @@ module ForestAdminAgent
137
137
  current += 1.send(time_range.downcase.pluralize.to_sym)
138
138
  end
139
139
 
140
- LineChart.new(result)
140
+ LineChart.new(result).serialize
141
141
  end
142
142
 
143
143
  def make_leaderboard
@@ -194,7 +194,7 @@ module ForestAdminAgent
194
194
  }
195
195
  end
196
196
 
197
- return LeaderboardChart.new(result)
197
+ return LeaderboardChart.new(result).serialize
198
198
  end
199
199
 
200
200
  raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
@@ -9,7 +9,7 @@ module ForestAdminAgent
9
9
  id: SecureRandom.uuid,
10
10
  type: 'stats',
11
11
  attributes: {
12
- value: chart.serialize
12
+ value: chart
13
13
  }
14
14
  }
15
15
  }
@@ -5,15 +5,31 @@ module ForestAdminAgent
5
5
  class LoggerService
6
6
  attr_reader :default_logger
7
7
 
8
+ LEVELS = {
9
+ 'Info' => Logger::INFO,
10
+ 'Debug' => Logger::DEBUG,
11
+ 'Warn' => Logger::WARN,
12
+ 'Error' => Logger::ERROR
13
+ }.freeze
14
+
8
15
  def initialize(logger_level = 'Info', logger = nil)
9
16
  @logger_level = logger_level
10
17
  @logger = logger
11
- @default_logger = MonoLogger.new('forest_admin')
18
+ @default_logger = MonoLogger.new($stdout)
12
19
  # TODO: HANDLE FORMATTER
13
20
  end
14
21
 
15
- def levels
16
- %w[Debug Info Warn Error]
22
+ def log(level, message)
23
+ if @logger
24
+ @logger.call(get_level(level), message)
25
+ else
26
+ @default_logger.add(get_level(level), message)
27
+ end
28
+ @logger || @default_logger
29
+ end
30
+
31
+ def get_level(level)
32
+ LEVELS[level]
17
33
  end
18
34
  end
19
35
  end
@@ -19,9 +19,8 @@ module ForestAdminAgent
19
19
 
20
20
  if branch?(filters)
21
21
  aggregator = filters[:aggregator].capitalize
22
- conditions = []
23
- filters[:conditions].each do |sub_tree|
24
- conditions << from_plain_object(collection, sub_tree)
22
+ conditions = filters[:conditions].map do |sub_tree|
23
+ from_plain_object(collection, sub_tree)
25
24
  end
26
25
 
27
26
  return conditions.size == 1 ? conditions[0] : ConditionTreeBranch.new(aggregator, conditions)
@@ -7,7 +7,7 @@ module ForestAdminAgent
7
7
  class SchemaEmitter
8
8
  LIANA_NAME = "forest-rails"
9
9
 
10
- LIANA_VERSION = "1.0.0-beta.40"
10
+ LIANA_VERSION = "1.0.0-beta.41"
11
11
 
12
12
  def self.get_serialized_schema(datasource)
13
13
  schema_path = Facades::Container.cache(:schema_path)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminAgent
2
- VERSION = "1.0.0-beta.40"
2
+ VERSION = "1.0.0-beta.41"
3
3
  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.40
4
+ version: 1.0.0.pre.beta.41
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-04-05 00:00:00.000000000 Z
12
+ date: 2024-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -244,6 +244,8 @@ files:
244
244
  - lib/forest_admin_agent/routes/abstract_related_route.rb
245
245
  - lib/forest_admin_agent/routes/abstract_route.rb
246
246
  - lib/forest_admin_agent/routes/action/action.rb
247
+ - lib/forest_admin_agent/routes/charts/api_chart_collection.rb
248
+ - lib/forest_admin_agent/routes/charts/api_chart_datasource.rb
247
249
  - lib/forest_admin_agent/routes/charts/charts.rb
248
250
  - lib/forest_admin_agent/routes/resources/count.rb
249
251
  - lib/forest_admin_agent/routes/resources/delete.rb