katalyst-koi 4.10.2 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86d353682a7508a9cb09164c404b77c7f9a6f6eb581c2312c3af0160ae3e2ec7
4
- data.tar.gz: 3b45058189a7ba04b89c28c50653724e7a4ed8a5423d5ab8bca569dcb654688e
3
+ metadata.gz: 9e93ae67d5b7a194d086ac058e4ce50b719a6b09f8683cc75a77a3bbe65ba540
4
+ data.tar.gz: 57cf5e6fecd3feda7033316da41920a9018e423d87ed953618ce1ee32ce6101d
5
5
  SHA512:
6
- metadata.gz: fe9716dcb12c3c67ef97ae43e95c5356519b23cfd2b5f8a5ee69f63cf2a4ba7473fcb5f3647b90d7d828896d8bf26f9f98d2f4162085f0f5ea9969e35b4e6f2a
7
- data.tar.gz: c1152404ac4844f7a21a9903e6998b4cd4b0aa48bf83205b013e3aa8c139d04444c039c3de2ed64190a7936b496be9b86164f38800e96eeb6eb41e030666b22d
6
+ metadata.gz: 2951257ff44bb56a689d18dbae88a1644f6e4840b0a3d0fb5718821a023d4a04ea4bf9ffeaf0be714b8240170510da04356ec1f25f9e98c4426927087df3662e
7
+ data.tar.gz: 70946f90ec2799e9076041b99154b389d03e699f4fe746f72bccb17c9b49ade2c1bd6e311427708c3ee13d01003f5eb2c484944f145869e6e40258d361c517ef
@@ -12,6 +12,12 @@ module Admin
12
12
  render locals: { collection: }
13
13
  end
14
14
 
15
+ def archived
16
+ collection = Collection.new.with_params(params).apply(Admin::User.archived.strict_loading)
17
+
18
+ render locals: { collection: }
19
+ end
20
+
15
21
  def show
16
22
  render :show, locals: { admin: }
17
23
  end
@@ -78,7 +84,6 @@ module Admin
78
84
 
79
85
  attribute :name, :string
80
86
  attribute :email, :string
81
- attribute :status, :archivable, default: :active
82
87
  attribute :last_sign_in_at, :date
83
88
  attribute :sign_in_count, :integer
84
89
  end
@@ -14,15 +14,6 @@ module Koi
14
14
  # Model.all # default scope, excludes archived
15
15
  # Model.archived # only returns archived records
16
16
  # Model.with_archived # returns all records
17
- #
18
- # Filtering:
19
- # Use the custom `:archivable` enum attribute in Admin::Collections to
20
- # filter on this property, e.g.
21
- #
22
- # attribute :status, :archivable, default: :active
23
- #
24
- # Note: although it's theoretically possible to archive something in the
25
- # future, this module does not support queries using dates.
26
17
  module Archivable
27
18
  extend ActiveSupport::Concern
28
19
 
@@ -31,17 +22,6 @@ module Koi
31
22
  scope :archived, -> { unscope(where: :archived_at).where.not(archived_at: nil) }
32
23
  scope :with_archived, -> { unscope(where: :archived_at) }
33
24
 
34
- scope :status, ->(status) do
35
- case status.to_s
36
- when "active"
37
- not_archived
38
- when "archived"
39
- archived
40
- else
41
- with_archived
42
- end
43
- end
44
-
45
25
  default_scope { not_archived }
46
26
 
47
27
  alias_method :archived?, :archived
@@ -70,6 +50,7 @@ module Koi
70
50
  def archive!
71
51
  archive
72
52
  save!(validate: false) if persisted?
53
+ self
73
54
  end
74
55
 
75
56
  # Mark a record as no longer archived. It will appear in default queries.
@@ -81,6 +62,7 @@ module Koi
81
62
  def restore!
82
63
  restore
83
64
  save!(validate: false) if persisted?
65
+ self
84
66
  end
85
67
  end
86
68
  end
@@ -0,0 +1,19 @@
1
+ <% content_for :header do %>
2
+ <%= render Koi::Header::IndexComponent.new(model: Admin::User, title: "Archived") do |component| %>
3
+ <% component.with_breadcrumb "Admins", admin_admin_users_path %>
4
+ <% end %>
5
+ <% end %>
6
+
7
+ <%= table_query_with(collection:) %>
8
+
9
+ <%= table_selection_with(collection:) do %>
10
+ <%= tag.button "Restore", formaction: restore_admin_admin_users_path, formmethod: :put %>
11
+ <% end %>
12
+
13
+ <%= table_with(collection:) do |row| %>
14
+ <% row.select %>
15
+ <% row.link :name, url: :admin_admin_user_path %>
16
+ <% row.text :email %>
17
+ <% end %>
18
+
19
+ <%== pagy_nav(collection.pagination) %>
@@ -1,6 +1,7 @@
1
1
  <% content_for :header do %>
