base_editing_bootstrap 0.9.1 → 0.10.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/CHANGELOG.md +8 -0
- data/README.md +3 -0
- data/app/controllers/base_editing_controller.rb +9 -2
- data/lib/base_editing_bootstrap/VERSION +1 -1
- data/lib/base_editing_bootstrap/searches/base.rb +8 -6
- data/lib/generators/base_editing_bootstrap/scaffold/scaffold_generator.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae3826e47810ce15c5ddb8c1e4abacb4af039cec40b2f2b835170691250357d0
|
4
|
+
data.tar.gz: '03069a335d73eaa8d449635c544315a154a66e18758f5d3e774f804e8fbf7d9b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 036470dfdaab3d46b054539d3a958bfed2138f443248f245917a1c258f420cf2a63174ff945ff164df62a001ad343814c48f87cf31c9cab696a9995b34d0b8ee
|
7
|
+
data.tar.gz: 2845c50faabf84b474f57c0144876e35661c22e38b042a4386f5c9f2eef01ba4f47b516cf6fff39cd051047920a1ac0de9da26978a5d0227952f8d201601a461
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
3
3
|
|
4
4
|
- - -
|
5
|
+
## 0.10.0 - 2024-06-26
|
6
|
+
#### Features
|
7
|
+
- Add sort configuration per controller - (0cca665) - Marino Bonetti
|
8
|
+
#### Miscellaneous Chores
|
9
|
+
- Add ignore to assets - (aff4ac6) - Marino Bonetti
|
10
|
+
|
11
|
+
- - -
|
12
|
+
|
5
13
|
## 0.9.1 - 2024-06-17
|
6
14
|
#### Bug Fixes
|
7
15
|
- Change http status check from symbol to number - (1ecd63d) - Marino Bonetti
|
data/README.md
CHANGED
@@ -86,6 +86,9 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
86
86
|
- Creare Controller:
|
87
87
|
```ruby
|
88
88
|
class PostsController < BaseEditingController
|
89
|
+
##
|
90
|
+
# Set default sort order for ransack
|
91
|
+
# self.default_sort= ["id"]
|
89
92
|
end
|
90
93
|
```
|
91
94
|
- Aggiungere la rotta: `resources :posts`
|
@@ -9,12 +9,19 @@ class BaseEditingController < RestrictedAreaController
|
|
9
9
|
:new_custom_polymorphic_path,
|
10
10
|
:show_custom_polymorphic_path
|
11
11
|
|
12
|
+
##
|
13
|
+
# Configure default sort in the index query.
|
14
|
+
# Works like documented in https://activerecord-hackery.github.io/ransack/getting-started/sorting/#sorting-in-the-controller
|
15
|
+
class_attribute :default_sorts, default: ["id"]
|
16
|
+
|
12
17
|
def index
|
13
18
|
authorize base_class
|
14
19
|
|
15
20
|
q = policy_scope(base_scope)
|
16
|
-
|
17
|
-
|
21
|
+
@search_instance = search_class.new(q, current_user,
|
22
|
+
params: params.permit(:page, :q => {}), # FIXME trovare modo per essere più "STRONG"
|
23
|
+
sorts: default_sorts
|
24
|
+
)
|
18
25
|
@search_instance = yield(@search_instance) if block_given?
|
19
26
|
end
|
20
27
|
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.10.0
|
@@ -7,24 +7,26 @@ module BaseEditingBootstrap::Searches
|
|
7
7
|
include ActiveModel::Naming
|
8
8
|
include ActiveModel::Conversion
|
9
9
|
|
10
|
-
attr_reader :model_klass, :user, :params, :scope
|
10
|
+
attr_reader :model_klass, :user, :params, :scope, :sorts
|
11
11
|
|
12
12
|
# @param [User] user
|
13
13
|
# @param [ActiveRecord::Associations::CollectionProxy] scope
|
14
|
-
|
14
|
+
# @param [Array<String (frozen)>] sort
|
15
|
+
def initialize(scope, user, params: {page: nil}, sorts: ["id"])
|
15
16
|
@model_klass = scope.klass
|
16
17
|
@user = user
|
17
18
|
@scope = scope
|
18
19
|
@params = params
|
20
|
+
@sorts = sorts
|
19
21
|
end
|
20
22
|
|
21
23
|
##
|
22
24
|
# Risultato della ricerca, fa da pipeline verso ransack
|
25
|
+
# Impostando il sort nel caso in cui non sia già stato impostato da ransack
|
23
26
|
def results
|
24
|
-
ransack_query
|
25
|
-
.
|
26
|
-
|
27
|
-
.page(params[:page])
|
27
|
+
ransack_query.tap { |r|
|
28
|
+
r.sorts = @sorts if r.sorts.empty?
|
29
|
+
}.result(distinct: true).page(params[:page])
|
28
30
|
end
|
29
31
|
|
30
32
|
def ransack_query
|
@@ -22,7 +22,7 @@ module BaseEditingBootstrap
|
|
22
22
|
opts = ["--no-helper", "--parent=BaseEditingController"]
|
23
23
|
opts << "--force" if options.force?
|
24
24
|
generate "controller", controller_class_name, *opts
|
25
|
-
|
25
|
+
# TODO usare i template ed aggiungere l'esempio della ricerca
|
26
26
|
route "resources :#{plural_name}"
|
27
27
|
|
28
28
|
template "spec/request.rb", File.join("spec/requests", "#{plural_file_name}_spec.rb")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_editing_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marino Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|