power_grid 0.1.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 +7 -0
- data/.github/workflows/ci.yml +24 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +272 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +6 -0
- data/app/components/power_grid/table_component.html.erb +127 -0
- data/app/components/power_grid/table_component.rb +29 -0
- data/app/javascript/controllers/power_grid/table_controller.js +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/assets/ui_mockup.png +0 -0
- data/lib/power_grid/base.rb +154 -0
- data/lib/power_grid/engine.rb +19 -0
- data/lib/power_grid/version.rb +3 -0
- data/lib/power_grid.rb +9 -0
- data/power_grid.gemspec +38 -0
- metadata +191 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 375c1ae59e3f85bc75cc81e1d5a6ff83e721a6aa2889e0e2bfcf7c95036957b0
|
|
4
|
+
data.tar.gz: 7f2e36254faba5169556809115868a146b3c4610d4efe68538defef60026bb6a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9de32b37843c0b4a2fc649d35c48bdb8bf55d13c6ecddb989d394b24e325f76caa6b93e6f695d9e2b86af62eeb98db4457b80df027eb4ae66a5487830b33fd1c
|
|
7
|
+
data.tar.gz: 49a17f93efe51b4e3a8a4b6f4a46cf0ad1117fb262479af8c77469a0f5cc7f1d0b0a8f4df453224a601fc7088ea7156a1f2639380a610611b85a7c22391e3957
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3']
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v3
|
|
18
|
+
- name: Set up Ruby
|
|
19
|
+
uses: ruby/setup-ruby@v1
|
|
20
|
+
with:
|
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
22
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
23
|
+
- name: Run tests
|
|
24
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at bhavin.nandani@rackspace.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
power_grid (0.1.0)
|
|
5
|
+
importmap-rails
|
|
6
|
+
rails (>= 6.0)
|
|
7
|
+
turbo-rails
|
|
8
|
+
view_component
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
13
|
+
actioncable (7.1.6)
|
|
14
|
+
actionpack (= 7.1.6)
|
|
15
|
+
activesupport (= 7.1.6)
|
|
16
|
+
nio4r (~> 2.0)
|
|
17
|
+
websocket-driver (>= 0.6.1)
|
|
18
|
+
zeitwerk (~> 2.6)
|
|
19
|
+
actionmailbox (7.1.6)
|
|
20
|
+
actionpack (= 7.1.6)
|
|
21
|
+
activejob (= 7.1.6)
|
|
22
|
+
activerecord (= 7.1.6)
|
|
23
|
+
activestorage (= 7.1.6)
|
|
24
|
+
activesupport (= 7.1.6)
|
|
25
|
+
mail (>= 2.7.1)
|
|
26
|
+
net-imap
|
|
27
|
+
net-pop
|
|
28
|
+
net-smtp
|
|
29
|
+
actionmailer (7.1.6)
|
|
30
|
+
actionpack (= 7.1.6)
|
|
31
|
+
actionview (= 7.1.6)
|
|
32
|
+
activejob (= 7.1.6)
|
|
33
|
+
activesupport (= 7.1.6)
|
|
34
|
+
mail (~> 2.5, >= 2.5.4)
|
|
35
|
+
net-imap
|
|
36
|
+
net-pop
|
|
37
|
+
net-smtp
|
|
38
|
+
rails-dom-testing (~> 2.2)
|
|
39
|
+
actionpack (7.1.6)
|
|
40
|
+
actionview (= 7.1.6)
|
|
41
|
+
activesupport (= 7.1.6)
|
|
42
|
+
cgi
|
|
43
|
+
nokogiri (>= 1.8.5)
|
|
44
|
+
racc
|
|
45
|
+
rack (>= 2.2.4)
|
|
46
|
+
rack-session (>= 1.0.1)
|
|
47
|
+
rack-test (>= 0.6.3)
|
|
48
|
+
rails-dom-testing (~> 2.2)
|
|
49
|
+
rails-html-sanitizer (~> 1.6)
|
|
50
|
+
actiontext (7.1.6)
|
|
51
|
+
actionpack (= 7.1.6)
|
|
52
|
+
activerecord (= 7.1.6)
|
|
53
|
+
activestorage (= 7.1.6)
|
|
54
|
+
activesupport (= 7.1.6)
|
|
55
|
+
globalid (>= 0.6.0)
|
|
56
|
+
nokogiri (>= 1.8.5)
|
|
57
|
+
actionview (7.1.6)
|
|
58
|
+
activesupport (= 7.1.6)
|
|
59
|
+
builder (~> 3.1)
|
|
60
|
+
cgi
|
|
61
|
+
erubi (~> 1.11)
|
|
62
|
+
rails-dom-testing (~> 2.2)
|
|
63
|
+
rails-html-sanitizer (~> 1.6)
|
|
64
|
+
activejob (7.1.6)
|
|
65
|
+
activesupport (= 7.1.6)
|
|
66
|
+
globalid (>= 0.3.6)
|
|
67
|
+
activemodel (7.1.6)
|
|
68
|
+
activesupport (= 7.1.6)
|
|
69
|
+
activerecord (7.1.6)
|
|
70
|
+
activemodel (= 7.1.6)
|
|
71
|
+
activesupport (= 7.1.6)
|
|
72
|
+
timeout (>= 0.4.0)
|
|
73
|
+
activestorage (7.1.6)
|
|
74
|
+
actionpack (= 7.1.6)
|
|
75
|
+
activejob (= 7.1.6)
|
|
76
|
+
activerecord (= 7.1.6)
|
|
77
|
+
activesupport (= 7.1.6)
|
|
78
|
+
marcel (~> 1.0)
|
|
79
|
+
activesupport (7.1.6)
|
|
80
|
+
base64
|
|
81
|
+
benchmark (>= 0.3)
|
|
82
|
+
bigdecimal
|
|
83
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
84
|
+
connection_pool (>= 2.2.5)
|
|
85
|
+
drb
|
|
86
|
+
i18n (>= 1.6, < 2)
|
|
87
|
+
logger (>= 1.4.2)
|
|
88
|
+
minitest (>= 5.1)
|
|
89
|
+
mutex_m
|
|
90
|
+
securerandom (>= 0.3)
|
|
91
|
+
tzinfo (~> 2.0)
|
|
92
|
+
addressable (2.8.8)
|
|
93
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
94
|
+
base64 (0.3.0)
|
|
95
|
+
benchmark (0.5.0)
|
|
96
|
+
bigdecimal (3.3.1)
|
|
97
|
+
builder (3.3.0)
|
|
98
|
+
capybara (3.39.2)
|
|
99
|
+
addressable
|
|
100
|
+
matrix
|
|
101
|
+
mini_mime (>= 0.1.3)
|
|
102
|
+
nokogiri (~> 1.8)
|
|
103
|
+
rack (>= 1.6.0)
|
|
104
|
+
rack-test (>= 0.6.3)
|
|
105
|
+
regexp_parser (>= 1.5, < 3.0)
|
|
106
|
+
xpath (~> 3.2)
|
|
107
|
+
cgi (0.5.1)
|
|
108
|
+
concurrent-ruby (1.3.5)
|
|
109
|
+
connection_pool (2.5.5)
|
|
110
|
+
crass (1.0.6)
|
|
111
|
+
date (3.5.1)
|
|
112
|
+
diff-lcs (1.6.2)
|
|
113
|
+
drb (2.2.3)
|
|
114
|
+
erb (4.0.4)
|
|
115
|
+
cgi (>= 0.3.3)
|
|
116
|
+
erubi (1.13.1)
|
|
117
|
+
globalid (1.3.0)
|
|
118
|
+
activesupport (>= 6.1)
|
|
119
|
+
i18n (1.14.7)
|
|
120
|
+
concurrent-ruby (~> 1.0)
|
|
121
|
+
importmap-rails (2.0.3)
|
|
122
|
+
actionpack (>= 6.0.0)
|
|
123
|
+
activesupport (>= 6.0.0)
|
|
124
|
+
railties (>= 6.0.0)
|
|
125
|
+
io-console (0.8.1)
|
|
126
|
+
irb (1.15.3)
|
|
127
|
+
pp (>= 0.6.0)
|
|
128
|
+
rdoc (>= 4.0.0)
|
|
129
|
+
reline (>= 0.4.2)
|
|
130
|
+
logger (1.7.0)
|
|
131
|
+
loofah (2.24.1)
|
|
132
|
+
crass (~> 1.0.2)
|
|
133
|
+
nokogiri (>= 1.12.0)
|
|
134
|
+
mail (2.9.0)
|
|
135
|
+
logger
|
|
136
|
+
mini_mime (>= 0.1.1)
|
|
137
|
+
net-imap
|
|
138
|
+
net-pop
|
|
139
|
+
net-smtp
|
|
140
|
+
marcel (1.1.0)
|
|
141
|
+
matrix (0.4.3)
|
|
142
|
+
method_source (1.1.0)
|
|
143
|
+
mini_mime (1.1.5)
|
|
144
|
+
mini_portile2 (2.8.9)
|
|
145
|
+
minitest (5.26.1)
|
|
146
|
+
mutex_m (0.3.0)
|
|
147
|
+
net-imap (0.4.22)
|
|
148
|
+
date
|
|
149
|
+
net-protocol
|
|
150
|
+
net-pop (0.1.2)
|
|
151
|
+
net-protocol
|
|
152
|
+
net-protocol (0.2.2)
|
|
153
|
+
timeout
|
|
154
|
+
net-smtp (0.5.1)
|
|
155
|
+
net-protocol
|
|
156
|
+
nio4r (2.7.5)
|
|
157
|
+
nokogiri (1.15.7)
|
|
158
|
+
mini_portile2 (~> 2.8.2)
|
|
159
|
+
racc (~> 1.4)
|
|
160
|
+
pp (0.6.3)
|
|
161
|
+
prettyprint
|
|
162
|
+
prettyprint (0.2.0)
|
|
163
|
+
psych (5.3.0)
|
|
164
|
+
date
|
|
165
|
+
stringio
|
|
166
|
+
public_suffix (5.1.1)
|
|
167
|
+
racc (1.8.1)
|
|
168
|
+
rack (3.2.4)
|
|
169
|
+
rack-session (2.1.1)
|
|
170
|
+
base64 (>= 0.1.0)
|
|
171
|
+
rack (>= 3.0.0)
|
|
172
|
+
rack-test (2.2.0)
|
|
173
|
+
rack (>= 1.3)
|
|
174
|
+
rackup (2.3.1)
|
|
175
|
+
rack (>= 3)
|
|
176
|
+
rails (7.1.6)
|
|
177
|
+
actioncable (= 7.1.6)
|
|
178
|
+
actionmailbox (= 7.1.6)
|
|
179
|
+
actionmailer (= 7.1.6)
|
|
180
|
+
actionpack (= 7.1.6)
|
|
181
|
+
actiontext (= 7.1.6)
|
|
182
|
+
actionview (= 7.1.6)
|
|
183
|
+
activejob (= 7.1.6)
|
|
184
|
+
activemodel (= 7.1.6)
|
|
185
|
+
activerecord (= 7.1.6)
|
|
186
|
+
activestorage (= 7.1.6)
|
|
187
|
+
activesupport (= 7.1.6)
|
|
188
|
+
bundler (>= 1.15.0)
|
|
189
|
+
railties (= 7.1.6)
|
|
190
|
+
rails-dom-testing (2.3.0)
|
|
191
|
+
activesupport (>= 5.0.0)
|
|
192
|
+
minitest
|
|
193
|
+
nokogiri (>= 1.6)
|
|
194
|
+
rails-html-sanitizer (1.6.2)
|
|
195
|
+
loofah (~> 2.21)
|
|
196
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
197
|
+
railties (7.1.6)
|
|
198
|
+
actionpack (= 7.1.6)
|
|
199
|
+
activesupport (= 7.1.6)
|
|
200
|
+
cgi
|
|
201
|
+
irb
|
|
202
|
+
rackup (>= 1.0.0)
|
|
203
|
+
rake (>= 12.2)
|
|
204
|
+
thor (~> 1.0, >= 1.2.2)
|
|
205
|
+
tsort (>= 0.2)
|
|
206
|
+
zeitwerk (~> 2.6)
|
|
207
|
+
rake (12.3.3)
|
|
208
|
+
rdoc (6.17.0)
|
|
209
|
+
erb
|
|
210
|
+
psych (>= 4.0.0)
|
|
211
|
+
tsort
|
|
212
|
+
regexp_parser (2.11.3)
|
|
213
|
+
reline (0.6.3)
|
|
214
|
+
io-console (~> 0.5)
|
|
215
|
+
rspec (3.13.2)
|
|
216
|
+
rspec-core (~> 3.13.0)
|
|
217
|
+
rspec-expectations (~> 3.13.0)
|
|
218
|
+
rspec-mocks (~> 3.13.0)
|
|
219
|
+
rspec-core (3.13.6)
|
|
220
|
+
rspec-support (~> 3.13.0)
|
|
221
|
+
rspec-expectations (3.13.5)
|
|
222
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
223
|
+
rspec-support (~> 3.13.0)
|
|
224
|
+
rspec-mocks (3.13.7)
|
|
225
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
226
|
+
rspec-support (~> 3.13.0)
|
|
227
|
+
rspec-rails (7.1.1)
|
|
228
|
+
actionpack (>= 7.0)
|
|
229
|
+
activesupport (>= 7.0)
|
|
230
|
+
railties (>= 7.0)
|
|
231
|
+
rspec-core (~> 3.13)
|
|
232
|
+
rspec-expectations (~> 3.13)
|
|
233
|
+
rspec-mocks (~> 3.13)
|
|
234
|
+
rspec-support (~> 3.13)
|
|
235
|
+
rspec-support (3.13.6)
|
|
236
|
+
securerandom (0.3.2)
|
|
237
|
+
sqlite3 (1.6.9)
|
|
238
|
+
mini_portile2 (~> 2.8.0)
|
|
239
|
+
stringio (3.1.9)
|
|
240
|
+
thor (1.4.0)
|
|
241
|
+
timeout (0.5.0)
|
|
242
|
+
tsort (0.2.0)
|
|
243
|
+
turbo-rails (2.0.12)
|
|
244
|
+
actionpack (>= 6.0.0)
|
|
245
|
+
railties (>= 6.0.0)
|
|
246
|
+
tzinfo (2.0.6)
|
|
247
|
+
concurrent-ruby (~> 1.0)
|
|
248
|
+
view_component (3.24.0)
|
|
249
|
+
activesupport (>= 5.2.0, < 8.2)
|
|
250
|
+
concurrent-ruby (~> 1)
|
|
251
|
+
method_source (~> 1.0)
|
|
252
|
+
websocket-driver (0.8.0)
|
|
253
|
+
base64
|
|
254
|
+
websocket-extensions (>= 0.1.0)
|
|
255
|
+
websocket-extensions (0.1.5)
|
|
256
|
+
xpath (3.2.0)
|
|
257
|
+
nokogiri (~> 1.8)
|
|
258
|
+
zeitwerk (2.6.18)
|
|
259
|
+
|
|
260
|
+
PLATFORMS
|
|
261
|
+
ruby
|
|
262
|
+
|
|
263
|
+
DEPENDENCIES
|
|
264
|
+
capybara
|
|
265
|
+
power_grid!
|
|
266
|
+
rake (~> 12.0)
|
|
267
|
+
rspec (~> 3.0)
|
|
268
|
+
rspec-rails
|
|
269
|
+
sqlite3 (~> 1.6.0)
|
|
270
|
+
|
|
271
|
+
BUNDLED WITH
|
|
272
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bhavin Rackspace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# PowerGrid
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/power_grid)
|
|
4
|
+
[](https://github.com/bhavinNandani/power_grid/actions/workflows/ci.yml)
|
|
5
|
+
|
|
6
|
+
**PowerGrid** is a production-ready, server-side processed table component for Rails applications. It combines the raw performance of Active Record with the responsiveness of modern UI frameworks like Hotwire and Stimulus.
|
|
7
|
+
|
|
8
|
+
Built with **ViewComponent**, **Turbo Frames**, **Stimulus**, and **TailwindCSS**, PowerGrid offers a premium, SPA-like experience without the complexity of a Javascript frontend framework.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🏎 **Server-Side Processing**: Efficiently handles huge datasets using Active Record `offset` and `limit`.
|
|
15
|
+
- ⚡️ **Hotwire Integration**: Instant sorting, filtering, and pagination updates via Turbo Frames.
|
|
16
|
+
- 🔍 **Advanced Search**:
|
|
17
|
+
- Multi-column search support.
|
|
18
|
+
- Search on **joined tables** via `sql_expression`.
|
|
19
|
+
- Automatic input debouncing.
|
|
20
|
+
- 📄 **Smart Pagination**:
|
|
21
|
+
- Numbered pagination window (e.g., `1 2 ... 5 6 7 ... 10`).
|
|
22
|
+
- Dynamic **Per Page** limits.
|
|
23
|
+
- 🔒 **Secure Scoping**: Supports `initial_scope` for tenant/user scoping (e.g., `current_user.posts`).
|
|
24
|
+
- 🎨 **Visuals**:
|
|
25
|
+
- Professional "Slate" color palette.
|
|
26
|
+
- Fully responsive and Dark Mode compatible.
|
|
27
|
+
- 🚀 **Optimization**: Built-in support for `includes` to automatically prevent N+1 queries.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Add this line to your application's Gemfile:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
gem 'power_grid'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
And then execute:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
$ bundle install
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### 1. Define your Grid
|
|
46
|
+
|
|
47
|
+
Create a class that inherits from `PowerGrid::Base`. This class defines your data source and columns.
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
# app/grids/users_grid.rb
|
|
51
|
+
class UsersGrid < PowerGrid::Base
|
|
52
|
+
scope { User.all }
|
|
53
|
+
|
|
54
|
+
# Basic columns
|
|
55
|
+
column :name, sortable: true, searchable: true
|
|
56
|
+
column :email, sortable: true, searchable: true
|
|
57
|
+
|
|
58
|
+
# Column with block formatting (for badges, links, etc.)
|
|
59
|
+
column :status do |user|
|
|
60
|
+
tag.span(user.status.humanize, class: "badge badge-#{user.status}")
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2. Instantiate in Controller
|
|
66
|
+
|
|
67
|
+
Initialize the grid in your controller action. You can pass an initial scope (like `current_user.posts`) to ensure security.
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
# app/controllers/users_controller.rb
|
|
71
|
+
def index
|
|
72
|
+
# @grid = UsersGrid.new(params)
|
|
73
|
+
# OR with scoping:
|
|
74
|
+
@grid = UsersGrid.new(params, initial_scope: current_user.posts)
|
|
75
|
+
end
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Render in View
|
|
79
|
+
|
|
80
|
+
Render the `PowerGrid::TableComponent`, passing the grid instance.
|
|
81
|
+
|
|
82
|
+
```erb
|
|
83
|
+
<!-- app/views/users/index.html.erb -->
|
|
84
|
+
<%= render PowerGrid::TableComponent.new(@grid) %>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## detailed API Reference
|
|
88
|
+
|
|
89
|
+
### `column(name, options = {}, &block)`
|
|
90
|
+
|
|
91
|
+
Defines a column in the table.
|
|
92
|
+
|
|
93
|
+
| Option | Type | Description |
|
|
94
|
+
| :--- | :--- | :--- |
|
|
95
|
+
| `sortable` | `boolean` | If true, the column header will be clickable to sort. |
|
|
96
|
+
| `searchable` | `boolean` | If true, the global search input will check this column using `LIKE`. |
|
|
97
|
+
| `sql_expression` | `string` | The raw SQL column name to use for sorting/searching. Essential for joined tables (e.g., `"posts.title"`). |
|
|
98
|
+
| `includes` | `symbol/array` | Association(s) to eager load when rendering this column to prevent N+1 queries. |
|
|
99
|
+
|
|
100
|
+
**Example: Joined Column**
|
|
101
|
+
```ruby
|
|
102
|
+
column :"posts.title",
|
|
103
|
+
searchable: true,
|
|
104
|
+
sortable: true,
|
|
105
|
+
sql_expression: "posts.title",
|
|
106
|
+
includes: :posts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `scope { ... }`
|
|
110
|
+
|
|
111
|
+
Defines the default Active Record scope. This is used if no `initial_scope` is passed to the initializer.
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
scope { User.active.order(created_at: :desc) }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `initialize(params, initial_scope: nil)`
|
|
118
|
+
|
|
119
|
+
- `params`: The Rails `params` hash (required for sorting/filtering state).
|
|
120
|
+
- `initial_scope`: Use this to pass context-aware relations, such as `current_account.invoices`. If provided, it overrides the class-level `scope`.
|
|
121
|
+
|
|
122
|
+
## Frontend Configuration
|
|
123
|
+
|
|
124
|
+
### TailwindCSS
|
|
125
|
+
|
|
126
|
+
PowerGrid creates HTML with standard Tailwind utility classes (using the `slate` color palette). Ensure your Tailwind configuration scans your gem paths or includes utilities for:
|
|
127
|
+
- Colors: `slate-50` to `slate-900`.
|
|
128
|
+
- Spacing, Borders, Flexbox, Typography.
|
|
129
|
+
|
|
130
|
+
### Hotwire & Stimulus
|
|
131
|
+
|
|
132
|
+
Ensure your application has `turbo-rails` and `stimulus-rails` installed.
|
|
133
|
+
The gem includes a Stimulus controller `power_grid--table_controller` which handles search input debouncing and auto-submission.
|
|
134
|
+
|
|
135
|
+
If using **Importmap** (default in Rails 7+), this is configured automatically.
|
|
136
|
+
If using **esbuild/webpack**, manually register the controller if needed, or ensure the gem's assets are in your load path.
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bhavinNandani/power_grid.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<div class="power-grid-container w-full bg-white dark:bg-slate-900 rounded-lg shadow ring-1 ring-slate-900/5" data-controller="power-grid-table">
|
|
2
|
+
|
|
3
|
+
<!-- Top Controls: Per Page & Search -->
|
|
4
|
+
<div class="flex flex-col sm:flex-row justify-between items-center p-4 border-b border-slate-200 dark:border-slate-700 space-y-3 sm:space-y-0">
|
|
5
|
+
<!-- Per Page -->
|
|
6
|
+
<div class="flex items-center text-sm text-slate-700 dark:text-slate-300">
|
|
7
|
+
<span class="mr-2">Show</span>
|
|
8
|
+
<%= form_with url: request.path, method: :get, data: { turbo_frame: "power_grid_table", turbo_action: "advance", power_grid_table_target: "form" }, class: "inline-block", id: "power_grid_form_#{request.path.parameterize}" do |f| %>
|
|
9
|
+
<% params.except(:per_page, :page).each do |key, value| %>
|
|
10
|
+
<%= hidden_field_tag key, value %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<!-- Reset page to 1 on limit change -->
|
|
13
|
+
<%= hidden_field_tag :page, 1 %>
|
|
14
|
+
|
|
15
|
+
<%= select_tag :per_page, options_for_select([10, 25, 50, 100], @grid.per_page),
|
|
16
|
+
class: "mx-1 mt-1 block w-20 rounded-md border-slate-300 py-1.5 text-base focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm dark:bg-slate-800 dark:border-slate-600 dark:text-white",
|
|
17
|
+
data: { action: "change->power-grid-table#search" }
|
|
18
|
+
%>
|
|
19
|
+
<% end %>
|
|
20
|
+
<span class="ml-2">entries</span>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<!-- Search -->
|
|
24
|
+
<div class="w-full sm:w-auto">
|
|
25
|
+
<div class="relative rounded-md shadow-sm">
|
|
26
|
+
<label for="search" class="sr-only">Search</label>
|
|
27
|
+
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
|
|
28
|
+
<svg class="h-5 w-5 text-slate-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
29
|
+
<path fill-rule="evenodd" d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z" clip-rule="evenodd" />
|
|
30
|
+
</svg>
|
|
31
|
+
</div>
|
|
32
|
+
<%= text_field_tag :q, params[:q], placeholder: "Search...",
|
|
33
|
+
class: "block w-full rounded-md border-0 py-1.5 pl-10 text-slate-900 ring-1 ring-inset ring-slate-300 placeholder:text-slate-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 dark:bg-slate-800 dark:text-white dark:ring-slate-600 dark:placeholder-slate-500",
|
|
34
|
+
data: { action: "input->power-grid-table#search" },
|
|
35
|
+
form: "power_grid_form_#{request.path.parameterize}"
|
|
36
|
+
%>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<%= turbo_frame_tag "power_grid_table" do %>
|
|
42
|
+
<div class="overflow-x-auto">
|
|
43
|
+
<table class="min-w-full divide-y divide-slate-200 dark:divide-slate-700">
|
|
44
|
+
<thead class="bg-slate-50 dark:bg-slate-800/80">
|
|
45
|
+
<tr>
|
|
46
|
+
<% columns.each do |key, options| %>
|
|
47
|
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider dark:text-slate-400">
|
|
48
|
+
<% if options[:sortable] %>
|
|
49
|
+
<%= link_to request.params.merge(order: key, dir: (params[:order] == key.to_s && params[:dir] == "asc" ? "desc" : "asc")), class: "group inline-flex items-center", data: { turbo_action: "advance" } do %>
|
|
50
|
+
<%= key.to_s.humanize %>
|
|
51
|
+
<span class="ml-2 flex-none rounded text-slate-400 group-hover:text-slate-600 dark:group-hover:text-slate-300">
|
|
52
|
+
<% if params[:order] == key.to_s %>
|
|
53
|
+
<%= params[:dir] == "asc" ? "▲" : "▼" %>
|
|
54
|
+
<% else %>
|
|
55
|
+
<svg class="h-4 w-4 opacity-0 group-hover:opacity-100" viewBox="0 0 20 20" fill="currentColor">
|
|
56
|
+
<path fill-rule="evenodd" d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z" clip-rule="evenodd" />
|
|
57
|
+
</svg>
|
|
58
|
+
<% end %>
|
|
59
|
+
</span>
|
|
60
|
+
<% end %>
|
|
61
|
+
<% else %>
|
|
62
|
+
<%= key.to_s.humanize %>
|
|
63
|
+
<% end %>
|
|
64
|
+
</th>
|
|
65
|
+
<% end %>
|
|
66
|
+
</tr>
|
|
67
|
+
</thead>
|
|
68
|
+
<tbody class="bg-white divide-y divide-slate-200 dark:bg-slate-900 dark:divide-slate-700">
|
|
69
|
+
<% records.each_with_index do |record, index| %>
|
|
70
|
+
<tr class="<%= index.even? ? 'bg-white dark:bg-slate-900' : 'bg-slate-50 dark:bg-slate-800/50' %> hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors">
|
|
71
|
+
<% columns.each do |key, options| %>
|
|
72
|
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-slate-900 dark:text-slate-100">
|
|
73
|
+
<% if options[:block] %>
|
|
74
|
+
<%= options[:block].call(record) %>
|
|
75
|
+
<% else %>
|
|
76
|
+
<%= record.send(key) %>
|
|
77
|
+
<% end %>
|
|
78
|
+
</td>
|
|
79
|
+
<% end %>
|
|
80
|
+
</tr>
|
|
81
|
+
<% end %>
|
|
82
|
+
<% if records.empty? %>
|
|
83
|
+
<tr>
|
|
84
|
+
<td colspan="<%= columns.size %>" class="px-6 py-10 text-center text-sm text-slate-500 dark:text-slate-400">
|
|
85
|
+
No matching records found
|
|
86
|
+
</td>
|
|
87
|
+
</tr>
|
|
88
|
+
<% end %>
|
|
89
|
+
</tbody>
|
|
90
|
+
</table>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<!-- Pagination Footer -->
|
|
94
|
+
<div class="flex items-center justify-between border-t border-slate-200 bg-white px-4 py-3 sm:px-6 dark:bg-slate-900 dark:border-slate-700">
|
|
95
|
+
<!-- Entries Info -->
|
|
96
|
+
<div class="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
|
|
97
|
+
<div>
|
|
98
|
+
<p class="text-sm text-slate-700 dark:text-slate-300">
|
|
99
|
+
Showing <span class="font-medium"><%= @grid.page_range_start %></span> to <span class="font-medium"><%= @grid.page_range_end %></span> of <span class="font-medium"><%= @grid.total_count %></span> entries
|
|
100
|
+
</p>
|
|
101
|
+
</div>
|
|
102
|
+
<div>
|
|
103
|
+
<!-- Numbered Pagination Controls -->
|
|
104
|
+
<nav class="isolate inline-flex -space-x-px rounded-md shadow-sm" aria-label="Pagination">
|
|
105
|
+
<% if @grid.current_page > 1 %>
|
|
106
|
+
<%= link_to "Previous", request.params.merge(page: @grid.current_page - 1), class: "relative inline-flex items-center rounded-l-md px-2 py-2 text-slate-400 ring-1 ring-inset ring-slate-300 hover:bg-slate-50 focus:z-20 focus:outline-offset-0 dark:ring-slate-600 dark:hover:bg-slate-800", data: { turbo_action: "advance" } %>
|
|
107
|
+
<% end %>
|
|
108
|
+
|
|
109
|
+
<% @grid.pagination_window.each do |page| %>
|
|
110
|
+
<% if page == :gap %>
|
|
111
|
+
<span class="relative inline-flex items-center px-4 py-2 text-sm font-semibold text-slate-700 ring-1 ring-inset ring-slate-300 focus:outline-offset-0 dark:text-slate-200 dark:ring-slate-600">...</span>
|
|
112
|
+
<% elsif page == @grid.current_page %>
|
|
113
|
+
<span class="relative z-10 inline-flex items-center bg-indigo-600 px-4 py-2 text-sm font-semibold text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"><%= page %></span>
|
|
114
|
+
<% else %>
|
|
115
|
+
<%= link_to page, request.params.merge(page: page), class: "relative inline-flex items-center px-4 py-2 text-sm font-semibold text-slate-900 ring-1 ring-inset ring-slate-300 hover:bg-slate-50 focus:z-20 focus:outline-offset-0 dark:text-slate-200 dark:ring-slate-600 dark:hover:bg-slate-800", data: { turbo_action: "advance" } %>
|
|
116
|
+
<% end %>
|
|
117
|
+
<% end %>
|
|
118
|
+
|
|
119
|
+
<% if @grid.current_page < @grid.total_pages %>
|
|
120
|
+
<%= link_to "Next", request.params.merge(page: @grid.current_page + 1), class: "relative inline-flex items-center rounded-r-md px-2 py-2 text-slate-400 ring-1 ring-inset ring-slate-300 hover:bg-slate-50 focus:z-20 focus:outline-offset-0 dark:ring-slate-600 dark:hover:bg-slate-800", data: { turbo_action: "advance" } %>
|
|
121
|
+
<% end %>
|
|
122
|
+
</nav>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
<% end %>
|
|
127
|
+
</div>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "view_component"
|
|
2
|
+
|
|
3
|
+
module PowerGrid
|
|
4
|
+
class TableComponent < ViewComponent::Base
|
|
5
|
+
include Turbo::FramesHelper
|
|
6
|
+
|
|
7
|
+
def initialize(grid_or_class, params: nil)
|
|
8
|
+
if grid_or_class.is_a?(Class)
|
|
9
|
+
@grid = grid_or_class.new(params)
|
|
10
|
+
else
|
|
11
|
+
@grid = grid_or_class
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def columns
|
|
16
|
+
@grid.class.defined_columns
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def records
|
|
20
|
+
@grid.records
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def sort_url(column, direction)
|
|
24
|
+
# TODO: Helper to generate URL with updated params
|
|
25
|
+
# For now just return hash or similar, we might need a helper that merges params
|
|
26
|
+
# We need request context or helpers provided by Rails
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = [ "form" ]
|
|
5
|
+
|
|
6
|
+
connect() {
|
|
7
|
+
console.log("PowerGrid Table Controller connected")
|
|
8
|
+
this.timeout = null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
search() {
|
|
12
|
+
clearTimeout(this.timeout)
|
|
13
|
+
this.timeout = setTimeout(() => {
|
|
14
|
+
this.formTarget.requestSubmit()
|
|
15
|
+
}, 300)
|
|
16
|
+
}
|
|
17
|
+
}
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "power_grid"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
Binary file
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
module PowerGrid
|
|
2
|
+
class Base
|
|
3
|
+
class << self
|
|
4
|
+
def scope(&block)
|
|
5
|
+
@scope_block = block
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def column(name, **options, &block)
|
|
9
|
+
@columns ||= {}
|
|
10
|
+
@columns[name] = options.merge(block: block)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def filter(name, **options)
|
|
14
|
+
@filters ||= {}
|
|
15
|
+
@filters[name] = options
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def defined_scope
|
|
19
|
+
@scope_block
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def defined_columns
|
|
23
|
+
@columns || {}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def defined_filters
|
|
27
|
+
@filters || {}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
attr_reader :params, :initial_scope
|
|
32
|
+
|
|
33
|
+
def initialize(params = {}, initial_scope: nil)
|
|
34
|
+
@params = params
|
|
35
|
+
@initial_scope = initial_scope
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def records
|
|
39
|
+
@records ||= begin
|
|
40
|
+
scope = @initial_scope || instance_eval(&self.class.defined_scope)
|
|
41
|
+
scope = apply_includes(scope)
|
|
42
|
+
scope = apply_includes(scope)
|
|
43
|
+
scope = apply_search(scope)
|
|
44
|
+
scope = apply_sort(scope)
|
|
45
|
+
|
|
46
|
+
# Capture total count after filtering but before pagination
|
|
47
|
+
@total_count = scope.count
|
|
48
|
+
|
|
49
|
+
scope = apply_pagination(scope)
|
|
50
|
+
scope
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def total_count
|
|
55
|
+
# Ensure records are loaded to populate @total_count
|
|
56
|
+
records unless defined?(@total_count)
|
|
57
|
+
@total_count
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def current_page
|
|
61
|
+
(params[:page] || 1).to_i
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def per_page
|
|
65
|
+
limit = (params[:per_page] || 10).to_i
|
|
66
|
+
limit > 100 ? 100 : limit # Cap at 100 for safety
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def offset
|
|
70
|
+
(current_page - 1) * per_page
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def page_range_start
|
|
74
|
+
return 0 if total_count == 0
|
|
75
|
+
offset + 1
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def page_range_end
|
|
79
|
+
end_val = offset + per_page
|
|
80
|
+
end_val > total_count ? total_count : end_val
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def total_pages
|
|
84
|
+
(total_count.to_f / per_page).ceil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def pagination_window(window: 2)
|
|
88
|
+
return (1..total_pages).to_a if total_pages <= (window * 2) + 5
|
|
89
|
+
|
|
90
|
+
current = current_page
|
|
91
|
+
last = total_pages
|
|
92
|
+
left = current - window
|
|
93
|
+
right = current + window
|
|
94
|
+
|
|
95
|
+
range = []
|
|
96
|
+
range << 1
|
|
97
|
+
range << :gap if left > 2
|
|
98
|
+
|
|
99
|
+
(left..right).each do |i|
|
|
100
|
+
range << i if i > 1 && i < last
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
range << :gap if right < last - 1
|
|
104
|
+
range << last
|
|
105
|
+
range
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
def apply_includes(scope)
|
|
111
|
+
includes_list = self.class.defined_columns.values.map { |opts| opts[:includes] }.compact
|
|
112
|
+
return scope if includes_list.empty?
|
|
113
|
+
|
|
114
|
+
scope.includes(*includes_list)
|
|
115
|
+
end
|
|
116
|
+
def apply_pagination(scope)
|
|
117
|
+
scope.offset(offset).limit(per_page)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def apply_search(scope)
|
|
122
|
+
query = params[:q]
|
|
123
|
+
return scope if query.blank?
|
|
124
|
+
|
|
125
|
+
searchable_columns = self.class.defined_columns.select { |_, opts| opts[:searchable] }
|
|
126
|
+
return scope if searchable_columns.empty?
|
|
127
|
+
|
|
128
|
+
conditions = searchable_columns.map do |name, opts|
|
|
129
|
+
# If sql_expression is provided, use it. Otherwise use the column name (which might be table.col)
|
|
130
|
+
# We cast to text/string for generic like search if needed, but for now simple LIKE
|
|
131
|
+
col_expr = opts[:sql_expression] || name.to_s
|
|
132
|
+
"#{col_expr} LIKE :query"
|
|
133
|
+
end.join(" OR ")
|
|
134
|
+
|
|
135
|
+
scope.where(conditions, query: "%#{query}%")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def apply_sort(scope)
|
|
139
|
+
order_column = params[:order]
|
|
140
|
+
direction = params[:dir] || "asc"
|
|
141
|
+
|
|
142
|
+
return scope unless order_column.present?
|
|
143
|
+
|
|
144
|
+
column_def = self.class.defined_columns[order_column.to_sym]
|
|
145
|
+
return scope unless column_def && column_def[:sortable]
|
|
146
|
+
|
|
147
|
+
# Use sql_expression for sorting if provided (useful for joined columns or calculated fields)
|
|
148
|
+
sort_expr = column_def[:sql_expression] || order_column
|
|
149
|
+
|
|
150
|
+
scope.order(sort_expr => direction)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "rails/all"
|
|
2
|
+
require "rails/engine"
|
|
3
|
+
require "turbo-rails"
|
|
4
|
+
|
|
5
|
+
module PowerGrid
|
|
6
|
+
class Engine < ::Rails::Engine
|
|
7
|
+
isolate_namespace PowerGrid
|
|
8
|
+
|
|
9
|
+
initializer "power_grid.assets" do |app|
|
|
10
|
+
if app.config.respond_to?(:assets)
|
|
11
|
+
app.config.assets.paths << root.join("app/javascript")
|
|
12
|
+
app.config.assets.paths << root.join("app/components")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Removed importmap auto-configuration to prevent "Is a directory" errors.
|
|
17
|
+
# Users can pin the controller manually if needed.
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/power_grid.rb
ADDED
data/power_grid.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'lib/power_grid/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "power_grid"
|
|
5
|
+
spec.version = PowerGrid::VERSION
|
|
6
|
+
spec.authors = ["Bhavin Rackspace"]
|
|
7
|
+
spec.email = ["bhavin.nandani@rackspace.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "A powerful, server-side processed table component for Rails."
|
|
10
|
+
spec.description = "PowerGrid provides a view component based table with server-side sorting, filtering, and pagination."
|
|
11
|
+
spec.homepage = "https://github.com/bhavinNandani/power_grid"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
|
14
|
+
|
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/bhavinNandani/power_grid"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/bhavinNandani/power_grid/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_dependency "rails", ">= 6.1", "< 8.0"
|
|
31
|
+
spec.add_dependency "view_component", ">= 2.0", "< 4.0"
|
|
32
|
+
spec.add_dependency "turbo-rails", ">= 1.0", "< 3.0"
|
|
33
|
+
spec.add_dependency "importmap-rails", ">= 1.0", "< 3.0"
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency "sqlite3", "~> 1.6"
|
|
36
|
+
spec.add_development_dependency "rspec-rails", "~> 5.0"
|
|
37
|
+
spec.add_development_dependency "capybara", "~> 3.0"
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: power_grid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bhavin Rackspace
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-12-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '6.1'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '8.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '6.1'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '8.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: view_component
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '4.0'
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '2.0'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '4.0'
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: turbo-rails
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '1.0'
|
|
60
|
+
- - "<"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '3.0'
|
|
63
|
+
type: :runtime
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '1.0'
|
|
70
|
+
- - "<"
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '3.0'
|
|
73
|
+
- !ruby/object:Gem::Dependency
|
|
74
|
+
name: importmap-rails
|
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '1.0'
|
|
80
|
+
- - "<"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
type: :runtime
|
|
84
|
+
prerelease: false
|
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '1.0'
|
|
90
|
+
- - "<"
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '3.0'
|
|
93
|
+
- !ruby/object:Gem::Dependency
|
|
94
|
+
name: sqlite3
|
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - "~>"
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '1.6'
|
|
100
|
+
type: :development
|
|
101
|
+
prerelease: false
|
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - "~>"
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '1.6'
|
|
107
|
+
- !ruby/object:Gem::Dependency
|
|
108
|
+
name: rspec-rails
|
|
109
|
+
requirement: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - "~>"
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '5.0'
|
|
114
|
+
type: :development
|
|
115
|
+
prerelease: false
|
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
117
|
+
requirements:
|
|
118
|
+
- - "~>"
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '5.0'
|
|
121
|
+
- !ruby/object:Gem::Dependency
|
|
122
|
+
name: capybara
|
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - "~>"
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '3.0'
|
|
128
|
+
type: :development
|
|
129
|
+
prerelease: false
|
|
130
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
131
|
+
requirements:
|
|
132
|
+
- - "~>"
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '3.0'
|
|
135
|
+
description: PowerGrid provides a view component based table with server-side sorting,
|
|
136
|
+
filtering, and pagination.
|
|
137
|
+
email:
|
|
138
|
+
- bhavin.nandani@rackspace.com
|
|
139
|
+
executables: []
|
|
140
|
+
extensions: []
|
|
141
|
+
extra_rdoc_files: []
|
|
142
|
+
files:
|
|
143
|
+
- ".github/workflows/ci.yml"
|
|
144
|
+
- ".gitignore"
|
|
145
|
+
- ".rspec"
|
|
146
|
+
- ".travis.yml"
|
|
147
|
+
- CODE_OF_CONDUCT.md
|
|
148
|
+
- Gemfile
|
|
149
|
+
- Gemfile.lock
|
|
150
|
+
- LICENSE.txt
|
|
151
|
+
- README.md
|
|
152
|
+
- Rakefile
|
|
153
|
+
- app/components/power_grid/table_component.html.erb
|
|
154
|
+
- app/components/power_grid/table_component.rb
|
|
155
|
+
- app/javascript/controllers/power_grid/table_controller.js
|
|
156
|
+
- bin/console
|
|
157
|
+
- bin/setup
|
|
158
|
+
- docs/assets/ui_mockup.png
|
|
159
|
+
- lib/power_grid.rb
|
|
160
|
+
- lib/power_grid/base.rb
|
|
161
|
+
- lib/power_grid/engine.rb
|
|
162
|
+
- lib/power_grid/version.rb
|
|
163
|
+
- power_grid.gemspec
|
|
164
|
+
homepage: https://github.com/bhavinNandani/power_grid
|
|
165
|
+
licenses:
|
|
166
|
+
- MIT
|
|
167
|
+
metadata:
|
|
168
|
+
allowed_push_host: https://rubygems.org
|
|
169
|
+
homepage_uri: https://github.com/bhavinNandani/power_grid
|
|
170
|
+
source_code_uri: https://github.com/bhavinNandani/power_grid
|
|
171
|
+
changelog_uri: https://github.com/bhavinNandani/power_grid/CHANGELOG.md
|
|
172
|
+
post_install_message:
|
|
173
|
+
rdoc_options: []
|
|
174
|
+
require_paths:
|
|
175
|
+
- lib
|
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: 2.7.0
|
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
|
+
requirements:
|
|
183
|
+
- - ">="
|
|
184
|
+
- !ruby/object:Gem::Version
|
|
185
|
+
version: '0'
|
|
186
|
+
requirements: []
|
|
187
|
+
rubygems_version: 3.1.6
|
|
188
|
+
signing_key:
|
|
189
|
+
specification_version: 4
|
|
190
|
+
summary: A powerful, server-side processed table component for Rails.
|
|
191
|
+
test_files: []
|