notifications 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cf008411221f8643f6272a4f492d6567f7e4c2e0391ee64aab731a3895c7e74
4
- data.tar.gz: 75455d8f4aafd04a1d2ec0b57fd4e50e61518b54a8e27667d8e694be5210747d
3
+ metadata.gz: 60fefd52121d61d6beb17f2ddc27a829b78147ded2c816e643d691c89ceb583d
4
+ data.tar.gz: 67eb1c905055995f9f7c15563e0e45c83a90654765ba1201296f1f3426590182
5
5
  SHA512:
6
- metadata.gz: 1dbee55f530440d4c1ed3000857ffdc4abcbb25825c06164b658fa67b7f19e29a872fc851cfa64b7477db7da491a4f25ab6e5cda6bf461942251220f7c1c687b
7
- data.tar.gz: 1feea3486d23c7e3e6598cdf012cd7f947cc017189b2258503c07236b8d1f71854cff20645d0e9df94bd6c548df8b6d4955d7e012407baba3eeafb6c6a842f7e
6
+ metadata.gz: db8c63d042a9f10e5e30931dd710ff98d1fe46cd2885b918a2cedc5c868a0accf021ae4fea485d98436b9f384aa1d43965b97e88285ffd3f1fddfd59c3e0e711
7
+ data.tar.gz: d198158df36b375edd8e474d132be772666d24e3a3afaaeeb074cfcae31eff3a810c86ab91fd96ef86e8b46efb4e8440bcb5de28f262aeecbbe81af30d956d8c
data/README.md CHANGED
@@ -10,15 +10,10 @@ Mountable notifications for any Rails applications.
10
10
 
11
11
  ## Installation
12
12
 
13
- ```ruby
14
- # Gemfile Rails ~> 5
15
- gem 'notifications', '~> 0.6.0'
16
- # Gemfile for Rails ~> 4.2
17
- gem 'notifications', '~> 0.5.0'
13
+ ```bash
14
+ $ bundle add notifications
18
15
  ```
19
16
 
20
- And then run `bundle install`.
21
-
22
17
  You now have a notifications generator in your Rails application:
23
18
 
24
19
  ```bash
@@ -73,7 +68,7 @@ read_count = Notification.read_count(current_user)
73
68
  # for non-user class
74
69
  Notifications.config.user_class = 'Member'
75
70
 
76
- #or change
71
+ #or change
77
72
 
78
73
  Notifications.configure do
79
74
  # Class name of you User model, default: 'User'
data/Rakefile CHANGED
@@ -1,24 +1,24 @@
1
1
  begin
2
- require 'bundler/setup'
2
+ require "bundler/setup"
3
3
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
5
  end
6
6
 
7
- APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
7
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
8
8
 
9
- load 'rails/tasks/engine.rake'
10
- load 'rails/tasks/statistics.rake'
9
+ load "rails/tasks/engine.rake"
10
+ load "rails/tasks/statistics.rake"
11
11
 
12
12
  Bundler::GemHelper.install_tasks
13
13
 
14
- require 'rake/testtask'
14
+ require "rake/testtask"
15
15
 
16
16
  Rake::TestTask.new(:test) do |t|
17
- t.libs << 'lib'
18
- t.libs << 'test'
19
- t.pattern = 'test/**/*_test.rb'
17
+ t.libs << "lib"
18
+ t.libs << "test"
19
+ t.pattern = "test/**/*_test.rb"
20
20
  t.verbose = false
21
21
  end
22
22
 
23
- task 'assets:precompile' => 'app:assets:precompile'
23
+ task "assets:precompile" => "app:assets:precompile"
24
24
  task default: :test
@@ -1,24 +1,28 @@
1
1
  module Notifications
2
2
  class NotificationsController < Notifications::ApplicationController
3
3
  def index
4
- @notifications = notifications.includes(:actor).order('id desc').page(params[:page])
4
+ @notifications = notifications.includes(:actor).order("id desc").page(params[:page])
5
5
 
6
6
  unread_ids = @notifications.reject(&:read?).select(&:id)
7
- Notification.read!(unread_ids)
7
+ Notification.read!(current_user, unread_ids)
8
8
 
9
9
  @notification_groups = @notifications.group_by { |note| note.created_at.to_date }
10
10
  end
11
11
 
12
+ def read
13
+ Notification.read!(current_user, params[:ids])
14
+ render json: { ok: 1 }
15
+ end
16
+
12
17
  def clean
13
18
  notifications.delete_all
14
19
  redirect_to notifications_path
15
20
  end
16
21
 
17
22
  private
