nquery 0.1.2 → 0.1.4
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/CHANGELOG.md +36 -0
- data/README.md +54 -0
- data/app/assets/builds/nquery/application.css +110 -6
- data/app/assets/builds/nquery/application.js +401 -37
- data/app/controllers/concerns/nquery/breadcrumbs.rb +2 -13
- data/app/controllers/concerns/nquery/chart_actions.rb +5 -5
- data/app/controllers/concerns/nquery/chart_results.rb +70 -9
- data/app/controllers/concerns/nquery/sharing_page.rb +38 -0
- data/app/controllers/nquery/application_controller.rb +2 -0
- data/app/controllers/nquery/dashboard/cards_controller.rb +28 -0
- data/app/controllers/nquery/dashboards_controller.rb +56 -11
- data/app/controllers/nquery/embed/charts_controller.rb +15 -13
- data/app/controllers/nquery/embed/dashboards_controller.rb +34 -8
- data/app/controllers/nquery/public/charts_controller.rb +19 -0
- data/app/controllers/nquery/public/dashboards_controller.rb +33 -0
- data/app/controllers/nquery/public_resources_controller.rb +79 -0
- data/app/controllers/nquery/queries_controller.rb +25 -48
- data/app/controllers/nquery/sharing/base_controller.rb +89 -0
- data/app/controllers/nquery/sharing/embed_tokens_controller.rb +41 -0
- data/app/controllers/nquery/sharing/embeddings_controller.rb +17 -0
- data/app/controllers/nquery/sharing/public_links_controller.rb +21 -0
- data/app/helpers/nquery/charts_helper.rb +13 -0
- data/app/helpers/nquery/sharing_helper.rb +67 -0
- data/app/javascript/nquery/controllers/chart_preview_controller.js +19 -1
- data/app/javascript/nquery/controllers/clipboard_controller.js +23 -0
- data/app/models/concerns/nquery/shareable.rb +43 -0
- data/app/models/nquery/chart.rb +18 -2
- data/app/models/nquery/dashboard.rb +131 -0
- data/app/models/nquery/data_source.rb +1 -1
- data/app/models/nquery/query.rb +72 -0
- data/app/services/nquery/application_service.rb +9 -0
- data/app/services/nquery/dashboards/card_parameters.rb +37 -0
- data/app/services/nquery/dashboards/filters.rb +75 -0
- data/app/services/nquery/dashboards/parameter_charts.rb +31 -0
- data/app/services/nquery/dashboards/parameter_rows.rb +60 -0
- data/app/views/layouts/nquery/application.html.erb +8 -0
- data/app/views/layouts/nquery/embed.html.erb +3 -1
- data/app/views/nquery/charts/_builder_form.html.erb +13 -6
- data/app/views/nquery/charts/_variable_row.html.erb +10 -0
- data/app/views/nquery/charts/_variables.html.erb +28 -0
- data/app/views/nquery/charts/embed.html.erb +5 -11
- data/app/views/nquery/charts/new.html.erb +2 -1
- data/app/views/nquery/charts/update.turbo_stream.erb +3 -0
- data/app/views/nquery/dashboard/charts/new.html.erb +2 -1
- data/app/views/nquery/dashboards/_chart_card.html.erb +27 -1
- data/app/views/nquery/dashboards/_parameter_chart_ids.html.erb +6 -0
- data/app/views/nquery/dashboards/_parameters.html.erb +159 -0
- data/app/views/nquery/dashboards/edit.html.erb +10 -0
- data/app/views/nquery/dashboards/embed.html.erb +9 -0
- data/app/views/nquery/dashboards/show.html.erb +41 -1
- data/app/views/nquery/embed/charts/show.html.erb +7 -8
- data/app/views/nquery/embed/dashboards/show.html.erb +12 -6
- data/app/views/nquery/embed/unavailable.html.erb +1 -0
- data/app/views/nquery/shared/_icon.html.erb +10 -0
- data/app/views/nquery/shared/_shared_chart_card.html.erb +20 -0
- data/app/views/nquery/shared/_sharing_panel.html.erb +94 -0
- data/app/views/nquery/shared/_sidebar.html.erb +1 -1
- data/app/views/nquery/shared/_topbar.html.erb +3 -0
- data/config/routes.rb +24 -1
- data/db/migrate/20260907120000_add_sharing_to_nquery_charts_and_dashboards.rb +19 -0
- data/db/migrate/20260907130000_remove_embedding_params_from_nquery_charts_and_dashboards.rb +8 -0
- data/db/migrate/20261005145000_add_parameters_to_nquery_dashboards.rb +7 -0
- data/db/migrate/20261005190000_add_parameters_to_nquery_queries.rb +7 -0
- data/lib/nquery/boolean.rb +9 -0
- data/lib/nquery/configuration.rb +6 -0
- data/lib/nquery/dashboard_parameters.rb +56 -0
- data/lib/nquery/data_sources/adapter.rb +10 -1
- data/lib/nquery/data_sources/mysql_adapter.rb +2 -2
- data/lib/nquery/data_sources/postgresql_adapter.rb +2 -2
- data/lib/nquery/data_sources/rails_adapter.rb +2 -7
- data/lib/nquery/data_sources/row_limit.rb +211 -0
- data/lib/nquery/embed_token_service.rb +10 -5
- data/lib/nquery/encryption.rb +1 -1
- data/lib/nquery/parameter_value.rb +97 -0
- data/lib/nquery/query_runner.rb +37 -4
- data/lib/nquery/seeder.rb +29 -7
- data/lib/nquery/statement_binds.rb +112 -0
- data/lib/nquery/version.rb +1 -1
- data/lib/nquery.rb +5 -0
- data/nquery.gemspec +2 -2
- metadata +40 -9
- data/app/javascript/nquery/controllers/query_editor_controller.js +0 -41
- data/app/views/nquery/queries/edit.html.erb +0 -40
- data/app/views/nquery/queries/new.html.erb +0 -37
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nquery
|
|
4
|
+
module Dashboards
|
|
5
|
+
# Records which dashboard parameters apply to one chart.
|
|
6
|
+
class CardParameters < ApplicationService
|
|
7
|
+
def initialize(dashboard:, chart:, linked_names:)
|
|
8
|
+
@dashboard = dashboard
|
|
9
|
+
@chart = chart
|
|
10
|
+
@linked_names = Array(linked_names).map(&:to_s)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
@dashboard.update!(parameters: rewritten_parameters)
|
|
15
|
+
@dashboard
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def rewritten_parameters
|
|
21
|
+
@dashboard.parameter_definitions.map do |row|
|
|
22
|
+
ids = current_chart_ids(row)
|
|
23
|
+
ids = if @linked_names.include?(row["name"])
|
|
24
|
+
ids | [@chart.id]
|
|
25
|
+
else
|
|
26
|
+
ids - [@chart.id]
|
|
27
|
+
end
|
|
28
|
+
row.merge("chart_ids" => ids)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def current_chart_ids(row)
|
|
33
|
+
@dashboard.linked_chart_ids(row)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nquery
|
|
4
|
+
module Dashboards
|
|
5
|
+
class Filters < ApplicationService
|
|
6
|
+
Result = Data.define(:filter_dashboard, :parameters)
|
|
7
|
+
|
|
8
|
+
def initialize(dashboard:, request_params:)
|
|
9
|
+
@dashboard = dashboard
|
|
10
|
+
@request_params = request_params
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
source = filter_dashboard.with_agreed_chart_variables
|
|
15
|
+
Result.new(
|
|
16
|
+
filter_dashboard: source,
|
|
17
|
+
parameters: DashboardParameters.call(
|
|
18
|
+
dashboard: without_cleared_defaults(source),
|
|
19
|
+
token_params: {},
|
|
20
|
+
request_params: filter_values(source)
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def filter_dashboard
|
|
28
|
+
return @dashboard unless @dashboard.errors.any?
|
|
29
|
+
|
|
30
|
+
Dashboard.find(@dashboard.id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def without_cleared_defaults(source)
|
|
34
|
+
cleared = cleared_names(source)
|
|
35
|
+
return source if cleared.empty?
|
|
36
|
+
|
|
37
|
+
rows = source.parameter_definitions.map do |row|
|
|
38
|
+
cleared.include?(row["name"]) ? row.merge("default" => "") : row
|
|
39
|
+
end
|
|
40
|
+
copy = source.dup
|
|
41
|
+
copy.id = source.id
|
|
42
|
+
copy.parameters = rows
|
|
43
|
+
copy.readonly!
|
|
44
|
+
copy
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def cleared_names(source)
|
|
48
|
+
submitted = permitted_params(source)
|
|
49
|
+
source.parameter_names.select { |name| submitted.key?(name) && submitted[name].to_s.strip.blank? }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def filter_values(source)
|
|
53
|
+
submitted = permitted_params(source)
|
|
54
|
+
source.parameter_definitions.each_with_object({}) do |row, values|
|
|
55
|
+
name = row["name"]
|
|
56
|
+
next if submitted.key?(name) && submitted[name].to_s.strip.blank?
|
|
57
|
+
|
|
58
|
+
text = submitted.key?(name) ? submitted[name].to_s.strip : row["default"].to_s.strip
|
|
59
|
+
values[name] = text if text.present?
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def permitted_params(source)
|
|
64
|
+
return {} if source.parameter_names.empty?
|
|
65
|
+
|
|
66
|
+
raw = if @request_params.respond_to?(:permit)
|
|
67
|
+
@request_params.permit(*source.parameter_names)
|
|
68
|
+
else
|
|
69
|
+
@request_params.to_h
|
|
70
|
+
end
|
|
71
|
+
raw.stringify_keys
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nquery
|
|
4
|
+
module Dashboards
|
|
5
|
+
# Connects one dashboard filter to the charts whose queries use its variable.
|
|
6
|
+
class ParameterCharts < ApplicationService
|
|
7
|
+
def initialize(dashboard:, name:, chart_ids:)
|
|
8
|
+
@dashboard = dashboard
|
|
9
|
+
@name = name.to_s
|
|
10
|
+
@chart_ids = Array(chart_ids).filter_map { |chart_id| Integer(chart_id, exception: false) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
parameters = @dashboard.parameter_definitions.map do |row|
|
|
15
|
+
next row unless row["name"] == @name
|
|
16
|
+
|
|
17
|
+
row.merge("chart_ids" => selected_chart_ids)
|
|
18
|
+
end
|
|
19
|
+
@dashboard.update!(parameters: parameters)
|
|
20
|
+
@dashboard
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def selected_chart_ids
|
|
26
|
+
allowed = @dashboard.charts.select { |chart| chart.uses_parameter?(@name) }.map(&:id)
|
|
27
|
+
@chart_ids & allowed
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nquery
|
|
4
|
+
module Dashboards
|
|
5
|
+
# Fills blank submitted parameter rows from charts whose queries declare the name.
|
|
6
|
+
class ParameterRows < ApplicationService
|
|
7
|
+
def initialize(dashboard:, attributes:)
|
|
8
|
+
@dashboard = dashboard
|
|
9
|
+
@attributes = attributes
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
fill_blank_rows
|
|
14
|
+
@attributes
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def fill_blank_rows
|
|
20
|
+
return unless @dashboard
|
|
21
|
+
|
|
22
|
+
Array(@attributes[:parameters]).each { |row| fill_row(row) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def fill_row(row)
|
|
26
|
+
return if row[:type].present?
|
|
27
|
+
|
|
28
|
+
source = chart_parameter(row[:name])
|
|
29
|
+
return unless source
|
|
30
|
+
|
|
31
|
+
row[:type] = source["type"]
|
|
32
|
+
row[:default] = source["default"] if row[:default].blank?
|
|
33
|
+
return if submitted_chart_ids?(row)
|
|
34
|
+
|
|
35
|
+
ids = charts_for(row[:name]).map(&:id)
|
|
36
|
+
row[:chart_ids] = ids if ids.any?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def submitted_chart_ids?(row)
|
|
40
|
+
Array(row[:chart_ids]).any?(&:present?)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def chart_parameter(name)
|
|
44
|
+
charts_for(name).filter_map { |chart| definition_named(chart, name) }.first
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def charts_for(name)
|
|
48
|
+
dashboard_charts.select { |chart| definition_named(chart, name) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def dashboard_charts
|
|
52
|
+
@dashboard_charts ||= @dashboard.charts.includes(:query).to_a
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def definition_named(chart, name)
|
|
56
|
+
chart.query&.parameter_definitions&.find { |definition| definition["name"] == name }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -13,10 +13,18 @@
|
|
|
13
13
|
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/sql/sql.min.js"></script>
|
|
14
14
|
<script src="https://cdn.jsdelivr.net/npm/sql-formatter@15.4.2/dist/sql-formatter.min.js"></script>
|
|
15
15
|
<%= javascript_include_tag "nquery/application", defer: true %>
|
|
16
|
+
<script>
|
|
17
|
+
try {
|
|
18
|
+
if (window.matchMedia("(min-width: 769px)").matches && localStorage.getItem("nq-sidebar-collapsed") === "true") {
|
|
19
|
+
document.documentElement.classList.add("nq-sidebar-collapsed")
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {}
|
|
22
|
+
</script>
|
|
16
23
|
</head>
|
|
17
24
|
<body class="nq-body">
|
|
18
25
|
<div class="nq-layout">
|
|
19
26
|
<%= render "nquery/shared/sidebar" %>
|
|
27
|
+
<button type="button" class="nq-sidebar-backdrop" hidden aria-label="Close navigation"></button>
|
|
20
28
|
<div class="nq-main">
|
|
21
29
|
<%= render "nquery/shared/topbar" %>
|
|
22
30
|
<main class="nq-content" id="main_content">
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<title>nquery embed</title>
|
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<meta name="robots" content="noindex">
|
|
6
7
|
<%= stylesheet_link_tag "nquery/application" %>
|
|
7
8
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
|
|
9
|
+
<%= javascript_include_tag "nquery/application", defer: true %>
|
|
8
10
|
</head>
|
|
9
|
-
<body class="
|
|
11
|
+
<body class="<%= embed_appearance_classes.join(" ") %>">
|
|
10
12
|
<%= yield %>
|
|
11
13
|
</body>
|
|
12
14
|
</html>
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
<% viz = chart.visualization.is_a?(Hash) ? chart.visualization : {} %>
|
|
2
2
|
<% chart_type = viz["type"].presence || "table" %>
|
|
3
3
|
<% active_chart_type = chart_builder_chart_types.include?(chart_type) ? chart_type : "bar" %>
|
|
4
|
-
<% builder_data = {
|
|
5
|
-
controller: "chart-builder",
|
|
6
|
-
query_save_url: chart.query&.persisted? ? query_path(chart.query) : nil
|
|
7
|
-
} %>
|
|
8
|
-
<% builder_data[:initial_result] = result if local_assigns[:result].present? %>
|
|
9
4
|
<%= form_with model: chart, url: form_url, class: "nq-form nq-chart-builder-form", html: {
|
|
10
|
-
data:
|
|
5
|
+
data: chart_builder_data(chart, result: result)
|
|
11
6
|
} do |f| %>
|
|
12
7
|
<%= render "nquery/charts/new_header",
|
|
13
8
|
f: f,
|
|
@@ -17,6 +12,16 @@
|
|
|
17
12
|
<div class="nq-chart-builder">
|
|
18
13
|
<div class="nq-chart-builder-layout">
|
|
19
14
|
<aside class="nq-card nq-chart-builder-panel nq-chart-builder-schema">
|
|
15
|
+
<div id="chart_variable_options" class="nq-chart-variable-options" hidden>
|
|
16
|
+
<h3 class="nq-panel-title">Parameter</h3>
|
|
17
|
+
<code data-chart-variable-options-name></code>
|
|
18
|
+
<label for="chart_variable_options_type">Type</label>
|
|
19
|
+
<select id="chart_variable_options_type" class="nq-input" data-chart-variable-options-type>
|
|
20
|
+
<%= options_for_select(Nquery::ParameterValue.type_options) %>
|
|
21
|
+
</select>
|
|
22
|
+
<label for="chart_variable_options_default">Default</label>
|
|
23
|
+
<input id="chart_variable_options_default" type="text" class="nq-input" placeholder="Optional" data-chart-variable-options-default>
|
|
24
|
+
</div>
|
|
20
25
|
<h3 class="nq-panel-title">Schema</h3>
|
|
21
26
|
<%= render "nquery/charts/schema_tree", schema: schema %>
|
|
22
27
|
</aside>
|
|
@@ -93,6 +98,8 @@
|
|
|
93
98
|
<% end %>
|
|
94
99
|
</div>
|
|
95
100
|
|
|
101
|
+
<%= render "nquery/charts/variables", chart: chart %>
|
|
102
|
+
|
|
96
103
|
<%= f.fields_for :query do |query_fields| %>
|
|
97
104
|
<div class="nq-sql-editor-shell">
|
|
98
105
|
<%= query_fields.text_area :statement,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="nq-chart-variables-row" data-variable-name="<%= definition["name"] %>">
|
|
2
|
+
<button type="button" class="nq-chart-variable-chip" data-variable-select aria-pressed="false">
|
|
3
|
+
<code data-variable-label>{{<%= definition["name"] %>}}</code>
|
|
4
|
+
</button>
|
|
5
|
+
<div class="nq-chart-variable-fields" hidden>
|
|
6
|
+
<%= hidden_field_tag "chart[query_attributes][parameters][][name]", definition["name"], id: "chart_variable_#{definition["name"]}_name", data: { variable_name_input: true } %>
|
|
7
|
+
<%= select_tag "chart[query_attributes][parameters][][type]", options_for_select(Nquery::ParameterValue.type_options, definition["type"]), id: "chart_variable_#{definition["name"]}_type", data: { variable_type: true } %>
|
|
8
|
+
<%= text_field_tag "chart[query_attributes][parameters][][default]", definition["default"].presence, id: "chart_variable_#{definition["name"]}_default", data: { variable_default: true } %>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<% definitions = chart.query&.parameter_definitions || [] %>
|
|
2
|
+
<div id="chart_variables" class="nq-chart-variables">
|
|
3
|
+
<% if chart.query&.errors&.include?(:parameters) %>
|
|
4
|
+
<div class="nq-form-errors" role="alert">
|
|
5
|
+
<ul>
|
|
6
|
+
<% chart.query.errors.full_messages_for(:parameters).each do |message| %>
|
|
7
|
+
<li><%= message %></li>
|
|
8
|
+
<% end %>
|
|
9
|
+
</ul>
|
|
10
|
+
</div>
|
|
11
|
+
<% end %>
|
|
12
|
+
<div class="nq-chart-variables-bar">
|
|
13
|
+
<span class="nq-panel-title">Parameters</span>
|
|
14
|
+
<div class="nq-chart-variables-rows" data-chart-variables-target="rows">
|
|
15
|
+
<% definitions.each do |definition| %>
|
|
16
|
+
<%= render "nquery/charts/variable_row", definition: definition %>
|
|
17
|
+
<% end %>
|
|
18
|
+
</div>
|
|
19
|
+
<button type="button" class="nq-btn nq-chart-variable-add" data-manages-loading="true" data-chart-variables-target="add">
|
|
20
|
+
<%= nq_icon(:plus) %>
|
|
21
|
+
<span>Add parameter</span>
|
|
22
|
+
</button>
|
|
23
|
+
</div>
|
|
24
|
+
<p class="nq-muted" data-chart-variables-target="empty" <%= "hidden" if definitions.any? %>>Add a variable to the query, such as <code>{{start_date}}</code>.</p>
|
|
25
|
+
<template data-chart-variables-target="template">
|
|
26
|
+
<%= render "nquery/charts/variable_row", definition: { "name" => "", "type" => "string", "default" => "" } %>
|
|
27
|
+
</template>
|
|
28
|
+
</div>
|
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
<h1>Embed: <%= @chart.name %></h1>
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<h3>Iframe snippet</h3>
|
|
11
|
-
<pre class="nq-code"><iframe src="<%= @embed_url %>" width="800" height="600" frameborder="0"></iframe></pre>
|
|
12
|
-
<% else %>
|
|
13
|
-
<p class="nq-muted">No embed token yet. Generate one from the admin panel (phase 1 UI placeholder).</p>
|
|
14
|
-
<% end %>
|
|
15
|
-
</div>
|
|
5
|
+
<%= render "nquery/shared/sharing_panel",
|
|
6
|
+
shareable: @shareable,
|
|
7
|
+
public_url: @public_url,
|
|
8
|
+
embed_url: @embed_url,
|
|
9
|
+
embed_token: @embed_token %>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
<% wiring_parameter = local_assigns[:wiring_parameter] %>
|
|
2
|
+
<div class="nq-dashboard-card<%= " is-wiring" if wiring_parameter %>"
|
|
2
3
|
style="grid-column: span <%= card.width %>; grid-row: span <%= card.height %>;"
|
|
3
4
|
data-dashboard-grid-target="card"
|
|
4
5
|
data-card-id="<%= card.id %>">
|
|
@@ -13,4 +14,29 @@
|
|
|
13
14
|
data-chart-preview-data-value="<%= card_result.to_json %>">
|
|
14
15
|
<canvas data-chart-preview-target="canvas" height="80"></canvas>
|
|
15
16
|
</div>
|
|
17
|
+
<% if wiring_parameter %>
|
|
18
|
+
<% parameter_name = wiring_parameter["name"] %>
|
|
19
|
+
<% uses_parameter = card.chart.uses_parameter?(parameter_name) %>
|
|
20
|
+
<% linked = uses_parameter && dashboard.parameter_linked_to_chart?(wiring_parameter, card.chart) %>
|
|
21
|
+
<div class="nq-dashboard-card-column">
|
|
22
|
+
<p class="nq-dashboard-card-column-label">Column to filter on</p>
|
|
23
|
+
<% if uses_parameter %>
|
|
24
|
+
<% other_chart_ids = dashboard.linked_chart_ids(wiring_parameter) - [card.chart.id] %>
|
|
25
|
+
<%= form_with url: parameter_charts_dashboard_path(dashboard, name: parameter_name, edit: "parameters", wire: parameter_name), method: :patch, class: "nq-dashboard-card-wire" do %>
|
|
26
|
+
<%= hidden_field_tag "chart_ids[]", "" %>
|
|
27
|
+
<% other_chart_ids.each do |chart_id| %>
|
|
28
|
+
<%= hidden_field_tag "chart_ids[]", chart_id %>
|
|
29
|
+
<% end %>
|
|
30
|
+
<%= select_tag "chart_ids[]",
|
|
31
|
+
options_for_select([["Select...", ""], ["{{#{parameter_name}}}", card.chart.id]], linked ? card.chart.id.to_s : ""),
|
|
32
|
+
id: "card_#{card.id}_parameter_#{parameter_name}",
|
|
33
|
+
class: "nq-input",
|
|
34
|
+
aria: { label: "Column to filter on" },
|
|
35
|
+
onchange: "this.form.requestSubmit()" %>
|
|
36
|
+
<% end %>
|
|
37
|
+
<% else %>
|
|
38
|
+
<%= select_tag "card_#{card.id}_parameter_#{parameter_name}", options_for_select([["Select...", ""]]), id: "card_#{card.id}_parameter_#{parameter_name}", class: "nq-input", disabled: true, aria: { label: "Column to filter on" } %>
|
|
39
|
+
<% end %>
|
|
40
|
+
</div>
|
|
41
|
+
<% end %>
|
|
16
42
|
</div>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<% filter_dashboard = local_assigns.fetch(:filter_dashboard, dashboard) %>
|
|
2
|
+
<% definitions = filter_dashboard.parameter_definitions %>
|
|
3
|
+
<% stored_definitions = dashboard.parameter_definitions %>
|
|
4
|
+
<% cards = local_assigns.fetch(:cards) { dashboard.dashboard_cards.includes(:chart) } %>
|
|
5
|
+
<% invalid_parameter_names = Array(local_assigns[:invalid_parameter_names]) %>
|
|
6
|
+
<% wiring_name = local_assigns[:wiring_name].to_s.presence %>
|
|
7
|
+
<% editing_parameters = can_edit && (local_assigns[:editing_parameters] || dashboard.errors[:parameters].any?) %>
|
|
8
|
+
<% visible_definitions = definitions.select { |definition| !definition.key?("chart_ids") || cards.any? { |card| filter_dashboard.parameter_linked_to_chart?(definition, card.chart) } } %>
|
|
9
|
+
<% if visible_definitions.any? %>
|
|
10
|
+
<%= form_with url: dashboard_path(dashboard), method: :get, class: "nq-dashboard-filter-bar", data: { turbo: false } do %>
|
|
11
|
+
<%= hidden_field_tag :edit, "parameters" if editing_parameters %>
|
|
12
|
+
<%= hidden_field_tag :wire, wiring_name if wiring_name %>
|
|
13
|
+
<% visible_definitions.each do |definition| %>
|
|
14
|
+
<% name = definition["name"] %>
|
|
15
|
+
<% selected = params.key?(name) ? params[name].presence : definition["default"].presence %>
|
|
16
|
+
<% invalid = invalid_parameter_names.include?(name) %>
|
|
17
|
+
<div class="nq-dashboard-filter<%= " is-invalid" if invalid %>">
|
|
18
|
+
<%= label_tag "dashboard_filter_#{name}", name.tr("_", " ").capitalize %>
|
|
19
|
+
<%= date_field_tag name, selected, id: "dashboard_filter_#{name}", class: "nq-input", onchange: "this.form.requestSubmit()" if definition["type"] == "date" %>
|
|
20
|
+
<%= datetime_local_field_tag name, selected, id: "dashboard_filter_#{name}", class: "nq-input", onchange: "this.form.requestSubmit()" if definition["type"] == "datetime" %>
|
|
21
|
+
<%= number_field_tag name, selected, id: "dashboard_filter_#{name}", class: "nq-input", step: 1, onchange: "this.form.requestSubmit()" if definition["type"] == "integer" %>
|
|
22
|
+
<%= text_field_tag name, selected, id: "dashboard_filter_#{name}", class: "nq-input", onchange: "this.form.requestSubmit()" if definition["type"] == "string" %>
|
|
23
|
+
<%= select_tag name, options_for_select([["True", "true"], ["False", "false"]], Nquery::ParameterValue.boolean_form_value(selected)), id: "dashboard_filter_#{name}", class: "nq-input", include_blank: "Any", onchange: "this.form.requestSubmit()" if definition["type"] == "boolean" %>
|
|
24
|
+
<%= text_field_tag name, selected, id: "dashboard_filter_#{name}", class: "nq-input", onchange: "this.form.requestSubmit()", placeholder: "550e8400-e29b-41d4-a716-446655440000", pattern: "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", title: "Enter a UUID" if definition["type"] == "uuid" %>
|
|
25
|
+
<% if invalid && definition["type"] == "uuid" %>
|
|
26
|
+
<p class="nq-dashboard-filter-error" role="alert">Enter a UUID.</p>
|
|
27
|
+
<% elsif invalid && definition["type"] == "boolean" %>
|
|
28
|
+
<p class="nq-dashboard-filter-error" role="alert">Choose true or false.</p>
|
|
29
|
+
<% end %>
|
|
30
|
+
</div>
|
|
31
|
+
<% end %>
|
|
32
|
+
<div class="nq-dashboard-filter-actions">
|
|
33
|
+
<%= submit_tag "Apply", class: "nq-btn" %>
|
|
34
|
+
<% if visible_definitions.any? { |definition| params[definition["name"]].present? || (definition["default"].present? && !params.key?(definition["name"])) } %>
|
|
35
|
+
<% clear_params = visible_definitions.to_h { |definition| [definition["name"], ""] } %>
|
|
36
|
+
<% clear_params["wire"] = wiring_name if wiring_name %>
|
|
37
|
+
<% clear_params["edit"] = "parameters" if editing_parameters %>
|
|
38
|
+
<%= link_to "Clear", dashboard_path(dashboard, clear_params), class: "nq-btn" %>
|
|
39
|
+
<% end %>
|
|
40
|
+
</div>
|
|
41
|
+
<% end %>
|
|
42
|
+
<% end %>
|
|
43
|
+
|
|
44
|
+
<% if can_edit && !editing_parameters %>
|
|
45
|
+
<%= link_to dashboard_path(dashboard, request.query_parameters.except("wire", "edit").merge("edit" => "parameters")), class: "nq-btn nq-dashboard-filter-edit" do %>
|
|
46
|
+
<%= nq_icon(:edit) %>
|
|
47
|
+
<span>Edit parameters</span>
|
|
48
|
+
<% end %>
|
|
49
|
+
<% elsif editing_parameters %>
|
|
50
|
+
<div class="nq-dashboard-filter-editor is-editing">
|
|
51
|
+
<div class="nq-dashboard-filter-editor-bar">
|
|
52
|
+
<span>Edit parameters</span>
|
|
53
|
+
<%= link_to "Done", dashboard_path(dashboard, request.query_parameters.except("wire", "edit")), class: "nq-btn" %>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="nq-dashboard-filter-panel">
|
|
56
|
+
<% if dashboard.errors[:parameters].any? %>
|
|
57
|
+
<div class="nq-form-errors" role="alert">
|
|
58
|
+
<p><strong>Please fix the following:</strong></p>
|
|
59
|
+
<ul>
|
|
60
|
+
<% dashboard.errors.full_messages_for(:parameters).each do |message| %>
|
|
61
|
+
<li><%= message %></li>
|
|
62
|
+
<% end %>
|
|
63
|
+
</ul>
|
|
64
|
+
</div>
|
|
65
|
+
<% end %>
|
|
66
|
+
<% linkable = cards.filter_map { |card| card.chart.query }.flat_map(&:parameter_definitions).uniq { |row| row["name"] }.reject { |row| definitions.any? { |saved| saved["name"] == row["name"] } } %>
|
|
67
|
+
<p class="nq-dashboard-filter-hint">Add a parameter here, or link a variable that already exists on a chart, such as <code>{{start_date}}</code>.</p>
|
|
68
|
+
<%= form_with model: dashboard, url: dashboard_path(dashboard), method: :patch, class: "nq-dashboard-parameter-create" do %>
|
|
69
|
+
<% stored_definitions.each_with_index do |definition, index| %>
|
|
70
|
+
<%= hidden_field_tag "dashboard[parameters][][name]", definition["name"], id: "dashboard_new_parameter_#{index}_name" %>
|
|
71
|
+
<%= hidden_field_tag "dashboard[parameters][][type]", definition["type"], id: "dashboard_new_parameter_#{index}_type" %>
|
|
72
|
+
<%= hidden_field_tag "dashboard[parameters][][default]", definition["default"], id: "dashboard_new_parameter_#{index}_default" %>
|
|
73
|
+
<%= render "parameter_chart_ids", definition: definition %>
|
|
74
|
+
<% end %>
|
|
75
|
+
<div class="nq-dashboard-filter-field">
|
|
76
|
+
<%= label_tag "dashboard_parameter_name", "Name" %>
|
|
77
|
+
<%= text_field_tag "dashboard[parameters][][name]", nil, id: "dashboard_parameter_name", class: "nq-input", placeholder: "active", pattern: "[a-z][a-z0-9_]*", required: true, autocomplete: "off" %>
|
|
78
|
+
</div>
|
|
79
|
+
<div class="nq-dashboard-filter-field">
|
|
80
|
+
<%= label_tag "dashboard_parameter_type", "Type" %>
|
|
81
|
+
<%= select_tag "dashboard[parameters][][type]", options_for_select(Nquery::ParameterValue.type_options, "string"), id: "dashboard_parameter_type", class: "nq-input" %>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="nq-dashboard-filter-field">
|
|
84
|
+
<%= label_tag "dashboard_parameter_default", "Default" %>
|
|
85
|
+
<%= text_field_tag "dashboard[parameters][][default]", nil, id: "dashboard_parameter_default", class: "nq-input", placeholder: "Optional" %>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="nq-dashboard-filter-add-action">
|
|
88
|
+
<%= submit_tag "Add parameter", class: "nq-btn nq-btn-primary" %>
|
|
89
|
+
</div>
|
|
90
|
+
<% end %>
|
|
91
|
+
<% if linkable.any? %>
|
|
92
|
+
<%= form_with model: dashboard, url: dashboard_path(dashboard), method: :patch, class: "nq-dashboard-filter-add" do %>
|
|
93
|
+
<% stored_definitions.each_with_index do |definition, index| %>
|
|
94
|
+
<%= hidden_field_tag "dashboard[parameters][][name]", definition["name"], id: "dashboard_saved_parameter_#{index}_name" %>
|
|
95
|
+
<%= hidden_field_tag "dashboard[parameters][][type]", definition["type"], id: "dashboard_saved_parameter_#{index}_type" %>
|
|
96
|
+
<%= hidden_field_tag "dashboard[parameters][][default]", definition["default"], id: "dashboard_saved_parameter_#{index}_default" %>
|
|
97
|
+
<%= render "parameter_chart_ids", definition: definition %>
|
|
98
|
+
<% end %>
|
|
99
|
+
<div class="nq-dashboard-filter-field">
|
|
100
|
+
<%= label_tag "dashboard_link_parameter", "Chart variable" %>
|
|
101
|
+
<%= select_tag "dashboard[parameters][][name]", options_for_select(linkable.map { |row| ["{{#{row["name"]}}} · #{Nquery::ParameterValue::TYPE_LABELS[row["type"]] || row["type"]}", row["name"]] }), id: "dashboard_link_parameter", class: "nq-input" %>
|
|
102
|
+
</div>
|
|
103
|
+
<div class="nq-dashboard-filter-add-action">
|
|
104
|
+
<%= submit_tag "Link filter", class: "nq-btn nq-btn-primary" %>
|
|
105
|
+
</div>
|
|
106
|
+
<% end %>
|
|
107
|
+
<% else %>
|
|
108
|
+
<p class="nq-muted">No chart variables are waiting to be linked.</p>
|
|
109
|
+
<% end %>
|
|
110
|
+
<% if definitions.any? %>
|
|
111
|
+
<ul class="nq-dashboard-filter-list">
|
|
112
|
+
<% definitions.each do |definition| %>
|
|
113
|
+
<li class="<%= "is-wiring" if wiring_name == definition["name"] %>">
|
|
114
|
+
<div class="nq-dashboard-filter-list-row">
|
|
115
|
+
<div class="nq-dashboard-filter-meta">
|
|
116
|
+
<%= link_to dashboard_path(dashboard, request.query_parameters.except("wire", "edit").merge("edit" => "parameters", "wire" => definition["name"])), class: "nq-dashboard-filter-field-link", aria: { current: (wiring_name == definition["name"] ? "true" : nil) } do %>
|
|
117
|
+
<code>{{<%= definition["name"] %>}}</code>
|
|
118
|
+
<% end %>
|
|
119
|
+
<span class="nq-badge nq-badge-filter nq-badge-filter-<%= definition["type"] %>"><%= Nquery::ParameterValue::TYPE_LABELS[definition["type"]] || definition["type"] %></span>
|
|
120
|
+
</div>
|
|
121
|
+
<span class="nq-dashboard-filter-default">
|
|
122
|
+
<% if definition["default"].present? %>
|
|
123
|
+
Default <strong><%= definition["default"] %></strong>
|
|
124
|
+
<% else %>
|
|
125
|
+
No default
|
|
126
|
+
<% end %>
|
|
127
|
+
</span>
|
|
128
|
+
<% if wiring_name == definition["name"] %>
|
|
129
|
+
<%= link_to "Done", dashboard_path(dashboard, request.query_parameters.except("wire", "edit").merge("edit" => "parameters")), class: "nq-btn" %>
|
|
130
|
+
<% end %>
|
|
131
|
+
<%= form_with url: dashboard_path(dashboard), method: :patch do %>
|
|
132
|
+
<%= hidden_field_tag :edit, "parameters" if editing_parameters %>
|
|
133
|
+
<%= hidden_field_tag :wire, wiring_name if wiring_name %>
|
|
134
|
+
<% others = stored_definitions.reject { |row| row["name"] == definition["name"] } %>
|
|
135
|
+
<% if others.empty? %>
|
|
136
|
+
<%= hidden_field_tag "dashboard[parameters][][name]", "" %>
|
|
137
|
+
<%= hidden_field_tag "dashboard[parameters][][type]", "date" %>
|
|
138
|
+
<%= hidden_field_tag "dashboard[parameters][][default]", "" %>
|
|
139
|
+
<% else %>
|
|
140
|
+
<% others.each do |row| %>
|
|
141
|
+
<%= hidden_field_tag "dashboard[parameters][][name]", row["name"] %>
|
|
142
|
+
<%= hidden_field_tag "dashboard[parameters][][type]", row["type"] %>
|
|
143
|
+
<%= hidden_field_tag "dashboard[parameters][][default]", row["default"] %>
|
|
144
|
+
<%= render "parameter_chart_ids", definition: row %>
|
|
145
|
+
<% end %>
|
|
146
|
+
<% end %>
|
|
147
|
+
<%= button_tag type: "submit", class: "nq-btn nq-btn-ghost" do %>
|
|
148
|
+
<%= nq_icon(:trash) %>
|
|
149
|
+
<span>Remove</span>
|
|
150
|
+
<% end %>
|
|
151
|
+
<% end %>
|
|
152
|
+
</div>
|
|
153
|
+
</li>
|
|
154
|
+
<% end %>
|
|
155
|
+
</ul>
|
|
156
|
+
<% end %>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
<% end %>
|
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
<%= form_with model: @dashboard, url: dashboard_path(@dashboard), method: :patch do |f| %>
|
|
6
6
|
<div class="nq-card nq-mb">
|
|
7
|
+
<% if @dashboard.errors.any? %>
|
|
8
|
+
<div class="nq-form-errors" role="alert">
|
|
9
|
+
<p><strong>Please fix the following:</strong></p>
|
|
10
|
+
<ul>
|
|
11
|
+
<% @dashboard.errors.full_messages.each do |message| %>
|
|
12
|
+
<li><%= message %></li>
|
|
13
|
+
<% end %>
|
|
14
|
+
</ul>
|
|
15
|
+
</div>
|
|
16
|
+
<% end %>
|
|
7
17
|
<div class="nq-form-row">
|
|
8
18
|
<%= f.label :name %>
|
|
9
19
|
<%= f.text_field :name, class: "nq-input" %>
|