mensa 0.9.8 → 0.9.9
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 +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/app/components/mensa/row_action/component.html.erb +1 -1
- data/app/components/mensa/row_action/component.rb +16 -0
- data/app/controllers/mensa/tables/row_actions_controller.rb +25 -0
- data/app/tables/mensa/action.rb +12 -0
- data/app/tables/mensa/config/action_dsl.rb +1 -0
- data/config/routes.rb +1 -0
- data/lib/mensa/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa5269cd718a91bde462e97b6ace9e7c56e7c7d443c04a2fcc49eb3c3028f79b
|
|
4
|
+
data.tar.gz: 520886c5eabd7bc6019c492844f4cf769b952187df5d6f4584a8d24655abb23b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 294e3a6d916b8034edcb1e6ecb914d49c3deac90d0c7bffee59c1978037af095a82a95e25be67aaaa8fe71c1c3d2c68e0b2cf0a8a57a835819f6a1daf5eced4f
|
|
7
|
+
data.tar.gz: 78fbaec64bca5bd634895343b99b80adc1959cd3df3d419458477598fa3c0909654f8a3cdf4232468b4edb7fdf78a2e91dee345fb36d830cce1f917aba1724ab
|
data/.shipkit.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
previous_version: 0.9.
|
|
2
|
+
previous_version: 0.9.8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.9
|
|
4
|
+
|
|
5
|
+
- A row action can `process` the record instead of linking somewhere, for
|
|
6
|
+
small actions that don't need a controller of their own:
|
|
7
|
+
`action(:activate) { process { |user| user.activate! } }`. It renders as a
|
|
8
|
+
Turbo POST link (so it works in a table inside a host form) to a Mensa
|
|
9
|
+
endpoint, which finds the record through the table's scope and its params,
|
|
10
|
+
runs the block when the action's `show` allows it, and redirects back.
|
|
11
|
+
`link_attributes` still apply, e.g. for a `turbo_confirm`.
|
|
12
|
+
|
|
3
13
|
## 0.9.8
|
|
4
14
|
|
|
5
15
|
- The export, save-view and rename-view dialogs are in the middle of the
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -75,6 +75,18 @@ class UserTable < ApplicationTable
|
|
|
75
75
|
show ->(user) { true }
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
# Or run a bit of code with the record, without a controller of your own.
|
|
79
|
+
# Mensa POSTs to its own endpoint, which finds the record through the table's
|
|
80
|
+
# scope (and only runs the action when `show` allows it), then redirects back.
|
|
81
|
+
action :activate do
|
|
82
|
+
title "Activate"
|
|
83
|
+
icon "fa-regular fa-check"
|
|
84
|
+
show ->(user) { !user.active? }
|
|
85
|
+
process do |user|
|
|
86
|
+
user.activate!
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
78
90
|
link { |user| edit_user_path(user) }
|
|
79
91
|
|
|
80
92
|
show_header true
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% if action.show.call(row.record) %>
|
|
2
|
-
<%= link_to(
|
|
2
|
+
<%= link_to(href, {class: "action", title: action.title}.deep_merge(attributes)) do %>
|
|
3
3
|
|
|
4
4
|
<% if icon = action.icon(row.record) %>
|
|
5
5
|
<i class="fa <%= icon %>"></i>
|
|
@@ -14,6 +14,22 @@ module Mensa
|
|
|
14
14
|
@row = row
|
|
15
15
|
@action = action
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
def href
|
|
19
|
+
if action.process?
|
|
20
|
+
# A Turbo POST link rather than button_to, a table can be inside a host form
|
|
21
|
+
table.path_with_params(helpers.mensa.table_row_action_path(table.name, action.name, row.record.id))
|
|
22
|
+
elsif action.link
|
|
23
|
+
table.original_view_context.instance_exec(row.record, &action.link)
|
|
24
|
+
else
|
|
25
|
+
""
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def attributes
|
|
30
|
+
attributes = action.link_attributes || {}
|
|
31
|
+
action.process? ? {data: {turbo_method: :post}}.deep_merge(attributes) : attributes
|
|
32
|
+
end
|
|
17
33
|
end
|
|
18
34
|
end
|
|
19
35
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mensa
|
|
4
|
+
module Tables
|
|
5
|
+
class RowActionsController < ::ApplicationController
|
|
6
|
+
def create
|
|
7
|
+
table_name = params[:table_id]
|
|
8
|
+
|
|
9
|
+
table = Mensa.for_name(table_name, params: Mensa::TableParams.from_request(params))
|
|
10
|
+
table.original_view_context = helpers
|
|
11
|
+
|
|
12
|
+
action = table.actions.find { |a| a.name == params[:name]&.to_sym && a.process? }
|
|
13
|
+
return head :not_found unless action
|
|
14
|
+
|
|
15
|
+
# Only records the table shows, and only when it shows the action
|
|
16
|
+
record = table.scope.find_by(table.model.primary_key => params[:record_id])
|
|
17
|
+
return head :not_found unless record && action.show.call(record)
|
|
18
|
+
|
|
19
|
+
action.process.call(record)
|
|
20
|
+
|
|
21
|
+
redirect_back_or_to helpers.mensa.table_path(table_name), status: :see_other
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/app/tables/mensa/action.rb
CHANGED
|
@@ -8,6 +8,13 @@ module Mensa
|
|
|
8
8
|
# link_attributes "data-turbo-method" => "delete"
|
|
9
9
|
# icon "fa-xmark"
|
|
10
10
|
# end
|
|
11
|
+
#
|
|
12
|
+
# Or run a bit of code with the record, without a controller of your own:
|
|
13
|
+
#
|
|
14
|
+
# action :activate do
|
|
15
|
+
# process { |user| user.activate! }
|
|
16
|
+
# icon "fa-check"
|
|
17
|
+
# end
|
|
11
18
|
class Action
|
|
12
19
|
include ConfigReaders
|
|
13
20
|
|
|
@@ -33,5 +40,10 @@ module Mensa
|
|
|
33
40
|
config_reader :link, call: false
|
|
34
41
|
config_reader :link_attributes
|
|
35
42
|
config_reader :show, call: false
|
|
43
|
+
config_reader :process, call: false
|
|
44
|
+
|
|
45
|
+
def process?
|
|
46
|
+
process.present?
|
|
47
|
+
end
|
|
36
48
|
end
|
|
37
49
|
end
|
data/config/routes.rb
CHANGED
|
@@ -4,6 +4,7 @@ Mensa::Engine.routes.draw do
|
|
|
4
4
|
resources :filters
|
|
5
5
|
resources :views, only: [:create, :update, :destroy]
|
|
6
6
|
resources :batch_actions, only: [:create]
|
|
7
|
+
post "row_actions/:name/:record_id", to: "row_actions#create", as: :row_action
|
|
7
8
|
resources :exports, only: [:index, :create, :destroy] do
|
|
8
9
|
member do
|
|
9
10
|
get :download
|
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.9.
|
|
4
|
+
version: 0.9.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
@@ -260,6 +260,7 @@ files:
|
|
|
260
260
|
- app/controllers/mensa/tables/batch_actions_controller.rb
|
|
261
261
|
- app/controllers/mensa/tables/exports_controller.rb
|
|
262
262
|
- app/controllers/mensa/tables/filters_controller.rb
|
|
263
|
+
- app/controllers/mensa/tables/row_actions_controller.rb
|
|
263
264
|
- app/controllers/mensa/tables/views_controller.rb
|
|
264
265
|
- app/controllers/mensa/tables_controller.rb
|
|
265
266
|
- app/helpers/mensa/application_helper.rb
|