hot-glue 0.6.27 → 0.6.28

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: a5a077658d795c25ef41694b36014191f2590351f6a1fa87e8419b049f03f5ad
4
- data.tar.gz: f2effbb98f5728fd70e2b7807903f86ad352a1dd3598562c3a450a804dcd51fb
3
+ metadata.gz: 139de0a1f6e85c50561d3b69a74618abe2fc808908b7d217adefcd23bf1ee569
4
+ data.tar.gz: 547d675591fbf331fb2019fc29ddb5bebb080cdd97f523f4c5b8c9ca703739f1
5
5
  SHA512:
6
- metadata.gz: bc1d59497e67ba88e9da7305bfe5b2664874178243c744860bc30335a6f835808e784cf0b67533bf7c31166c48fdc4e5af0db55382623e9c07a3dc9f754beb81
7
- data.tar.gz: 6fbc0bfbc0cb9651802525f711566bf3b67ad9b34a4742600412c1addfe69fb20eab93a6bab363776a7eead66245fc120e22a554ecbd45303fafbdaaec49468f
6
+ metadata.gz: 565d6cc9513225395e67015b00b7ef669be883fed53777d0a737328018241a7e2982dc2783bca48962ec7c0eb469ed816ca624b0c444d28f392b103b234364f6
7
+ data.tar.gz: 1ab45d51300b844444206c685b8ac068dc9b5e22e5399691d342173a5c00c9e0a238673b599a326a8f5919b6e6df78b4f3937fe6fcaf89a328701957cd36626c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.6.26.1)
4
+ hot-glue (0.6.27)
5
5
  ffaker (~> 2.16)
6
6
  kaminari (~> 1.2)
7
7
  rails (> 5.1)
data/README.md CHANGED
@@ -1680,7 +1680,7 @@ Within each option is a label and ruby scope, separated by a colon (:).
1680
1680
 
1681
1681
  The label comes before the colon the ruby scope. The ruby scope should be specified here without a dot. Each ruby scope must be defined on your model. If there is no scope specified, we assume "all", but we still need to specify a label for "All", which is why in the example above "All" has no colon after it.
1682
1682
 
1683
- example
1683
+ #### Radio Example
1684
1684
 
1685
1685
  `--phantom-search='radio_status[Pending:pending|Rejected:rejected|Accepted:accepted|All]'`
1686
1686
 
@@ -1702,10 +1702,33 @@ This produces a search interface with four options listed as radio buttons:
1702
1702
 
1703
1703
  The pending, approved, and rejected options will return search results with the corresponding scopes applied. The 'All' option will behave as a no-op, leaving the root search intact (giving all of the other modifications that Hot glue provides in different functionality).
1704
1704
 
1705
- #### Predicate Search
1706
- NOT IMPLEMENTED YET
1707
- TODO: implement me
1705
+ ##### Checkboxes example
1706
+
1707
+ `rails generate hot_glue:scaffold Invoice --gd --phantom-search='checkboxes_AAA[With Paid:not_paid:|Hide free accounts::without_free_accounts]'`
1708
+
1709
+
1710
+ The syntax is similiar to the radio buttons except that each choice (within `[...]`, separated by `|`) is required to have THREE options, separated by colons `:`
1711
+ 1) the label
1712
+ 2) the OFF case (checkbox is unchecked)
1713
+ 3) the ON case (checkbox is checked)
1714
+
1715
+ The scope definition between the `:` characters **may be empty**, in which case this is interprested as "all"
1716
+
1717
+ Since checkboxes start as off (unchecked) by default, you can create layouts that show the normal case with the checkboxes off, but show special cases with the checkboxes on.
1718
+ (This can either exclude or include depending on your preference.)
1708
1719
 
