mensa 0.10.2 → 0.11.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/.shipkit.yml +1 -1
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +1 -1
- data/README.md +129 -0
- data/app/assets/stylesheets/mensa/application.css +2 -0
- data/app/components/mensa/cells/component.css +47 -0
- data/app/components/mensa/cells/component_controller.js +406 -0
- data/app/components/mensa/table/component.css +22 -0
- data/app/components/mensa/table/component.html.erb +18 -5
- data/app/components/mensa/table/component.rb +6 -1
- data/app/components/mensa/table/component_controller.js +52 -0
- data/app/components/mensa/table_row/component.rb +7 -3
- data/app/components/mensa/tree/component.css +28 -0
- data/app/components/mensa/tree/component_controller.js +99 -0
- data/app/components/mensa/view/component.html.erb +3 -5
- data/app/components/mensa/view/component.rb +22 -0
- data/app/controllers/concerns/mensa/table_from_request.rb +37 -0
- data/app/controllers/mensa/tables/commands_controller.rb +30 -0
- data/app/controllers/mensa/tables/rows_controller.rb +28 -0
- data/app/controllers/mensa/tables_controller.rb +3 -22
- data/app/javascript/mensa/controllers/index.js +6 -0
- data/app/tables/mensa/base.rb +37 -0
- data/app/tables/mensa/cell.rb +51 -2
- data/app/tables/mensa/column.rb +55 -0
- data/app/tables/mensa/command.rb +57 -0
- data/app/tables/mensa/config/column_dsl.rb +3 -0
- data/app/tables/mensa/config/command_dsl.rb +19 -0
- data/app/tables/mensa/config/editable_dsl.rb +27 -0
- data/app/tables/mensa/config/table_dsl.rb +18 -0
- data/app/tables/mensa/grouping.rb +2 -1
- data/app/tables/mensa/row.rb +24 -0
- data/app/tables/mensa/scope.rb +9 -0
- data/app/tables/mensa/tree.rb +157 -0
- data/app/tables/mensa/tree_paging.rb +38 -0
- data/app/views/mensa/tables/rows/update.turbo_stream.erb +3 -0
- data/config/locales/en.yml +4 -0
- data/config/locales/nl.yml +4 -0
- data/config/routes.rb +2 -0
- data/lib/mensa/configuration.rb +2 -0
- data/lib/mensa/version.rb +1 -1
- metadata +14 -1
data/app/tables/mensa/column.rb
CHANGED
|
@@ -111,9 +111,64 @@ module Mensa
|
|
|
111
111
|
# Columns with SQL are sortable unless `sortable false`, others only with
|
|
112
112
|
# an explicit `sortable true`
|
|
113
113
|
def sortable?
|
|
114
|
+
# A tree's order is its tree's
|
|
115
|
+
return false if table.tree?
|
|
116
|
+
|
|
114
117
|
config[:sortable].nil? ? sql? : !!config[:sortable]
|
|
115
118
|
end
|
|
116
119
|
|
|
120
|
+
# Whether its cells are edited in place (`editable`), saved by the table's
|
|
121
|
+
# `update`
|
|
122
|
+
def editable?
|
|
123
|
+
config[:editable].present? && config[:editable] != false && table.update_block.present?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Whether the record's cell may be edited
|
|
127
|
+
def editable_for?(record)
|
|
128
|
+
return false unless editable?
|
|
129
|
+
|
|
130
|
+
show = editable_config[:show]
|
|
131
|
+
(show.nil? || show.call(record)) ? true : false
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# The input it's edited with: :text, :number, :date, :time or :select
|
|
135
|
+
def edit_as
|
|
136
|
+
as = editable_config[:as]
|
|
137
|
+
return as.to_sym if as.present?
|
|
138
|
+
return :select if editable_config[:collection].present?
|
|
139
|
+
|
|
140
|
+
case type
|
|
141
|
+
when :integer, :decimal, :float, :bigint then :number
|
|
142
|
+
when :date then :date
|
|
143
|
+
when :time then :time
|
|
144
|
+
else :text
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# A select's options, as [[label, value], …]
|
|
149
|
+
def edit_collection
|
|
150
|
+
collection = editable_config[:collection]
|
|
151
|
+
collection = collection.call if collection.respond_to?(:call)
|
|
152
|
+
Array(collection).map { |option| option.is_a?(Array) ? [option.first.to_s, option.last.to_s] : [option.to_s, option.to_s] }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# The value put in the input for the record, given the one shown
|
|
156
|
+
def edit_value(record, shown)
|
|
157
|
+
value = editable_config[:value]
|
|
158
|
+
value = value.call(record) if value.respond_to?(:call)
|
|
159
|
+
value = shown if value.nil?
|
|
160
|
+
|
|
161
|
+
case value
|
|
162
|
+
when Date then value.iso8601
|
|
163
|
+
when Time, DateTime, ActiveSupport::TimeWithZone then (edit_as == :time) ? value.strftime("%H:%M") : value.to_date.iso8601
|
|
164
|
+
else value.to_s
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def editable_config
|
|
169
|
+
config[:editable].is_a?(Hash) ? config[:editable] : {}
|
|
170
|
+
end
|
|
171
|
+
|
|
117
172
|
# Returns true if the column supports filtering: columns with SQL unless
|
|
118
173
|
# `filter false`, others only with a filter that has its own scope
|
|
119
174
|
def filter?
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa
|
|
4
|
+
# Something done to the selected row with a key, in a table with a selected
|
|
5
|
+
# cell (see Keyboard commands in the README):
|
|
6
|
+
#
|
|
7
|
+
# command :indent do
|
|
8
|
+
# key "Tab"
|
|
9
|
+
# show ->(category) { category.position.positive? }
|
|
10
|
+
# process { |category| category.indent! }
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# command :add_below do
|
|
14
|
+
# key "Enter"
|
|
15
|
+
# edit true
|
|
16
|
+
# process { |category| category.siblings.create!(position: category.position + 1) }
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# Mensa POSTs to its own endpoint, which finds the record through the
|
|
20
|
+
# table's scope and only runs the command when `show` allows it.
|
|
21
|
+
class Command
|
|
22
|
+
include ConfigReaders
|
|
23
|
+
|
|
24
|
+
defined_by Mensa::Config::CommandDsl
|
|
25
|
+
|
|
26
|
+
attr_reader :name, :table
|
|
27
|
+
|
|
28
|
+
def initialize(name, config:, table:)
|
|
29
|
+
@name = name
|
|
30
|
+
@table = table
|
|
31
|
+
@config = self.class.definition.merge(config || {})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
config_reader :key
|
|
35
|
+
config_reader :title
|
|
36
|
+
config_reader :show, call: false
|
|
37
|
+
config_reader :process, call: false
|
|
38
|
+
config_reader :edit?
|
|
39
|
+
|
|
40
|
+
def show?(record) = (show.nil? || evaluate(show, record)) ? true : false
|
|
41
|
+
|
|
42
|
+
# Runs it with the record, in the view context when there is one, so route
|
|
43
|
+
# helpers work; the record to select afterwards
|
|
44
|
+
def perform(record, view_context = nil)
|
|
45
|
+
result = evaluate(process, record, view_context)
|
|
46
|
+
result.is_a?(ActiveRecord::Base) ? result : record
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def evaluate(block, record, view_context = nil)
|
|
52
|
+
return block.call(record) unless view_context
|
|
53
|
+
|
|
54
|
+
view_context.instance_exec(record, &block)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -27,6 +27,9 @@ module Mensa::Config
|
|
|
27
27
|
option :aggregates, default: []
|
|
28
28
|
option :render, dsl: Mensa::Config::RenderDsl
|
|
29
29
|
option :filter, dsl: Mensa::Config::FilterDsl
|
|
30
|
+
# Edited in its cell: `editable true`, or with a block, see EditableDsl.
|
|
31
|
+
# The table's `update` saves it
|
|
32
|
+
option :editable, dsl: Mensa::Config::EditableDsl
|
|
30
33
|
|
|
31
34
|
# aggregates :sum, :min, :max
|
|
32
35
|
def aggregates(*functions)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa::Config
|
|
4
|
+
# A key that does something to the selected row, see Mensa::Command
|
|
5
|
+
class CommandDsl
|
|
6
|
+
include DslLogic
|
|
7
|
+
|
|
8
|
+
# The key, as "Tab", "Shift+Tab", "Alt+Shift+ArrowUp", "Ctrl+Enter", "Delete"
|
|
9
|
+
option :key
|
|
10
|
+
option :title, default: -> { name.to_s.humanize }
|
|
11
|
+
# Whether it may be done to the record
|
|
12
|
+
option :show, default: ->(record) { true }
|
|
13
|
+
# Does it, with the record. May return the record to select afterwards
|
|
14
|
+
# (e.g. one it made)
|
|
15
|
+
option :process
|
|
16
|
+
# Start editing the selected row's first editable cell afterwards
|
|
17
|
+
option :edit, default: false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa::Config
|
|
4
|
+
# How a column's cells are edited:
|
|
5
|
+
#
|
|
6
|
+
# column(:kind) do
|
|
7
|
+
# editable do
|
|
8
|
+
# as :select
|
|
9
|
+
# collection { [["Small", "small"], ["Large", "large"]] }
|
|
10
|
+
# show ->(record) { !record.locked? }
|
|
11
|
+
# value { |record| record.kind }
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
14
|
+
class EditableDsl
|
|
15
|
+
include DslLogic
|
|
16
|
+
|
|
17
|
+
# The input: :text, :number, :date, :time or :select. By the column's
|
|
18
|
+
# type when not given, :select with a collection
|
|
19
|
+
option :as
|
|
20
|
+
# The options of a select, [[label, value], …]
|
|
21
|
+
option :collection
|
|
22
|
+
# Whether the record's cell may be edited
|
|
23
|
+
option :show, default: ->(record) { true }
|
|
24
|
+
# The value put in the input, when it isn't the one shown
|
|
25
|
+
option :value
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -72,9 +72,27 @@ module Mensa::Config
|
|
|
72
72
|
# Aggregates shown per group, e.g. `aggregates market_cap: :sum`
|
|
73
73
|
option :aggregates
|
|
74
74
|
|
|
75
|
+
# Show the rows as a tree of their parent column, depth first, siblings by
|
|
76
|
+
# their position column (by primary key without one):
|
|
77
|
+
#
|
|
78
|
+
# tree parent: :parent_id, position: :position
|
|
79
|
+
option :tree
|
|
80
|
+
# Rows on a page of a tree, made of whole top-level subtrees
|
|
81
|
+
option :tree_page_size, default: 200
|
|
82
|
+
|
|
75
83
|
# Actions
|
|
76
84
|
option :action, dsl_hash: Mensa::Config::ActionDsl
|
|
77
85
|
|
|
86
|
+
# Saves a value edited in a cell of an editable column, called with the
|
|
87
|
+
# record, the column's name and the value; returns true, or the errors
|
|
88
|
+
# (a string or an array of them)
|
|
89
|
+
#
|
|
90
|
+
# update { |category, column, value| category.update(column => value) || category.errors.full_messages }
|
|
91
|
+
option :update
|
|
92
|
+
|
|
93
|
+
# Something done to the selected row with a key, see Mensa::Command
|
|
94
|
+
option :command, dsl_hash: Mensa::Config::CommandDsl
|
|
95
|
+
|
|
78
96
|
option :batch, dsl_hash: Mensa::Config::BatchDsl
|
|
79
97
|
|
|
80
98
|
option :render, dsl: Mensa::Config::RenderDsl
|
|
@@ -16,7 +16,8 @@ module Mensa
|
|
|
16
16
|
|
|
17
17
|
name = current_group_by
|
|
18
18
|
col = column(name) if name.present?
|
|
19
|
-
|
|
19
|
+
# A tree's rows are in the tree's order, not grouped
|
|
20
|
+
@group_column = (col if col&.groupable? && scope.is_a?(ActiveRecord::Relation) && !tree?)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def grouped?
|
data/app/tables/mensa/row.rb
CHANGED
|
@@ -25,6 +25,25 @@ module Mensa
|
|
|
25
25
|
record[Mensa::Grouping::GROUP_VALUE_ALIAS] if record.respond_to?(:has_attribute?) && record.has_attribute?(Mensa::Grouping::GROUP_VALUE_ALIAS)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# In a tree, how deep it is: 0 at the top
|
|
29
|
+
def depth
|
|
30
|
+
tree_value(:depth).to_i
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# In a tree, whether it has children shown
|
|
34
|
+
def children?
|
|
35
|
+
tree_value(:children) ? true : false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# In a filtered tree, whether it's there only as an ancestor of a match
|
|
39
|
+
def context?
|
|
40
|
+
table.tree? && tree_value(:matched) == false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def id
|
|
44
|
+
record.id if record.respond_to?(:id)
|
|
45
|
+
end
|
|
46
|
+
|
|
28
47
|
def link_attributes
|
|
29
48
|
return {} unless link
|
|
30
49
|
|
|
@@ -39,6 +58,11 @@ module Mensa
|
|
|
39
58
|
|
|
40
59
|
private
|
|
41
60
|
|
|
61
|
+
def tree_value(name)
|
|
62
|
+
key = "mensa_tree_#{name}"
|
|
63
|
+
record[key] if record.respond_to?(:has_attribute?) && record.has_attribute?(key)
|
|
64
|
+
end
|
|
65
|
+
|
|
42
66
|
def append_navigation_context(url)
|
|
43
67
|
return url if url.blank?
|
|
44
68
|
|
data/app/tables/mensa/scope.rb
CHANGED
|
@@ -6,6 +6,7 @@ module Mensa
|
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
7
|
include Search
|
|
8
8
|
include Grouping
|
|
9
|
+
include Tree
|
|
9
10
|
|
|
10
11
|
included do
|
|
11
12
|
end
|
|
@@ -29,6 +30,9 @@ module Mensa
|
|
|
29
30
|
def ordered_scope
|
|
30
31
|
return @ordered_scope if @ordered_scope
|
|
31
32
|
|
|
33
|
+
# A tree's rows are its scope's, matching or above what matches
|
|
34
|
+
return @ordered_scope = tree_ordered_scope if tree?
|
|
35
|
+
|
|
32
36
|
# Builds the search order clause too, so do this first
|
|
33
37
|
relation = filtered_scope
|
|
34
38
|
|
|
@@ -51,16 +55,21 @@ module Mensa
|
|
|
51
55
|
@selected_scope = ordered_scope
|
|
52
56
|
@selected_scope = @selected_scope.select((id_column? ? [:id] : []) + columns.filter_map(&:attribute))
|
|
53
57
|
@selected_scope = @selected_scope.select(group_select) if grouped?
|
|
58
|
+
@selected_scope = @selected_scope.select(*tree_selects) if tree?
|
|
54
59
|
|
|
55
60
|
@selected_scope
|
|
56
61
|
end
|
|
57
62
|
|
|
58
63
|
def paged_scope
|
|
64
|
+
return tree_paged_scope if tree?
|
|
65
|
+
|
|
59
66
|
pagy_object
|
|
60
67
|
@records
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
def pagy_details
|
|
71
|
+
return tree_paging if tree?
|
|
72
|
+
|
|
64
73
|
pagy_object
|
|
65
74
|
@pagy_details
|
|
66
75
|
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa
|
|
4
|
+
# Shows rows as a tree (`tree parent: :parent_id, position: :position`):
|
|
5
|
+
# depth first, each row after its parent, siblings by their position (then
|
|
6
|
+
# primary key). A filter or search shows the rows that match and their
|
|
7
|
+
# ancestors, which are there for context only (Row#context?). Pages are
|
|
8
|
+
# whole top-level subtrees, as many as fit in tree_page_size rows; one that
|
|
9
|
+
# is larger is a page of its own.
|
|
10
|
+
#
|
|
11
|
+
# One recursive query, over the table's scope, gives every row shown its
|
|
12
|
+
# depth, its path (its rank among its siblings at each level, so ordering by
|
|
13
|
+
# it is depth first), whether it matched and whether it has children shown.
|
|
14
|
+
module Tree
|
|
15
|
+
extend ActiveSupport::Concern
|
|
16
|
+
|
|
17
|
+
TREE_ALIAS = "mensa_tree"
|
|
18
|
+
# A deeper tree has a parent pointing back into itself
|
|
19
|
+
MAX_DEPTH = 100
|
|
20
|
+
|
|
21
|
+
def tree?
|
|
22
|
+
config[:tree].present? && scope.is_a?(ActiveRecord::Relation)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def tree_parent_column
|
|
26
|
+
(config.dig(:tree, :parent) || :parent_id).to_s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def tree_position_column
|
|
30
|
+
config.dig(:tree, :position)&.to_s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tree_page_size
|
|
34
|
+
[config[:tree_page_size].to_i, 1].max
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The subquery giving each row shown its place: id, depth, path, matched,
|
|
38
|
+
# children
|
|
39
|
+
def tree_sql
|
|
40
|
+
@tree_sql ||= build_tree_sql
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Joined to the scope: only the rows shown, in the tree's order. Joined as
|
|
44
|
+
# an Arel node, not a string: Rails counts the tables named in a string
|
|
45
|
+
# join, and the scope's own joins are in the subquery, so its associations
|
|
46
|
+
# would be given other aliases than the columns use
|
|
47
|
+
def tree_ordered_scope
|
|
48
|
+
table = model.arel_table
|
|
49
|
+
tree = Arel::Nodes::TableAlias.new(Arel::Nodes::Grouping.new(Arel.sql(tree_sql)), TREE_ALIAS)
|
|
50
|
+
join = Arel::Nodes::InnerJoin.new(tree, Arel::Nodes::On.new(tree[:id].eq(table[model.primary_key])))
|
|
51
|
+
scope.joins(join).reorder(Arel.sql("#{TREE_ALIAS}.path"))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def tree_selects
|
|
55
|
+
[
|
|
56
|
+
Arel.sql("#{TREE_ALIAS}.depth AS mensa_tree_depth"),
|
|
57
|
+
Arel.sql("#{TREE_ALIAS}.children AS mensa_tree_children"),
|
|
58
|
+
Arel.sql("#{TREE_ALIAS}.matched AS mensa_tree_matched")
|
|
59
|
+
]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The pages: the first and last top-level rank of each, and its rows
|
|
63
|
+
def tree_pages
|
|
64
|
+
@tree_pages ||= begin
|
|
65
|
+
counts = model.connection.select_rows("SELECT path[1], COUNT(*) FROM (#{tree_sql}) #{TREE_ALIAS} GROUP BY 1 ORDER BY 1")
|
|
66
|
+
pages = []
|
|
67
|
+
counts.each do |root, count|
|
|
68
|
+
root = root.to_i
|
|
69
|
+
count = count.to_i
|
|
70
|
+
if pages.empty? || pages.last[:rows] + count > tree_page_size
|
|
71
|
+
pages << {first: root, last: root, rows: count}
|
|
72
|
+
else
|
|
73
|
+
pages.last[:last] = root
|
|
74
|
+
pages.last[:rows] += count
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
pages
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def tree_page_number
|
|
82
|
+
page = current_page.to_i
|
|
83
|
+
page.clamp(1, [tree_pages.size, 1].max)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def tree_paged_scope
|
|
87
|
+
page = tree_pages[tree_page_number - 1]
|
|
88
|
+
return selected_scope.none unless page
|
|
89
|
+
|
|
90
|
+
selected_scope.where(Arel.sql("#{TREE_ALIAS}.path[1] BETWEEN #{page[:first].to_i} AND #{page[:last].to_i}"))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def tree_paging
|
|
94
|
+
@tree_paging ||= Mensa::TreePaging.new(pages: tree_pages, page: tree_page_number, request: request)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def build_tree_sql
|
|
100
|
+
connection = model.connection
|
|
101
|
+
model_table = model.quoted_table_name
|
|
102
|
+
primary_key = "#{model_table}.#{connection.quote_column_name(model.primary_key)}"
|
|
103
|
+
parent = "#{model_table}.#{connection.quote_column_name(tree_parent_column)}"
|
|
104
|
+
position = tree_position_column ? "#{model_table}.#{connection.quote_column_name(tree_position_column)}" : "NULL::integer"
|
|
105
|
+
|
|
106
|
+
base = scope.unscope(:select, :order, :limit, :offset)
|
|
107
|
+
.select(Arel.sql("DISTINCT #{primary_key} AS id, #{parent} AS parent_id, #{position} AS position"))
|
|
108
|
+
matched = filtered_scope.unscope(:select, :order, :limit, :offset).select(Arel.sql(primary_key))
|
|
109
|
+
filtering = current_query.present? || active_filters.any?
|
|
110
|
+
|
|
111
|
+
# Without a filter every row is shown and matches; with one, the matches
|
|
112
|
+
# and their ancestors
|
|
113
|
+
visible = if filtering
|
|
114
|
+
<<~SQL
|
|
115
|
+
mensa_up(id, depth) AS (
|
|
116
|
+
SELECT id, 0 FROM mensa_base WHERE id IN (SELECT id FROM mensa_matched)
|
|
117
|
+
UNION
|
|
118
|
+
SELECT mensa_base.parent_id, mensa_up.depth + 1 FROM mensa_base JOIN mensa_up ON mensa_base.id = mensa_up.id
|
|
119
|
+
WHERE mensa_base.parent_id IS NOT NULL AND mensa_up.depth < #{MAX_DEPTH}
|
|
120
|
+
),
|
|
121
|
+
mensa_visible AS (
|
|
122
|
+
SELECT mensa_base.*, mensa_base.id IN (SELECT id FROM mensa_matched) AS matched FROM mensa_base
|
|
123
|
+
WHERE mensa_base.id IN (SELECT id FROM mensa_up)
|
|
124
|
+
),
|
|
125
|
+
SQL
|
|
126
|
+
else
|
|
127
|
+
"mensa_visible AS (SELECT mensa_base.*, TRUE AS matched FROM mensa_base),\n"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
<<~SQL.squish
|
|
131
|
+
WITH RECURSIVE
|
|
132
|
+
mensa_base AS (#{base.to_sql}),
|
|
133
|
+
mensa_matched AS (#{filtering ? matched.to_sql : "SELECT NULL AS id WHERE FALSE"}),
|
|
134
|
+
#{visible}
|
|
135
|
+
mensa_ranked AS (
|
|
136
|
+
SELECT mensa_visible.*, mensa_root.root,
|
|
137
|
+
ROW_NUMBER() OVER (PARTITION BY CASE WHEN mensa_root.root THEN NULL ELSE mensa_visible.parent_id END
|
|
138
|
+
ORDER BY mensa_visible.position NULLS LAST, mensa_visible.id) AS rank
|
|
139
|
+
FROM mensa_visible
|
|
140
|
+
CROSS JOIN LATERAL (
|
|
141
|
+
SELECT mensa_visible.parent_id IS NULL OR NOT EXISTS (SELECT 1 FROM mensa_visible parents WHERE parents.id = mensa_visible.parent_id) AS root
|
|
142
|
+
) mensa_root
|
|
143
|
+
),
|
|
144
|
+
mensa_walk(id, depth, path) AS (
|
|
145
|
+
SELECT id, 0, ARRAY[rank] FROM mensa_ranked WHERE root
|
|
146
|
+
UNION ALL
|
|
147
|
+
SELECT mensa_ranked.id, mensa_walk.depth + 1, mensa_walk.path || mensa_ranked.rank
|
|
148
|
+
FROM mensa_ranked JOIN mensa_walk ON mensa_ranked.parent_id = mensa_walk.id
|
|
149
|
+
WHERE NOT mensa_ranked.root AND mensa_walk.depth < #{MAX_DEPTH}
|
|
150
|
+
)
|
|
151
|
+
SELECT mensa_walk.id, mensa_walk.depth, mensa_walk.path, mensa_ranked.matched,
|
|
152
|
+
EXISTS (SELECT 1 FROM mensa_visible children WHERE children.parent_id = mensa_walk.id) AS children
|
|
153
|
+
FROM mensa_walk JOIN mensa_ranked ON mensa_ranked.id = mensa_walk.id
|
|
154
|
+
SQL
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa
|
|
4
|
+
# A tree's pages (Mensa::Tree), which differ in size, with what the paging
|
|
5
|
+
# line asks of Pagy: the rows' count, from and to, the last page, and the
|
|
6
|
+
# pages' links (from a Pagy of one item per page)
|
|
7
|
+
class TreePaging
|
|
8
|
+
attr_reader :page
|
|
9
|
+
|
|
10
|
+
def initialize(pages:, page:, request:)
|
|
11
|
+
@pages = pages
|
|
12
|
+
@page = page
|
|
13
|
+
@request = request
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def count = @pages.sum { it[:rows] }
|
|
17
|
+
|
|
18
|
+
def last = [@pages.size, 1].max
|
|
19
|
+
|
|
20
|
+
def from
|
|
21
|
+
return 0 if @pages.empty?
|
|
22
|
+
|
|
23
|
+
@pages.first(page - 1).sum { it[:rows] } + 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to = @pages.first(page).sum { it[:rows] }
|
|
27
|
+
|
|
28
|
+
def series_nav(**)
|
|
29
|
+
pagy.series_nav(**)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def pagy
|
|
35
|
+
@pagy ||= Pagy::Offset.new(count: last, limit: 1, page: page, request: Pagy::Request.new({request: @request}))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/config/locales/en.yml
CHANGED
data/config/locales/nl.yml
CHANGED
|
@@ -140,6 +140,10 @@ nl:
|
|
|
140
140
|
format_plain: Eenvoudig CSV-bestand
|
|
141
141
|
cancel: Annuleer
|
|
142
142
|
submit: Exporteren
|
|
143
|
+
tree:
|
|
144
|
+
toggle: In- of uitklappen
|
|
145
|
+
editing:
|
|
146
|
+
not_saved: Dit kon niet worden opgeslagen
|
|
143
147
|
paging:
|
|
144
148
|
info: "%{model} %{from}-%{to} van %{count} weergeven"
|
|
145
149
|
empty_state:
|
data/config/routes.rb
CHANGED
|
@@ -5,6 +5,8 @@ Mensa::Engine.routes.draw do
|
|
|
5
5
|
resources :views, only: [:create, :update, :destroy]
|
|
6
6
|
resources :batch_actions, only: [:new, :create]
|
|
7
7
|
post "row_actions/:name/:record_id", to: "row_actions#create", as: :row_action
|
|
8
|
+
resources :rows, only: [:update]
|
|
9
|
+
post "commands/:name/:record_id", to: "commands#create", as: :command
|
|
8
10
|
resources :exports, only: [:index, :create, :destroy] do
|
|
9
11
|
member do
|
|
10
12
|
get :download
|
data/lib/mensa/configuration.rb
CHANGED
|
@@ -60,6 +60,7 @@ module Mensa
|
|
|
60
60
|
group_by_toggle: "fa-regular fa-rectangle-list",
|
|
61
61
|
group_by_selected: "fa-solid fa-check",
|
|
62
62
|
group_toggle: "fa-solid fa-chevron-down",
|
|
63
|
+
tree_toggle: "fa-solid fa-chevron-down",
|
|
63
64
|
header_order_indicator_asc: "fa-solid fa-sm fa-arrow-up",
|
|
64
65
|
header_order_indicator_desc: "fa-solid fa-sm fa-arrow-down",
|
|
65
66
|
header_order_indicator_numeric_asc: "fa-solid fa-sm fa-arrow-down-1-9",
|
|
@@ -106,6 +107,7 @@ module Mensa
|
|
|
106
107
|
# group_by_toggle: "fa-light fa-rectangle-list",
|
|
107
108
|
# group_by_selected: "fa-light fa-check",
|
|
108
109
|
# group_toggle: "fa-light fa-chevron-down",
|
|
110
|
+
# tree_toggle: "fa-light fa-chevron-down",
|
|
109
111
|
# header_order_indicator_asc: "fa-regular fa-sm fa-arrow-up-short-wide",
|
|
110
112
|
# header_order_indicator_desc: "fa-regular fa-sm fa-arrow-down-wide-short",
|
|
111
113
|
# views_trigger: "fa-light fa-sort",
|
data/lib/mensa/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mensa
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
@@ -199,6 +199,8 @@ files:
|
|
|
199
199
|
- app/components/mensa/cell/component.css
|
|
200
200
|
- app/components/mensa/cell/component.html.erb
|
|
201
201
|
- app/components/mensa/cell/component.rb
|
|
202
|
+
- app/components/mensa/cells/component.css
|
|
203
|
+
- app/components/mensa/cells/component_controller.js
|
|
202
204
|
- app/components/mensa/column_customizer/component.css
|
|
203
205
|
- app/components/mensa/column_customizer/component.html.erb
|
|
204
206
|
- app/components/mensa/column_customizer/component.rb
|
|
@@ -247,6 +249,8 @@ files:
|
|
|
247
249
|
- app/components/mensa/table_row/component.css
|
|
248
250
|
- app/components/mensa/table_row/component.html.erb
|
|
249
251
|
- app/components/mensa/table_row/component.rb
|
|
252
|
+
- app/components/mensa/tree/component.css
|
|
253
|
+
- app/components/mensa/tree/component_controller.js
|
|
250
254
|
- app/components/mensa/view/component.css
|
|
251
255
|
- app/components/mensa/view/component.html.erb
|
|
252
256
|
- app/components/mensa/view/component.rb
|
|
@@ -256,11 +260,14 @@ files:
|
|
|
256
260
|
- app/components/mensa/views/component.rb
|
|
257
261
|
- app/components/mensa/views/component_controller.js
|
|
258
262
|
- app/controllers/concerns/.keep
|
|
263
|
+
- app/controllers/concerns/mensa/table_from_request.rb
|
|
259
264
|
- app/controllers/mensa/application_controller.rb
|
|
260
265
|
- app/controllers/mensa/tables/batch_actions_controller.rb
|
|
266
|
+
- app/controllers/mensa/tables/commands_controller.rb
|
|
261
267
|
- app/controllers/mensa/tables/exports_controller.rb
|
|
262
268
|
- app/controllers/mensa/tables/filters_controller.rb
|
|
263
269
|
- app/controllers/mensa/tables/row_actions_controller.rb
|
|
270
|
+
- app/controllers/mensa/tables/rows_controller.rb
|
|
264
271
|
- app/controllers/mensa/tables/views_controller.rb
|
|
265
272
|
- app/controllers/mensa/tables_controller.rb
|
|
266
273
|
- app/helpers/mensa/application_helper.rb
|
|
@@ -284,10 +291,13 @@ files:
|
|
|
284
291
|
- app/tables/mensa/batch_action.rb
|
|
285
292
|
- app/tables/mensa/cell.rb
|
|
286
293
|
- app/tables/mensa/column.rb
|
|
294
|
+
- app/tables/mensa/command.rb
|
|
287
295
|
- app/tables/mensa/config/action_dsl.rb
|
|
288
296
|
- app/tables/mensa/config/batch_dsl.rb
|
|
289
297
|
- app/tables/mensa/config/column_dsl.rb
|
|
298
|
+
- app/tables/mensa/config/command_dsl.rb
|
|
290
299
|
- app/tables/mensa/config/dsl_logic.rb
|
|
300
|
+
- app/tables/mensa/config/editable_dsl.rb
|
|
291
301
|
- app/tables/mensa/config/filter_dsl.rb
|
|
292
302
|
- app/tables/mensa/config/format_dsl.rb
|
|
293
303
|
- app/tables/mensa/config/render_dsl.rb
|
|
@@ -303,11 +313,14 @@ files:
|
|
|
303
313
|
- app/tables/mensa/search.rb
|
|
304
314
|
- app/tables/mensa/system_view.rb
|
|
305
315
|
- app/tables/mensa/table_params.rb
|
|
316
|
+
- app/tables/mensa/tree.rb
|
|
317
|
+
- app/tables/mensa/tree_paging.rb
|
|
306
318
|
- app/views/mensa/exports/_badge.html.erb
|
|
307
319
|
- app/views/mensa/exports/_dialog.html.erb
|
|
308
320
|
- app/views/mensa/exports/_list.html.erb
|
|
309
321
|
- app/views/mensa/tables/batch_actions/new.html.erb
|
|
310
322
|
- app/views/mensa/tables/filters/show.turbo_stream.erb
|
|
323
|
+
- app/views/mensa/tables/rows/update.turbo_stream.erb
|
|
311
324
|
- app/views/mensa/tables/show.html.erb
|
|
312
325
|
- app/views/mensa/tables/show.turbo_stream.erb
|
|
313
326
|
- app/views/mensa/tables/views/create.turbo_stream.erb
|