From 9fefe078a4a15f396db38bf33fc8ca5c761d93c4 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Fri, 1 Aug 2014 21:54:43 -0400 Subject: [PATCH 01/11] changed spec to fill in text field instead of select --- config/settings.yml | 8 ++++---- spec/support/features/form_helpers.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 938551103..9859accd7 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -29,11 +29,11 @@ # This setting is used in 'app/models/concerns/search.rb'. bounds: [[25.7084, -124.085], [48.9084, -67.085]] -#################################################### +############################### # -# GENERIC EMAIL DOMAIN SETTINGS FOR ADMIN INTERFACE +# SETTINGS FOR ADMIN INTERFACE # -#################################################### +############################### # # An array of email domain names used by the admin interface to determine which # users get to access which locations. For convenience, the API allows a client @@ -66,7 +66,7 @@ generic_domains: # This link appears when an admin views their locations and organizations. # See app/views/admin/locations/index.html.haml and # app/views/admin/organizations/index.html.haml. -admin_support_email: ohanapi@codeforamerica.org +admin_support_email: ######################### # diff --git a/spec/support/features/form_helpers.rb b/spec/support/features/form_helpers.rb index ff54ab0d8..fa9be6fd5 100644 --- a/spec/support/features/form_helpers.rb +++ b/spec/support/features/form_helpers.rb @@ -161,7 +161,7 @@ def delete_all_urls end def fill_in_all_required_fields - select 'Parent Agency', from: 'location_organization_id' + fill_in 'location_organization_id', with: 'Parent Agency' fill_in 'location_name', with: 'New Parent Agency location' fill_in 'location_description', with: 'new description' click_link 'Add a street address' From 6abea3956f80583b4c6fbc1e7aef84d8fcfd1035 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sat, 2 Aug 2014 21:16:49 -0400 Subject: [PATCH 02/11] added jquery-ui-rails to the Gemfile --- Gemfile | 1 + Gemfile.lock | 3 +++ app/assets/javascripts/application.js | 1 + 3 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index 075429879..ea6782615 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ gem 'protected_attributes' # Front end gem 'jquery-rails' +gem 'jquery-ui-rails' gem 'haml-rails', '~> 0.5.3' # Server for deployment diff --git a/Gemfile.lock b/Gemfile.lock index 9d05309bd..62f2ebad1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,8 @@ GEM jquery-rails (3.1.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (5.0.0) + railties (>= 3.2.16) json (1.8.1) kaminari (0.16.1) actionpack (>= 3.0.0) @@ -276,6 +278,7 @@ DEPENDENCIES geocoder haml-rails (~> 0.5.3) jquery-rails + jquery-ui-rails kaminari listen (~> 1.0) newrelic_rpm diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b40fe089f..f5e71130c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require jquery //= require jquery_ujs +//= require jquery-ui //= require bootstrap //= require bootstrap-modal //= require_tree . From 14558279ab9ecf880845c28488543be78a3475a2 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sat, 2 Aug 2014 21:20:58 -0400 Subject: [PATCH 03/11] changed form to text field instead of select --- app/views/admin/locations/forms/_new_location_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/locations/forms/_new_location_form.html.haml b/app/views/admin/locations/forms/_new_location_form.html.haml index 43634cffd..6709f75d9 100644 --- a/app/views/admin/locations/forms/_new_location_form.html.haml +++ b/app/views/admin/locations/forms/_new_location_form.html.haml @@ -9,7 +9,7 @@ %header = f.label :organization_id, 'Choose an organization to create this location for.' %p - = f.select :organization_id, @orgs.collect { |org| [org.second, org.first] }, include_blank: true + = f.text_field :organization_id, data: {autocomplete_source: admin_organizations_path} = render 'admin/locations/forms/location_name', f: f = render 'admin/locations/forms/admin_emails', f: f From d20f74b831b16ee304927cab96d28ad63d4972cf Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sat, 2 Aug 2014 21:31:45 -0400 Subject: [PATCH 04/11] added autocomplete custom route and matching action in Organizations controller --- app/controllers/api/v1/organizations_controller.rb | 5 +++++ app/views/admin/locations/forms/_new_location_form.html.haml | 2 +- config/routes.rb | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/organizations_controller.rb b/app/controllers/api/v1/organizations_controller.rb index c21e4e14e..6f7912aff 100644 --- a/app/controllers/api/v1/organizations_controller.rb +++ b/app/controllers/api/v1/organizations_controller.rb @@ -41,6 +41,11 @@ def locations render json: locations, each_serializer: LocationsSerializer, status: 200 generate_pagination_headers(locations) end + + def populate_autocomplete + @categories = Organization.order(:name).where("name like ?", "%#{params[:term]}%") + render json: @organizations.map(&:name) + end end end end diff --git a/app/views/admin/locations/forms/_new_location_form.html.haml b/app/views/admin/locations/forms/_new_location_form.html.haml index 6709f75d9..908e53099 100644 --- a/app/views/admin/locations/forms/_new_location_form.html.haml +++ b/app/views/admin/locations/forms/_new_location_form.html.haml @@ -9,7 +9,7 @@ %header = f.label :organization_id, 'Choose an organization to create this location for.' %p - = f.text_field :organization_id, data: {autocomplete_source: admin_organizations_path} + = f.text_field :organization_id, data: {autocomplete_source: @orgs} = render 'admin/locations/forms/location_name', f: f = render 'admin/locations/forms/admin_emails', f: f diff --git a/config/routes.rb b/config/routes.rb index e3ea0dcd8..91a6e5136 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ resources :organizations, except: :show + get 'organizations/populate_autocomplete', to: 'organizations#populate_autocomplete' get 'locations/:location_id/services/confirm_delete_service', to: 'services#confirm_delete_service', as: :confirm_delete_service get 'organizations/confirm_delete_organization', to: 'organizations#confirm_delete_organization', as: :confirm_delete_organization get 'locations/confirm_delete_location', to: 'locations#confirm_delete_location', as: :confirm_delete_location From 776a1bef32b3b4d931fa9e97c15af4177d3704a2 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sat, 2 Aug 2014 21:36:17 -0400 Subject: [PATCH 05/11] added autocomplete coffescript --- app/assets/javascripts/orgs_autocomplete.js.coffee | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/assets/javascripts/orgs_autocomplete.js.coffee diff --git a/app/assets/javascripts/orgs_autocomplete.js.coffee b/app/assets/javascripts/orgs_autocomplete.js.coffee new file mode 100644 index 000000000..0e5ef386e --- /dev/null +++ b/app/assets/javascripts/orgs_autocomplete.js.coffee @@ -0,0 +1,3 @@ +jQuery -> + $('#location_organization_id').autocomplete + source: $('#location_organization_id').data('autocomplete-source') From bf7ffd80ef02568a25de59643a763c627e4ba21a Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sat, 2 Aug 2014 22:03:58 -0400 Subject: [PATCH 06/11] server-side, case-insensitive, auto-complete now populating view --- app/assets/stylesheets/application.css.scss | 24 ++++++++++++++++++- .../admin/organizations_controller.rb | 5 ++++ .../api/v1/organizations_controller.rb | 5 ---- .../forms/_new_location_form.html.haml | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 9209212a8..d66040b21 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -59,7 +59,6 @@ -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15); -moz-box-shadow: 0 1px 2px rgba(0,0,0,.15); box-shadow: 0 1px 2px rgba(0,0,0,.15); - border:1px solid #C8D4E8; margin-bottom:20px; header @@ -188,3 +187,26 @@ a.boxed-action:hover, a.boxed-action:active margin-bottom:0px; } } + +ul.ui-autocomplete { + position: absolute; + list-style: none; + margin: 0; + padding: 0; + border: solid 1px #999; + cursor: default; + li { + background-color: #FFF; + border-top: solid 1px #DDD; + margin: 0; + padding: 0; + a { + color: #000; + display: block; + padding: 3px; + } + a.ui-state-hover, a.ui-state-active { + background-color: #FFFCB2; + } + } +} diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 2a16d6bba..dbc07ef14 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -73,5 +73,10 @@ def confirm_delete_organization format.js end end + + def populate_autocomplete + @organizations = Organization.order(:name).where("name ilike ?", "%#{params[:term]}%") + render json: @organizations.map(&:name) + end end end diff --git a/app/controllers/api/v1/organizations_controller.rb b/app/controllers/api/v1/organizations_controller.rb index 6f7912aff..c21e4e14e 100644 --- a/app/controllers/api/v1/organizations_controller.rb +++ b/app/controllers/api/v1/organizations_controller.rb @@ -41,11 +41,6 @@ def locations render json: locations, each_serializer: LocationsSerializer, status: 200 generate_pagination_headers(locations) end - - def populate_autocomplete - @categories = Organization.order(:name).where("name like ?", "%#{params[:term]}%") - render json: @organizations.map(&:name) - end end end end diff --git a/app/views/admin/locations/forms/_new_location_form.html.haml b/app/views/admin/locations/forms/_new_location_form.html.haml index 908e53099..e1120bafe 100644 --- a/app/views/admin/locations/forms/_new_location_form.html.haml +++ b/app/views/admin/locations/forms/_new_location_form.html.haml @@ -9,7 +9,7 @@ %header = f.label :organization_id, 'Choose an organization to create this location for.' %p - = f.text_field :organization_id, data: {autocomplete_source: @orgs} + = f.text_field :organization_id, data: { autocomplete_source: admin_organizations_populate_autocomplete_path } = render 'admin/locations/forms/location_name', f: f = render 'admin/locations/forms/admin_emails', f: f From ff2bafc5119eddc5011c1764b4eefce9c2f5b56e Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sun, 3 Aug 2014 09:51:10 -0400 Subject: [PATCH 07/11] submitting a form with an existing org in the autocomplete field works now --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ app/controllers/admin/locations_controller.rb | 2 ++ app/controllers/admin/organizations_controller.rb | 1 - 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ea6782615..f96b6ce21 100644 --- a/Gemfile +++ b/Gemfile @@ -81,4 +81,5 @@ group :development do gem 'spring' gem 'spring-commands-rspec' gem 'listen', '~> 1.0' + gem 'pry-rails' end diff --git a/Gemfile.lock b/Gemfile.lock index 62f2ebad1..812042d6c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -120,6 +120,7 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.0) minitest (5.4.0) @@ -149,6 +150,12 @@ GEM powerpack (0.0.9) protected_attributes (1.0.8) activemodel (>= 4.0.1, < 5.0) + pry (0.10.0) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.2) + pry (>= 0.9.10) quiet_assets (1.0.3) railties (>= 3.1, < 5.0) rack (1.5.2) @@ -287,6 +294,7 @@ DEPENDENCIES pg_search poltergeist protected_attributes + pry-rails quiet_assets (>= 1.0.2) rack-cors rack-timeout diff --git a/app/controllers/admin/locations_controller.rb b/app/controllers/admin/locations_controller.rb index 4d881bca4..7e2d7713b 100644 --- a/app/controllers/admin/locations_controller.rb +++ b/app/controllers/admin/locations_controller.rb @@ -49,7 +49,9 @@ def new end def create + organization_id = Organization.find_by(name: params[:location][:organization_id]).id @location = Location.new(params[:location]) + @location.organization_id = organization_id @admin_decorator = AdminDecorator.new(current_admin) @orgs = @admin_decorator.orgs diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index dbc07ef14..a2a1f06c0 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -44,7 +44,6 @@ def new def create @organization = Organization.new(params[:organization]) - respond_to do |format| if @organization.save format.html do From 753892c12020dd659405dc2e5e22354d4e751224 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sun, 3 Aug 2014 10:09:30 -0400 Subject: [PATCH 08/11] fixed a couple of styling issues --- app/controllers/admin/locations_controller.rb | 2 +- app/controllers/admin/organizations_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/locations_controller.rb b/app/controllers/admin/locations_controller.rb index 7e2d7713b..f5d95f1d1 100644 --- a/app/controllers/admin/locations_controller.rb +++ b/app/controllers/admin/locations_controller.rb @@ -49,8 +49,8 @@ def new end def create - organization_id = Organization.find_by(name: params[:location][:organization_id]).id @location = Location.new(params[:location]) + organization_id = Organization.find_by(name: params[:location][:organization_id]).id unless params[:location][:organization_id] == '' @location.organization_id = organization_id @admin_decorator = AdminDecorator.new(current_admin) @orgs = @admin_decorator.orgs diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index a2a1f06c0..91e7b36b0 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -74,8 +74,8 @@ def confirm_delete_organization end def populate_autocomplete - @organizations = Organization.order(:name).where("name ilike ?", "%#{params[:term]}%") - render json: @organizations.map(&:name) + @organizations = Organization.order(:name).where('name ilike ?', '%#{params[:term]}%') + render json: @organizations.map(&:name) end end end From f73d78b280e9028b38ada4154184d7f59c53c592 Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sun, 3 Aug 2014 10:10:47 -0400 Subject: [PATCH 09/11] added title to autocomplete text field --- app/views/admin/locations/forms/_new_location_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/locations/forms/_new_location_form.html.haml b/app/views/admin/locations/forms/_new_location_form.html.haml index e1120bafe..6f3dcee01 100644 --- a/app/views/admin/locations/forms/_new_location_form.html.haml +++ b/app/views/admin/locations/forms/_new_location_form.html.haml @@ -9,7 +9,7 @@ %header = f.label :organization_id, 'Choose an organization to create this location for.' %p - = f.text_field :organization_id, data: { autocomplete_source: admin_organizations_populate_autocomplete_path } + = f.text_field :organization_id, data: { autocomplete_source: admin_organizations_populate_autocomplete_path }, title: 'Start typing the name of the organization for this location and select it from the dropdown' = render 'admin/locations/forms/location_name', f: f = render 'admin/locations/forms/admin_emails', f: f From 0318604b2db44576f7139c922008dc99e9bc266f Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sun, 3 Aug 2014 11:14:58 -0400 Subject: [PATCH 10/11] refactoring to account for user submitting non-existing organization --- app/controllers/admin/locations_controller.rb | 4 +++- app/controllers/admin/organizations_controller.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/locations_controller.rb b/app/controllers/admin/locations_controller.rb index f5d95f1d1..114b648f3 100644 --- a/app/controllers/admin/locations_controller.rb +++ b/app/controllers/admin/locations_controller.rb @@ -50,7 +50,9 @@ def new def create @location = Location.new(params[:location]) - organization_id = Organization.find_by(name: params[:location][:organization_id]).id unless params[:location][:organization_id] == '' + if Organization.exists?(name: params[:location][:organization_id]) + organization_id = Organization.find_by(name: params[:location][:organization_id]).id + end @location.organization_id = organization_id @admin_decorator = AdminDecorator.new(current_admin) @orgs = @admin_decorator.orgs diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 91e7b36b0..17b060f9d 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -74,7 +74,7 @@ def confirm_delete_organization end def populate_autocomplete - @organizations = Organization.order(:name).where('name ilike ?', '%#{params[:term]}%') + @organizations = Organization.order(:name).where('name ilike ?', "%#{params[:term]}%") render json: @organizations.map(&:name) end end From cb0da11e1334e08393ab56a83f11d2328471b49c Mon Sep 17 00:00:00 2001 From: BYWallace Date: Sun, 3 Aug 2014 11:26:31 -0400 Subject: [PATCH 11/11] restored settings.yml to original state --- config/settings.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 9859accd7..938551103 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -29,11 +29,11 @@ # This setting is used in 'app/models/concerns/search.rb'. bounds: [[25.7084, -124.085], [48.9084, -67.085]] -############################### +#################################################### # -# SETTINGS FOR ADMIN INTERFACE +# GENERIC EMAIL DOMAIN SETTINGS FOR ADMIN INTERFACE # -############################### +#################################################### # # An array of email domain names used by the admin interface to determine which # users get to access which locations. For convenience, the API allows a client @@ -66,7 +66,7 @@ generic_domains: # This link appears when an admin views their locations and organizations. # See app/views/admin/locations/index.html.haml and # app/views/admin/organizations/index.html.haml. -admin_support_email: +admin_support_email: ohanapi@codeforamerica.org ######################### #