activity_notification 0.0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +74 -58
- data/README.md +53 -26
- data/activity_notification.gemspec +2 -0
- data/app/controllers/activity_notification/notifications_controller.rb +4 -4
- data/app/mailers/activity_notification/mailer.rb +9 -3
- data/app/views/activity_notification/mailer/default/default.html.erb +9 -4
- data/app/views/activity_notification/mailer/default/default.text.erb +10 -0
- data/app/views/activity_notification/notifications/default/_default.html.erb +173 -34
- data/app/views/activity_notification/notifications/default/_index.html.erb +119 -11
- data/app/views/activity_notification/notifications/default/destroy.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/index.html.erb +25 -14
- data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/show.html.erb +1 -1
- data/gemfiles/Gemfile.rails-4.2 +0 -2
- data/gemfiles/Gemfile.rails-4.2.lock +3 -3
- data/gemfiles/Gemfile.rails-5.0 +1 -3
- data/lib/activity_notification.rb +10 -9
- data/lib/activity_notification/apis/notification_api.rb +108 -14
- data/lib/activity_notification/common.rb +11 -2
- data/lib/activity_notification/config.rb +13 -13
- data/lib/activity_notification/helpers/view_helpers.rb +26 -4
- data/lib/activity_notification/mailers/helpers.rb +8 -4
- data/lib/activity_notification/models.rb +4 -0
- data/lib/activity_notification/models/concerns/group.rb +32 -0
- data/lib/activity_notification/models/concerns/notifiable.rb +60 -32
- data/lib/activity_notification/models/concerns/notifier.rb +17 -1
- data/lib/activity_notification/models/concerns/target.rb +114 -55
- data/lib/activity_notification/models/notification.rb +26 -25
- data/lib/activity_notification/rails.rb +1 -0
- data/lib/activity_notification/renderable.rb +8 -3
- data/lib/activity_notification/roles/acts_as_common.rb +28 -0
- data/lib/activity_notification/roles/acts_as_group.rb +38 -0
- data/lib/activity_notification/roles/acts_as_notifiable.rb +56 -22
- data/lib/activity_notification/roles/acts_as_notifier.rb +25 -2
- data/lib/activity_notification/roles/acts_as_target.rb +27 -9
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +1 -1
- data/spec/concerns/apis/notification_api_spec.rb +361 -2
- data/spec/concerns/common_spec.rb +36 -0
- data/spec/concerns/models/group_spec.rb +61 -0
- data/spec/concerns/models/notifiable_spec.rb +37 -0
- data/spec/concerns/models/notifier_spec.rb +48 -0
- data/spec/concerns/models/target_spec.rb +81 -31
- data/spec/factories/dummy/dummy_group.rb +4 -0
- data/spec/helpers/view_helpers_spec.rb +13 -0
- data/spec/mailers/mailer_spec.rb +8 -1
- data/spec/models/dummy/dummy_group_spec.rb +6 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_app/app/assets/stylesheets/reset.css +85 -0
- data/spec/rails_app/app/assets/stylesheets/style.css +244 -0
- data/spec/rails_app/app/controllers/articles_controller.rb +1 -1
- data/spec/rails_app/app/models/admin.rb +2 -1
- data/spec/rails_app/app/models/article.rb +9 -2
- data/spec/rails_app/app/models/comment.rb +8 -2
- data/spec/rails_app/app/models/dummy/dummy_group.rb +4 -0
- data/spec/rails_app/app/models/user.rb +8 -3
- data/spec/rails_app/app/views/articles/_form.html.erb +14 -10
- data/spec/rails_app/app/views/articles/edit.html.erb +8 -6
- data/spec/rails_app/app/views/articles/index.html.erb +59 -67
- data/spec/rails_app/app/views/articles/new.html.erb +7 -5
- data/spec/rails_app/app/views/articles/show.html.erb +47 -36
- data/spec/rails_app/app/views/layouts/_header.html.erb +36 -9
- data/spec/rails_app/app/views/layouts/application.html.erb +8 -6
- data/spec/rails_app/config/environments/development.rb +9 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +1 -1
- data/spec/rails_app/db/schema.rb +14 -20
- data/spec/rails_app/db/seeds.rb +5 -5
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +13 -0
- data/spec/roles/acts_as_group_spec.rb +32 -0
- data/spec/roles/acts_as_notifiable_spec.rb +1 -1
- data/spec/roles/acts_as_notifier_spec.rb +15 -0
- data/spec/roles/acts_as_target_spec.rb +1 -1
- metadata +52 -2
@@ -2,19 +2,23 @@
|
|
2
2
|
<% if @article.errors.any? %>
|
3
3
|
<div id="error_explanation">
|
4
4
|
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
|
5
|
-
|
6
5
|
<ul>
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
<% @article.errors.full_messages.each do |message| %>
|
7
|
+
<li><%= message %></li>
|
8
|
+
<% end %>
|
10
9
|
</ul>
|
11
10
|
</div>
|
12
11
|
<% end %>
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
<div class="
|
18
|
-
<%= f.
|
13
|
+
<div class="input_wrapper">
|
14
|
+
<%= f.text_field :title, placeholder: "title..." %>
|
15
|
+
</div>
|
16
|
+
<div class="textarea_wrapper">
|
17
|
+
<%= f.text_area :body, placeholder: "body..." %>
|
18
|
+
</div>
|
19
|
+
<div class="submit_button_wrapper">
|
20
|
+
<button class="green_button" type="submit">
|
21
|
+
<%= submit_message %>
|
22
|
+
</button>
|
19
23
|
</div>
|
20
|
-
<% end %>
|
24
|
+
<% end %>
|
@@ -1,6 +1,8 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
<%= render 'form' %>
|
4
|
-
|
5
|
-
<%= link_to 'Show', @article %>
|
6
|
-
<%= link_to 'Back', articles_path %>
|
1
|
+
<section>
|
2
|
+
<h1>Editing Article</h1>
|
3
|
+
<%= render partial: 'form', locals: { submit_message: "Update Article" } %>
|
4
|
+
<div class="left_button_wrapper">
|
5
|
+
<%= link_to 'Show', @article, class: "gray_button" %>
|
6
|
+
<%= link_to 'Back', articles_path, class: "gray_button" %>
|
7
|
+
</div>
|
8
|
+
</section>
|
@@ -1,67 +1,59 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
<
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
<
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
<
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
</tr>
|
61
|
-
<% end %>
|
62
|
-
</tbody>
|
63
|
-
</table>
|
64
|
-
|
65
|
-
<br>
|
66
|
-
|
67
|
-
<%= link_to 'New Article', new_article_path %>
|
1
|
+
<section>
|
2
|
+
<h1>Listing Users</h1>
|
3
|
+
<% User.all.each do |user| %>
|
4
|
+
<div class="list_wrapper">
|
5
|
+
<div class="list_image"></div>
|
6
|
+
<div class="list_description_wrapper">
|
7
|
+
<p class="list_description">
|
8
|
+
<span><%= user.name %></span> · <%= user.email %><br>
|
9
|
+
<%= link_to 'Notifications', user_notifications_path(user) %>
|
10
|
+
</p>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</section>
|
15
|
+
|
16
|
+
<section>
|
17
|
+
<h1>Listing Admins</h1>
|
18
|
+
<% Admin.all.each do |admin| %>
|
19
|
+
<div class="list_wrapper">
|
20
|
+
<div class="list_image"></div>
|
21
|
+
<div class="list_description_wrapper">
|
22
|
+
<p class="list_description">
|
23
|
+
<span><%= admin.user.name %></span> · <%= admin.user.email %><br>
|
24
|
+
<%= link_to 'Notifications', admin_notifications_path(admin) %>
|
25
|
+
</p>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
29
|
+
</section>
|
30
|
+
|
31
|
+
<section>
|
32
|
+
<div class="create_button_wrapper">
|
33
|
+
<%= link_to 'New Article', new_article_path, class: "create_button green_button" %>
|
34
|
+
</div>
|
35
|
+
<h1>Listing Articles</h1>
|
36
|
+
<% @articles.each do |article| %>
|
37
|
+
<div class="list_wrapper">
|
38
|
+
<div class="list_image large"></div>
|
39
|
+
<div class="list_description_wrapper">
|
40
|
+
<h3 class="list_title">
|
41
|
+
<%= link_to article.title, article %>
|
42
|
+
</h3>
|
43
|
+
<p class="list_description">
|
44
|
+
<span><%= article.user.name %></span> · <%= article.created_at.strftime("%b %d %H:%M") %><br>
|
45
|
+
<%= article.body.truncate(60) if article.body.present? %><br>
|
46
|
+
<%= link_to 'Read', article %>
|
47
|
+
</p>
|
48
|
+
<div class="list_button_wrapper">
|
49
|
+
<% if user_signed_in? and article.author?(current_user) %>
|
50
|
+
<%= link_to 'Edit Article', edit_article_path(article), class: "gray_button" %>
|
51
|
+
<% end %>
|
52
|
+
<% if user_signed_in? and (article.author?(current_user) or current_user.admin?) %>
|
53
|
+
<%= link_to 'Destroy Article', article, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
|
54
|
+
<% end %>
|
55
|
+
</div>
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
<% end %>
|
59
|
+
</section>
|
@@ -1,5 +1,7 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
<%= render 'form' %>
|
4
|
-
|
5
|
-
<%= link_to 'Back', articles_path %>
|
1
|
+
<section>
|
2
|
+
<h1>New Article</h1>
|
3
|
+
<%= render partial: 'form', locals: { submit_message: "Create Article" } %>
|
4
|
+
<div class="left_button_wrapper">
|
5
|
+
<%= link_to 'Back', articles_path, class: "gray_button" %>
|
6
|
+
</div>
|
7
|
+
</section>
|
@@ -1,38 +1,49 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
<
|
4
|
-
<
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
<%=
|
9
|
-
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
<section>
|
2
|
+
<h1><%= @article.title %></h1>
|
3
|
+
<p><%= @article.body %></p>
|
4
|
+
<div class="list_wrapper">
|
5
|
+
<div class="list_image"></div>
|
6
|
+
<div class="list_description_wrapper">
|
7
|
+
<p class="list_description">
|
8
|
+
<span><%= @article.user.name %></span> · <%= @article.created_at.strftime("%b %d %H:%M") %><br>
|
9
|
+
</p>
|
10
|
+
<div class="list_button_wrapper">
|
11
|
+
<%= link_to 'Edit Article', edit_article_path(@article), class: "gray_button" %>
|
12
|
+
<%= link_to 'Destroy Article', @article, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
<h2>Listing Comments</h2>
|
17
|
+
<% @article.comments.includes(:user).each do |comment| %>
|
18
|
+
<div class="list_wrapper">
|
19
|
+
<div class="list_image"></div>
|
20
|
+
<div class="list_description_wrapper">
|
21
|
+
<p class="list_description">
|
22
|
+
<span><%= comment.user.name %></span> · <%= comment.created_at.strftime("%b %d %H:%M") %><br>
|
23
|
+
<%= comment.body %>
|
24
|
+
</p>
|
25
|
+
<div class="list_button_wrapper">
|
26
|
+
<% if user_signed_in? and (comment.author?(current_user) or current_user.admin?) %>
|
27
|
+
<%= link_to 'Destroy Comment', comment, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
33
|
+
<% if user_signed_in? %>
|
34
|
+
<%= form_for(@comment) do |f| %>
|
35
|
+
<%= f.hidden_field :article_id, value: @article.id %>
|
36
|
+
<div class="textarea_wrapper">
|
37
|
+
<%= f.text_area :body, placeholder: "Write a comment..." %>
|
38
|
+
</div>
|
39
|
+
<div class="submit_button_wrapper">
|
40
|
+
<button class="green_button" type="submit">
|
41
|
+
Create Comment
|
42
|
+
</button>
|
43
|
+
</div>
|
26
44
|
<% end %>
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
<h2>New Comment</h2>
|
31
|
-
<%= form_for(@comment) do |f| %>
|
32
|
-
<%= f.hidden_field :article_id, value: @article.id %>
|
33
|
-
<%= f.text_area :body %>
|
34
|
-
|
35
|
-
<div class="actions">
|
36
|
-
<%= f.submit %>
|
45
|
+
<% end %>
|
46
|
+
<div class="left_button_wrapper">
|
47
|
+
<%= link_to 'Back', articles_path, class: "gray_button" %>
|
37
48
|
</div>
|
38
|
-
|
49
|
+
</section>
|
@@ -1,10 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%#= render_notifications_of current_user, fallback: :default, index_content: :none %>
|
8
|
-
<% else %>
|
9
|
-
<%= link_to 'Login', new_user_session_path %>
|
1
|
+
<% if notice.present? %>
|
2
|
+
<div class="notice_wrapper">
|
3
|
+
<p class="notice">
|
4
|
+
<%= notice %>
|
5
|
+
</p>
|
6
|
+
</div>
|
10
7
|
<% end %>
|
8
|
+
|
9
|
+
<header>
|
10
|
+
<div class="header_area">
|
11
|
+
<div class="header_root_wrapper">
|
12
|
+
<%= link_to 'ActivityNotification', root_path %>
|
13
|
+
</div>
|
14
|
+
<div class="header_menu_wrapper">
|
15
|
+
<p>
|
16
|
+
<% if user_signed_in? %>
|
17
|
+
<%= current_user.name %>
|
18
|
+
<%= "(admin)" if current_user.admin? %>
|
19
|
+
<%= link_to 'Logout', destroy_user_session_path, method: :delete %>
|
20
|
+
<% else %>
|
21
|
+
<%= link_to 'Login', new_user_session_path %>
|
22
|
+
<% end %>
|
23
|
+
</p>
|
24
|
+
</div>
|
25
|
+
<div class="header_notification_wrapper">
|
26
|
+
<% if user_signed_in? %>
|
27
|
+
<%= render_notifications_of current_user, fallback: :default, index_content: :with_attributes %>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
<div class="header_menu_wrapper">
|
31
|
+
<p>
|
32
|
+
<%= link_to 'Preview email', "/rails/mailers" %>
|
33
|
+
<%= " · " unless user_signed_in? %>
|
34
|
+
</p>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
</header>
|
@@ -1,13 +1,15 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>
|
5
|
-
|
6
|
-
<%= javascript_include_tag 'application'
|
4
|
+
<title>ActivityNotification</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
6
|
+
<%= javascript_include_tag 'application' %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
</head>
|
9
9
|
<body>
|
10
|
-
<%= render 'layouts/header' %>
|
11
|
-
|
10
|
+
<%= render 'layouts/header' %>
|
11
|
+
<article>
|
12
|
+
<%= yield %>
|
13
|
+
</article>
|
12
14
|
</body>
|
13
|
-
</html>
|
15
|
+
</html>
|
@@ -41,4 +41,13 @@ Rails.application.configure do
|
|
41
41
|
|
42
42
|
# For devise and notification email
|
43
43
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
44
|
+
|
45
|
+
# For notification email preview
|
46
|
+
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
|
47
|
+
|
48
|
+
# Configration for bullet
|
49
|
+
config.after_initialize do
|
50
|
+
Bullet.enable = true
|
51
|
+
Bullet.alert = true
|
52
|
+
end
|
44
53
|
end
|
data/spec/rails_app/db/schema.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -17,54 +16,50 @@ ActiveRecord::Schema.define(version: 20160715050433) do
|
|
17
16
|
t.integer "user_id"
|
18
17
|
t.datetime "created_at"
|
19
18
|
t.datetime "updated_at"
|
19
|
+
t.index ["user_id"], name: "index_admins_on_user_id"
|
20
20
|
end
|
21
21
|
|
22
|
-
add_index "admins", ["user_id"], name: "index_admins_on_user_id"
|
23
|
-
|
24
22
|
create_table "articles", force: :cascade do |t|
|
25
23
|
t.integer "user_id"
|
26
24
|
t.string "title"
|
27
25
|
t.string "body"
|
28
26
|
t.datetime "created_at"
|
29
27
|
t.datetime "updated_at"
|
28
|
+
t.index ["user_id"], name: "index_articles_on_user_id"
|
30
29
|
end
|
31
30
|
|
32
|
-
add_index "articles", ["user_id"], name: "index_articles_on_user_id"
|
33
|
-
|
34
31
|
create_table "comments", force: :cascade do |t|
|
35
32
|
t.integer "user_id"
|
36
33
|
t.integer "article_id"
|
37
34
|
t.string "body"
|
38
35
|
t.datetime "created_at"
|
39
36
|
t.datetime "updated_at"
|
37
|
+
t.index ["article_id"], name: "index_comments_on_article_id"
|
38
|
+
t.index ["user_id"], name: "index_comments_on_user_id"
|
40
39
|
end
|
41
40
|
|
42
|
-
add_index "comments", ["article_id"], name: "index_comments_on_article_id"
|
43
|
-
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
|
44
|
-
|
45
41
|
create_table "notifications", force: :cascade do |t|
|
46
|
-
t.integer "target_id", null: false
|
47
42
|
t.string "target_type", null: false
|
48
|
-
t.integer "
|
43
|
+
t.integer "target_id", null: false
|
49
44
|
t.string "notifiable_type", null: false
|
45
|
+
t.integer "notifiable_id", null: false
|
50
46
|
t.string "key", null: false
|
51
|
-
t.integer "group_id"
|
52
47
|
t.string "group_type"
|
48
|
+
t.integer "group_id"
|
53
49
|
t.integer "group_owner_id"
|
54
|
-
t.integer "notifier_id"
|
55
50
|
t.string "notifier_type"
|
51
|
+
t.integer "notifier_id"
|
56
52
|
t.text "parameters"
|
57
53
|
t.datetime "opened_at"
|
58
54
|
t.datetime "created_at"
|
59
55
|
t.datetime "updated_at"
|
56
|
+
t.index ["group_owner_id"], name: "index_notifications_on_group_owner_id"
|
57
|
+
t.index ["group_type", "group_id"], name: "index_notifications_on_group_type_and_group_id"
|
58
|
+
t.index ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id"
|
59
|
+
t.index ["notifier_type", "notifier_id"], name: "index_notifications_on_notifier_type_and_notifier_id"
|
60
|
+
t.index ["target_type", "target_id"], name: "index_notifications_on_target_type_and_target_id"
|
60
61
|
end
|
61
62
|
|
62
|
-
add_index "notifications", ["group_owner_id"], name: "index_notifications_on_group_owner_id"
|
63
|
-
add_index "notifications", ["group_type", "group_id"], name: "index_notifications_on_group_type_and_group_id"
|
64
|
-
add_index "notifications", ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id"
|
65
|
-
add_index "notifications", ["notifier_type", "notifier_id"], name: "index_notifications_on_notifier_type_and_notifier_id"
|
66
|
-
add_index "notifications", ["target_type", "target_id"], name: "index_notifications_on_target_type_and_target_id"
|
67
|
-
|
68
63
|
create_table "users", force: :cascade do |t|
|
69
64
|
t.string "email", default: "", null: false
|
70
65
|
t.string "encrypted_password", default: "", null: false
|
@@ -74,8 +69,7 @@ ActiveRecord::Schema.define(version: 20160715050433) do
|
|
74
69
|
t.string "name"
|
75
70
|
t.datetime "created_at"
|
76
71
|
t.datetime "updated_at"
|
72
|
+
t.index ["email"], name: "index_users_on_email"
|
77
73
|
end
|
78
74
|
|
79
|
-
add_index "users", ["email"], name: "index_users_on_email"
|
80
|
-
|
81
75
|
end
|