18
-
19
- def notifications
20
- raise 'You need reqiure user login for /notifications page.' unless current_user
21
- Notification.where(user_id: current_user.id)
22
- end
23
+ def notifications
24
+ raise "You need reqiure user login for /notifications page." unless current_user
25
+ Notification.where(user_id: current_user.id)
26
+ end
23
27
  end
24
28
  end
@@ -1,7 +1,8 @@
1
1
  Notifications::Engine.routes.draw do
2
- resources :notifications, path: '' do
2
+ resources :notifications, path: "" do
3
3
  collection do
4
4
  delete :clean
5
+ post :read
5
6
  end
6
7
  end
7
8
  end
@@ -1,8 +1,8 @@
1
- require 'rails/generators'
1
+ require "rails/generators"
2
2
  module Notifications
3
3
  module Generators
4
4
  class ControllersGenerator < Rails::Generators::Base #:nodoc:
5
- source_root File.expand_path('../../../app/controllers', __dir__)
5
+ source_root File.expand_path("../../../app/controllers", __dir__)
6
6
  desc "Used to copy Notifications's controllers to your application's controllers."
7
7
 
8
8
  def copy_controllers
@@ -1,9 +1,9 @@
1
- require 'rails/generators'
1
+ require "rails/generators"
2
2
  module Notifications
3
3
  module Generators
4
4
  class I18nGenerator < Rails::Generators::Base
5
5
  desc "Create Notifications's default I18n files"
6
- source_root File.expand_path('../../..', __dir__)
6
+ source_root File.expand_path("../../..", __dir__)
7
7
 
8
8
  def add_locales
9
9
  %w[en.yml zh-CN.yml].each do |fname|
@@ -1,27 +1,27 @@
1
- require 'rails/generators'
1
+ require "rails/generators"
2
2
  module Notifications
3
3
  module Generators
4
4
  class InstallGenerator < Rails::Generators::Base
5
5
  desc "Create Notifications's base files"
6
- source_root File.expand_path('../../..', __dir__)
6
+ source_root File.expand_path("../../..", __dir__)
7
7
 
8
8
  def add_initializer
9
9
  path = "#{Rails.root}/config/initializers/notifications.rb"
10
10
  if File.exist?(path)
11
- puts 'Skipping config/initializers/notifications.rb creation, as file already exists!'
11
+ puts "Skipping config/initializers/notifications.rb creation, as file already exists!"
12
12
  else
13
- puts 'Adding Notifications initializer (config/initializers/notifications.rb)...'
14
- template 'config/initializers/notifications.rb', path
13
+ puts "Adding Notifications initializer (config/initializers/notifications.rb)..."
14
+ template "config/initializers/notifications.rb", path
15
15
  end
16
16
  end
17
17
 
18
18
  def add_models
19
19
  path = "#{Rails.root}/app/models/notification.rb"
20
20
  if File.exist?(path)
21
- puts 'Skipping notification.rb creation, as file already exists!'
21
+ puts "Skipping notification.rb creation, as file already exists!"
22
22
  else
23
- puts 'Adding model (notification.rb)...'
24
- template 'app/models/notification.rb', path
23
+ puts "Adding model (notification.rb)..."
24
+ template "app/models/notification.rb", path
25
25
  end
26
26
  end
27
27
 
@@ -30,7 +30,7 @@ module Notifications
30
30
  end
31
31
 
32
32
  def add_migrations
33
- exec('rake notifications:install:migrations')
33
+ exec("rake notifications:install:migrations")
34
34
  end
35
35
  end
36
36
  end
@@ -1,13 +1,13 @@
1
- require 'rails/generators'
1
+ require "rails/generators"
2
2
  module Notifications
3
3
  module Generators
4
4
  class ViewsGenerator < Rails::Generators::Base #:nodoc:
5
- source_root File.expand_path('../../..', __dir__)
5
+ source_root File.expand_path("../../..", __dir__)
6
6
  desc "Used to copy Notifications's views to your application's views."
7
7
 
8
8
  def copy_views
9
- directory 'app/views/notifications', 'app/views/notifications'
10
- template 'app/assets/stylesheets/notifications.scss', 'app/assets/stylesheets/notifications.scss'
9
+ directory "app/views/notifications", "app/views/notifications"
10
+ template "app/assets/stylesheets/notifications.scss", "app/assets/stylesheets/notifications.scss"
11
11
  end
12
12
  end
13
13
  end
@@ -1,20 +1,20 @@
1
- require 'notifications/model'
2
- require 'notifications/engine'
3
- require 'notifications/configuration'
4
- require 'notifications/version'
5
- require 'kaminari'
1
+ require "notifications/model"
2
+ require "notifications/engine"
3
+ require "notifications/configuration"
4
+ require "notifications/version"
5
+ require "kaminari"
6
6
 
