Class: Skadi::Dashboard
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Skadi::Dashboard
- Defined in:
- app/models/skadi/dashboard.rb
Defined Under Namespace
Classes: ChartNotFoundError, DatasetConfigurationError, Error, UnsupportedDatabaseError, UnsupportedOperatorError
Constant Summary collapse
- DEFAULT_CONFIGURATION =
[ { "id" => "7cec5a7a-7bf7-403f-b15e-b2e45944182c", "title" => "Dashboard 1", "children" => [ { "id" => "7cec5a7a-7bf7-403f-b15e-b2e45944182d", "type" => "line", "title" => "Visits and Checkouts", "time_series" => "weekly", "verified_visits" => true, "unique_by" => "visit", "visit_tracking" => "any", "datasets" => [ { "id" => "7cec5a7a-7bf7-403f-b15e-b2e45944182e", "label" => "Visits", "type" => "visits", }.freeze, ].freeze, }.freeze, ].freeze, }.freeze, ].freeze
Instance Attribute Summary collapse
-
#can_dangerously_use_sql ⇒ Object
Used by the validator to prevent the unauthorised use of SQL, while allowing existing charts that use SQL to be duplicated.
Class Method Summary collapse
Instance Method Summary collapse
- #chart_data(chart_id, filters) ⇒ Object
-
#sql_strings ⇒ Object
Returns an array containing the SQL queries in the persisted record - i.e.
Instance Attribute Details
#can_dangerously_use_sql ⇒ Object
Used by the validator to prevent the unauthorised use of SQL, while allowing existing charts that use SQL to be duplicated.
12 13 14 |
# File 'app/models/skadi/dashboard.rb', line 12 def can_dangerously_use_sql @can_dangerously_use_sql end |
Class Method Details
.default_configuration ⇒ Object
41 |
# File 'app/models/skadi/dashboard.rb', line 41 def self.default_configuration = DEFAULT_CONFIGURATION.deep_dup |
Instance Method Details
#chart_data(chart_id, filters) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/skadi/dashboard.rb', line 43 def chart_data(chart_id, filters) chart_configuration = find_chart_by_id(chart_id) unless chart_id.nil? raise ChartNotFoundError.new("Unable to find chart with id #{chart_id.inspect}") unless chart_configuration return DashboardQuery.chart_query(chart_configuration, filters) end |
#sql_strings ⇒ Object
Returns an array containing the SQL queries in the persisted record - i.e. those that non-permitted users can use/run
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/skadi/dashboard.rb', line 52 def sql_strings return [] unless configuration_was.is_a?(Array) charts = configuration_was.flat_map do |tab| (tab.is_a?(Hash) && tab["children"].is_a?(Array)) ? tab["children"] : [] end datasets = charts.flat_map do |chart| (chart.is_a?(Hash) && chart["datasets"].is_a?(Array)) ? chart["datasets"] : [] end return datasets.flat_map do |dataset| next [] unless dataset.is_a?(Hash) && dataset["type"] == "sql" && dataset["sql"].is_a?(String) [ dataset["sql"] ] end end |