trk_datatables 0.2.9 → 0.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 520b6d86f27312cd4c8bb89e62943f542be727954446ce8c4be03790727f7a4d
4
- data.tar.gz: dd881cc122ffd0cbec3eca16db24ed65cfc98921d22080920d8df167a8c7260c
3
+ metadata.gz: 03d60af4ffecbd22baf81e7700ab5e3ec8b32e85ad7daa91017621ad972667d6
4
+ data.tar.gz: d6e0f467c5cda0e6ad41019d0eb23505a65194759c6c25d1dee3a7d441d23fe1
5
5
  SHA512:
6
- metadata.gz: f7f62cc8d55ca17597c9c65d3aaf646f16f92a94873b97c83847e6e01f843f951ec74796e8064ed81cab802a404599006b3a7c321ecb672fc909c9f5e669724c
7
- data.tar.gz: 27ea4d1cf61af80539f66502256a173c603416030da3943947fcf5d43eaefd068fe0112a7fa0d87aa2cca493f77b759c76f3c151afd1ecd3d85c44b1804e7216
6
+ metadata.gz: 6a98588013bfa4d99ccbbb55691cb7f028551f8d784ee869bf8dec2e9f4d68d8f4c8b4f36369bf0b7c56d49bafbef9b9b94933a52260b94c292c530fd21bfbaa
7
+ data.tar.gz: 1f5566bb0db920cb827a19b9bf0109a3e247a176e7310e57f05a608647a477d97d1e883d4e4e1dca4b6af520fdc620c5de041f65fcc7bd60206975549eaa4f08
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.2.9)
4
+ trk_datatables (0.2.10)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -256,7 +256,7 @@ For specific columns you can use following keys
256
256
  * `order: false` disable ordering for this column
257
257
  * `select_options: Post.statuses` generate select box instead of text input
258
258
  * `predefined_ranges: {}` for datetime fiels add ranges to pick up from
259
- * `hide: true` hide column with display none
259
+ * `hide: true` hide column with display none, for example `{ hide: @view.params[:user_id].present? }`
260
260
  * `class_name: 'Admin::User'` use different class name than
261
261
  `table_name.classify` (in this case of `admin_users` will be `AdminUser`)
262
262
  * `column_type_in_db` one of the: `:string`, `:integer`, `:date`, `:datetime`,
@@ -332,7 +332,7 @@ def columns
332
332
  end
333
333
 
334
334
  # in view
