mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-04 12:14:37 +08:00
Refactor the settings page, rename setting to tooltips_enabled
This commit is contained in:
parent
384371802c
commit
586a442abc
8 changed files with 146 additions and 108 deletions
|
@ -66,13 +66,13 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
notificationsSettings();
|
notificationsSettings();
|
||||||
initNotificationSettingsForm();
|
tooltipSettings();
|
||||||
|
initTogglableSettingsForm();
|
||||||
|
|
||||||
// Setup notification checkbox buttons
|
// Setup notification checkbox buttons
|
||||||
function notificationsSettings() {
|
function notificationsSettings() {
|
||||||
var notification_settings = [ "recent_notification",
|
var notification_settings = [ "recent_notification",
|
||||||
"assignments_notification",
|
"assignments_notification" ]
|
||||||
"popovers_enabled" ]
|
|
||||||
|
|
||||||
for (var i = 0; i < notification_settings.length; i++ ) {
|
for (var i = 0; i < notification_settings.length; i++ ) {
|
||||||
var setting = $('[name="' + notification_settings[i] + '"]');
|
var setting = $('[name="' + notification_settings[i] + '"]');
|
||||||
|
@ -142,9 +142,22 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize tooltips settings form
|
||||||
|
function tooltipSettings() {
|
||||||
|
var toggleInput = $('[name="tooltips_enabled"]');
|
||||||
|
toggleInput
|
||||||
|
.checkboxpicker({ onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle' });
|
||||||
|
|
||||||
|
if (toggleInput.attr('value') === 'true') {
|
||||||
|
toggleInput.prop('checked', true);
|
||||||
|
} else {
|
||||||
|
toggleInput.prop('checked', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// triggers submit action when the user clicks
|
// triggers submit action when the user clicks
|
||||||
function initNotificationSettingsForm() {
|
function initTogglableSettingsForm() {
|
||||||
$('#notifications-settings-panel')
|
$('#togglable-settings-panel')
|
||||||
.find('.btn-group')
|
.find('.btn-group')
|
||||||
.on('click', function() {
|
.on('click', function() {
|
||||||
$(this).submit();
|
$(this).submit();
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Users
|
||||||
before_action :load_user, only: [
|
before_action :load_user, only: [
|
||||||
:index,
|
:index,
|
||||||
:update,
|
:update,
|
||||||
:notifications_settings
|
:update_togglable_settings
|
||||||
]
|
]
|
||||||
layout 'fluid'
|
layout 'fluid'
|
||||||
|
|
||||||
|
@ -30,19 +30,25 @@ module Users
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_settings
|
def update_togglable_settings
|
||||||
@user.assignments_notification =
|
read_from_params(:assignments_notification) do |val|
|
||||||
params[:assignments_notification] ? true : false
|
@user.assignments_notification = val
|
||||||
@user.recent_notification =
|
end
|
||||||
params[:recent_notification] ? true : false
|
read_from_params(:recent_notification) do |val|
|
||||||
@user.recent_email_notification =
|
@user.recent_notification = val
|
||||||
params[:recent_notification_email] ? true : false
|
end
|
||||||
@user.assignments_email_notification =
|
read_from_params(:recent_notification_email) do |val|
|
||||||
params[:assignments_notification_email] ? true : false
|
@user.recent_email_notification = val
|
||||||
@user.system_message_email_notification =
|
end
|
||||||
params[:system_message_notification_email] ? true : false
|
read_from_params(:assignments_notification_email) do |val|
|
||||||
@user.popovers_enabled =
|
@user.assignments_email_notification = val
|
||||||
params[:popovers_enabled] ? true : false
|
end
|
||||||
|
read_from_params(:system_message_notification_email) do |val|
|
||||||
|
@user.system_message_email_notification = val
|
||||||
|
end
|
||||||
|
read_from_params(:tooltips_enabled) do |val|
|
||||||
|
@user.settings[:tooltips_enabled] = val
|
||||||
|
end
|
||||||
if @user.save
|
if @user.save
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
|
@ -73,6 +79,10 @@ module Users
|
||||||
:time_zone
|
:time_zone
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_from_params(name)
|
||||||
|
yield(params.include?(name) ? true : false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,8 +44,8 @@ class User < ApplicationRecord
|
||||||
recent: true,
|
recent: true,
|
||||||
recent_email: false,
|
recent_email: false,
|
||||||
system_message_email: false,
|
system_message_email: false,
|
||||||
popovers_enabled: true
|
},
|
||||||
}
|
tooltips_enabled: true
|
||||||
)
|
)
|
||||||
|
|
||||||
# Relations
|
# Relations
|
||||||
|
@ -457,8 +457,8 @@ class User < ApplicationRecord
|
||||||
NOTIFICATIONS_TYPES = %w(assignments_notification recent_notification
|
NOTIFICATIONS_TYPES = %w(assignments_notification recent_notification
|
||||||
assignments_email_notification
|
assignments_email_notification
|
||||||
recent_email_notification
|
recent_email_notification
|
||||||
system_message_email_notification
|
system_message_email_notification)
|
||||||
popovers_enabled )
|
|
||||||
# declare notifications getters
|
# declare notifications getters
|
||||||
NOTIFICATIONS_TYPES.each do |name|
|
NOTIFICATIONS_TYPES.each do |name|
|
||||||
define_method(name) do
|
define_method(name) do
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
data-atwho-rep-items-url="<%= atwho_rep_items_team_path(current_team) %>"
|
data-atwho-rep-items-url="<%= atwho_rep_items_team_path(current_team) %>"
|
||||||
data-atwho-menu-items="<%= atwho_menu_items_team_path(current_team) %>"
|
data-atwho-menu-items="<%= atwho_menu_items_team_path(current_team) %>"
|
||||||
data-file-max-size-mb="<%= Rails.configuration.x.file_max_size_mb %>"
|
data-file-max-size-mb="<%= Rails.configuration.x.file_max_size_mb %>"
|
||||||
data-popover_v2_enabled="<%= current_user.popovers_enabled %>"
|
data-tooltips-enabled="<%= current_user.settings[:tooltips_enabled] %>"
|
||||||
<% end %>
|
<% end %>
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
|
@ -50,52 +50,27 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="notification-settings-container">
|
<%= form_for(@user,
|
||||||
<h4><%= t('notifications.title') %></h4>
|
url: update_togglable_settings_path(format: :json),
|
||||||
<%= form_for(@user,
|
html: { method: :post, id: 'togglable-settings-panel' },
|
||||||
url: notifications_settings_path(format: :json),
|
remote: true) do |f| %>
|
||||||
html: { method: :post, id: 'notifications-settings-panel' },
|
<div class="notification-settings-container">
|
||||||
remote: true) do |f| %>
|
<h4><%= t('notifications.title') %></h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<span class="assignment hidden-sm">
|
<span class="assignment hidden-sm">
|
||||||
<i class="fas fa-newspaper"></i>
|
<i class="fas fa-newspaper"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<strong><%=t 'notifications.form.assignments' %></strong>
|
|
||||||
<p><%=t 'notifications.form.assignments_description' %></p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-4">
|
|
||||||
<%=t 'notifications.form.notification_scinote' %>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="col-sm-10">
|
||||||
<div class="col-sm-4">
|
<strong><%=t 'notifications.form.assignments' %></strong>
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<p><%=t 'notifications.form.assignments_description' %></p>
|
||||||
</div>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<%= check_box_tag :assignments_notification_email, @user.assignments_email_notification %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-2">
|
|
||||||
<%= image_tag 'icon_small/missing.png', class: 'img-circle ' %>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<strong><%=t 'notifications.form.recent_notification' %></strong>
|
|
||||||
<p><%=t 'notifications.form.recent_notification_description' %></p>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<%=t 'notifications.form.notification_scinote' %>
|
<%=t 'notifications.form.notification_scinote' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :recent_notification, @user.recent_notification %>
|
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -103,58 +78,83 @@
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<%=t 'notifications.form.notification_email' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :recent_notification_email, @user.recent_email_notification %>
|
<%= check_box_tag :assignments_notification_email, @user.assignments_email_notification %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-2">
|
|
||||||
<span class="system-message hidden-sm"><i class="fas fa-chess-rook" aria-hidden="true"></i></span>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<strong><%=t 'notifications.form.system_message' %></strong>
|
|
||||||
<p><%=t 'notifications.form.system_message_description' %></p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-4">
|
|
||||||
<%=t 'notifications.form.notification_scinote' %>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<%= check_box_tag :system_message_notification %>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-sm-4">
|
<div class="row">
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<div class="col-sm-2">
|
||||||
|
<%= image_tag 'icon_small/missing.png', class: 'img-circle ' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<strong><%=t 'notifications.form.recent_notification' %></strong>
|
||||||
|
<p><%=t 'notifications.form.recent_notification_description' %></p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<%=t 'notifications.form.notification_scinote' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= check_box_tag :recent_notification, @user.recent_notification %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<%=t 'notifications.form.notification_email' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= check_box_tag :recent_notification_email, @user.recent_email_notification %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<span class="system-message hidden-sm"><i class="fas fa-chess-rook" aria-hidden="true"></i></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<strong><%=t 'notifications.form.system_message' %></strong>
|
||||||
|
<p><%=t 'notifications.form.system_message_description' %></p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<%=t 'notifications.form.notification_scinote' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= check_box_tag :system_message_notification %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="row">
|
||||||
<%= check_box_tag :system_message_notification_email, @user.system_message_email_notification %>
|
<div class="col-sm-4">
|
||||||
|
<%=t 'notifications.form.notification_email' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= check_box_tag :system_message_notification_email, @user.system_message_email_notification %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4><%= t('users.settings.account.preferences.edit.tips.title') %></h4>
|
<hr>
|
||||||
<div class="row">
|
<div class="tooltips-settings-container">
|
||||||
<div class="col-sm-2">
|
<h4><%= t('users.settings.account.preferences.edit.tips.title') %></h4>
|
||||||
<span class="assignment hidden-sm">
|
<div class="row">
|
||||||
<i class="fas fa-newspaper"></i>
|
<div class="col-sm-2">
|
||||||
</span>
|
</div>
|
||||||
</div>
|
<div class="col-sm-10">
|
||||||
<div class="col-sm-10">
|
<p><%=t 'users.settings.account.preferences.edit.tips.text1' %></p>
|
||||||
<p><%=t 'users.settings.account.preferences.edit.tips.text1' %></p>
|
<p><%=t 'users.settings.account.preferences.edit.tips.text2' %></p>
|
||||||
<p><%=t 'users.settings.account.preferences.edit.tips.text2' %></p>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-sm-4">
|
||||||
<div class="col-sm-4">
|
<%=t 'users.settings.account.preferences.edit.tips.toggle' %>
|
||||||
<%=t 'users.settings.account.preferences.edit.tips.toggle' %>
|
</div>
|
||||||
</div>
|
<div class="col-sm-8">
|
||||||
<div class="col-sm-8">
|
<%= check_box_tag :tooltips_enabled, @user.settings[:tooltips_enabled] %>
|
||||||
<%= check_box_tag :popovers_enabled, @user.popovers_enabled %>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -56,9 +56,9 @@ Rails.application.routes.draw do
|
||||||
put 'users/settings/account/preferences',
|
put 'users/settings/account/preferences',
|
||||||
to: 'users/settings/account/preferences#update',
|
to: 'users/settings/account/preferences#update',
|
||||||
as: 'update_preferences'
|
as: 'update_preferences'
|
||||||
post 'users/settings/account/preferences/notifications_settings',
|
post 'users/settings/account/preferences/togglable_settings',
|
||||||
to: 'users/settings/account/preferences#notifications_settings',
|
to: 'users/settings/account/preferences#update_togglable_settings',
|
||||||
as: 'notifications_settings',
|
as: 'update_togglable_settings',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
|
|
||||||
# Change user's current team
|
# Change user's current team
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
class AddTooltipsEnabledToUserSettings < ActiveRecord::Migration[5.1]
|
||||||
|
def up
|
||||||
|
User.find_each do |user|
|
||||||
|
user.settings[:tooltips_enabled] = true
|
||||||
|
user.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
User.find_each do |user|
|
||||||
|
user.settings.delete(:tooltips_enabled)
|
||||||
|
user.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20180524091143) do
|
ActiveRecord::Schema.define(version: 20180905142400) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
Loading…
Add table
Reference in a new issue