Skip to content

Commit

Permalink
Gem update and config updates to pass rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
gryphon committed Oct 5, 2024
1 parent 7fb0f9a commit 40e21f3
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 161 deletions.
334 changes: 185 additions & 149 deletions Gemfile.lock

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Provides powerful set of functionality for showing tables of data:
* Customize visible fields for each user
* Exporting table to XLSX

Requires and works only with Ransack, Kaminari, Bootstrap CSS, Rails, simple_form and Turbo gems.

## Setup

* Run ```rails generate custom_table install``` to create User migration and Initializer
Expand Down Expand Up @@ -63,7 +65,7 @@ This gem provides custom_table method for your controller which does Ransack sea
@q = @vegetables.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty? # Sets default sorting for ransack

@vegetables = @q.result(distinct: true)
@vegetables = @q.result(distict: true)
@vegetables = @vegetables.page(params[:page]).per(params[:per] || 25)
end

Expand Down Expand Up @@ -214,11 +216,16 @@ You can declare how each field is displayed. Just add it as block within field:
= fs.field :name do
= @instance.name.upcase

## Testing
## Testing hints for your app

Use ```custom_table_use_all_fields``` GET param with any value to show all available fields in your feature tests

## Development

Running tests: rspec
Running tests:

* `bundle install`
* `bundle exec rails db:migrate`
* `RAILS_ENV=test bundle exec rspec`


2 changes: 1 addition & 1 deletion app/assets/stylesheets/custom_table/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ table.custom-table {



tr.sticky, thead.sticky, thead.sticky-lg-top {
tr.sticky, thead.sticky {
position: sticky;
background: white;
z-index: 1;
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/custom_table/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def update
if current_user.save_custom_table_settings(model, variant, fields: p[:fields])
flash[:notice] = t("custom_table.customization_saved")
respond_to do |format|
format.html { render nil, status: :ok }
format.turbo_stream {render turbo_stream: turbo_stream.action(:refresh, nil)}
end
else
Expand All @@ -66,6 +67,7 @@ def destroy
if current_user.destroy_custom_table_settings(model, variant)
flash[:notice] = t("custom_table.customization_saved")
respond_to do |format|
format.html { render nil, status: :ok }
format.turbo_stream {render turbo_stream: turbo_stream.action(:refresh, nil)}
end
else
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/custom_table/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def field_value_for item, field, definitions: nil, variant: nil
elsif item.class.columns_hash[field.to_s] && item.class.columns_hash[field.to_s].type == :boolean
return boolean_icon(item.send(field)) rescue ""
elsif item.class.defined_enums.has_key?(field.to_s)
return ((item.send("human_#{field}") rescue item.send(field).presence) || not_set).to_s rescue ""
return (item.send("human_#{field}") rescue (item.send(field).presence || not_set)).to_s rescue ""
elsif item.class.columns_hash[field.to_s] && [:date].include?(item.class.columns_hash[field.to_s].type)
return (item.send(field).blank? ? not_set : l(item.send(field), format: :short)) rescue ""
elsif item.class.columns_hash[field.to_s] && [:datetime].include?(item.class.columns_hash[field.to_s].type)
return (item.send(field).blank? ? not_set : l(item.send(field), format: CustomTable.configuration.date_format)) rescue ""
elsif item.class.columns_hash[field.to_s] && [:datetime].include?(item.class.columns_hash[field.to_s].type)
return (item.send(field).blank? ? not_set : l(item.send(field), format: CustomTable.configuration.datetime_format)) rescue ""
elsif item.class.columns_hash[field.to_s] && [:integer, :float, :decimal].include?(item.class.columns_hash[field.to_s].type)
return not_set if (item.send(field) rescue nil).nil?
return item.send(field) if !defs.nil? && defs[:amount] === false # Showing simple output if amount is false
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/custom_table_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CustomTableSettings
extend ActiveSupport::Concern

included do
serialize :custom_table
serialize :custom_table, coder: YAML
end

def save_custom_table_settings model_class, variant = nil, fields: nil, sorts: nil, per_page: nil
Expand Down
2 changes: 1 addition & 1 deletion app/views/custom_table/_table_row.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

- if local_assigns[:sortable]
%td
%i.sort-handler.me-2{class: custom_table_move_icon_class}
%i.fa.fa-grip-vertical.sort-handler.me-2

- if local_assigns[:with_select]
%td.checkbox-col
Expand Down
1 change: 1 addition & 0 deletions custom_table.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "capybara"
spec.add_development_dependency "roo"
spec.add_development_dependency 'database_cleaner-active_record'
spec.add_development_dependency 'sqlite3'

spec.add_dependency "rails", "~> 7.0"
spec.add_dependency "ransack", '~> 4.0'
Expand Down
3 changes: 3 additions & 0 deletions lib/custom_table/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Configuration
attr_accessor :show_search_icon
attr_accessor :move_totals_top
attr_accessor :date_format
attr_accessor :datetime_format

def initialize
@icons_framework = :bi
Expand All @@ -13,6 +14,8 @@ def initialize
@show_search_icon = false
@move_totals_top = false
@date_format = :default
@datetime_format = :short

end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Rails.application.config.assets.version = "1.0"

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
Expand Down
3 changes: 1 addition & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_22_112857) do
ActiveRecord::Schema[7.2].define(version: 2023_06_22_112857) do
create_table "orders", force: :cascade do |t|
t.string "code"
t.string "name"
Expand All @@ -37,5 +37,4 @@
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

end

0 comments on commit 40e21f3

Please sign in to comment.