1720
+ In this Invoice scaffold, we have two scopes, searching for fields on our invoice model:
1721
+
1722
+ `scope :not_paid, -> {where(paid_at: nil)}`
1723
+ `scope :without_free_accounts, -> {where(free_account: false)}`
1724
+
1725
+ In the checkboxes phantom search we build above, notice by default:
1726
+
1727
+ - the PAID invoices do not appear in the search result (the scope `.not_paid` is applied as the OFF scope for the "With Paid" choice. So when you load the page, you see only unpaid invoices. If you check "With Paid" checkbox, there is no scope specified "all" is used indicating not modification is applied and all records are shown.
1728
+ - both free & non-free accounts (which are simply tracked by a boolean `free_account`) are shown by default, but when you use the "Hide free accounts" checkbox, the scope `.without_free_accounts` is applied, thus hiding the free accounts.
1729
+
1730
+ Remember, unlike radio choices which apply exclusively (since the user can select only 1 radio choice at time), checkboxes create
1731
+ combined search criteria. These combine with all of the other search criteria within the search set, making one big "AND ... AND ... AND" query.
1709
1732
 
1710
1733
  ### `--stimmify` or `--stimmify=xyz`
1711
1734
 
@@ -2210,6 +2233,11 @@ These automatic pickups for partials are detected at build time. This means that
2210
2233
 
2211
2234
 
2212
2235
  # VERSION HISTORY
2236
+
2237
+ #### 2025-09-26 - v.0.6.28
2238
+ - Checkboxes option for Phantom Search (previously phantom searches only supported radio).
2239
+ See "Checkboxes example" under the docs for `--phantom-search` above
2240
+
2213
2241
  #### 2025-09-24 - v0.6.27
2214
2242
  - Fixes to namespaced models (this is when the model file has a namespace); it now correctly does not namespace the route (fix to plurality)
2215
2243
 
@@ -149,22 +149,29 @@ module HotGlue
149
149
  # phantom searches
150
150
  @phantom_search.each_key do |search_field|
151
151
  data = @phantom_search[search_field]
152
- if data[:type] == "radio"
153
- res << "<div>"
152
+ res << "<div>"
153
+ res << "<label>#{data[:name]}</label><br />"
154
154
 
155
- res << "<label>#{data[:name]}</label><br />"
156
-
157
- data[:choices].each do |choice|
155
+ data[:choices].each do |choice|
156
+ dom_label = choice[:label].downcase.gsub(" ","_")
157
+ if data[:type] == "radio"
158
158
  res << "\n<input type='radio'
159
- id='#{search_field}_search__#{choice[:label]}'
160
- name='q[0][#{search_field}_search]' value='#{choice[:label]}'
161
- <%= 'checked' if @q['0'][:#{search_field}_search] == \"#{choice[:label]}\" %> />"
162
- res << "\n<label for='#{search_field}_search__#{choice[:label]}'>#{choice[:label]}</label> <br/>"
159
+ id='#{search_field}_search__#{dom_label}}'
160
+ name='q[0][#{search_field}_search]' value='#{dom_label}'
161
+ <%= 'checked' if @q['0'][:#{search_field}_search] == \"#{dom_label}\" %> />"
162
+ elsif data[:type] == "checkboxes"
163
+ res << "\n<input type='checkbox'
164
+ id='#{search_field}_search__#{dom_label}'
165
+ name='q[0][#{search_field}_search__#{dom_label}]'
166
+ value='1'
167
+ <%= 'checked' if @q['0'][:#{search_field}_search__#{dom_label}] %> />"
168
+
163
169
  end
170
+ res << "\n<label for='#{search_field}_search__#{dom_label}'>#{choice[:label]}</label> <br/>"
171
+ end
164
172
 
165
- res << "</div>"
173
+ res << "</div>"
166
174
 
167
- end
168
175
  end
169
176
 
170
177
 
@@ -731,16 +731,30 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
731
731
  }
732
732
 
733
733
  choices.each do |choice|
734
- choice_label = choice.split(":")[0]
735
- choice_scope = choice.split(":")[1]
736
- if choice_scope.nil?
734
+ if type == "radio"
735
+ choice_label = choice.split(":")[0]
736
+ choice_scope = choice.split(":")[1]
737
+ elsif type == "checkboxes"
738
+ choice_label = choice.split(":")[0]
739
+ choice_scope_negative = choice.split(":")[1]
740
+ choice_scope = choice.split(":")[2]
741
+ end
742
+
743
+ if choice_scope.nil? || choice_scope.strip.empty?
737
744
  choice_scope = "all"
738
745
  end
739
746
 
747
+ if choice_scope_negative.nil? || choice_scope_negative.strip.empty?
748
+ choice_scope_negative = "all"
749
+ end
750
+
740
751
  choice_scope = ".#{choice_scope}" if !choice_scope.start_with?(".")
752
+ choice_scope_negative = ".#{choice_scope_negative}" if !choice_scope_negative.start_with?(".")
753
+
741
754
  @phantom_search[label.to_sym][:choices] << {
742
755
  label: choice_label,
743
756
  scope: choice_scope,
757
+ scope_negative: choice_scope_negative,
744
758
  }
745
759
  end
746
760
  puts "phantom search #{@phantom_search}"
@@ -1834,11 +1848,25 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1834
1848
  end
1835
1849
 
1836
1850
  @phantom_search.each do |phantom_key, phantom_data|
1837
- phantom_data[:choices].each do |choice|
1838
- unless choice[:scope] == ".all"
1839
- res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search] == \"#{choice[:label]}\""
1851
+ if phantom_data[:type] == "radio"
1852
+ phantom_data[:choices].each do |choice|
1853
+ unless choice[:scope] == ".all"
1854
+ res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search] == \"#{choice[:label]}\""
1855
+ end
1856
+ end
1857
+ elsif phantom_data[:type] == "checkboxes"
1858
+ phantom_data[:choices].each do |choice|
1859
+
1860
+ # positive case
1861
+ unless choice[:scope] == ".all"
1862
+ res << "\n @#{plural} = @#{plural}#{choice[:scope]} if @q['0'][:#{phantom_key}_search__#{choice[:label].gsub(" ", "_").downcase}] == \"1\""
1863
+ end
1864
+ unless choice[:scope_negative] == ".all"
1865
+ res << "\n @#{plural} = @#{plural}#{choice[:scope_negative]} if @q['0'][:#{phantom_key}_search___#{choice[:label].gsub(" ", "_").downcase}] != \"1\""
1866
+ end
1840
1867
  end
1841
1868
  end
1869
+
1842
1870
  res << "\n"
1843
1871
  end
1844
1872
 
@@ -1907,12 +1935,24 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1907
1935
  }.reduce({}, :merge)