335
- link_to 'Active', search_posts_path(PostsDatatable.param_set('posts.status':
335
+ link_to 'Active', search_posts_path(PostsDatatable.param_set('posts.status',
336
336
  Post.statues.values_at(:published, :promoted)))
337
337
  ```
338
338
 
@@ -575,7 +575,7 @@ Default [DOM](https://datatables.net/reference/option/dom) is
575
575
  To set parameters that you can use for links to set column search value, use
576
576
  this `PostsDatatable.param_set 'users.email', 'my@email.com'`. For between
577
577
  search you can use range `Time.zone.today..(Time.zone.today + 1.year)` and for
578
- in multiple values use array `[Post.statuses[:draft]]`.
578
+ in multiple values use array `[Post.statuses[:draft]]`:
579
579
 
580
580
  ```
581
581
  <%= link_to 'Active posts for my@email.com', \
@@ -591,6 +591,15 @@ in multiple values use array `[Post.statuses[:draft]]`.
591
591
  This will fill proper column search values so you do not need to do it manually
592
592
  (`post_path(:columns=>{"3"=>{:search=>{:value=>"my@email.com"}},
593
593
  "2"=>{:search=>{:value=>"1|2"}}}, :user_id=>1)`)
594
+ Please note that user_id is not inside datatable params so it will not be used
595
+ for next search params (all other search params are used with Datatables and
596
+ will remain on next search) so you need to manually add that param
597
+ ```
598
+ <%= @datatable.render_html search_posts_path(user_id: params[:user_id], format: :json) %>
599
+ ```
600
+
601
+ You can use generic name `params[:non_table_filter]` and split with colon
602
+ `user_id:123` but that is not needed.
594
603
 
595
604
  For form fields you can use similar helper that will return name which points to
596
605
  specific column, for example:
@@ -614,10 +623,39 @@ For global search you can use `[search][value]` for example
614
623
  <% end %>
615
624
  ```
616
625
 
617
- If you need, you can fetch params with this helper
626
+ If you need, you can fetch params with this helper and for example, show the
627
+ link for that record
628
+
629
+ ```
630
+ if @datatable.param_get("locations.name").present? &&
631
+ (location = Location.find_by(name: @datatable.param_get("locations.name")))
632
+ page_description "For <a href='#{location_path(location)}'>#{location.name}</a>"
633
+ breadcrumb "Dashboard": dashboard_path, location.name => location_path(location), "Package Sales": nil
634
+ else
635
+ breadcrumb "Dashboard": dashboard_path, "Package Sales": nil
636
+ end
637
+ ```
618
638
 
639
+ For other filter params which are not in columns you can use non table params
619
640
  ```
620
- datatable.param_get 'users.email'
641
+ # on dashboard
642
+ <%= link_to 'Locations', isp_locations_path(non_table_filter: "reseller_operator_id:#{@reseller_operator.id}") %>
643
+
644
+ # on index
645
+ if params[:non_table_filter].present? &&
646
+ (reseller_operator = ResellerOperator.find(params[:non_table_filter].split(":").second))
647
+ page_description "For <a href='#{reseller_operator_path(reseller_operator)}'>#{reseller_operator.company_name}</a>"
648
+ breadcrumb 'Dashboard' => isp_dashboard_path, reseller_operator.company_name => reseller_operator_path(reseller_operator), 'Locations' => nil
649
+ else
650
+ breadcrumb 'Dashboard' => isp_dashboard_path, 'Locations' => nil
651
+ end
652
+
653
+ # in datatables
654
+ case @view.params[:non_table_filter].to_s.split(':').first
655
+ when 'reseller_operator_id'
656
+ reseller_operator = ResellerOperator.find @view.params[:non_table_filter].split(':').second
657
+ all_isp_locations = all_isp_locations.where(reseller_operator: reseller_operator)
658
+ end
621
659
  ```
622
660
 
623
661
  You can set filters on datatable even params are blank, for example
@@ -679,7 +717,9 @@ end
679
717
 
680
718
  You can use condition to provide different data, for example let's assume
681
719
  `@view.api_user?` returns true for json requests from mobile app. Here is
682
- example that provides different columns for normal and api_user:
720
+ example that provides different columns for normal and api_user.
721
+ Note that when you are using different columns for some reason in `@view` you
722
+ need to provide view in `param_set` so it can check the same conditionals.
683
723
 
684
724
  ```
685
725
  # app/datatables/posts_datatable.rb
@@ -689,8 +729,14 @@ class PostsDatatable < TrkDatatables::ActiveRecord
689
729
  end
690
730
 
691
731
  def columns_for_html
732
+ balance = @view.current_location
733
+ {}
734
+ else
735
+ { 'integer_calculated_in_db.balance_amount_in_cents': { search: false, title: 'Balance' } }
736
+ end
692
737
  {
693
738
  'subscribers.subscriberid': {},
739
+ **balance,
694
740
  'subscribers.name': {},
695
741
  }
696
742
  end
@@ -709,8 +755,14 @@ class PostsDatatable < TrkDatatables::ActiveRecord
709
755
 
710
756
  def rows_for_html(filtered)
711
757
  filtered.map do |subscriber|
758
+ balance = if Constant.STILL_WITH_OLD_CODE
759
+ []
760
+ else
761
+ [@view.humanized_money_with_symbol(Money.new(location.balance_amount_in_cents)) : 'NA']
762
+ end
712
763
  [
713
764
  @view.link_to(subscriber.subscriberid, subscriber),
765
+ *balance,
714
766
  subscriber.name,
715
767
  ]
716
768
  end
@@ -730,6 +782,10 @@ class PostsDatatable < TrkDatatables::ActiveRecord
730
782
  @view.api_user? ? columns_for_api : nil
731
783
  end
732
784
  end
785
+
786
+ # On some dashboard page provide @view using `self` to param_set
787
+ link_to 'Active', search_posts_path(PostsDatatable.param_set('posts.status',
788
+ :active, self))
733
789
  ```
734
790
 
735
791
  ## Test your datatables
@@ -13,8 +13,8 @@ module TrkDatatables
13
13
  # @example
14
14
  # link_to 'Published posts for user1',
15
15
  # posts_path(PostsDatatable.param_set('posts.status', :published).merge(user_id: user1.id))
16
- def param_set(column_key, value)
17
- datatable = new OpenStruct.new(params: {})
16
+ def param_set(column_key, value, view = nil)
17
+ datatable = new view || OpenStruct.new(params: {})
18
18
  value = value.join MULTIPLE_OPTION_SEPARATOR if value.is_a? Array
19
19
  value = [value.first, value.last].join BETWEEN_SEPARATOR if value.is_a? Range
20
20
  column_index = datatable.index_by_column_key column_key
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.2.9'.freeze
2
+ VERSION = '0.2.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-03 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport