Merge pull request #262 from ZmagoD/zd_add_notification_types_to_constants

Enables notifications to be extended
This commit is contained in:
Zmago Devetak 2016-11-08 13:08:15 +01:00 committed by GitHub
commit 82a12f0fce
4 changed files with 21 additions and 2 deletions

View file

@ -3,7 +3,7 @@ class Notification < ActiveRecord::Base
has_many :users, through: :user_notifications has_many :users, through: :user_notifications
belongs_to :generator_user, class_name: 'User' 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) def already_seen(user)
UserNotification.where(notification: self, user: user) UserNotification.where(notification: self, user: user)

View file

@ -2,6 +2,7 @@
<li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>"> <li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>">
<div class="row"> <div class="row">
<div class="col-xs-3 col-md-1"> <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' %> <% if notification.type_of == 'recent_changes' %>
<div class="text-center"> <div class="text-center">
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar img-circle' %> <%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar img-circle' %>

View file

@ -2,6 +2,7 @@
<li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>"> <li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>">
<div class="row"> <div class="row">
<div class="col-xs-2"> <div class="col-xs-2">
<span style="display: none;" data-hook="user-notification-recent-list-item"></span>
<% if notification.type_of == 'recent_changes' %> <% if notification.type_of == 'recent_changes' %>
<div class="text-center"> <div class="text-center">
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar' %> <%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar' %>

View 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