1908
1936
 
1909
1937
  phantom_search_fields = @phantom_search.collect{| k,v|
1910
- default = v[:choices][0]
1911
- {
1912
- "#{k}_match".to_sym => "",
1913
- "#{k}_search".to_sym => "#{default[:label]}"
1914
- }
1915
- }.reduce({}, :merge)
1938
+ if v[:type] == "radio"
1939
+ default = v[:choices][0]
1940
+ {
1941
+ "#{k}_match".to_sym => "",
1942
+ "#{k}_search".to_sym => "#{default[:label]}"
1943
+ }
1944
+ elsif v[:type] == "checkboxes"
1945
+ v[:choices].collect{ |c|
1946
+ {
1947
+ "#{k}_#{c[:label].gsub(" ", "_").downcase}".to_sym => ""
1948
+ }
1949
+ }
1950
+ end
1951
+ }
1952
+
1953
+ phantom_search_fields.flatten!
1954
+ phantom_search_fields = phantom_search_fields.reduce({}, :merge)
1955
+
1916
1956
  return {"0" => (default_fields.merge(phantom_search_fields))}
1917
1957
  end
1918
1958
  end
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.6.27'
3
+ CURRENT = '0.6.28'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.27
4
+ version: 0.6.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-24 00:00:00.000000000 Z
11
+ date: 2025-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails