Skip to content

Grid protip gets two different collection types #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/helpers/protips_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'cfm'

module ProtipsHelper

def protip_search_results_to_render(protips)
(protips.results if protips.respond_to?(:results)) || protips.try(:all)
end

def protip_summary
"A protip by #{@protip.user.username} about #{@protip.topics.to_sentence}."
end
Expand Down Expand Up @@ -296,12 +301,12 @@ def protip_stat_class(protip)

def formatted_best_stat_value(protip)
value =
case best_stat_name(protip).to_sym
when :views
views_stat_value(protip)
else
best_stat_value(protip)
end
case best_stat_name(protip).to_sym
when :views
views_stat_value(protip)
else
best_stat_value(protip)
end
number_to_human(value, units: {unit: "", thousand: "k"})
end

Expand Down
41 changes: 21 additions & 20 deletions app/views/protips/_grid.html.haml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
-reset_protip_result_index
-show_job = defined?(opportunity) && !opportunity.nil?
- reset_protip_result_index
- show_job = defined?(opportunity) && opportunity.present?
- width = (defined?(width) && width) || 4
- show_ad_every = width*2+width-2
- items = show_job ? protips.each_slice(show_ad_every).map{|row| row.count == show_ad_every ? row.concat(['show-ad', nil]) : row }.flatten : protips
- show_ad_every = width * 2 + width - 2
- items = show_job ? protips.each_slice(show_ad_every).map{ |row| row.count == show_ad_every ? row.concat(['show-ad', nil]) : row }.flatten : protips

- if collection.failure?
- logger.ap(collection, :debug)
- if collection.respond_to?(:failure?) && collection.failure?
.error
="#{collection.error} Meanwhile you can "
=link_to 'create a pro tip', new_protip_path
= "#{collection.error} Meanwhile you can "
= link_to 'create a pro tip', new_protip_path
= "about #{@topic}" unless @topic.nil?

-items.in_groups_of(width, nil).each_with_index do |group, row|
-if (row > 0) && blur_protips?
- items.in_groups_of(width, nil).each_with_index do |group, row|
- if (row > 0) && blur_protips?
.blurred-tips
=render :partial => "sessions/join_buttons", :locals => {:message => "Join to start earning badges for your open source contributions, discover protips and connect with other developers"}
-break
= render(partial: 'sessions/join_buttons', locals: { message: 'Join to start earning badges for your open source contributions, discover protips and connect with other developers' })
- break
%ul.protips-grid.cf
-group.each do |protip|
-if protip == 'show-ad'
=render :partial => 'opportunities/mini', :locals => {:opportunity => opportunity}
-elsif !protip.nil?
- group.each do |protip|
- if protip == 'show-ad'
= render(partial: 'opportunities/mini', locals: { opportunity: opportunity })
-elsif protip.present?
- if protip = protip.load rescue nil # HACK: User deleted, protip no longer exists. Won't be found.
%li{:class => (protip.kind == 'link' ? 'ext-link' : '') }
= render :partial => 'protips/mini', :locals => {:protip => protip, :mode => mode}
%li{ class: (protip.kind == 'link' ? 'ext-link' : '') }
= render(partial: 'protips/mini', locals: { protip: protip, mode: mode })

- unless collection.nil? || !collection.respond_to?(:next_page) || collection.next_page.nil? || hide_more
- next_url = url_for(params.merge(:tags=> params[:tags], :q => params[:q], :source => params[:action], :controller =>params[:controller], :page => collection.current_page + 1, :section => (defined?(section) ? section : nil), :width => width, :mode => mode ))
%div{:class => ("#{number_to_word(width)}-cols-more" unless width.nil?)}
#more=link_to 'More', next_url, :class => 'final-more track' , :rel => 'next', :remote => true, :method => (params[:action] == "search" ? :post : :get), 'data-action' => 'more protips', 'data-from' => params[:action]
- next_url = url_for(params.merge(tags: params[:tags], q: params[:q], source: params[:action], controller:params[:controller], page: collection.current_page + 1, section: (defined?(section) ? section : nil), width: width, mode: mode ))
%div{ class: ("#{number_to_word(width)}-cols-more" unless width.nil?) }
#more= link_to('More', next_url, class: 'final-more track', rel: 'next', remote: true, method: (params[:action] == 'search' ? :post : :get), 'data-action' => 'more protips', 'data-from' => params[:action])
40 changes: 16 additions & 24 deletions app/views/protips/topic.html.haml
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
-#-content_for :javascript do
-# -if @topic_user
-# %script="logUsage('viewed', 'users protips');"
-# -else
-# %script="logUsage('viewed', 'topics protips');"

= render :partial => "head", :locals => {:topic => @topic}
= render(partial: 'head', locals: { topic: @topic })

.secondary-notice
%p
-if @topic_user
-if @topic_user && signed_in? && @topic_user == current_user
- if @topic_user
- if @topic_user && signed_in? && @topic_user == current_user
These are your links, code snippets, posts and other pro tips you have created or upvoted. Have a quick pro tip to
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
or
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
- if @topic_user.protips.reject(&:created_automagically?).count == 0
%br Pro tips you currently see here are created automagically from repos you follow/consider useful or slideshares you've created
-else
==These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
- else
== These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
or
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
-elsif signed_in?
%p
=link_to('Share', new_protip_path(:topics => @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
-else
=link_to('Sign in', root_path)
==to start sharing your #{@topic} pro tips or
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
- elsif signed_in?
%p= link_to('Share', new_protip_path(topics: @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
- else
= link_to('Sign in', root_path)
== to start sharing your #{@topic} pro tips or
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')

#browse-results
= render :partial => "grid", :locals => {:protips => (@protips.results if @protips.respond_to?(:results)) || @protips.try(:all), :collection => @protips, :url => :tagged_protips_path, :hide_more => false, :mode => 'popup'}
#browse-results= render(partial: 'grid', locals: { protips: protip_search_results_to_render(@protips), collection: @protips, url: :tagged_protips_path, hide_more: false, mode: 'popup' })
13 changes: 7 additions & 6 deletions spec/helpers/protips_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

RSpec.describe ProtipsHelper, :type => :helper do


end
RSpec.describe ProtipsHelper, type: :helper do
describe ".protip_search_results_to_render" do
it 'has no protips to render' do
expect(helper.protip_search_results_to_render(nil)).to be_nil
end
end
end