2
2
  <%= render Koi::Header::IndexComponent.new(model: Admin::User) do |component| %>
3
3
  <% component.with_action "New", new_admin_admin_user_path %>
4
+ <% component.with_action "Archived", archived_admin_admin_users_path %>
4
5
  <% end %>
5
6
  <% end %>
6
7
 
@@ -8,10 +9,9 @@
8
9
 
9
10
  <%= table_selection_with(collection:) do %>
10
11
  <%= tag.button "Archive", formaction: archive_admin_admin_users_path, formmethod: :put %>
11
- <%= tag.button "Restore", formaction: restore_admin_admin_users_path, formmethod: :put %>
12
12
  <% end %>
13
13
 
14
- <%= table_with(collection:) do |row, admin| %>
14
+ <%= table_with(collection:) do |row| %>
15
15
  <% row.select %>
16
16
  <% row.link :name, url: :admin_admin_user_path %>
17
17
  <% row.text :email %>
@@ -15,11 +15,6 @@ en:
15
15
  labels:
16
16
  new: New
17
17
  search: Search
18
- view:
19
- status:
20
- active: "%{model} that are not archived"
21
- archived: "%{model} that are archived"
22
- all: "All %{model}, archived or not"
23
18
  helpers:
24
19
  hint:
25
20
  default:
data/config/routes.rb CHANGED
@@ -10,6 +10,7 @@ Rails.application.routes.draw do
10
10
  resources :admin_users do
11
11
  resources :credentials, only: %i[new create destroy]
12
12
  post :invite, on: :member, to: "tokens#create"
13
+ get :archived, on: :collection
13
14
  put :archive, on: :collection
14
15
  put :restore, on: :collection
15
16
  end
data/lib/koi/engine.rb CHANGED
@@ -63,10 +63,6 @@ module Koi
63
63
  Pagy::I18n.load(locale: "en", filepath: root.join("config/locales/pagy.en.yml"))
64
64
  end
65
65
 
66
- initializer "koi.tables" do
67
- Katalyst::Tables.config.collection_types[:archivable] = "Koi::Collection::Type::Archivable"
68
- end
69
-
70
66
  initializer "koi.views" do
71
67
  ActiveSupport.on_load(:action_view) do
72
68
  # Workaround for de-duplicating nested module paths for admin controllers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-koi
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.2
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
@@ -364,6 +364,7 @@ files:
364
364
  - app/models/concerns/koi/model/archivable.rb
365
365
  - app/models/url_rewrite.rb
366
366
  - app/views/admin/admin_users/_fields.html.erb
367
+ - app/views/admin/admin_users/archived.html.erb
367
368
  - app/views/admin/admin_users/edit.html.erb
368
369
  - app/views/admin/admin_users/index.html.erb
369
370
  - app/views/admin/admin_users/new.html.erb
@@ -445,7 +446,6 @@ files:
445
446
  - lib/katalyst/koi.rb
446
447
  - lib/koi.rb
447
448
  - lib/koi/caching.rb
448
- - lib/koi/collection/type/archivable.rb
449
449
  - lib/koi/config.rb
450
450
  - lib/koi/engine.rb
451
451
  - lib/koi/extensions/object_rendering.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Koi
4
- module Collection
5
- module Type
6
- # Add support for `attribute :status, :archivable, default: :active` to
7
- # Koi collections to support filtering on Koi::Model::Archivable models.
8
- class Archivable < Katalyst::Tables::Collection::Type::Enum
9
- def initialize(scope: :status)
10
- super(multiple: false, scope:)
11
- end
12
-
13
- def type
14
- :archivable
15
- end
16
-
17
- def examples_for(scope, attribute)
18
- _, model, = model_and_column_for(scope, attribute)
19
-
20
- %i[active archived all].map do |key|
21
- example(key, describe_key(model, attribute, key))
22
- end
23
- end
24
-
25
- private
26
-
27
- def describe_key(model, attribute, key)
28
- description = I18n.t("koi.view.#{attribute.name}.#{key}", model: model.model_name.human)
29
- description += " (default)" if key.to_s.eql?(attribute.original_value.to_s)
30
- description
31
- end
32
- end
33
- end
34
- end
35
- end