diff --git a/app/assets/javascripts/modules/modal.js b/app/assets/javascripts/modules/modal.js index 6af759c..f3f9e6d 100644 --- a/app/assets/javascripts/modules/modal.js +++ b/app/assets/javascripts/modules/modal.js @@ -44,17 +44,6 @@ jQuery(document).ready(function($){ } }); - // Prevent Enter key to click on the first button of the form, which is the link to the - // other form only when the trackdon modal form is visible - $(document).keydown(function(event){ - if(event.which=='13'){ - if( $('form[id="new_donation"]').parents("#modal-track").hasClass('.is-visible') ){ - event.preventDefault(); - $('form:visible').submit(); - } - } - }); - //close modal when clicking the esc keyboard button $(document).keyup(function(event){ event.preventDefault(); diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6a9801f..6d9eaf7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -60,6 +60,7 @@ @import "objects/justify-columns"; @import "objects/content"; @import "objects/modal"; +@import "objects/headings"; /* * 5. Layout @@ -186,7 +187,7 @@ form.simple_form input[type='checkbox'] { width: auto; } form.simple_form textarea { height: 100px; } form.simple_form input[type='submit'] { width: 40%;} -.alert { background: #EBE8CC; padding-top: 1em; padding-bottom: 1em; margin-bottom: 2em; } +.alert { background: $light_background; padding-top: 1em; padding-bottom: 1em; margin-bottom: 2em; } .success, .info, .warning, .danger { } #main_content > .alert { padding-left: 5%; @@ -206,8 +207,8 @@ td { #logo { position: absolute; top: 0; width: 100px; height: 100%; text-align: center; vertical-align: middle; font-weight: 700} #logo a { display: block; padding: 12px 8px; font-size: 13px; text-decoration: none; text-transform: uppercase; } h1.logo { background: $secondary-color; text-transform: uppercase; display: inline-block; padding: 8px 16px; color: #FFF; font-size: 24px; font-weight: normal; } -h1 { font-size: 32px; } -h2 { font-size: 24px; } +// h1 { font-size: 32px; } +// h2 { font-size: 24px; } #header { font-size: 14px;} #header ul { margin: 0; padding: 0; } #header ul li { list-style-type: none; display: inline-block; margin-right: 4px } diff --git a/app/assets/stylesheets/layout/_donations.scss b/app/assets/stylesheets/layout/_donations.scss index 8fa2c92..0b201ab 100644 --- a/app/assets/stylesheets/layout/_donations.scss +++ b/app/assets/stylesheets/layout/_donations.scss @@ -1,4 +1,4 @@ -/* +c/* * * Donation object * --------------- @@ -63,7 +63,7 @@ color: $secondary_color; font-size: 1em; color: #666; - margin: 0 10px 10px 0; + margin: 0 10px 10px 40px; border: none; .date { @@ -82,6 +82,8 @@ h2 { font-size: 1.1em; font-weight: normal; + color: $secondary_color; + border: none; } .donation { margin-top: 1em; diff --git a/app/assets/stylesheets/layout/_user-profile.scss b/app/assets/stylesheets/layout/_user-profile.scss index 0b26a57..2611978 100644 --- a/app/assets/stylesheets/layout/_user-profile.scss +++ b/app/assets/stylesheets/layout/_user-profile.scss @@ -25,15 +25,6 @@ top: 0; left: 0; } - - h2 { - color: $main-color; - border-bottom: 2px solid $main-color; - border-top: none; - padding: 0 0 .15em 0; - font-size: 1.1em; - } - .counters { h2 { border: none; diff --git a/app/assets/stylesheets/objects/_buttons.scss b/app/assets/stylesheets/objects/_buttons.scss index a0012b7..a378afb 100644 --- a/app/assets/stylesheets/objects/_buttons.scss +++ b/app/assets/stylesheets/objects/_buttons.scss @@ -47,4 +47,9 @@ a.btn.not_active:hover { color: #FFF; border: none; } +} +.notice-box { + border-radius: 4px; + background: $light_background; + font-size: .85em; } \ No newline at end of file diff --git a/app/assets/stylesheets/objects/_content.scss b/app/assets/stylesheets/objects/_content.scss index 3eb9f9e..81cb51d 100644 --- a/app/assets/stylesheets/objects/_content.scss +++ b/app/assets/stylesheets/objects/_content.scss @@ -20,9 +20,9 @@ This object is the column holding the content of the page. There are a few flavo padding-right: 5%; @include min-screen(880) { - padding-left: 20px; - padding-right: 20px; - width: 710px; + // padding-left: 20px; + // padding-right: 20px; + // width: 710px; } } diff --git a/app/assets/stylesheets/objects/_headings.scss b/app/assets/stylesheets/objects/_headings.scss new file mode 100644 index 0000000..7758b94 --- /dev/null +++ b/app/assets/stylesheets/objects/_headings.scss @@ -0,0 +1,7 @@ +h2 { + color: $main-color; + border-bottom: 2px solid $main-color; + border-top: none; + padding: 0 0 .15em 0; + font-size: 1.1em; +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa6fa36..91eb888 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,4 +76,7 @@ def modal_error(flash_type, message) flash["modal_#{flash_type}_error".to_sym] = message end + def set_current_external_services + @current_external_services = ExternalServiceManager.new(current_user) + end end diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb index 69c1cdb..64ae241 100644 --- a/app/controllers/donations_controller.rb +++ b/app/controllers/donations_controller.rb @@ -2,9 +2,11 @@ class DonationsController < ApplicationController before_action :logged_in_user, only: [:edit, :update, :destroy] before_action :load_user_donation, only: [:edit, :complete, :update, :destroy] + before_action :set_current_external_services, only: [:index] def index - @donations = Donation.includes(:project, :user).sorted + @donations = fetch_donations.includes(:project, :user).sorted + @featured_donations = @donations.featured.limit(5) end def show @@ -40,6 +42,19 @@ def destroy private + def fetch_donations + donations = Donation + @donations_from_everybody = true + + if logged_in? && current_user.following_users_count > 0 + friends_ids = current_user.following_users.pluck(:id) + donations = donations.from_users(friends_ids) + @donations_from_everybody = false + end + + donations + end + def donation_params params.require(:donation).permit(:quantity, :currency, :date, :comment, :quantity_privacy, :show_comment, :recurring, :project_id, project_attributes: [:name, :description, :url, :id, :category_id]) diff --git a/app/controllers/external_authentications_controller.rb b/app/controllers/external_authentications_controller.rb index 0c83e8b..fc62adc 100644 --- a/app/controllers/external_authentications_controller.rb +++ b/app/controllers/external_authentications_controller.rb @@ -59,8 +59,4 @@ def set_user @user = current_user end - def set_current_external_services - @current_external_services = ExternalServiceManager.new(current_user) - end - end diff --git a/app/models/donation.rb b/app/models/donation.rb index 38edb50..304503c 100644 --- a/app/models/donation.rb +++ b/app/models/donation.rb @@ -14,6 +14,8 @@ class Donation < ActiveRecord::Base scope :quantity_private, -> { where(quantity_privacy: true) } scope :sorted, -> { order(date: :desc) } scope :last_month, -> { where('date >= ?', 1.month.ago) } + scope :from_users, ->(users_ids) { where(user_id: users_ids) } + scope :featured, -> { where("char_length(comment) > 134 ") } validates :project_id, presence: true validates :user_id, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 2d15a0d..2374d75 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,6 @@ class User < ActiveRecord::Base has_secure_password validations: false has_many :donations, dependent: :destroy - has_many :recurring_donations, dependent: :destroy has_many :projects, through: :donations has_many :invitations @@ -76,10 +75,6 @@ def send_password_reset_email UserMailer.password_reset(self).deliver_now end - def has_private_donations? - donations.quantity_private.any? - end - def generate_password_reset_token! generate_token(:password_reset_token) save! @@ -89,6 +84,10 @@ def invitation self.invitation_token.present? && Invitation.find_valid_token(self.invitation_token) end + def all_external_services_connected? + twitter_id.present? && facebook_id.present? + end + private def set_currency diff --git a/app/views/donations/_connect_with_friends.html.erb b/app/views/donations/_connect_with_friends.html.erb new file mode 100644 index 0000000..566711d --- /dev/null +++ b/app/views/donations/_connect_with_friends.html.erb @@ -0,0 +1,16 @@ +
+

