aaf-lipstick 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af9c68e4deac36e4db55f6ef974766b13b677e68
4
- data.tar.gz: 770684535258aa99da8e34fba2dd8e67970aae78
3
+ metadata.gz: 75906600a085f50a0b3d80772c1d5940ae298870
4
+ data.tar.gz: d6ade2c9c85ad0216b717a27b7e347ac596b4846
5
5
  SHA512:
6
- metadata.gz: dbbea5205224e289e48ab3bf6c734e9b180220acc84ecf8c88d60c220443c7a21315740b243386b91d5018fcfc61919b3147c56ad9637b5edfc883b64c5c6712
7
- data.tar.gz: a9f845b89206bc2d54b25d60c6e5d70adfc554c37d2612fda9bb0d7be3d4100bc33f332ffc1821860f6104bf93e962ee3d8368fe5b7ad9e5e3006782e8467afc
6
+ metadata.gz: 4defc3c82b44fcac690d1b148cb61a80d02ba38f2b91414b13d112de03f0c07d621cf74c5861df692bbd7afd6decfde9a71e0390dbfe5025f011b85201cc223f
7
+ data.tar.gz: 77cb1e383a77d6a872f1dedb8145ecee7206a83524bb406b3d337fe843f4748adc27523217411a8870c4c0717d7a7e7a2af568883389f3aa8fca97c66524170f
data/lib/lipstick.rb CHANGED
@@ -12,6 +12,7 @@ require 'lipstick/helpers'
12
12
  require 'lipstick/email_message'
13
13
  require 'lipstick/images'
14
14
  require 'lipstick/filterable'
15
+ require 'lipstick/sortable'
15
16
  require 'lipstick/auto_validation'
16
17
  require 'lipstick/engine'
17
18
  require 'lipstick/version'
@@ -11,3 +11,4 @@ require 'lipstick/helpers/form_validation_builder'
11
11
  require 'lipstick/helpers/bootstrap_form_builder'
12
12
  require 'lipstick/helpers/form_helper'
13
13
  require 'lipstick/helpers/pagination_link_renderer'
14
+ require 'lipstick/helpers/sortable_helper'
@@ -35,21 +35,24 @@ module Lipstick
35
35
  form_tag(url_for_options, options) { yield }
36
36
  end
37
37
 
38
- def search_form_tag(filter, url: nil)
38
+ def search_form_tag(filter, url: nil,
39
+ placeholder: 'Search within these entries')
39
40
  form_tag(url, method: :get) do
40
- field_block { search_form_input_tag(filter) }
41
+ field_block { search_form_input_tag(filter, placeholder) }
41
42
  end
42
43
  end
43
44
 
44
- def search_form_input_tag(filter)
45
+ def search_form_input_tag(filter, placeholder)
45
46
  content_tag('div', class: 'row') do
46
- content_tag('div', grouped_search_field(filter), class: 'col-lg-12')
47
+ content_tag('div', grouped_search_field(
48
+ filter, placeholder
49
+ ), class: 'col-lg-12')
47
50
  end
48
51
  end
49
52
 
50
- def search_filter_text_field(filter)
53
+ def search_filter_text_field(filter, placeholder)
51
54
  orig_text_field_tag(:filter, filter,
52
- placeholder: 'Search within these entries',
55
+ placeholder: placeholder,
53
56
  autocomplete: 'off',
54
57
  class: 'form-control')
55
58
  end
@@ -61,9 +64,9 @@ module Lipstick
61
64
  end
62
65
  end
63
66
 
64
- def grouped_search_field(filter)
67
+ def grouped_search_field(filter, placeholder)
65
68
  content_tag('div', class: 'input-group') do
66
- concat(search_filter_text_field(filter))
69
+ concat(search_filter_text_field(filter, placeholder))
67
70
  concat(content_tag('span', search_button, class: 'input-group-btn'))
68
71
  end
69
72
  end
@@ -121,8 +121,9 @@ module Lipstick
121
121
  li_opts = {}
122
122
  li_opts[:class] = 'active' if page == current
123
123
 
124
- url_opts = template.params.permit(:page, :per_page, :filter, :direction)
125
- .merge(page: page)
124
+ url_opts = template.params.permit(
125
+ :page, :per_page, :filter, :direction, :sort_by
126
+ ).merge(page: page)
126
127
  opts = opts.merge(href: template.url_for(url_opts))
127
128
 
128
129
  template.content_tag('li', li_opts) do
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lipstick
4
+ module Helpers
5
+ module SortableHelper
6
+ include ActionView::Helpers
7
+
8
+ def sortable_link(name, param_name = nil)
9
+ param_name ||= name.parameterize.underscore.downcase
10
+ direction = Lipstick::Sortable.direction(params[:direction])
11
+ opposite_direction =
12
+ Lipstick::Sortable.opposite_direction(params[:direction])
13
+
14
+ if params[:sort_by] == param_name
15
+ sortable_active_link(name, param_name, direction, opposite_direction)
16
+ else
17
+ link_to name, sort_by: param_name, direction: direction
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def sortable_active_link(name, param_name, direction, opposite_direction)
24
+ link_to sort_by: param_name, direction: opposite_direction do
25
+ concat("#{name} ")
26
+ concat(
27
+ content_tag('div', class: 'glyphicon') do
28
+ content_tag('div',
29
+ class: "glyphicon-chevron-#{icon(direction)}") do
30
+ end
31
+ end
32
+ )
33
+ end
34
+ end
35
+
36
+ def icon(direction)
37
+ direction == 'asc' ? 'up' : 'down'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lipstick
4
+ module Sortable
5
+ class << self
6
+ DIRECTIONS = %w[asc desc].freeze
7
+
8
+ def direction(direction)
9
+ direction = DIRECTIONS.find { |x| x == direction&.downcase }
10
+ direction ||= DIRECTIONS.first
11
+
12
+ direction
13
+ end
14
+
15
+ def opposite_direction(direction)
16
+ (DIRECTIONS - [direction(direction)]).first
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ attr_reader :sortable_by_cases, :sortable_by_else
22
+
23
+ def sortable_by(sort_cases, sort_else)
24
+ @sortable_by_cases = sort_cases
25
+ @sortable_by_else = sort_else
26
+ end
27
+
28
+ def sortable_sort(sort_by, direction)
29
+ sort_by = sort_by&.to_sym
30
+ direction = Lipstick::Sortable.direction(direction)
31
+
32
+ if sort_by && sortable_by_cases.key?(sort_by)
33
+ sortable_by_cases[sort_by].call(direction)
34
+ else
35
+ sortable_by_else.call(direction)
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.included(base)
41
+ base.extend(ClassMethods)
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lipstick
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aaf-lipstick
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Mangelsdorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-06 00:00:00.000000000 Z
11
+ date: 2019-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -321,9 +321,11 @@ files:
321
321
  - lib/lipstick/helpers/layout_helper.rb
322
322
  - lib/lipstick/helpers/nav_helper.rb
323
323
  - lib/lipstick/helpers/pagination_link_renderer.rb
324
+ - lib/lipstick/helpers/sortable_helper.rb
324
325
  - lib/lipstick/images.rb
325
326
  - lib/lipstick/images/email_banner.rb
326
327
  - lib/lipstick/images/processor.rb
328
+ - lib/lipstick/sortable.rb
327
329
  - lib/lipstick/version.rb
328
330
  homepage: https://github.com/ausaccessfed/aaf-lipstick
329
331
  licenses: