about summary refs log tree commit diff
path: root/app/views/stream_entries
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-04 18:03:12 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-03-04 18:03:12 +0100
commit3de71887d849103ed62e8b04b54c630763881010 (patch)
tree0e8d784434229a474d11b02af9b220e94a92b426 /app/views/stream_entries
parent4ced609497bc736cb2b1aec921ba5ca7a23a7f53 (diff)
Add non-JS fallback for polls on public pages (#10155)
Diffstat (limited to 'app/views/stream_entries')
-rw-r--r--app/views/stream_entries/_detailed_status.html.haml3
-rw-r--r--app/views/stream_entries/_poll.html.haml25
-rw-r--r--app/views/stream_entries/_simple_status.html.haml3
3 files changed, 29 insertions, 2 deletions
diff --git a/app/views/stream_entries/_detailed_status.html.haml b/app/views/stream_entries/_detailed_status.html.haml
index b9327a546..b19d2452a 100644
--- a/app/views/stream_entries/_detailed_status.html.haml
+++ b/app/views/stream_entries/_detailed_status.html.haml
@@ -23,7 +23,8 @@
     .e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
   - if status.poll
-    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json
+    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
+      = render partial: 'stream_entries/poll', locals: { poll: status.poll }
   - elsif !status.media_attachments.empty?
     - if status.media_attachments.first.video?
       - video = status.media_attachments.first
diff --git a/app/views/stream_entries/_poll.html.haml b/app/views/stream_entries/_poll.html.haml
new file mode 100644
index 000000000..974aff9bd
--- /dev/null
+++ b/app/views/stream_entries/_poll.html.haml
@@ -0,0 +1,25 @@
+- options = (!poll.expired? && poll.hide_totals?) ? poll.unloaded_options : poll.loaded_options
+- voted = poll.votes.where(account: current_user.account).exists?
+- show_results = voted || poll.expired?
+
+.poll
+  %ul
+    - options.each do |option|
+      %li
+        - if show_results
+          - percent = 100 * option.votes_count / poll.votes_count
+          %span.poll__chart{ style: "width: #{percent}%" }
+          %label.poll__text><
+            %span.poll__number= percent
+            = option.title
+        - else
+          %label.poll__text><
+            %span.poll__input{ class: poll.multiple ? 'checkbox' : nil}><
+            = option.title
+  .poll__footer
+    - unless show_results
+      %button.button.button-secondary{ disabled: true }
+        = t('statuses.poll.vote')
+    %span= t('statuses.poll.total_votes', count: poll.votes_count)
+    ·
+    %span= poll.expires_at
diff --git a/app/views/stream_entries/_simple_status.html.haml b/app/views/stream_entries/_simple_status.html.haml
index a000c02f4..68e48edbb 100644
--- a/app/views/stream_entries/_simple_status.html.haml
+++ b/app/views/stream_entries/_simple_status.html.haml
@@ -27,7 +27,8 @@
     .e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
   - if status.poll
-    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json
+    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
+      = render partial: 'stream_entries/poll', locals: { poll: status.poll }
   - elsif !status.media_attachments.empty?
     - if status.media_attachments.first.video?
       - video = status.media_attachments.first