<%= t('.connect_with_facebook_and_twitter') %>

+

<%= t('.never_publish') %>

+ + <% css_classes = ['float-left', 'float-right'] %> + +
+ <% if !@current_external_services.include?(:twitter) %> + <%= link_to(t('.twitter'), '/auth/twitter', class: "btn #{css_classes.shift}") %> + <% end %> + + <% if !@current_external_services.include?(:facebook) %> + <%= link_to(t('.facebook'), '/auth/facebook', class: "btn #{css_classes.shift}") %> + <% end %> +
+
diff --git a/app/views/donations/_donation.html.erb b/app/views/donations/_donation.html.erb index 8b9667a..1de9b81 100644 --- a/app/views/donations/_donation.html.erb +++ b/app/views/donations/_donation.html.erb @@ -24,7 +24,7 @@ <% end %> - <%= render partial: 'donations/donation_do_widget', locals: {donation: donation} %> + <%# render partial: 'donations/donation_do_widget', locals: {donation: donation} %> <% if donation.comment.present? && !in_complete_donation_page? %>
diff --git a/app/views/donations/_post_in_social_networks.html.erb b/app/views/donations/_post_in_social_networks.html.erb new file mode 100644 index 0000000..ad83f43 --- /dev/null +++ b/app/views/donations/_post_in_social_networks.html.erb @@ -0,0 +1,8 @@ +
+

<%= t('.no_friends_activity') %>

+ + +
diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb index 5da8779..93e96e1 100644 --- a/app/views/donations/index.html.erb +++ b/app/views/donations/index.html.erb @@ -1,11 +1,37 @@ <% set_meta_tags :description => t('metas.donations.home.description') %> -
+
-

<%= title t('metas.donations.home.title') %>

+
- <% @donations.each do |donation| %> - <%= render partial: 'donation', locals: {donation: donation} %> - <% end %> +

