contunue
This commit is contained in:
parent
16d208d3c1
commit
732b89b3d7
|
@ -1,33 +0,0 @@
|
|||
# Private: Finders of all sorts: methods to find FlashNotify records, methods to find
|
||||
# other records which belong to given FlashNotify.
|
||||
#
|
||||
# This module gets included into FlashNotify.
|
||||
module FlashNotify::Finders
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :published, -> { where(published: true) }
|
||||
|
||||
after_commit :clear_caches
|
||||
after_touch :clear_caches
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
# Public: Get cached first published FlashNotify record.
|
||||
#
|
||||
# Returns FlashNotify record or nil.
|
||||
def published_first_cached
|
||||
Rails.cache.fetch('FlashNotify.published.first') do
|
||||
published.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Private: after_commit and after_touch hook which clears find_cached cache.
|
||||
def clear_caches
|
||||
Rails.cache.delete('FlashNotify.published.first')
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'digest/md5'
|
||||
|
||||
class FlashNotify < ActiveRecord::Base
|
||||
include FlashNotify::Finders
|
||||
|
||||
STATUSES = %w[error success info]
|
||||
|
||||
validates :status, inclusion: {in: STATUSES}
|
||||
validates :body_ru, :body_en, :status, presence: true
|
||||
|
||||
def hash_id
|
||||
@digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}")
|
||||
end
|
||||
|
||||
def body(language)
|
||||
read_attribute("body_#{language}")
|
||||
end
|
||||
|
||||
def should_show?(cookie_hash_id)
|
||||
cookie_hash_id != hash_id && published
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
- if current_user || APP_CONFIG['anonymous_access']
|
||||
.flash_notify
|
||||
- if (flash_notify = FlashNotify.published_first_cached) && flash_notify.should_show?(cookies[:flash_notify_hash])
|
||||
.alert{class: "alert-#{flash_notify.status}"}
|
||||
= flash_notify.body(I18n.locale).html_safe
|
||||
%a.close#close-alert{:'data-dismiss'=>"alert", href: "#"} ×
|
||||
|
||||
:javascript
|
||||
var FLASH_HASH_ID = "#{flash_notify.hash_id}";
|
Loading…
Reference in New Issue