mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-13 21:33:20 +01:00
Add settings page for push notifications
This commit is contained in:
parent
c8f5511a38
commit
752cf1506b
10 changed files with 58 additions and 1 deletions
|
@ -4,6 +4,8 @@ class Ajax::WebPushController < AjaxController
|
||||||
def key
|
def key
|
||||||
certificate = Rpush::Webpush::App.find_by(name: "webpush").certificate
|
certificate = Rpush::Webpush::App.find_by(name: "webpush").certificate
|
||||||
|
|
||||||
|
@response[:status] = :okay
|
||||||
|
@response[:success] = true
|
||||||
@response[:key] = JSON.parse(certificate)["public_key"]
|
@response[:key] = JSON.parse(certificate)["public_key"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::PushNotificationsController < ApplicationController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@subscriptions = current_user.web_push_subscriptions
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,7 +14,7 @@ export function enableHandler (event: Event): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
post('/ajax/web_push', {
|
post('/ajax/webpush', {
|
||||||
body: {
|
body: {
|
||||||
subscription
|
subscription
|
||||||
},
|
},
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
"components/mobile-nav",
|
"components/mobile-nav",
|
||||||
"components/notifications",
|
"components/notifications",
|
||||||
"components/profile",
|
"components/profile",
|
||||||
|
"components/push-settings",
|
||||||
"components/question",
|
"components/question",
|
||||||
"components/smiles",
|
"components/smiles",
|
||||||
"components/themes",
|
"components/themes",
|
||||||
|
|
7
app/javascript/styles/components/_push-settings.scss
Normal file
7
app/javascript/styles/components/_push-settings.scss
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.push-notifications {
|
||||||
|
&-unavailable {
|
||||||
|
body.cap-service-worker.cap-notification & {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
app/views/settings/_push_notifications.haml
Normal file
17
app/views/settings/_push_notifications.haml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
.card.push-notifications-settings
|
||||||
|
.card-body
|
||||||
|
%p= t('.description')
|
||||||
|
%p= t('.subscription_count', count: subscriptions.count)
|
||||||
|
|
||||||
|
.push-notifications-unavailable.text-danger
|
||||||
|
%i.fa.fa-warning
|
||||||
|
= t('.unsupported')
|
||||||
|
|
||||||
|
.push-notifications-current-target.d-none.text-success
|
||||||
|
%i.fa.fa-check
|
||||||
|
= t('.current_target')
|
||||||
|
|
||||||
|
.button-group{ role: 'group' }
|
||||||
|
%button.btn.btn-primary{ data: { action: 'push-enable' } }= t('.subscribe')
|
||||||
|
%button.btn.btn-primary{ data: { action: 'push-disable' } }= t('.unsubscribe_current')
|
||||||
|
%button.btn.btn-danger{ data: { action: 'push-remove-all' } }= t('.unsubscribe_all')
|
4
app/views/settings/push_notifications/index.haml
Normal file
4
app/views/settings/push_notifications/index.haml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
= render "settings/push_notifications", subscriptions: @subscriptions
|
||||||
|
|
||||||
|
- provide(:title, generate_title(t(".title")))
|
||||||
|
- parent_layout "user/settings"
|
|
@ -8,6 +8,7 @@
|
||||||
= list_group_item t(".mutes"), settings_muted_path
|
= list_group_item t(".mutes"), settings_muted_path
|
||||||
= list_group_item t(".blocks"), settings_blocks_path
|
= list_group_item t(".blocks"), settings_blocks_path
|
||||||
= list_group_item t(".theme"), edit_settings_theme_path
|
= list_group_item t(".theme"), edit_settings_theme_path
|
||||||
|
= list_group_item t(".push_notifications"), settings_push_notifications_path
|
||||||
= list_group_item t(".data"), settings_data_path
|
= list_group_item t(".data"), settings_data_path
|
||||||
= list_group_item t(".export"), settings_export_path
|
= list_group_item t(".export"), settings_export_path
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,18 @@ en:
|
||||||
body: "Raised content includes all the different boxes and panels you can see across the site."
|
body: "Raised content includes all the different boxes and panels you can see across the site."
|
||||||
accent:
|
accent:
|
||||||
example: "Some text on top of a accented area on a raised element!"
|
example: "Some text on top of a accented area on a raised element!"
|
||||||
|
push_notifications:
|
||||||
|
index:
|
||||||
|
title: "Push Notifications"
|
||||||
|
subscription_count:
|
||||||
|
zero: "You are not currently subscribed to push notifications on any devices."
|
||||||
|
one: "You are currently receiving push notifications on one device."
|
||||||
|
other: "You are currently receiving push notifications on %{count} devices."
|
||||||
|
unsupported: "This browser does not support push notifications."
|
||||||
|
current_target: "You are currently receiving push notifications on this device."
|
||||||
|
subscribe: "Enable on this device"
|
||||||
|
unsubscribe_current: "Disable on this device"
|
||||||
|
unsubscribe_all: "Disable on all devices"
|
||||||
shared:
|
shared:
|
||||||
links:
|
links:
|
||||||
about: "About"
|
about: "About"
|
||||||
|
@ -594,6 +606,8 @@ en:
|
||||||
theme: "Theme"
|
theme: "Theme"
|
||||||
data: "Your Data"
|
data: "Your Data"
|
||||||
export: "Export"
|
export: "Export"
|
||||||
|
blocks: "Blocks"
|
||||||
|
push_notifications: "Push Notifications"
|
||||||
moderation:
|
moderation:
|
||||||
inbox:
|
inbox:
|
||||||
header:
|
header:
|
||||||
|
|
|
@ -89,6 +89,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get :data, to: "data#index"
|
get :data, to: "data#index"
|
||||||
|
|
||||||
|
resources :push_notifications, only: %i[index]
|
||||||
|
|
||||||
namespace :two_factor_authentication do
|
namespace :two_factor_authentication do
|
||||||
get :otp_authentication, to: "otp_authentication#index"
|
get :otp_authentication, to: "otp_authentication#index"
|
||||||
patch :otp_authentication, to: "otp_authentication#update"
|
patch :otp_authentication, to: "otp_authentication#update"
|
||||||
|
|
Loading…
Reference in a new issue