lintity 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dfa928e67ae36f6fabd78f3ca81dfdb437d2b3c0a113cb5e04d8d08a19101dc4
4
+ data.tar.gz: 50cfef8c00bafcd82944e70b346b72b90ef0eb52587d59149f7e3a005df63da5
5
+ SHA512:
6
+ metadata.gz: c52bec211f5442cca8e4422487dfd544de53ed105e28c2ff21179bdf96c777efe103cf4a260ab18accaa871b3fc2b79dd6de4bf5acd1ebe6ba6c79c2ac5ff97f
7
+ data.tar.gz: 68fbebac842f5042ffd78e67024dc61cfe92ec144cc614f58484257db1e50433b6e64d18a6dd5044d616a16f80c194b0d8ca632ec3228009b6d657b2c865aa2d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Rem
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Lintity
2
+ Training gem (Engine) that shows list of entities
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem "lintity"
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install lintity
19
+ ```
20
+ ## System Requirements
21
+ * Ruby >= 3.0
22
+ * Ruby On Rails >= 7.0
23
+ * gem 'importmap-rails'
24
+ * gem 'stimulus-rails'
25
+ * bootstrap 5
26
+ * gem 'font-awesome-rails'
27
+ * ActiveRecord
28
+
29
+ ## Usage
30
+ Create your controller
31
+ ```ruby
32
+ class CustomersController < Lintity::EntityListController #inherit
33
+ layout 'application' #use own main layout
34
+ before_action :set_customer, only: [:edit]
35
+
36
+ def index
37
+ @search_path = customers_path
38
+
39
+ @records =
40
+ if @filter_field
41
+ Customer.where("#{@filter_field} #{@filter_sign} ?", @filter_value.to_i) #implementing filter result
42
+ else
43
+ Customer.all
44
+ end
45
+ end
46
+
47
+ def edit; end
48
+
49
+ private
50
+
51
+ def init_fields #your fields from model
52
+ @fields_settings = [
53
+ { field: 'name', name: 'Name', type: 'edit', path: Proc.new { |customer_id| edit_customer_path(id: customer_id) } }, #Add path for edit of a record
54
+ { field: 'phone', name: 'Phone', type: 'info' },
55
+ { field: 'address', name: 'Address', type: 'info' },
56
+ { field: 'ordered', name: 'Ordered', type: 'numeric_filter' },
57
+ { field: 'no_of_orders', name: 'No Of Orders', type: 'numeric_filter' },
58
+ { field: 'total_amount', name: 'Total Amount', type: 'numeric_filter' },
59
+ ]
60
+ end
61
+
62
+ def set_customer
63
+ @customer = Customer.find(params[:id])
64
+ end
65
+ end
66
+ ```
67
+
68
+ ## Results
69
+ * Entity List View:
70
+ ![list](https://user-images.githubusercontent.com/14085661/172581037-c439c2f5-8c6b-4eb0-a5f0-21db755f427c.jpg)
71
+
72
+ * Filter
73
+ ![filter](https://user-images.githubusercontent.com/14085661/172581112-c98d9c0a-3c8c-4ee7-a651-9827435377cb.jpg)
74
+
75
+ ## License
76
+ 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,8 @@
1
+ require "bundler/setup"
2
+
3
+ #APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ //= link_directory ../stylesheets/lintity .css
2
+ //= link_tree ../javascripts/lintity .js
@@ -0,0 +1 @@
1
+ import * as jq from 'jquery';
@@ -0,0 +1,15 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["modal", "fieldvalue", "fieldcaption"]
5
+
6
+ numberic_filter({ params }) {
7
+ console.log(`field ${ params.field }`)
8
+
9
+ var myModal = new bootstrap.Modal(this.modalTarget)
10
+ this.fieldvalueTarget.id = params.field
11
+ this.fieldvalueTarget.name = params.field
12
+ this.fieldcaptionTarget.innerText = params.field
13
+ myModal.show()
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Lintity
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ module Lintity
2
+ class EntityListController < ApplicationController
3
+ before_action :init_fields, only: [:index]
4
+ before_action :check_filters, only: [:index]
5
+
6
+ def index; end
7
+
8
+ private
9
+
10
+ def check_filters
11
+ filters = @fields_settings ? @fields_settings.select { |rec| rec[:type] == 'numeric_filter' } : []
12
+ filters.each do |filter_field_info|
13
+ break if check_filter_field(filter_field_info)
14
+ end
15
+ end
16
+
17
+ def check_filter_field(filter_field_info)
18
+ filter_name = filter_field_info[:field]
19
+ field_caption = filter_field_info[:name]
20
+ return nil unless params[filter_name]
21
+
22
+ @filter_field = filter_name.to_s
23
+ @filter_value = params[filter_name]
24
+ @filter_caption = field_caption
25
+
26
+ @filter_sign =
27
+ case params[:filter_option]
28
+ when 'more'
29
+ '>='
30
+ when 'less'
31
+ '<='
32
+ else
33
+ '='
34
+ end
35
+ @filter_field
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ module Lintity
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Lintity
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Lintity
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Lintity
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Lintity</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "lintity/application", media: "all" %>
9
+
10
+ <%= javascript_importmap_tags %>
11
+
12
+ <%= javascript_import_module_tag "lintity/application" %>
13
+ </head>
14
+ <body>
15
+
16
+ <%= yield %>
17
+
18
+ </body>
19
+ </html>
@@ -0,0 +1,66 @@
1
+ <div data-controller="entity-list">
2
+ <table class="table table-striped table-bordered">
3
+ <thead>
4
+ <tr>
5
+ <% @fields_settings.each do |field_info| %>
6
+ <th>
7
+ <%=
8
+ case field_info[:type]
9
+ when 'edit'
10
+ field_info[:name]
11
+ when 'info'
12
+ field_info[:name]
13
+ when 'numeric_filter'
14
+ button_tag "#{field_info[:name]}<i class=\"fa fa-filter #{ 'text-success' if @filter_field == field_info[:field] }\"></i>".html_safe, class: 'btn btn-link', data: {'entity-list-field-param'=>field_info[:field], 'action'=>"click->entity-list#numberic_filter"}
15
+ end
16
+ %>
17
+ </th>
18
+ <% end %>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% @records.each do |record| %>
23
+ <tr class="table-row">
24
+ <% @fields_settings.each do |field_info| %>
25
+ <td>
26
+ <%=
27
+ case field_info[:type]
28
+ when 'edit'
29
+ caption = record[field_info[:field]]
30
+ link_to( caption ? caption : '(empty)', field_info[:path].call(record.id) )
31
+ when 'info', 'numeric_filter'
32
+ record[field_info[:field]]
33
+ end
34
+ %>
35
+ </td>
36
+ <% end %>
37
+ </tr>
38
+ <% end %>
39
+ </tbody>
40
+ </table>
41
+
42
+ <!-- Modal -->
43
+ <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" data-entity-list-target="modal">
44
+ <div class="modal-dialog">
45
+ <div class="modal-content">
46
+ <div class="modal-header">
47
+ <h5>Set Filter for "<span data-entity-list-target="fieldcaption"></span>"</h5>
48
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
49
+ </div>
50
+ <%= form_tag @search_path, method: :get, :enforce_utf8=>false do %>
51
+ <div class="modal-body">
52
+ <%= number_field_tag "field_replace", '', :class=>"form-control", :placeholder=>"Set filter value...", :autofocus=>'true', step: :any, 'data-entity-list-target'=>"fieldvalue" %>
53
+ <br/>
54
+ <%= select_tag :filter_option, options_from_collection_for_select([OpenStruct.new(id: 'eq', name: '='), OpenStruct.new(id: 'less', name: '<='), OpenStruct.new(id: 'more', name: '>=')], "id", "name"), :class=>"form-control" %>
55
+
56
+ </div>
57
+ <div class="modal-footer">
58
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
59
+ <input type="submit" class="btn btn-primary" name="Save changes"/>
60
+ </div>
61
+ <% end %>
62
+ </div>
63
+ </div>
64
+ </div>
65
+
66
+ </div>
@@ -0,0 +1,3 @@
1
+ pin "jquery", to: "https://code.jquery.com/jquery-3.6.0.min.js", preload: true
2
+ pin "lintity/application"
3
+ pin_all_from Lintity::Engine.root.join("app/assets/javascripts/lintity/controllers"), under: "controllers", to: "lintity/controllers"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Lintity::Engine.routes.draw do
2
+ get 'entity_list/index'
3
+ end
@@ -0,0 +1,15 @@
1
+ module Lintity
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Lintity
4
+
5
+ initializer 'lintity.importmap', before: 'importmap' do |app|
6
+ app.config.importmap.paths << root.join('config/importmap.rb')
7
+ app.config.importmap.cache_sweepers << root.join('app/assets/javascripts')
8
+ end
9
+
10
+ initializer 'lintity.assets' do |app|
11
+ app.config.assets.precompile += %w(lintity_manifest)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Lintity
2
+ VERSION = "0.1.0"
3
+ end
data/lib/lintity.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "lintity/version"
2
+ require "lintity/engine"
3
+
4
+ module Lintity
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :lintity do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lintity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fat Shinobi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-08 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: '7.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.2.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.2.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: importmap-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Rails gem to create list of entities
48
+ email:
49
+ - r3mnik@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - app/assets/config/lintity_manifest.js
58
+ - app/assets/javascripts/lintity/application.js
59
+ - app/assets/javascripts/lintity/controllers/entity_list_controller.js
60
+ - app/assets/stylesheets/lintity/application.css
61
+ - app/controllers/lintity/application_controller.rb
62
+ - app/controllers/lintity/entity_list_controller.rb
63
+ - app/helpers/lintity/application_helper.rb
64
+ - app/jobs/lintity/application_job.rb
65
+ - app/mailers/lintity/application_mailer.rb
66
+ - app/models/lintity/application_record.rb
67
+ - app/views/layouts/lintity/application.html.erb
68
+ - app/views/lintity/entity_list/index.html.erb
69
+ - config/importmap.rb
70
+ - config/routes.rb
71
+ - lib/lintity.rb
72
+ - lib/lintity/engine.rb
73
+ - lib/lintity/version.rb
74
+ - lib/tasks/lintity_tasks.rake
75
+ homepage: https://github.com/fatshinobi/lintity
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ homepage_uri: https://github.com/fatshinobi/lintity
80
+ source_code_uri: https://github.com/fatshinobi/lintity
81
+ changelog_uri: https://github.com/fatshinobi/lintity
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.2.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Rails gem to create list of entities
101
+ test_files: []