angsa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +4 -0
- data/lib/angsa/base.rb +65 -0
- data/lib/angsa/pagination.rb +10 -0
- data/lib/angsa/searching.rb +44 -0
- data/lib/angsa/sorting.rb +20 -0
- data/lib/angsa/version.rb +5 -0
- data/lib/angsa.rb +8 -0
- data/lib/generators/angsa/install_generator.rb +9 -0
- data/lib/generators/angsa/js_generator.rb +36 -0
- data/lib/generators/angsa/table_generator.rb +24 -0
- data/lib/generators/angsa/templates/angsa_gridjs_controller.js +119 -0
- data/lib/generators/angsa/templates/angsa_stimulus_controller.js +31 -0
- data/lib/generators/angsa/templates/table_setup.rb +14 -0
- data/sig/angsa.rbs +4 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b7ac88bfda0d089508dedc70127219c25598afa1f987f08e724fc6bdcbd2320
|
4
|
+
data.tar.gz: 47bb55cb83f05d9a991f6e2437f60dec4c103ebfbc591187a152dabf194017c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 720ec9bf7509e0354722fb46a22df70f6ed1171544f4b2253363479effd43f936399fa2e831fd20ec86ca3df9b966e561fd89c5a55d6e62677c01cd08b716067
|
7
|
+
data.tar.gz: 56b9368d85618471312599f2ffb215327a1214953b6c7b0ade745667fcd4cb4e865eed516de2ceab07bb917589d0b4470c093bb70ba360d016d9f93c03558a3b
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at kennedy@elevateacademy.my. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Kennedy Wee
|
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,37 @@
|
|
1
|
+
# Angsa
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/angsa`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add angsa
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install angsa
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/angsa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/angsa/blob/master/CODE_OF_CONDUCT.md).
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
34
|
+
|
35
|
+
## Code of Conduct
|
36
|
+
|
37
|
+
Everyone interacting in the Angsa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/angsa/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/angsa/base.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'pagination'
|
4
|
+
require_relative 'sorting'
|
5
|
+
require_relative 'searching'
|
6
|
+
|
7
|
+
module Angsa
|
8
|
+
class Base
|
9
|
+
include Pagination
|
10
|
+
include Sorting
|
11
|
+
include Searching
|
12
|
+
|
13
|
+
attr_reader :params, :model
|
14
|
+
def initialize(params, model)
|
15
|
+
@params = params
|
16
|
+
@model = model
|
17
|
+
end
|
18
|
+
|
19
|
+
def columns
|
20
|
+
raise NotImplementedError, 'columns is not implemented in derived class'
|
21
|
+
end
|
22
|
+
|
23
|
+
def associations
|
24
|
+
columns.map { |column| column[:source].to_s.split('.').first if column[:source].to_s.include?('.') }.compact.uniq
|
25
|
+
end
|
26
|
+
|
27
|
+
def data_model
|
28
|
+
records = model.all
|
29
|
+
records = records.includes(*associations) if associations.any?
|
30
|
+
apply_search(records, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def data
|
34
|
+
records = data_model
|
35
|
+
records = apply_sorting(records, params)
|
36
|
+
records = apply_pagination(records, params)
|
37
|
+
extract_records(records)
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_records(records)
|
41
|
+
records.map do |record|
|
42
|
+
columns.map do |column|
|
43
|
+
source = column[:source].split('.')
|
44
|
+
[column[:name], source.size == 1 ? record.send(source.first) : record.send(source.first).send(source.last)]
|
45
|
+
end.to_h
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def as_json(*)
|
50
|
+
{
|
51
|
+
total: total_count,
|
52
|
+
data: data,
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def total_count
|
57
|
+
data_model.count
|
58
|
+
end
|
59
|
+
|
60
|
+
def print_columns
|
61
|
+
puts columns
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Angsa
|
2
|
+
module Searching
|
3
|
+
def apply_search(records, params)
|
4
|
+
return records unless params[:search]
|
5
|
+
|
6
|
+
conditions, values, associations = build_search_conditions_values_and_associations(columns, records, params)
|
7
|
+
|
8
|
+
associations.each do |association|
|
9
|
+
records = records.joins(association.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
records.where(conditions.join(' OR '), values)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_search_conditions_values_and_associations(columns, records, params)
|
16
|
+
conditions = []
|
17
|
+
values = {}
|
18
|
+
associations = []
|
19
|
+
|
20
|
+
columns.each do |column|
|
21
|
+
next unless column[:searchable] # Skip columns that aren't searchable
|
22
|
+
|
23
|
+
source_parts = column[:source].split('.')
|
24
|
+
if source_parts.size == 1
|
25
|
+
# This is an attribute of the Course model
|
26
|
+
if column[:type] == :string
|
27
|
+
conditions << "LOWER(#{records.all.table_name}.#{source_parts.first}) LIKE :search"
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# This is an attribute of an associated model
|
31
|
+
association, attribute = source_parts
|
32
|
+
if column[:type] == :string
|
33
|
+
conditions << "LOWER(#{association.pluralize}.#{attribute}) LIKE :search"
|
34
|
+
associations << association
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
values[:search] = "%#{params[:search].downcase}%"
|
40
|
+
|
41
|
+
return conditions, values, associations.uniq
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Angsa
|
2
|
+
module Sorting
|
3
|
+
def apply_sorting(records, params)
|
4
|
+
if params[:order] && params[:dir]
|
5
|
+
sort = columns.find { |column| column[:name].to_s == params[:order] }
|
6
|
+
if sort
|
7
|
+
if sort[:source].include?('.')
|
8
|
+
# This is an attribute of an associated model
|
9
|
+
association, attribute = sort[:source].split('.')
|
10
|
+
records = records.joins(association.to_sym).order("#{association.pluralize}.#{attribute} #{params[:dir]}")
|
11
|
+
else
|
12
|
+
# This is an attribute of the Course model
|
13
|
+
records = records.order("#{sort[:source]} #{params[:dir]}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
records
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/angsa.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Angsa
|
2
|
+
class JsGenerator < Rails::Generators::Base
|
3
|
+
desc 'Generate the stimulus controller based on the table setup.'
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
argument :model, type: :string
|
6
|
+
|
7
|
+
# main function to generate based on setup
|
8
|
+
def generate_stimulus_controller
|
9
|
+
angsa_class = "#{model}Angsa".constantize.new(nil)
|
10
|
+
@columns = angsa_class.columns.map { |col| col[:name].to_s.capitalize }
|
11
|
+
|
12
|
+
template 'angsa_stimulus_controller.js', File.join('app', 'javascript', 'controllers', "#{stimulus_controller_path}.js")
|
13
|
+
end
|
14
|
+
|
15
|
+
# make the class name
|
16
|
+
def stimulus_controller_name
|
17
|
+
stimulus_controller_path.classify
|
18
|
+
end
|
19
|
+
|
20
|
+
def angsa_api_url
|
21
|
+
model_name
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# for the controller path
|
27
|
+
def stimulus_controller_path
|
28
|
+
"#{model.underscore}_angsa_controller"
|
29
|
+
end
|
30
|
+
|
31
|
+
# get the model name
|
32
|
+
def model_name
|
33
|
+
"#{model.downcase}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Angsa
|
2
|
+
class TableGenerator < Rails::Generators::Base
|
3
|
+
desc 'Generate table setup for a model'
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
argument :model, type: :string
|
6
|
+
|
7
|
+
def generate_table_setup
|
8
|
+
template 'table_setup.rb', File.join('app', 'angsa', "#{setup_table_path}.rb")
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def setup_table_path
|
13
|
+
"#{model.downcase}_angsa"
|
14
|
+
end
|
15
|
+
|
16
|
+
def model_class_name
|
17
|
+
"#{model.classify}Angsa"
|
18
|
+
end
|
19
|
+
|
20
|
+
def model_name
|
21
|
+
"#{model}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import { Grid } from 'gridjs';
|
3
|
+
|
4
|
+
export default class AngsaGridjsController extends Controller {
|
5
|
+
connect() {
|
6
|
+
this.initializeGrid();
|
7
|
+
}
|
8
|
+
|
9
|
+
initializeGrid() {
|
10
|
+
const grid = new Grid({
|
11
|
+
language: this.languageConfig(),
|
12
|
+
columns: this.columnsConfig(),
|
13
|
+
server: {
|
14
|
+
url: this.apiUrl(),
|
15
|
+
then: this.dataProcessor(),
|
16
|
+
total: this.totalRecords(),
|
17
|
+
},
|
18
|
+
pagination: this.paginationConfig(),
|
19
|
+
search: this.searchConfig(),
|
20
|
+
sort: this.sortConfig(),
|
21
|
+
});
|
22
|
+
|
23
|
+
grid.render(document.getElementById('gridjs'))
|
24
|
+
}
|
25
|
+
|
26
|
+
languageConfig() {
|
27
|
+
return {
|
28
|
+
search: {
|
29
|
+
placeholder: '🔍 Search...',
|
30
|
+
},
|
31
|
+
// pagination: {
|
32
|
+
// previous: '⬅️',
|
33
|
+
// next: '➡️',
|
34
|
+
// showing: '😃 Displaying',
|
35
|
+
// results: () => 'Records',
|
36
|
+
// },
|
37
|
+
};
|
38
|
+
}
|
39
|
+
|
40
|
+
columnsConfig() {
|
41
|
+
throw new Error('columnsConfig() must be implemented in the child class.');
|
42
|
+
}
|
43
|
+
|
44
|
+
apiUrl() {
|
45
|
+
throw new Error('apiUrl() must be implemented in the child class.');
|
46
|
+
}
|
47
|
+
|
48
|
+
dataProcessor() {
|
49
|
+
throw new Error('dataProcessor() must be implemented in the child class.');
|
50
|
+
}
|
51
|
+
|
52
|
+
totalRecords() {
|
53
|
+
return (data) => data.total;
|
54
|
+
}
|
55
|
+
|
56
|
+
paginationConfig() {
|
57
|
+
return {
|
58
|
+
enabled: true,
|
59
|
+
limit: 10,
|
60
|
+
server: {
|
61
|
+
url: (prev, page, limit) => {
|
62
|
+
return `${prev}${prev.includes('?') ? '&' : '?'}limit=${limit}&offset=${page * limit}`;
|
63
|
+
},
|
64
|
+
},
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
sortConfig() {
|
69
|
+
return {
|
70
|
+
enabled: true,
|
71
|
+
multiColumn: false,
|
72
|
+
server: {
|
73
|
+
url: (prev, columns) => {
|
74
|
+
if (!columns.length) return prev;
|
75
|
+
|
76
|
+
const col = columns[0];
|
77
|
+
const dir = col.direction === 1 ? 'asc' : 'desc';
|
78
|
+
const colName = this.columnsConfig()[col.index].toLowerCase();
|
79
|
+
|
80
|
+
// Get the base URL without any query parameters
|
81
|
+
const baseUrl = prev.split('?')[0];
|
82
|
+
|
83
|
+
// Remove existing order and dir parameters
|
84
|
+
const searchParams = new URLSearchParams(prev.split('?')[1] || '');
|
85
|
+
searchParams.delete('order');
|
86
|
+
searchParams.delete('dir');
|
87
|
+
|
88
|
+
// Add new order and dir parameters
|
89
|
+
searchParams.set('order', colName);
|
90
|
+
searchParams.set('dir', dir);
|
91
|
+
|
92
|
+
// Return the modified URL
|
93
|
+
return `${baseUrl}?${searchParams.toString()}`;
|
94
|
+
},
|
95
|
+
},
|
96
|
+
};
|
97
|
+
}
|
98
|
+
|
99
|
+
searchConfig() {
|
100
|
+
return {
|
101
|
+
server: {
|
102
|
+
url: (prev, keyword) => {
|
103
|
+
// Get the base URL without any query parameters
|
104
|
+
const baseUrl = prev.split('?')[0];
|
105
|
+
|
106
|
+
// Remove existing search parameter
|
107
|
+
const searchParams = new URLSearchParams(prev.split('?')[1] || '');
|
108
|
+
searchParams.delete('search');
|
109
|
+
|
110
|
+
// Add new search parameter
|
111
|
+
searchParams.set('search', keyword);
|
112
|
+
|
113
|
+
// Return the modified URL
|
114
|
+
return `${baseUrl}?${searchParams.toString()}`;
|
115
|
+
},
|
116
|
+
},
|
117
|
+
};
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { html } from 'gridjs';
|
2
|
+
import AngsaGridjsController from './angsa_gridjs_controller';
|
3
|
+
|
4
|
+
export default class <%= stimulus_controller_name %> extends AngsaGridjsController {
|
5
|
+
columnsConfig(){
|
6
|
+
// TODO: Return the appropriate columns for your model
|
7
|
+
return [
|
8
|
+
<%= @columns.map { |column| ' \"#{column}\"' }.join(",\n") %>
|
9
|
+
// {
|
10
|
+
// name: 'Actions',
|
11
|
+
// formatter: (_, row) => html(`<a href='${this.apiUrl().replace('.json', '')}/${row.cells[3].data}'><i class='far fa-arrow-alt-circle-right'></></a>`)
|
12
|
+
// },
|
13
|
+
]
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
apiUrl() {
|
19
|
+
// TODO: Return the appropriate API URL for your model
|
20
|
+
return '<%= angsa_api_url %>s.json';
|
21
|
+
}
|
22
|
+
|
23
|
+
dataProcessor() {
|
24
|
+
// TODO: Return the appropriate data processing function for your model
|
25
|
+
return (data) => data.data.map((item) => [
|
26
|
+
<% @columns.each do |column| %>
|
27
|
+
item.<%= column.downcase %>,
|
28
|
+
<% end %>
|
29
|
+
]);
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= model_class_name %> < Angsa::Base
|
2
|
+
def initialize(params)
|
3
|
+
super(params, <%= model_name %>)
|
4
|
+
end
|
5
|
+
|
6
|
+
def columns
|
7
|
+
[
|
8
|
+
# TODO: Declare your columns here with the provided params
|
9
|
+
# { name: :id, source: 'id', searchable: false, type: :integer },
|
10
|
+
# { name: :name, source: 'name', searchable: true, type: :string },
|
11
|
+
# { name: :available, source: 'available', searchable: true, type: :boolean },
|
12
|
+
]
|
13
|
+
end
|
14
|
+
end
|
data/sig/angsa.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angsa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kennedy Wee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The Angsa gem is a server-side tool for Ruby on Rails applications that
|
14
|
+
provides pagination, sorting, and search capabilities for ActiveRecord models. It
|
15
|
+
is specifically designed to work with Grid.js, a JavaScript library for table grid
|
16
|
+
layouts.
|
17
|
+
email:
|
18
|
+
- kennedy@elevateacademy.my
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/angsa.rb
|
30
|
+
- lib/angsa/base.rb
|
31
|
+
- lib/angsa/pagination.rb
|
32
|
+
- lib/angsa/searching.rb
|
33
|
+
- lib/angsa/sorting.rb
|
34
|
+
- lib/angsa/version.rb
|
35
|
+
- lib/generators/angsa/install_generator.rb
|
36
|
+
- lib/generators/angsa/js_generator.rb
|
37
|
+
- lib/generators/angsa/table_generator.rb
|
38
|
+
- lib/generators/angsa/templates/angsa_gridjs_controller.js
|
39
|
+
- lib/generators/angsa/templates/angsa_stimulus_controller.js
|
40
|
+
- lib/generators/angsa/templates/table_setup.rb
|
41
|
+
- sig/angsa.rbs
|
42
|
+
homepage: https://github.com/kennedywee/angsa
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://github.com/kennedywee/angsa
|
47
|
+
source_code_uri: https://github.com/kennedywee/angsa
|
48
|
+
changelog_uri: https://github.com/kennedywee/angsa/blob/main/CHANGELOG.md
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 3.1.3
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.3.26
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: The Angsa gem is a server-side helper for Rails applications, offering pagination,
|
68
|
+
sorting, and search functionalities for ActiveRecord models, tailored for Grid.js,
|
69
|
+
a JavaScript grid library.
|
70
|
+
test_files: []
|