mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 15:36:22 +08:00
Merge pull request #262 from ZmagoD/zd_add_notification_types_to_constants
Enables notifications to be extended
This commit is contained in:
commit
82a12f0fce
|
@ -3,7 +3,7 @@ class Notification < ActiveRecord::Base
|
|||
has_many :users, through: :user_notifications
|
||||
belongs_to :generator_user, class_name: 'User'
|
||||
|
||||
enum type_of: [:assignment, :recent_changes, :system_message]
|
||||
enum type_of: Extends::NOTIFICATIONS_TYPES
|
||||
|
||||
def already_seen(user)
|
||||
UserNotification.where(notification: self, user: user)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>">
|
||||
<div class="row">
|
||||
<div class="col-xs-3 col-md-1">
|
||||
<span style="display: none;" data-hook="user-notification-list-item"></span>
|
||||
<% if notification.type_of == 'recent_changes' %>
|
||||
<div class="text-center">
|
||||
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar img-circle' %>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>">
|
||||
<div class="row">
|
||||
<div class="col-xs-2">
|
||||
<span style="display: none;" data-hook="user-notification-recent-list-item"></span>
|
||||
<% if notification.type_of == 'recent_changes' %>
|
||||
<div class="text-center">
|
||||
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar' %>
|
||||
|
|
17
config/initializers/extends.rb
Normal file
17
config/initializers/extends.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Extends class holds the arrays for the models enum fields
|
||||
# so that can be extended in sub modules.
|
||||
|
||||
class Extends
|
||||
# To extend the enum fields in the engine you have to put in
|
||||
# lib/engine_name/engine.rb file as in the example:
|
||||
|
||||
# > initializer 'add_additional enum values to my model' do
|
||||
# > Extends::MY_ARRAY_OF_ENUM_VALUES.merge!(value1, value2, ....)
|
||||
# > end
|
||||
# >
|
||||
|
||||
# Notification types. Should not be freezed, as modules might append to this.
|
||||
NOTIFICATIONS_TYPES = { assignment: 0,
|
||||
recent_changes: 1,
|
||||
system_message: 2 }
|
||||
end
|
Loading…
Reference in a new issue