<%= title t('metas.donations.home.title') %>

+ + <% if logged_in? %> + <% if @donations_from_everybody %> + <% if current_user.all_external_services_connected? %> + <%= render 'post_in_social_networks' %> +

<%= t('.donations_everybody') %>

+ <% else %> + <%= render 'connect_with_friends' %> + <% end %> + <% end %> + <% end %> + + <% @donations.each do |donation| %> + <%= render partial: 'donation', locals: {donation: donation} %> + <% end %> +
+ +
diff --git a/app/views/shared/_modal_login.html.erb b/app/views/shared/_modal_login.html.erb index dcea4fc..aa372f4 100644 --- a/app/views/shared/_modal_login.html.erb +++ b/app/views/shared/_modal_login.html.erb @@ -19,6 +19,7 @@
+ <%= modal_flash_message(:login) %>

<%= t 'sessions.new.or_choose_tradition' %>

@@ -42,7 +43,7 @@
- <%= f.button t('sessions.new.create_account'), class: "btn btn-secondary float-left create-account", tabindex: 4 %> + <%= link_to t('sessions.new.create_account'), '', class: "btn btn-secondary float-left create-account", tabindex: 4 %> <%= f.submit t('sessions.new.login_action'), class: "btn btn-primary float-right", tabindex: 3 %>
@@ -100,7 +101,7 @@ <%= f.hidden_field :invitation_token, value: params[:invitation_token] %>
- <%= f.button t('sessions.new.already_have_account'), class: "btn btn-secondary float-left login" %> + <%= link_to t('sessions.new.already_have_account'), '', class: "btn btn-secondary float-left login" %> <%= f.submit t('sessions.new.create_account'), class: "btn btn-primary float-right" %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 00ec893..d7cad77 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -125,6 +125,18 @@ en: complete: great_just_one_thing: 'Great! Just one thing before you are done:' tell_why_you_have_donated: 'Tell why you have donated, that will make the most impact in your friends and recruit more donors for the project.' + connect_with_friends: + connect_with_facebook_and_twitter: "Connect with Facebook and Twitter to see your friend's activity" + never_publish: 'We never publish without your permission, we hate it!' + facebook: Facebook + twitter: Twitter + index: + donations_everybody: 'Donations from everybody:' + featured_donations: Featured donations + post_in_social_networks: + no_friends_activity: 'None of your friends have yet tracked any donation. Post about your donations in Twitter and Facebook so they get inspired!' + twitter: Twitter + facebook: Facebook # donations form how_much_question: 'How much?' when_did_you_donate: 'When did you donate?' diff --git a/config/locales/es.yml b/config/locales/es.yml index 9f1756b..8d07f46 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -152,6 +152,19 @@ es: complete: great_just_one_thing: 'Genial! Solo una cosita más: ' tell_why_you_have_donated: 'Explica por qué has donado, eso tendrá el mayor impacto en tus amigos y reclutarás a más donantes para el projecto.' + connect_with_friends: + connect_with_facebook_and_twitter: "Conecta con Facebook y Twitter para ver la actividad de tus amigos" + never_publish: 'Nunca publicaremos nada sin tu permiso, ¡lo odiamos!' + facebook: Facebook + twitter: Twitter + index: + featured_donations: Donaciones destacadas + donations_everybody: 'Donaciones de todo el mundo:' + post_in_social_networks: + no_friends_activity: 'None of your friends have yet tracked any donation. Post about your donations in Twitter and Facebook so they get inspired!' + no_friends_activity: 'Ninguno de tus amigos ha guardado una donación aún. ¡Postea sobre tus donaciones en Facebook y Twitter para que se inspiren!' + twitter: Twitter + facebook: Facebook how_much_question: '¿Cuánto?' when_did_you_donate: '¿Cuándo donaste?' i_want_to_explain_why: 'Quiero explicar por qué he donado para animar a otros' diff --git a/spec/features/last_donations_spec.rb b/spec/features/last_donations_spec.rb index ffce25a..1942308 100644 --- a/spec/features/last_donations_spec.rb +++ b/spec/features/last_donations_spec.rb @@ -31,9 +31,10 @@ visit donations_page - expect(page).to have_css('.donation:nth-child(2)', text: 'Bruce donated to Wikiwadus # Mar 01 2015') - expect(page).to have_css('.donation:nth-child(3)', text: 'Yorch donated to Wikiwadus # Jan 01 2015') - expect(page).to have_css('.donation:nth-child(4)', text: 'Bruce donated to Gnome # Feb 01 2014') - expect(page).to have_css('.donation:nth-child(5)', text: 'Yorch donated to Gnome # Jan 01 2014') + donations = page.all(:css, '.donation') + expect(donations[0].text).to start_with('Bruce donated to Wikiwadus # Mar 01 2015') + expect(donations[1].text).to start_with('Yorch donated to Wikiwadus # Jan 01 2015') + expect(donations[2].text).to start_with('Bruce donated to Gnome # Feb 01 2014') + expect(donations[3].text).to start_with('Yorch donated to Gnome # Jan 01 2014') end end