ucb_rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/ucb_rails/admin/users_controller.rb +2 -6
- data/app/helpers/ucb_rails/ldap_person_search_helper.rb +3 -0
- data/app/helpers/ucb_rails/lps_typeahead_helper.rb +14 -45
- data/app/helpers/ucb_rails/renderer/lps_typeahead_search_field.rb +90 -0
- data/app/models/ucb_rails/user_typeahead.rb +81 -0
- data/app/views/ucb_rails/lps/_modal.html.haml +6 -3
- data/app/views/ucb_rails/lps/_results.html.haml +33 -20
- data/app/views/ucb_rails/lps/search.js.haml +2 -1
- data/lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps.js +3 -5
- data/lib/generators/ucb_rails/templates/app/assets/stylesheets/ucb_rails.css.scss +6 -1
- data/lib/ucb_rails/version.rb +1 -1
- metadata +10 -9
- data/app/models/ucb_rails/user_table_active.rb +0 -3
@@ -54,12 +54,8 @@ class UcbRails::Admin::UsersController < UcbRails::Admin::BaseController
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def typeahead_search
|
57
|
-
|
58
|
-
|
59
|
-
values = tokens.map { |e| "%#{e}%" }
|
60
|
-
where = ["#{wheres}", *values]
|
61
|
-
results = UcbRails::User.where(*where).limit(10)
|
62
|
-
render json: results.map { |r| {uid: r.uid, first_last_name: r.first_last_name} }
|
57
|
+
uta = UcbRails::UserTypeahead.new
|
58
|
+
render json: uta.results(params.fetch(:query))
|
63
59
|
end
|
64
60
|
|
65
61
|
private
|
@@ -1,50 +1,19 @@
|
|
1
|
+
# Helper class that produces a person search widget than includes typeahead and
|
2
|
+
# CalNet lookup functionality.
|
1
3
|
module UcbRails::LpsTypeaheadHelper
|
2
|
-
|
4
|
+
|
5
|
+
# @option options [Symbol] :name (:person_search) the name of the <input> field
|
6
|
+
# @option options [String] :label ('User') the text of the field label
|
7
|
+
# @option options [Boolean] :required (false) is the field required
|
8
|
+
# @option options [String] :value (params[:name]) the value of the field
|
9
|
+
# @option options [String] :placeholder ('Type name to search') the html +placeholder+ attribute
|
10
|
+
# @option options [String] :hint ('Click icon to search CalNet') hint text
|
11
|
+
# @option options [String] :result_link_text ('Select') the text of the link button in search results
|
12
|
+
# @option options [String] :result_link_class ('lps-typeahead-item') class to be added the the results link
|
13
|
+
# @option options [String] :uid_dom_id ('uid') the dom-id of the (hidden) uid <input>
|
14
|
+
# @option options [String] :search_url ('/ucb_rails/admin/users/typeahead_search') the search url for typeahead
|
3
15
|
def lps_typeahead_search_field(options={})
|
4
|
-
|
5
|
-
required = options.delete(:required)
|
6
|
-
label = options.delete(:label) || 'User'
|
7
|
-
value = options.delete(:value) || params[name]
|
8
|
-
placeholder = options.delete(:placeholder) || 'Type name to search'
|
9
|
-
hint = options.delete(:hint) || 'Click icon to search CalNet'
|
10
|
-
|
11
|
-
result_link_text = options.delete(:result_link_text) || 'Select'
|
12
|
-
result_link_class = options.delete(:result_link_class) || 'lps-typeahead-item'
|
13
|
-
|
14
|
-
uid_dom_id = options.delete(:uid_dom_id) || 'uid'
|
15
|
-
search_url = options.delete(:search_url) || typeahead_search_ucb_rails_admin_users_path
|
16
|
-
|
17
|
-
content_tag(:div, class: 'control-group lps-typeahead') do
|
18
|
-
label_tag(name, class: label_classes(required)) do
|
19
|
-
required_marker(required) +
|
20
|
-
label
|
21
|
-
|
22
|
-
end +
|
23
|
-
content_tag(:div, class: 'controls') do
|
24
|
-
content_tag(:div, class: 'input-append') do
|
25
|
-
text_field_tag(name, value, placeholder: placeholder, class: 'typeahead-lps-search', data: { uid_dom_id: uid_dom_id, url: search_url }) +
|
26
|
-
content_tag(:span, class: 'add-on') do
|
27
|
-
icon('search', class: 'ldap-person-search', data: {search_field_name: name, result_link_text: result_link_text, result_link_class: result_link_class})
|
28
|
-
end
|
29
|
-
end +
|
30
|
-
content_tag(:p, hint, class: 'help-block')
|
31
|
-
end
|
32
|
-
end
|
16
|
+
UcbRails::Renderer::LpsTypeaheadSearchField.new(self, options).html
|
33
17
|
end
|
34
18
|
|
35
|
-
private
|
36
|
-
|
37
|
-
def label_classes(required)
|
38
|
-
Array['control-label'].tap do |klasses|
|
39
|
-
klasses << 'required' if required
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def required_marker(required)
|
44
|
-
if required
|
45
|
-
content_tag(:abbr, '*', title: 'required') + ' '
|
46
|
-
else
|
47
|
-
''
|
48
|
-
end
|
49
|
-
end
|
50
19
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module UcbRails
|
2
|
+
module Renderer
|
3
|
+
|
4
|
+
class LpsTypeaheadSearchField < Base
|
5
|
+
|
6
|
+
attr_accessor :name, :label, :required, :value, :placeholder, :hint, :result_link_text, :result_link_class, :uid_dom_id, :search_url
|
7
|
+
|
8
|
+
def initialize(template, options={})
|
9
|
+
super
|
10
|
+
parse_options
|
11
|
+
end
|
12
|
+
|
13
|
+
def html
|
14
|
+
content_tag(:div, class: 'control-group lps-typeahead') do
|
15
|
+
label_html +
|
16
|
+
content_tag(:div, class: 'controls') do
|
17
|
+
content_tag(:div, class: 'input-append') do
|
18
|
+
text_field_html +
|
19
|
+
span_html
|
20
|
+
end +
|
21
|
+
content_tag(:p, hint, class: 'help-block')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def label_html
|
29
|
+
required_marker = required ? content_tag(:abbr, '*', title: 'required') + ' ' : ''
|
30
|
+
label_classes = 'control-label'
|
31
|
+
label_classes << ' required' if required
|
32
|
+
|
33
|
+
label_tag(name, class: label_classes) do
|
34
|
+
required_marker +
|
35
|
+
label
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def text_field_html
|
40
|
+
text_field_tag(name, value, {
|
41
|
+
autocomplete: 'off',
|
42
|
+
class: 'typeahead-lps-search',
|
43
|
+
placeholder: placeholder,
|
44
|
+
data: {
|
45
|
+
uid_dom_id: uid_dom_id,
|
46
|
+
url: search_url
|
47
|
+
}
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
def span_html
|
52
|
+
span_options = {
|
53
|
+
class: 'add-on ldap-person-search',
|
54
|
+
data: {
|
55
|
+
search_field_name: name,
|
56
|
+
result_link_text: result_link_text,
|
57
|
+
result_link_class: result_link_class
|
58
|
+
}
|
59
|
+
}
|
60
|
+
content_tag(:span, span_options) do
|
61
|
+
icon('search')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_options
|
66
|
+
self.name = options.delete(:name) || 'person_search'
|
67
|
+
self.label = options.delete(:label) || 'User'
|
68
|
+
self.required = options.delete(:required)
|
69
|
+
self.value = options.delete(:value) || params[name]
|
70
|
+
self.placeholder = options.delete(:placeholder) || 'Type name to search'
|
71
|
+
self.hint = options.delete(:hint) || 'Click icon to search CalNet'
|
72
|
+
self.result_link_text = options.delete(:result_link_text) || 'Select'
|
73
|
+
self.result_link_class = options.delete(:result_link_class) || 'lps-typeahead-item'
|
74
|
+
self.uid_dom_id = options.delete(:uid_dom_id) || 'uid'
|
75
|
+
self.search_url = options.delete(:search_url) || typeahead_search_ucb_rails_admin_users_path
|
76
|
+
|
77
|
+
validate_options
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate_options
|
81
|
+
return if options.blank?
|
82
|
+
|
83
|
+
msg = "Unknown lps_typeahead_search_field option(s): #{options.keys.map(&:inspect).join(', ')}. "
|
84
|
+
msg << "Did you mean one of :name, :required, :label, :value, :placeholder, :hint, :result_link_text, :result_link_class, :uid_dom_id, :search_url"
|
85
|
+
raise ArgumentError, msg
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module UcbRails
|
2
|
+
|
3
|
+
# Class for getting results for ldap person search typeahead fields.
|
4
|
+
#
|
5
|
+
# By default it will search the UcbRails::User table, but this is configurable:
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# class MyController < ApplicationController
|
9
|
+
#
|
10
|
+
# def search
|
11
|
+
# uta = UserTypeahead.new
|
12
|
+
# render :json uta.results('art')
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
class UserTypeahead
|
18
|
+
attr_accessor :klass, :search_column, :uid_column, :first_last_name_column, :limit
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# UserTypeahead.new
|
24
|
+
# UserTypeahead.new(klass: Faculty, search_column: 'full_name', uid_column: 'net_id', limit: 25)
|
25
|
+
# @param options [Hash]
|
26
|
+
# @option options [Object] :klass (UcbRails::User) the (+ActiveRecord+) class to search
|
27
|
+
# @option options [Symbol] :search_column (:first_last_name) the column to search
|
28
|
+
# @option options [Symbol] :uid_column (:uid) the column holding the +uid+
|
29
|
+
# @option options [Symbol] :first_last_name (search_column) the column holding the first/last names
|
30
|
+
# @option options [FixNum] :limit (10) number of rows to return
|
31
|
+
# @return [UcbRails::UserTypeahead]
|
32
|
+
def initialize(options={})
|
33
|
+
self.klass = options.delete(:klass) || UcbRails::User
|
34
|
+
self.search_column = options.delete(:search_column) || :first_last_name
|
35
|
+
self.limit = options.delete(:limit) || 10
|
36
|
+
self.uid_column = options.delete(:uid_column) || :uid
|
37
|
+
self.first_last_name_column = options.delete(:first_last_name_column) || search_column
|
38
|
+
validate_options(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the data matching _query_.
|
42
|
+
# @example
|
43
|
+
# uta = UserTypeahead.new
|
44
|
+
# uta.results('art') #=> [{uid: '1', first_last_name: 'Art Andrews'}, ...]
|
45
|
+
# @param query [String] search term to match name fields on
|
46
|
+
# @return [Array(Hash)]
|
47
|
+
def results(query)
|
48
|
+
klass
|
49
|
+
.where(where(query))
|
50
|
+
.limit(limit)
|
51
|
+
.map { |row| row_to_hash(row) }
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def where(query)
|
57
|
+
tokens = query.to_s.strip.split(/\s+/)
|
58
|
+
wheres = tokens.map { |e| "#{search_column} like ?" }.join(' and ')
|
59
|
+
values = tokens.map { |e| "%#{e}%" }
|
60
|
+
|
61
|
+
["#{wheres}", *values]
|
62
|
+
end
|
63
|
+
|
64
|
+
def row_to_hash(row)
|
65
|
+
{
|
66
|
+
uid: row.send(uid_column),
|
67
|
+
first_last_name: row.send(first_last_name_column)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def validate_options(options)
|
72
|
+
if options.present?
|
73
|
+
msg = "Unknown UcbRails::UserTypeahead.new option(s): #{options.keys.map(&:inspect).join(', ')}. "
|
74
|
+
msg << "Did you mean one of :klass, :search_column, :uid_column, :first_last_name_column, :limit"
|
75
|
+
raise ArgumentError, msg
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
= modal(id: 'lps-modal') do
|
2
|
-
= modal_header
|
3
|
-
|
2
|
+
= modal_header do
|
3
|
+
%h3.title Search For Person
|
4
4
|
= render partial: 'ucb_rails/lps/form'
|
5
|
+
= modal_body do
|
5
6
|
#lps-results
|
6
|
-
= modal_footer
|
7
|
+
= modal_footer do
|
8
|
+
#matches.pull-left
|
9
|
+
= modal_footer_close_button
|
@@ -1,21 +1,34 @@
|
|
1
|
-
-
|
2
|
-
%
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
%
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
%
|
16
|
-
|
17
|
-
|
18
|
-
%td= entry.last_name
|
19
|
-
%td= entry.email
|
20
|
-
%td= entry.departments
|
1
|
+
= ucbr_table_tag(class: 'table-condensed') do
|
2
|
+
%thead
|
3
|
+
%tr
|
4
|
+
%th{style: 'width="1%"'}
|
5
|
+
%th First Name
|
6
|
+
%th Last Name
|
7
|
+
%th Email
|
8
|
+
%th Department
|
9
|
+
%tbody
|
10
|
+
- @lps_entries.each do |entry|
|
11
|
+
- entry_id = "ldap_uid_#{entry.uid}"
|
12
|
+
%tr{id: entry_id, class: ldap_entry_class(entry)}
|
13
|
+
%td= link_to_ldap_person_entry(entry)
|
14
|
+
%td= entry.first_name
|
15
|
+
%td= entry.last_name
|
16
|
+
%td= entry.email
|
17
|
+
%td= entry.departments
|
21
18
|
|
19
|
+
:javascript
|
20
|
+
$('#lps-modal table').dataTable({
|
21
|
+
"bPaginate": false,
|
22
|
+
"bFilter": false,
|
23
|
+
"bInfo": false,
|
24
|
+
"oLanguage": {
|
25
|
+
"sEmptyTable": "No matches for your search."
|
26
|
+
},
|
27
|
+
"aaSorting": [ [1, "asc"], [2, "asc"] ],
|
28
|
+
"aoColumnDefs": [
|
29
|
+
{ "bSortable": false, "aTargets": [ 0 ] }, // selection link
|
30
|
+
{ "aDataSort": [ 1, 2 ], "aTargets": [ 1 ] }, // first name
|
31
|
+
{ "aDataSort": [ 2, 1 ], "aTargets": [ 2 ] }, // last name
|
32
|
+
{ "aDataSort": [ 3, 1, 2 ], "aTargets": [ 3 ] }, // department
|
33
|
+
]
|
34
|
+
});
|
@@ -5,12 +5,12 @@ $(function() {
|
|
5
5
|
$('#first_name').val('');
|
6
6
|
$('#last_name').val('');
|
7
7
|
$("#lps-results").empty();
|
8
|
+
$('#matches').empty();
|
8
9
|
}
|
9
10
|
|
10
11
|
function setHiddenField(link, dataAttribute) {
|
11
12
|
var selector = '#' + dataAttribute;
|
12
13
|
var value = link.data(dataAttribute);
|
13
|
-
|
14
14
|
$(selector).val(value);
|
15
15
|
}
|
16
16
|
|
@@ -32,7 +32,6 @@ $(function() {
|
|
32
32
|
// open search dialog
|
33
33
|
$('.ldap-person-search').click(function() {
|
34
34
|
$('#lps-modal').modal('show');
|
35
|
-
$('#first_name').focus();
|
36
35
|
|
37
36
|
var link = $(this);
|
38
37
|
setHiddenFields(link);
|
@@ -42,11 +41,10 @@ $(function() {
|
|
42
41
|
// Clear button
|
43
42
|
$('#lps-clear').click(function() {
|
44
43
|
clearLdapPersonSearchForm();
|
45
|
-
});
|
44
|
+
});
|
46
45
|
|
47
46
|
// modal shown
|
48
|
-
$("#lps-modal").on('
|
49
|
-
//clearLdapPersonSearchForm();
|
47
|
+
$("#lps-modal").on('shown', function() {
|
50
48
|
$("#first_name").focus();
|
51
49
|
});
|
52
50
|
|
@@ -25,6 +25,11 @@ table {
|
|
25
25
|
#lps-modal {
|
26
26
|
width: 750px;
|
27
27
|
|
28
|
+
.title {
|
29
|
+
margin-top: 10px;
|
30
|
+
margin-bottom: 15px;
|
31
|
+
}
|
32
|
+
|
28
33
|
form {
|
29
34
|
input[type="text"] {
|
30
35
|
width: 140px;
|
@@ -44,7 +49,7 @@ table {
|
|
44
49
|
}
|
45
50
|
|
46
51
|
div.control-group.lps-typeahead {
|
47
|
-
|
52
|
+
span.ldap-person-search {
|
48
53
|
cursor: pointer;
|
49
54
|
}
|
50
55
|
|
data/lib/ucb_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucb_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -208,17 +208,17 @@ dependencies:
|
|
208
208
|
requirement: !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|
211
|
-
- -
|
211
|
+
- - ~>
|
212
212
|
- !ruby/object:Gem::Version
|
213
|
-
version:
|
213
|
+
version: 0.0.2
|
214
214
|
type: :runtime
|
215
215
|
prerelease: false
|
216
216
|
version_requirements: !ruby/object:Gem::Requirement
|
217
217
|
none: false
|
218
218
|
requirements:
|
219
|
-
- -
|
219
|
+
- - ~>
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
221
|
+
version: 0.0.2
|
222
222
|
- !ruby/object:Gem::Dependency
|
223
223
|
name: bootstrap-view-helpers
|
224
224
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,7 +242,7 @@ dependencies:
|
|
242
242
|
requirements:
|
243
243
|
- - ~>
|
244
244
|
- !ruby/object:Gem::Version
|
245
|
-
version: 0.0.
|
245
|
+
version: 0.0.3
|
246
246
|
type: :runtime
|
247
247
|
prerelease: false
|
248
248
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -250,7 +250,7 @@ dependencies:
|
|
250
250
|
requirements:
|
251
251
|
- - ~>
|
252
252
|
- !ruby/object:Gem::Version
|
253
|
-
version: 0.0.
|
253
|
+
version: 0.0.3
|
254
254
|
- !ruby/object:Gem::Dependency
|
255
255
|
name: user_announcements
|
256
256
|
requirement: !ruby/object:Gem::Requirement
|
@@ -546,6 +546,7 @@ files:
|
|
546
546
|
- app/helpers/ucb_rails/lps_typeahead_helper.rb
|
547
547
|
- app/helpers/ucb_rails/renderer/base.rb
|
548
548
|
- app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
|
549
|
+
- app/helpers/ucb_rails/renderer/lps_typeahead_search_field.rb
|
549
550
|
- app/models/ucb_rails/ldap_person/entry.rb
|
550
551
|
- app/models/ucb_rails/ldap_person/finder.rb
|
551
552
|
- app/models/ucb_rails/ldap_person/test_finder.rb
|
@@ -557,7 +558,7 @@ files:
|
|
557
558
|
- app/models/ucb_rails/user_session_manager/in_people_ou.rb
|
558
559
|
- app/models/ucb_rails/user_session_manager/in_people_ou_add_to_users_table.rb
|
559
560
|
- app/models/ucb_rails/user_session_manager/ldap_person_user_wrapper.rb
|
560
|
-
- app/models/ucb_rails/
|
561
|
+
- app/models/ucb_rails/user_typeahead.rb
|
561
562
|
- app/views/ucb_rails/admin/users/_form.html.haml
|
562
563
|
- app/views/ucb_rails/admin/users/_user.html.haml
|
563
564
|
- app/views/ucb_rails/admin/users/edit.html.haml
|