From a737bd3cfd2c03f029ae672788dad20a3c0e6460 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 8 Mar 2018 09:47:15 -0500 Subject: [PATCH] changes for notifications --- app/controllers/access_controller.rb | 2 - app/controllers/users_controller.rb | 17 +- app/helpers/application_helper.rb | 2 +- app/models/user.rb | 3 +- app/views/access/approve_access_post.js.erb | 1 - app/views/access/deny_access_post.js.erb | 1 - app/views/layouts/_foot.html.erb | 2 +- package-lock.json | 9436 +++++++++++++++++++ 8 files changed, 9452 insertions(+), 12 deletions(-) delete mode 100644 app/views/access/approve_access_post.js.erb delete mode 100644 app/views/access/deny_access_post.js.erb create mode 100644 package-lock.json diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index affb7179..38dd1351 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -62,7 +62,6 @@ class AccessController < ApplicationController request = AccessRequest.find(params[:request_id]) request.approve respond_to do |format| - format.js format.json do head :ok end @@ -74,7 +73,6 @@ 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/users_controller.rb b/app/controllers/users_controller.rb index 8a1cd760..19195f9a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,12 +7,19 @@ class UsersController < ApplicationController # GET /users/current def current - #if current_user + if current_user # these are just options, saying include these values, they aren't the values themselves - render json: current_user.to_json({follows: true, email: true, follow_settings: true, emails_allowed: true}) - #else - # render json: nil - #end + render json: current_user.to_json({ + follows: true, + email: true, + follow_settings: true, + emails_allowed: true, + inviteCode: true, + unread_notifications_count: user_unread_notifications_count + }) + else + render json: nil + end end # GET /users/1.json diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a773ff5f..9a8b4b75 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,7 +5,7 @@ module ApplicationHelper "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end - def user_unread_notification_count + def user_unread_notifications_count return 0 if current_user.nil? @uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt| receipt.is_read ? total : total + 1 diff --git a/app/models/user.rb b/app/models/user.rb index f87c03d3..b2b1790d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,8 @@ class User < ApplicationRecord json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1' end json['email'] = email if options[:email] - json['emails_allowed'] = emails_allowed if options[:emails_allowed] + json['invite_code'] = code if options[:inviteCode] + json['unread_notifications_count'] = options[:unread_notifications_count] if not options[:unread_notifications_count].nil? json end diff --git a/app/views/access/approve_access_post.js.erb b/app/views/access/approve_access_post.js.erb deleted file mode 100644 index 24db9b80..00000000 --- a/app/views/access/approve_access_post.js.erb +++ /dev/null @@ -1 +0,0 @@ -$('.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 deleted file mode 100644 index 64b89256..00000000 --- a/app/views/access/deny_access_post.js.erb +++ /dev/null @@ -1 +0,0 @@ -$('.main-text').text('Fair enough.') \ No newline at end of file diff --git a/app/views/layouts/_foot.html.erb b/app/views/layouts/_foot.html.erb index bc3d4223..c1f99f37 100644 --- a/app/views/layouts/_foot.html.erb +++ b/app/views/layouts/_foot.html.erb @@ -1,6 +1,6 @@