7
7
  module Notifications
8
8
  class << self
9
9
  def config
10
10
  return @config if defined?(@config)
11
11
  @config = Configuration.new
12
- @config.user_class = 'User'
13
- @config.user_name_method = 'name'
12
+ @config.user_class = "User"
13
+ @config.user_name_method = "name"
14
14
  @config.user_avatar_url_method = nil
15
15
  @config.user_profile_url_method = nil
16
16
  @config.authenticate_user_method = nil
17
- @config.current_user_method = 'current_user'
17
+ @config.current_user_method = "current_user"
18
18
  @config
19
19
  end
20
20
 
@@ -0,0 +1,12 @@
1
+ module Notifications
2
+ class Base
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ class_methods do
9
+ def
10
+ end
11
+ end
12
+ end
@@ -2,7 +2,7 @@ module Notifications
2
2
  module Model
3
3
  extend ActiveSupport::Concern
4
4
 
5
- DEFAULT_AVATAR = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAMAAAAJixmgAAAAFVBMVEWkpKSnp6eqqqq3t7fS0tLV1dXZ2dmshcKEAAAAtklEQVR4Ae3XsRGAAAjAQFRk/5HtqaTz5H+DlInvAQAAAAAAAAAAAAAAAAAAAACymiveO6o7BQsWLFiwYMGCBS8PFixYsGDBggULFixYsGDBggULFixYsGDBggULFixYsGDBc4IFCxYsWLBgwYIFC14ZfOeAPRQ8IliwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQv+JQAAAAAAAAAAAAAAAAAAAOAB4KJfdHmj+kwAAAAASUVORK5CYII='
5
+ DEFAULT_AVATAR = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAMAAAAJixmgAAAAFVBMVEWkpKSnp6eqqqq3t7fS0tLV1dXZ2dmshcKEAAAAtklEQVR4Ae3XsRGAAAjAQFRk/5HtqaTz5H+DlInvAQAAAAAAAAAAAAAAAAAAAACymiveO6o7BQsWLFiwYMGCBS8PFixYsGDBggULFixYsGDBggULFixYsGDBggULFixYsGDBc4IFCxYsWLBgwYIFC14ZfOeAPRQ8IliwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQv+JQAAAAAAAAAAAAAAAAAAAOAB4KJfdHmj+kwAAAAASUVORK5CYII="
6
6
 
7
7
  included do
8
8
  belongs_to :actor, class_name: Notifications.config.user_class, optional: true
@@ -14,7 +14,6 @@ module Notifications
14
14
 
15
15
  scope :unread, -> { where(read_at: nil) }
16
16
  scope :read, -> { where.not(read_at: nil) }
17
-
18
17
  end
19
18
 
20
19
  def read?
@@ -22,7 +21,7 @@ module Notifications
22
21
  end
23
22
 
24
23
  def actor_name
25
- return '' if self.actor.blank?
24
+ return "" if self.actor.blank?
26
25
  self.actor.send(Notifications.config.user_name_method)
27
26
  end
28
27
 
@@ -39,9 +38,9 @@ module Notifications
39
38
  end
40
39
 
41
40
  module ClassMethods
42
- def read!(ids = [])
41
+ def read!(user, ids = [])
43
42
  return if ids.blank?
44
- Notification.where(id: ids).update_all(read_at: Time.now)
43
+ Notification.where(user: user, id: ids).update_all(read_at: Time.now)
45
44
  end
46
45
 
47
46
  def unread_count(user)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Notifications
4
- VERSION = '1.0.0'
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari
@@ -64,6 +64,7 @@ files:
64
64
  - lib/generators/notifications/install_generator.rb
65
65
  - lib/generators/notifications/views_generator.rb
66
66
  - lib/notifications.rb
67
+ - lib/notifications/base.rb
67
68
  - lib/notifications/configuration.rb
68
69
  - lib/notifications/engine.rb
69
70
  - lib/notifications/model.rb
@@ -73,7 +74,7 @@ homepage: https://github.com/rails-engine/notifications
73
74
  licenses:
74
75
  - MIT
75
76
  metadata: {}
76
- post_install_message:
77
+ post_install_message:
77
78
  rdoc_options: []
78
79
  require_paths:
79
80
  - lib
@@ -88,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  - !ruby/object:Gem::Version
89
90
  version: '0'
90
91
  requirements: []
91
- rubygems_version: 3.0.3
92
- signing_key:
92
+ rubygems_version: 3.1.2
93
+ signing_key:
93
94
  specification_version: 4
94
95
  summary: Rails mountable Notification for any applications.
95
96
  test_files: []