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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 381f05d45f31b238938d693c7aa3cd400548d1e1ae0d0ad7cbe741a90e848388
4
- data.tar.gz: 404d83a3470a1aed66274acf316c8de5ef9cc5979b1b9690966bd75f9827d54c
3
+ metadata.gz: fa5269cd718a91bde462e97b6ace9e7c56e7c7d443c04a2fcc49eb3c3028f79b
4
+ data.tar.gz: 520886c5eabd7bc6019c492844f4cf769b952187df5d6f4584a8d24655abb23b
5
5
  SHA512:
6
- metadata.gz: 7d136de094a54f232f539adb89955e25bae6cf203adf00601bedb186dcd1b733421920cb1596bdcdf72eb14716d7c2cc227284b2d39a69a8eeb21b1efeebbc87
7
- data.tar.gz: 0b0b225894bcb23f2443a853e30396c184dc38a3fb7a8a46fa1b3abca2c98fa0879858e3f74f80b94d3d063799d9031755955b9bd1c8c5164eba6d9db1e23a24
6
+ metadata.gz: 294e3a6d916b8034edcb1e6ecb914d49c3deac90d0c7bffee59c1978037af095a82a95e25be67aaaa8fe71c1c3d2c68e0b2cf0a8a57a835819f6a1daf5eced4f
7
+ data.tar.gz: 78fbaec64bca5bd634895343b99b80adc1959cd3df3d419458477598fa3c0909654f8a3cdf4232468b4edb7fdf78a2e91dee345fb36d830cce1f917aba1724ab
data/.shipkit.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- previous_version: 0.9.7
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mensa (0.9.7)
4
+ mensa (0.9.8)
5
5
  csv
6
6
  importmap-rails
7
7
  pagy (>= 43)
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(action.link ? table.original_view_context.instance_exec(row.record, &action.link) : "", {class: "action", title: action.title}.merge(action.link_attributes || {})) do %>
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
@@ -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
@@ -9,6 +9,7 @@ module Mensa::Config
9
9
  option :show, default: ->(record) { true }
10
10
  option :link
11
11
  option :link_attributes, default: {}
12
+ option :process
12
13
 
13
14
  delegate :t, to: :I18n
14
15
  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
@@ -1,3 +1,3 @@
1
1
  module Mensa
2
- VERSION = "0.9.8"
2
+ VERSION = "0.9.9"
3
3
  end
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.8
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