From 876c61a18e14eebb53f018248af70f4e28ebcaec Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sat, 11 Feb 2017 09:06:01 -0500 Subject: [PATCH] Better experience of notifications. (#1066) * all the good changes * follows * dont send duplicates * remove follow_type for now * dont add all the extra stuff we're not implementing yet * refactor * lots of fixes * notifications improvements * bad merge --- app/assets/stylesheets/notifications.scss.erb | 33 ++++++++++- app/controllers/access_controller.rb | 2 + app/controllers/notifications_controller.rb | 13 ++++- app/views/access/approve_access_post.js.erb | 1 + app/views/access/deny_access_post.js.erb | 1 + app/views/notifications/index.html.erb | 55 ++++++++++--------- app/views/notifications/show.html.erb | 46 ++++++++++++++-- config/routes.rb | 2 + 8 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 app/views/access/approve_access_post.js.erb create mode 100644 app/views/access/deny_access_post.js.erb diff --git a/app/assets/stylesheets/notifications.scss.erb b/app/assets/stylesheets/notifications.scss.erb index 16f96407..2f750f90 100644 --- a/app/assets/stylesheets/notifications.scss.erb +++ b/app/assets/stylesheets/notifications.scss.erb @@ -83,6 +83,7 @@ $unread_notifications_dot_size: 8px; .notification-body { margin-left: 50px; + line-height: 20px; .in-bold { font-family: 'din-medium', Sans-Serif; @@ -130,9 +131,35 @@ $unread_notifications_dot_size: 8px; - .notificationPage .notification-body { - p, div { - margin: 1em auto; + .notificationPage { + .thirty-two-avatar { + display: inline-block; + width: 32px; + height: 32px; + border-radius: 16px; + vertical-align: middle; + } + + .button { + line-height: 32px; + + img { + margin-top: 8px; + } + + &.decline { + background: #DB5D5D; + &:hover { + background: #DC4B4B; + } + } + } + + .notification-body { + p, div { + margin: 1em auto; + line-height: 20px; + } } } } diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index 7c93e1eb..4ce85022 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -61,6 +61,7 @@ class AccessController < ApplicationController request = AccessRequest.find(params[:request_id]) request.approve respond_to do |format| + format.js format.json do head :ok end @@ -72,6 +73,7 @@ class AccessController < ApplicationController request = AccessRequest.find(params[:request_id]) request.deny respond_to do |format| + format.js format.json do head :ok end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 16049fc0..210c0b43 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -21,7 +21,18 @@ class NotificationsController < ApplicationController def show @receipt.update(is_read: true) respond_to do |format| - format.html + format.html do + case @notification.notification_code + when MAP_ACCESS_APPROVED, MAP_INVITE_TO_EDIT + redirect_to map_path(@notification.notified_object.map) + when TOPIC_ADDED_TO_MAP + redirect_to map_path(@notification.notified_object.map) + when TOPIC_CONNECTED_1 + redirect_to topic_path(@notification.notified_object.topic1) + when TOPIC_CONNECTED_2 + redirect_to topic_path(@notification.notified_object.topic2) + end + end format.json do render json: @notification.as_json.merge( is_read: @receipt.is_read diff --git a/app/views/access/approve_access_post.js.erb b/app/views/access/approve_access_post.js.erb new file mode 100644 index 00000000..24db9b80 --- /dev/null +++ b/app/views/access/approve_access_post.js.erb @@ -0,0 +1 @@ +$('.main-text').text($('.requesterName').text() + ' has been shared on the map and notified.') \ No newline at end of file diff --git a/app/views/access/deny_access_post.js.erb b/app/views/access/deny_access_post.js.erb new file mode 100644 index 00000000..64b89256 --- /dev/null +++ b/app/views/access/deny_access_post.js.erb @@ -0,0 +1 @@ +$('.main-text').text('Fair enough.') \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 77de7f65..e965f481 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -18,34 +18,35 @@
<%= notification.sender.name %>
- <%= + <% case notification.notification_code - when MAP_ACCESS_APPROVED - map = notification.notified_object.map - output = 'granted your request to edit map ' + map.name + '' - when MAP_ACCESS_REQUEST - map = notification.notified_object.map - output = 'wants permission to map with you on ' + map.name + '  
Offer a response
' - when MAP_INVITE_TO_EDIT - map = notification.notified_object.map - output = 'gave you edit access to map ' + map.name + '' - when TOPIC_ADDED_TO_MAP - topic = notification.notified_object.eventable - map = notification.notified_object.map - output = 'added topic ' + topic.name + ' to map ' + map.name + '' - when TOPIC_CONNECTED_1 - topic1 = notification.notified_object.topic1 - topic2 = notification.notified_object.topic2 - output = 'connected ' + topic1.name + ' to ' + topic2.name + '' - when TOPIC_CONNECTED_2 - topic1 = notification.notified_object.topic1 - topic2 = notification.notified_object.topic2 - output = 'connected ' + topic2.name + ' to ' + topic1.name + '' - when MESSAGE_FROM_DEVS - output = notification.subject - end - raw output - %> + when MAP_ACCESS_APPROVED %> + <% map = notification.notified_object.map %> + granted your request to edit map <%= map.name %> + <% when MAP_ACCESS_REQUEST %> + <% map = notification.notified_object.map %> + wants permission to map with you on <%= map.name %> + <% if !notification.notified_object.answered %> +   
Offer a response
+ <% end %> + <% when MAP_INVITE_TO_EDIT %> + <% map = notification.notified_object.map %> + gave you edit access to map <%= map.name %> + <% when TOPIC_ADDED_TO_MAP %> + <% topic = notification.notified_object.eventable + map = notification.notified_object.map %> + added topic <%= topic.name %> to map <%= map.name %> + <% when TOPIC_CONNECTED_1 %> + <% topic1 = notification.notified_object.topic1 + topic2 = notification.notified_object.topic2 %> + connected <%= topic1.name %> to <%= topic2.name %> + <% when TOPIC_CONNECTED_2 %> + <% topic1 = notification.notified_object.topic1 + topic2 = notification.notified_object.topic2 %> + connected <%= topic2.name %> to <%= topic1.name %> + <% when MESSAGE_FROM_DEVS %> + <%= notification.subject %> + <% end %>
<% end %>
diff --git a/app/views/notifications/show.html.erb b/app/views/notifications/show.html.erb index b56fb177..a552aa77 100644 --- a/app/views/notifications/show.html.erb +++ b/app/views/notifications/show.html.erb @@ -6,10 +6,48 @@ <%= link_to 'Back to notifications', notifications_path %>
-

<%= @notification.subject %>

-
- <%= raw @notification.body %> -
+

+ <% case @notification.notification_code + when MAP_ACCESS_REQUEST + request = @notification.notified_object + map = request.map %> + <%= image_tag @notification.sender.image(:thirtytwo), class: 'thirty-two-avatar' %> <%= request.user.name %> wants to collaborate on map <%= map.name %> + <% else %> + <%= @notification.subject %> + <% end %> +

+ <% case @notification.notification_code + when MAP_ACCESS_REQUEST %> +
+

+ <% if false && request.answered %> + <% if request.approved %> + You already responded to this access request, and allowed access. + <% elsif !request.approved %> + You already responded to this access request, and declined access. If you changed your mind, you can still grant + them access by going to the map and adding them as a collaborator. + <% end %> + <% else %> + <%= image_tag asset_path('ellipsis.gif'), class: 'hidden' %> + <%= link_to 'Allow', approve_access_post_map_path(id: map.id, request_id: request.id), remote: true, method: :post, class: 'button allow' %> + <%= link_to 'Decline', deny_access_post_map_path(id: map.id, request_id: request.id), remote: true, method: :post, class: 'button decline' %> + + <% end %> +

+ <%= link_to 'Go to map', map_url(map) %> +   <%= link_to 'View mapper profile', explore_path(id: request.user.id) %> +
+ <% else %> +
+ <%= raw @notification.body %> +
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 9d0a894c..1eae4b96 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,9 +37,11 @@ Metamaps::Application.routes.draw do default: { format: :json } post 'approve_access/:request_id', to: 'access#approve_access_post', + as: :approve_access_post, default: { format: :json } post 'deny_access/:request_id', to: 'access#deny_access_post', + as: :deny_access_post, default: { format: :json } post :access, to: 'access#access', default: { format: :json }