From 5d394614431e7682c16a7c541698c9ab9d690758 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 23 Jul 2015 14:09:14 +0200 Subject: [PATCH 1/3] Display polls on mobile devices --- app/assets/stylesheets/mobile/mobile.scss | 1 + app/assets/stylesheets/mobile/polls.scss | 8 ++++++ .../_status_message.mobile.haml | 28 ++++++++++++++++++- config/locales/diaspora/en.yml | 6 ++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/mobile/polls.scss diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index 45f3fbe6b..ec9031692 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -10,6 +10,7 @@ @import "mobile/tags"; @import "mobile/conversations"; @import "mobile/settings"; +@import "mobile/polls"; a { color: #2489ce; diff --git a/app/assets/stylesheets/mobile/polls.scss b/app/assets/stylesheets/mobile/polls.scss new file mode 100644 index 000000000..3cf2748c8 --- /dev/null +++ b/app/assets/stylesheets/mobile/polls.scss @@ -0,0 +1,8 @@ +.stream_element .poll { + border-top: 1px solid $border-grey; + margin-top: 20px; + padding-top: 10px; + .poll-head .question { + font-weight: bold; + } +} diff --git a/app/views/status_messages/_status_message.mobile.haml b/app/views/status_messages/_status_message.mobile.haml index 5aba5358d..774d2da54 100644 --- a/app/views/status_messages/_status_message.mobile.haml +++ b/app/views/status_messages/_status_message.mobile.haml @@ -16,8 +16,34 @@ %div{:class => direction_for(post.text)} != post.message.markdownified + - if post.poll + .poll + .poll-head + .poll-stats.pull-right + = t("polls.votes", count: post.poll.participation_count) + .question + = post.poll.question + .poll-content + - post.poll.poll_answers.each do |answer| + .result-row + .result-head + - percentage = 0 + - if post.poll.participation_count > 0 + - percentage = (answer.vote_count / post.poll.participation_count * 100).round + .percentage.pull-right + = "#{percentage}%" + .answer + = answer.answer + .progress + .progress-bar{role: "progressbar", + aria: {valuenow: "#{percentage}", + valuemin: "0", + valuemax: "100"}, + style: "width: #{percentage}%;"} + %span.sr-only + = "#{percentage}%" - if post.o_embed_cache != o_embed_html post.o_embed_cache - -if post.open_graph_cache + - if post.open_graph_cache .opengraph != og_html post.open_graph_cache diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 969360426..85e597c7e 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -975,6 +975,12 @@ en: or_select_one_existing: "or select one from your already existing %{photos}" comment_email_subject: "%{name}’s photo" + polls: + votes: + zero: "%{count} votes so far" + one: "%{count} vote so far" + other: "%{count} votes so far" + posts: presenter: title: "A post from %{name}" From 6fafa731e6457f6fcfe3c432da58b048b96d2cac Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 23 Jul 2015 15:52:59 +0200 Subject: [PATCH 2/3] Display locations on mobile devices --- app/assets/stylesheets/mobile/mobile.scss | 2 +- app/assets/stylesheets/mobile/polls.scss | 8 ------ .../stylesheets/mobile/stream_element.scss | 16 ++++++++++++ app/views/shared/_post_info.mobile.haml | 3 +++ app/views/status_messages/_poll.mobile.haml | 25 ++++++++++++++++++ .../_status_message.mobile.haml | 26 +------------------ config/locales/diaspora/en.yml | 1 + 7 files changed, 47 insertions(+), 34 deletions(-) delete mode 100644 app/assets/stylesheets/mobile/polls.scss create mode 100644 app/assets/stylesheets/mobile/stream_element.scss create mode 100644 app/views/status_messages/_poll.mobile.haml diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index ec9031692..f2d094d62 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -10,7 +10,7 @@ @import "mobile/tags"; @import "mobile/conversations"; @import "mobile/settings"; -@import "mobile/polls"; +@import "mobile/stream_element"; a { color: #2489ce; diff --git a/app/assets/stylesheets/mobile/polls.scss b/app/assets/stylesheets/mobile/polls.scss deleted file mode 100644 index 3cf2748c8..000000000 --- a/app/assets/stylesheets/mobile/polls.scss +++ /dev/null @@ -1,8 +0,0 @@ -.stream_element .poll { - border-top: 1px solid $border-grey; - margin-top: 20px; - padding-top: 10px; - .poll-head .question { - font-weight: bold; - } -} diff --git a/app/assets/stylesheets/mobile/stream_element.scss b/app/assets/stylesheets/mobile/stream_element.scss new file mode 100644 index 000000000..13734c6a9 --- /dev/null +++ b/app/assets/stylesheets/mobile/stream_element.scss @@ -0,0 +1,16 @@ +.stream_element { + .location { + color: $text-grey; + font-size: $font-size-small; + white-space: normal; + } + + .poll { + border-top: 1px solid $border-grey; + margin-top: 20px; + padding-top: 10px; + .poll-head .question { + font-weight: bold; + } + } +} diff --git a/app/views/shared/_post_info.mobile.haml b/app/views/shared/_post_info.mobile.haml index fa262d27e..03d6aa504 100644 --- a/app/views/shared/_post_info.mobile.haml +++ b/app/views/shared/_post_info.mobile.haml @@ -30,3 +30,6 @@ = t('public') - else = t('limited') + - if !post.is_a?(Reshare) and post.location + .location + = t("posts.show.location", location: post.location.address) diff --git a/app/views/status_messages/_poll.mobile.haml b/app/views/status_messages/_poll.mobile.haml new file mode 100644 index 000000000..30dec659f --- /dev/null +++ b/app/views/status_messages/_poll.mobile.haml @@ -0,0 +1,25 @@ +.poll + .poll-head + .poll-stats.pull-right + = t("polls.votes", count: poll.participation_count) + .question + = poll.question + .poll-content + - poll.poll_answers.each do |answer| + .result-row + .result-head + - percentage = 0 + - if poll.participation_count > 0 + - percentage = (answer.vote_count / poll.participation_count * 100).round + .percentage.pull-right + = "#{percentage}%" + .answer + = answer.answer + .progress + .progress-bar{role: "progressbar", + aria: {valuenow: "#{percentage}", + valuemin: "0", + valuemax: "100"}, + style: "width: #{percentage}%;"} + %span.sr-only + = "#{percentage}%" diff --git a/app/views/status_messages/_status_message.mobile.haml b/app/views/status_messages/_status_message.mobile.haml index 774d2da54..52f60ba74 100644 --- a/app/views/status_messages/_status_message.mobile.haml +++ b/app/views/status_messages/_status_message.mobile.haml @@ -17,31 +17,7 @@ %div{:class => direction_for(post.text)} != post.message.markdownified - if post.poll - .poll - .poll-head - .poll-stats.pull-right - = t("polls.votes", count: post.poll.participation_count) - .question - = post.poll.question - .poll-content - - post.poll.poll_answers.each do |answer| - .result-row - .result-head - - percentage = 0 - - if post.poll.participation_count > 0 - - percentage = (answer.vote_count / post.poll.participation_count * 100).round - .percentage.pull-right - = "#{percentage}%" - .answer - = answer.answer - .progress - .progress-bar{role: "progressbar", - aria: {valuenow: "#{percentage}", - valuemin: "0", - valuemax: "100"}, - style: "width: #{percentage}%;"} - %span.sr-only - = "#{percentage}%" + = render "status_messages/poll", poll: post.poll - if post.o_embed_cache != o_embed_html post.o_embed_cache - if post.open_graph_cache diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 85e597c7e..20f166c0c 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -985,6 +985,7 @@ en: presenter: title: "A post from %{name}" show: + location: "Posted from: %{location}" destroy: "Delete" permalink: "Permalink" not_found: "Sorry, we couldn’t find that post." From 79dfdfa224068d103d132f3840a579bb1ee9968d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 23 Jul 2015 17:30:05 +0200 Subject: [PATCH 3/3] Add integration tests for mobile polls and locations --- spec/factories.rb | 7 +++++++ spec/integration/mobile_posts_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spec/integration/mobile_posts_spec.rb diff --git a/spec/factories.rb b/spec/factories.rb index 42c39caca..a9989e077 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -99,6 +99,12 @@ FactoryGirl.define do end end + factory(:status_message_with_location) do + after(:build) do |sm| + FactoryGirl.create(:location, status_message: sm) + end + end + factory(:status_message_with_photo) do sequence(:text) {|n| "There are #{n} ninjas in this photo." } after(:build) do |sm| @@ -134,6 +140,7 @@ FactoryGirl.define do end factory(:location) do + address "unicorn city" lat 1 lng 2 end diff --git a/spec/integration/mobile_posts_spec.rb b/spec/integration/mobile_posts_spec.rb new file mode 100644 index 000000000..058b06948 --- /dev/null +++ b/spec/integration/mobile_posts_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +describe PostsController, type: :request do + context "with a poll" do + let(:sm) { FactoryGirl.build(:status_message_with_poll, public: true) } + + it "displays the poll" do + get "/posts/#{sm.id}", format: :mobile + + expect(response.status).to eq(200) + expect(response.body).to match(/div class='poll'/) + expect(response.body).to match(/#{sm.poll.poll_answers.first.answer}/) + end + end + + context "with a location" do + let(:sm) { FactoryGirl.build(:status_message_with_location, public: true) } + + it "displays the location" do + get "/posts/#{sm.id}", format: :mobile + + expect(response.status).to eq(200) + expect(response.body).to match(/div class='location'/) + expect(response.body).to match(/#{I18n.t("posts.show.location", location: sm.location.address)}/) + end + end +end