Last active
August 29, 2015 13:57
-
-
Save josemarluedke/9540425 to your computer and use it in GitHub Desktop.
Neighbor.ly near projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index | |
| @city = user_city | |
| @project_locations = project_locations(@city) | |
| @near_projects = Project.with_state('online').near(@city, 100).visible.order('distance').limit(4) | |
| used_ids += @near_projects.map(&:id) if @near_projects.any? | |
| end | |
| def near | |
| raise ActionController::UnknownController unless request.xhr? | |
| @projects = apply_scopes(Project).with_state('online').near(params[:location], 100).visible.order('distance').page(params[:page]).per(4) | |
| render layout: false | |
| end | |
| private | |
| def user_city | |
| if current_user && current_user.address.present? | |
| current_user.address | |
| #elsif request.location.present? && request.location.city.present? && request.location.country_code == 'US' | |
| #request.location.city | |
| else | |
| 'Kansas City, MO' | |
| end | |
| end | |
| def project_locations(current_city) | |
| locations = Project.with_state('online').locations | |
| locations.concat([current_city]) unless locations.include?(current_city) | |
| locations | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe 'GET near' do | |
| describe 'html format' do | |
| before { get :near, location: 'Kansas City, MO' } | |
| it { expect(response.status).to eq(404) } | |
| end | |
| describe 'xhr request' do | |
| before { xhr :get, :near, location: 'Kansas City, MO' } | |
| it { expect(response).to be_success } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Neighborly.Projects = {} if Neighborly.Projects is undefined | |
| Neighborly.Projects.Index = Backbone.View.extend | |
| el: '.home-page' | |
| initialize: -> | |
| $('.locations-dropdown a').click(this.changeCity) | |
| changeCity: (event)-> | |
| event.preventDefault() | |
| $el = $(event.currentTarget) | |
| url = $el.attr('href') | |
| $('a.change-city').html($el.html()) | |
| $el.parents('[data-dropdown-content]').foundation('dropdown', 'close', $el.parents('[data-dropdown-content]')) | |
| $.ajax( | |
| url: url | |
| beforeSend: -> | |
| $('section.near .content').addClass('loading-section') | |
| success: (data) -> | |
| $('section.near .content').html data | |
| $('section.near .content').removeClass('loading-section') | |
| error: -> | |
| $('section.near .content').removeClass('loading-section') | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| section.near | |
| header | |
| +clearfix | |
| h3 | |
| float: left | |
| a.change-city | |
| text-decoration: underline | |
| text-transform: uppercase | |
| &:after | |
| @extend [class^="icon-et-"]:before | |
| @extend .icon-et-down-open-mini:before | |
| margin-left: +emCalc(5px) | |
| text-decoration: none | |
| .locations-dropdown | |
| font-size: 75% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - if projects == 1 | |
| - n_columns = 9 | |
| - elsif projects == 2 | |
| - n_columns = 6 | |
| - elsif projects == 3 | |
| - n_columns = 3 | |
| - else | |
| - n_columns = 12 | |
| .columns[class="large-#{ n_columns }"] | |
| = link_to start_path do | |
| section.start-one[class="n-columns-#{ n_columns }"] | |
| h3 = t('.title') | |
| - if n_columns == 3 | |
| - button_text = t('.small_button') | |
| - else | |
| - button_text = t('.button') | |
| = link_to button_text, start_path, class: "button custom with-icon #{ n_columns == 3 ? 'medium' : 'large' }" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| section.near | |
| header | |
| h3 | |
| i.icon-et-location | |
| = t('.near') | |
| | | |
| = link_to @city, '#', class: 'change-city', data: { dropdown: 'drop-locations' } | |
| ul[id="drop-locations" class="f-dropdown locations-dropdown" data-dropdown-content] | |
| - for location in @project_locations | |
| li = link_to location, near_projects_path(location: location) | |
| .row.content | |
| - for project in @near_projects | |
| = render 'project', project: project | |
| = render 'projects/start_one', projects: @near_projects.size if @near_projects.size < 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment