activity_notification 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  4. data/.github/pull_request_template.md +13 -0
  5. data/.gitignore +10 -3
  6. data/.travis.yml +6 -5
  7. data/CHANGELOG.md +22 -0
  8. data/Gemfile +8 -2
  9. data/Procfile +1 -1
  10. data/README.md +153 -1510
  11. data/activity_notification.gemspec +4 -1
  12. data/app/channels/activity_notification/notification_api_channel.rb +12 -0
  13. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
  14. data/app/channels/activity_notification/notification_channel.rb +1 -1
  15. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  16. data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
  17. data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
  18. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
  19. data/app/controllers/activity_notification/notifications_controller.rb +79 -53
  20. data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
  21. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
  22. data/app/controllers/activity_notification/subscriptions_controller.rb +78 -69
  23. data/app/views/activity_notification/notifications/default/_default.html.erb +18 -18
  24. data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +14 -14
  25. data/app/views/activity_notification/notifications/default/index.html.erb +6 -6
  26. data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
  27. data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
  28. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +3 -31
  29. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +7 -7
  30. data/app/views/activity_notification/subscriptions/default/index.html.erb +11 -7
  31. data/bin/deploy_on_heroku.sh +3 -1
  32. data/docs/CODE_OF_CONDUCT.md +76 -0
  33. data/docs/CONTRIBUTING.md +36 -0
  34. data/docs/Functions.md +1130 -0
  35. data/docs/Setup.md +674 -0
  36. data/docs/Testing.md +148 -0
  37. data/gemfiles/Gemfile.rails-4.2 +3 -0
  38. data/gemfiles/Gemfile.rails-5.0 +3 -0
  39. data/gemfiles/Gemfile.rails-5.1 +3 -0
  40. data/gemfiles/Gemfile.rails-5.2 +3 -0
  41. data/gemfiles/{Gemfile.rails-6.0.rc → Gemfile.rails-6.0} +5 -3
  42. data/lib/activity_notification.rb +13 -1
  43. data/lib/activity_notification/apis/notification_api.rb +29 -92
  44. data/lib/activity_notification/apis/subscription_api.rb +20 -8
  45. data/lib/activity_notification/apis/swagger.rb +6 -0
  46. data/lib/activity_notification/config.rb +41 -21
  47. data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
  48. data/lib/activity_notification/controllers/common_controller.rb +44 -20
  49. data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
  50. data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
  51. data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
  52. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
  53. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
  54. data/lib/activity_notification/controllers/devise_authentication_controller.rb +7 -6
  55. data/lib/activity_notification/gem_version.rb +14 -0
  56. data/lib/activity_notification/helpers/errors.rb +2 -0
  57. data/lib/activity_notification/helpers/view_helpers.rb +4 -0
  58. data/lib/activity_notification/mailers/helpers.rb +17 -10
  59. data/lib/activity_notification/models/concerns/notifiable.rb +26 -10
  60. data/lib/activity_notification/models/concerns/subscriber.rb +12 -1
  61. data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
  62. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
  63. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
  64. data/lib/activity_notification/models/concerns/target.rb +36 -10
  65. data/lib/activity_notification/models/notification.rb +1 -0
  66. data/lib/activity_notification/models/subscription.rb +1 -0
  67. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
  68. data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
  69. data/lib/activity_notification/optional_targets/base.rb +7 -13
  70. data/lib/activity_notification/orm/active_record/notification.rb +17 -1
  71. data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
  72. data/lib/activity_notification/orm/dynamoid.rb +28 -0
  73. data/lib/activity_notification/orm/dynamoid/extension.rb +79 -1
  74. data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
  75. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  76. data/lib/activity_notification/orm/mongoid.rb +22 -0
  77. data/lib/activity_notification/orm/mongoid/notification.rb +17 -1
  78. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  79. data/lib/activity_notification/rails/routes.rb +132 -48
  80. data/lib/activity_notification/renderable.rb +13 -2
  81. data/lib/activity_notification/roles/acts_as_notifiable.rb +38 -20
  82. data/lib/activity_notification/version.rb +1 -1
  83. data/lib/generators/activity_notification/controllers_generator.rb +2 -1
  84. data/lib/generators/templates/activity_notification.rb +8 -0
  85. data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
  86. data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
  87. data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
  88. data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
  89. data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
  90. data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
  91. data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
  92. data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
  93. data/lib/generators/templates/models/README +8 -4
  94. data/lib/generators/templates/models/notification.rb +1 -1
  95. data/lib/generators/templates/models/subscription.rb +1 -1
  96. data/package.json +8 -0
  97. data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
  98. data/spec/channels/notification_api_channel_spec.rb +51 -0
  99. data/spec/channels/notification_api_with_devise_channel_spec.rb +78 -0
  100. data/spec/concerns/apis/notification_api_spec.rb +37 -2
  101. data/spec/concerns/models/notifiable_spec.rb +64 -0
  102. data/spec/concerns/models/subscriber_spec.rb +13 -16
  103. data/spec/concerns/models/target_spec.rb +32 -0
  104. data/spec/concerns/renderable_spec.rb +2 -2
  105. data/spec/controllers/controller_spec_utility.rb +136 -0
  106. data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
  107. data/spec/controllers/notifications_api_controller_spec.rb +19 -0
  108. data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
  109. data/spec/controllers/notifications_controller_shared_examples.rb +54 -79
  110. data/spec/controllers/notifications_controller_spec.rb +1 -2
  111. data/spec/controllers/notifications_with_devise_controller_spec.rb +3 -12
  112. data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
  113. data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
  114. data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
  115. data/spec/controllers/subscriptions_controller_shared_examples.rb +94 -121
  116. data/spec/controllers/subscriptions_controller_spec.rb +1 -2
  117. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +3 -12
  118. data/spec/helpers/view_helpers_spec.rb +4 -11
  119. data/spec/mailers/mailer_spec.rb +41 -0
  120. data/spec/models/notification_spec.rb +17 -0
  121. data/spec/models/subscription_spec.rb +0 -13
  122. data/spec/optional_targets/action_cable_api_channel_spec.rb +37 -0
  123. data/spec/optional_targets/action_cable_channel_spec.rb +44 -0
  124. data/spec/optional_targets/amazon_sns_spec.rb +0 -2
  125. data/spec/optional_targets/slack_spec.rb +0 -2
  126. data/spec/rails_app/Rakefile +9 -0
  127. data/spec/rails_app/app/assets/config/manifest.js +3 -0
  128. data/spec/rails_app/app/assets/images/.keep +0 -0
  129. data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
  130. data/spec/rails_app/app/controllers/application_controller.rb +1 -1
  131. data/spec/rails_app/app/controllers/articles_controller.rb +6 -3
  132. data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
  133. data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
  134. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
  135. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
  136. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
  137. data/spec/rails_app/app/controllers/users_controller.rb +21 -0
  138. data/spec/rails_app/app/javascript/App.vue +104 -0
  139. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +83 -0
  140. data/spec/rails_app/app/javascript/components/Top.vue +99 -0
  141. data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
  142. data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
  143. data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
  144. data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
  145. data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
  146. data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
  147. data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
  148. data/spec/rails_app/app/javascript/config/development.js +5 -0
  149. data/spec/rails_app/app/javascript/config/environment.js +7 -0
  150. data/spec/rails_app/app/javascript/config/production.js +5 -0
  151. data/spec/rails_app/app/javascript/config/test.js +5 -0
  152. data/spec/rails_app/app/javascript/packs/application.js +18 -0
  153. data/spec/rails_app/app/javascript/packs/spa.js +11 -0
  154. data/spec/rails_app/app/javascript/store/auth.js +37 -0
  155. data/spec/rails_app/app/models/admin.rb +16 -15
  156. data/spec/rails_app/app/models/article.rb +26 -21
  157. data/spec/rails_app/app/models/comment.rb +24 -71
  158. data/spec/rails_app/app/models/user.rb +43 -20
  159. data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
  160. data/spec/rails_app/app/views/articles/index.html.erb +51 -7
  161. data/spec/rails_app/app/views/articles/show.html.erb +1 -1
  162. data/spec/rails_app/app/views/layouts/_header.html.erb +8 -10
  163. data/spec/rails_app/app/views/spa/index.html.erb +2 -0
  164. data/spec/rails_app/babel.config.js +72 -0
  165. data/spec/rails_app/bin/webpack +18 -0
  166. data/spec/rails_app/bin/webpack-dev-server +18 -0
  167. data/spec/rails_app/config/application.rb +15 -2
  168. data/spec/rails_app/config/environment.rb +2 -1
  169. data/spec/rails_app/config/environments/development.rb +5 -0
  170. data/spec/rails_app/config/environments/production.rb +3 -0
  171. data/spec/rails_app/config/environments/test.rb +5 -0
  172. data/spec/rails_app/config/initializers/activity_notification.rb +8 -0
  173. data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
  174. data/spec/rails_app/config/initializers/mysql.rb +9 -0
  175. data/spec/rails_app/config/locales/activity_notification.en.yml +2 -2
  176. data/spec/rails_app/config/routes.rb +33 -1
  177. data/spec/rails_app/config/webpack/development.js +5 -0
  178. data/spec/rails_app/config/webpack/environment.js +7 -0
  179. data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
  180. data/spec/rails_app/config/webpack/production.js +5 -0
  181. data/spec/rails_app/config/webpack/test.js +5 -0
  182. data/spec/rails_app/config/webpacker.yml +97 -0
  183. data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
  184. data/spec/rails_app/db/schema.rb +4 -1
  185. data/spec/rails_app/db/seeds.rb +1 -0
  186. data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
  187. data/spec/rails_app/package.json +23 -0
  188. data/spec/rails_app/postcss.config.js +12 -0
  189. data/spec/roles/acts_as_group_spec.rb +0 -2
  190. data/spec/roles/acts_as_notifiable_spec.rb +1 -3
  191. data/spec/roles/acts_as_notifier_spec.rb +0 -2
  192. data/spec/roles/acts_as_target_spec.rb +0 -4
  193. data/spec/spec_helper.rb +7 -15
  194. data/spec/version_spec.rb +31 -0
  195. metadata +187 -13
@@ -0,0 +1,99 @@
1
+ <template>
2
+ <div>
3
+ <section>
4
+ <h1>Authentecated User</h1>
5
+ <div class="list_wrapper">
6
+ <div class="list_image"></div>
7
+ <div class="list_description_wrapper">
8
+ <div class="list_description">
9
+ <div v-if="userSignedIn">
10
+ <span>{{ currentUser.name }}</span> · {{ currentUser.email }} · <router-link v-bind:to="{ path: '/logout' }">Logout</router-link><br>
11
+ </div>
12
+ <div v-else>
13
+ <span>Not logged in</span> · <router-link v-bind:to="{ path: '/login' }">Login</router-link><br>
14
+ </div>
15
+ <router-link v-bind:to="{ name : 'AuthenticatedUserNotificationsIndex' }">Notifications</router-link> /
16
+ <router-link v-bind:to="{ name : 'AuthenticatedUserSubscriptionsIndex' }">Subscriptions</router-link>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </section>
21
+
22
+ <section>
23
+ <h1>Listing Users</h1>
24
+ <div v-for="user in users" :key="`${user.id}`" class="list_wrapper">
25
+ <div class="list_image"></div>
26
+ <div class="list_description_wrapper">
27
+ <p class="list_description">
28
+ <span>{{ user.name }}</span> · {{ user.email }}<br>
29
+ <router-link v-bind:to="{ name : 'UnauthenticatedTargetNotificationsIndex', params : { target_type: 'users', target_id: user.id, target: user }}">Notifications</router-link> /
30
+ <router-link v-bind:to="{ name : 'UnauthenticatedTargetSubscriptionsIndex', params : { target_type: 'users', target_id: user.id, target: user }}">Subscriptions</router-link>
31
+ </p>
32
+ </div>
33
+ </div>
34
+ </section>
35
+
36
+ <section>
37
+ <h1>Authentecated User as Admin</h1>
38
+ <div class="list_wrapper">
39
+ <div class="list_image"></div>
40
+ <div class="list_description_wrapper">
41
+ <div class="list_description">
42
+ <div v-if="userSignedIn">
43
+ <span>{{ currentUser.name }}</span> · {{ currentUser.email }} · <span v-if="currentUser.admin">(admin)</span><span v-else>(not admin)</span><br>
44
+ </div>
45
+ <div v-else>
46
+ <span>Not logged in</span> · <router-link v-bind:to="{ path: '/login' }">Login</router-link><br>
47
+ </div>
48
+ <router-link v-bind:to="{ name : 'AuthenticatedAdminNotificationsIndex' }">Notifications</router-link> /
49
+ <router-link v-bind:to="{ name : 'AuthenticatedAdminSubscriptionsIndex' }">Subscriptions</router-link>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </section>
54
+
55
+ <section>
56
+ <h1>Listing Admins</h1>
57
+ <div v-for="admin in admins" :key="`${admin.id}`" class="list_wrapper">
58
+ <div class="list_image"></div>
59
+ <div class="list_description_wrapper">
60
+ <p class="list_description">
61
+ <span>{{ admin.user.name }}</span> · {{ admin.user.email }}<br>
62
+ <router-link v-bind:to="{ name : 'UnauthenticatedTargetNotificationsIndex', params : { target_type: 'admins', target_id: admin.id, target: admin }}">Notifications</router-link> /
63
+ <router-link v-bind:to="{ name : 'UnauthenticatedTargetSubscriptionsIndex', params : { target_type: 'admins', target_id: admin.id, target: admin }}">Subscriptions</router-link>
64
+ </p>
65
+ </div>
66
+ </div>
67
+ </section>
68
+ </div>
69
+ </template>
70
+
71
+ <script>
72
+ import axios from 'axios'
73
+ import authStore from "../store/auth"
74
+
75
+ export default {
76
+ name: 'Top',
77
+ data () {
78
+ return {
79
+ userSignedIn: authStore.getters.userSignedIn,
80
+ currentUser: authStore.getters.currentUser,
81
+ users: [],
82
+ admins: []
83
+ }
84
+ },
85
+ mounted () {
86
+ axios
87
+ .get('/users')
88
+ .then(response => {
89
+ this.users = response.data.users;
90
+ this.admins = this.users
91
+ .filter(user => user.admin)
92
+ .map(user => Object.assign(Object.create(user.admin), { user: user }))
93
+ })
94
+ }
95
+ }
96
+ </script>
97
+
98
+ <style scoped>
99
+ </style>
@@ -0,0 +1,200 @@
1
+ <template>
2
+ <div class="notification_wrapper">
3
+ <div class="notification_header">
4
+ <h1>
5
+ Notifications to {{ currentTarget.printable_target_name }}
6
+ <a href="#" v-on:click="openAll()" data-remote="true">
7
+ <span class="notification_count"><span v-bind:class="[unopenedNotificationCount > 0 ? 'unopened' : '']">
8
+ {{ unopenedNotificationCount }}
9
+ </span></span>
10
+ </a>
11
+ </h1>
12
+ <h3>
13
+ <span class="action_cable_status">{{ actionCableStatus }}</span>
14
+ </h3>
15
+ </div>
16
+ <div class="notifications">
17
+ <div v-for="notification in notifications" :key="`${notification.id}_${notification.opened_at}_${notification.group_notification_count}`">
18
+ <notification :targetNotification="notification" :targetApiPath="targetApiPath" @getUnopenedNotificationCount="getUnopenedNotificationCount" />
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </template>
23
+
24
+ <script>
25
+ import axios from 'axios'
26
+ import Push from 'push.js'
27
+ import Notification from './Notification.vue'
28
+
29
+ export default {
30
+ name: 'NotificationsIndex',
31
+ components: {
32
+ Notification
33
+ },
34
+ props: {
35
+ target_type: {
36
+ type: String,
37
+ required: true
38
+ },
39
+ target_id: {
40
+ type: [String, Number]
41
+ },
42
+ targetApiPath: {
43
+ type: String,
44
+ default: function () {
45
+ if (this.target_type && this.target_id) {
46
+ return '/' + this.target_type + '/' + this.target_id;
47
+ } else {
48
+ return '';
49
+ }
50
+ }
51
+ },
52
+ target: {
53
+ type: Object
54
+ }
55
+ },
56
+ data () {
57
+ return {
58
+ currentTarget: { printable_target_name: '' },
59
+ unopenedNotificationCount: 0,
60
+ notifications: [],
61
+ actionCableStatus: "Disabled"
62
+ }
63
+ },
64
+ mounted () {
65
+ if (this.target) {
66
+ this.currentTarget = this.target;
67
+ this.subscribeActionCable();
68
+ } else {
69
+ this.getCurrentTarget();
70
+ }
71
+ this.getNotifications();
72
+ this.getUnopenedNotificationCount();
73
+ },
74
+ channels: {
75
+ 'ActivityNotification::NotificationApiChannel': {
76
+ connected() {
77
+ this.actionCableStatus = "Online";
78
+ },
79
+ disconnected() {
80
+ this.actionCableStatus = "Offline";
81
+ },
82
+ rejected() {
83
+ this.actionCableStatus = "Offline (unauthorized)";
84
+ },
85
+ received(data) {
86
+ this.notify(data);
87
+ }
88
+ },
89
+ 'ActivityNotification::NotificationApiWithDeviseChannel': {
90
+ connected() {
91
+ this.actionCableStatus = "Online (authorized)";
92
+ },
93
+ disconnected() {
94
+ this.actionCableStatus = "Offline";
95
+ },
96
+ rejected() {
97
+ this.actionCableStatus = "Offline (unauthorized)";
98
+ },
99
+ received(data) {
100
+ this.notify(data);
101
+ }
102
+ }
103
+ },
104
+ methods: {
105
+ getCurrentTarget () {
106
+ axios
107
+ .get(this.targetApiPath)
108
+ .then(response => {
109
+ this.currentTarget = response.data;
110
+ this.subscribeActionCable();
111
+ })
112
+ },
113
+ getNotifications () {
114
+ axios
115
+ .get(this.targetApiPath + '/notifications', { params: this.$route.query })
116
+ .then(response => (this.notifications = response.data.notifications))
117
+ .catch (error => {
118
+ if (error.response.status == 401) {
119
+ this.$router.push('/logout');
120
+ }
121
+ })
122
+ },
123
+ getUnopenedNotificationCount () {
124
+ if (this.$route.query.filter == 'opened') {
125
+ this.unopenedNotificationCount = 0;
126
+ } else {
127
+ axios
128
+ .get(this.targetApiPath + '/notifications', { params: Object.assign({ filter: 'unopened' }, this.$route.query) })
129
+ .then(response => (this.unopenedNotificationCount = response.data.count))
130
+ .catch (error => {
131
+ if (error.response.status == 401) {
132
+ this.$router.push('/logout');
133
+ }
134
+ })
135
+ }
136
+ },
137
+ openAll () {
138
+ axios
139
+ .post(this.targetApiPath + '/notifications/open_all')
140
+ .then(response => {
141
+ if (response.status == 200) {
142
+ this.getNotifications();
143
+ this.getUnopenedNotificationCount();
144
+ }
145
+ })
146
+ },
147
+ subscribeActionCable () {
148
+ if (this.currentTarget['notification_action_cable_allowed?']) {
149
+ if (!this.currentTarget['notification_action_cable_with_devise?']) {
150
+ this.$cable.subscribe({
151
+ channel: 'ActivityNotification::NotificationApiChannel',
152
+ target_type: this.target_type, target_id: this.currentTarget.id
153
+ });
154
+ } else {
155
+ this.$cable.subscribe({
156
+ channel: 'ActivityNotification::NotificationApiWithDeviseChannel',
157
+ target_type: this.target_type, target_id: this.currentTarget.id,
158
+ 'access-token': axios.defaults.headers.common['access-token'],
159
+ 'client': axios.defaults.headers.common['client'],
160
+ 'uid': axios.defaults.headers.common['uid']
161
+ });
162
+ }
163
+ }
164
+ },
165
+ notify (data) {
166
+ // Display notification
167
+ if (data.group_owner == null) {
168
+ this.notifications.unshift(data.notification);
169
+ this.getUnopenedNotificationCount();
170
+ } else {
171
+ this.notifications.splice(this.notifications.findIndex(n => n.id === data.group_owner.id), 1);
172
+ this.notifications.unshift(data.group_owner);
173
+ this.getUnopenedNotificationCount();
174
+ }
175
+ // Push notificaion using Web Notification API by Push.js
176
+ Push.create('ActivityNotification', {
177
+ body: data.notification.text,
178
+ timeout: 5000,
179
+ onClick: function () {
180
+ location.href = data.notification.notifiable_path;
181
+ this.close();
182
+ }
183
+ });
184
+ }
185
+ }
186
+ }
187
+ </script>
188
+
189
+ <style scoped>
190
+ .notification_wrapper .notification_header h1 span span{
191
+ color: #fff;
192
+ background-color: #e5e5e5;
193
+ border-radius: 4px;
194
+ font-size: 12px;
195
+ padding: 4px 8px;
196
+ }
197
+ .notification_wrapper .notification_header h1 span span.unopened{
198
+ background-color: #f87880;
199
+ }
200
+ </style>
@@ -0,0 +1,133 @@
1
+ <template>
2
+ <div v-bind:class="`notification_${notification.id}`">
3
+ <div v-if="!notification.opened_at">
4
+ <a href="#" v-on:click="open(notification)" data-remote="true" class="unopened_wrapper">
5
+ <div class="unopened_circle"></div>
6
+ <div class="unopened_description_wrapper">
7
+ <p class="unopened_description">Open</p>
8
+ </div>
9
+ </a>
10
+ <a href="#" v-on:click="move(notification, '?open=true')" data-remote="true">
11
+ <notification-content :notification="notification" />
12
+ </a>
13
+ <div class="unopened_wrapper"></div>
14
+ </div>
15
+ <div v-else>
16
+ <a href="#" v-on:click="move(notification, '')" data-remote="true">
17
+ <notification-content :notification="notification" />
18
+ </a>
19
+ </div>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ import axios from 'axios'
25
+ import NotificationContent from './NotificationContent.vue'
26
+
27
+ export default {
28
+ name: 'Notification',
29
+ components: {
30
+ NotificationContent
31
+ },
32
+ props: {
33
+ targetNotification: {
34
+ type: Object,
35
+ required: true
36
+ },
37
+ targetApiPath: {
38
+ type: String,
39
+ required: true
40
+ }
41
+ },
42
+ data () {
43
+ return {
44
+ notification: this.targetNotification,
45
+ baseURL: axios.defaults.baseURL + this.targetApiPath
46
+ }
47
+ },
48
+ methods: {
49
+ open (notification) {
50
+ axios
51
+ .put(this.targetApiPath + '/notifications/' + notification.id + '/open')
52
+ .then(response => {
53
+ if (response.status == 200) {
54
+ this.$emit('getUnopenedNotificationCount')
55
+ this.notification = response.data.notification
56
+ }
57
+ })
58
+ .catch (error => {
59
+ if (error.response.status == 401) {
60
+ this.$router.push('/logout');
61
+ }
62
+ })
63
+ },
64
+ move (notification, paramsString) {
65
+ axios
66
+ .get(this.targetApiPath + '/notifications/' + notification.id + '/move' + paramsString)
67
+ .then(response => {
68
+ if (response.status == 200) {
69
+ window.location.href = response.request.responseURL;
70
+ }
71
+ })
72
+ .catch (error => {
73
+ if (error.response.status == 401) {
74
+ this.$router.push('/logout');
75
+ }
76
+ })
77
+ }
78
+ }
79
+ }
80
+ </script>
81
+
82
+ <style scoped>
83
+ /* unopened_circle */
84
+ .unopened_wrapper{
85
+ position: absolute;
86
+ margin-top: 20px;
87
+ margin-left: 56px;
88
+ }
89
+ .unopened_wrapper .unopened_circle {
90
+ display: block;
91
+ width: 10px;
92
+ height: 10px;
93
+ position: absolute;
94
+ border-radius: 50%;
95
+ background-color: #27a5eb;
96
+ z-index: 2;
97
+ }
98
+ .unopened_wrapper:hover > .unopened_description_wrapper{
99
+ display: block;
100
+ }
101
+ .unopened_wrapper .unopened_description_wrapper {
102
+ display: none;
103
+ position: absolute;
104
+ margin-top: 26px;
105
+ margin-left: -24px;
106
+ }
107
+ .unopened_wrapper .unopened_description_wrapper .unopened_description {
108
+ position: absolute;
109
+ color: #fff;
110
+ font-size: 12px;
111
+ text-align: center;
112
+
113
+ border-radius: 4px;
114
+ background: rgba(0, 0, 0, 0.8);
115
+ padding: 4px 12px;
116
+ z-index: 999;
117
+ }
118
+ .unopened_wrapper .unopened_description_wrapper .unopened_description:before {
119
+ border: solid transparent;
120
+ border-top-width: 0;
121
+ content: "";
122
+ display: block;
123
+ position: absolute;
124
+ width: 0;
125
+ left: 50%;
126
+ top: -5px;
127
+ margin-left: -5px;
128
+ height: 0;
129
+ border-width: 0 5px 5px 5px;
130
+ border-color: transparent transparent rgba(0, 0, 0, 0.8) transparent;
131
+ z-index: 0;
132
+ }
133
+ </style>
@@ -0,0 +1,122 @@
1
+ <template>
2
+ <div v-bind:class="[notification.opened_at ? 'opened' : 'unopened', 'notification_list']">
3
+ <div class="notification_list_cover"></div>
4
+ <div class="list_image"></div>
5
+ <div class="list_text_wrapper">
6
+ <!-- Custom view -->
7
+ <p v-if="notification.key == 'article.update'" class="list_text">
8
+ <strong>{{ notification.notifier.name }}</strong> updated his or her article "{{ notification.notifiable.title }}".
9
+ <br>
10
+ <span class="created_at">{{ new Date(notification.created_at) | moment('timezone', 'UTC', "MMM DD HH:mm") }}</span>
11
+ </p>
12
+ <!-- Default view -->
13
+ <p v-else class="list_text">
14
+ <strong v-if="notification.notifier">{{ notification.notifier.printable_notifier_name }}</strong>
15
+ <strong v-else>Someone</strong>
16
+ <span v-if="notification.group_member_notifier_count > 0">
17
+ and {{ notification.group_member_notifier_count }} other
18
+ <span v-if="notification.notifier">{{ notification.notifier.printable_type.toLowerCase() | pluralize(notification.group_member_notifier_count) }}</span>
19
+ <span v-else>people</span>
20
+ </span>
21
+ notified you of
22
+ <span v-if="notification.notifiable" key="notification-group">
23
+ <span v-if="notification.group_members.length">
24
+ {{ notification.group_notification_count }} {{notification.notifiable_type.toLowerCase() | pluralize(notification.group_notification_count) }} including
25
+ </span>
26
+ {{ notification.printable_notifiable_name }}
27
+ <span v-if="notification.group"> in {{ notification.group.printable_group_name }}</span>
28
+ </span>
29
+ <span v-else key="notification-group">
30
+ <span v-if="notification.group_members.length" key="group-members">
31
+ {{ notification.group_notification_count }} {{notification.notifiable_type.toLowerCase() | pluralize(notification.group_notification_count) }}
32
+ </span>
33
+ <span v-else key="group-members">
34
+ a {{ notification.notifiable_typetoLowerCase() | pluralize(0) }}
35
+ </span>
36
+ <span v-if="notification.group"> in {{ notification.group.printable_group_name }}</span>
37
+ but the notifiable is not found. It may have been deleted.
38
+ </span>
39
+ <br>
40
+ <span class="created_at">{{ new Date(notification.created_at) | moment('timezone', 'UTC', "MMM DD hh:mm") }}</span>
41
+ </p>
42
+ </div>
43
+ </div>
44
+ </template>
45
+
46
+ <script>
47
+ export default {
48
+ name: 'NotificationContent',
49
+ props: {
50
+ notification: {
51
+ type: Object,
52
+ required: true
53
+ }
54
+ }
55
+ }
56
+ </script>
57
+
58
+ <style scoped>
59
+ /* list */
60
+ .notification_list {
61
+ padding: 15px 10px;
62
+ position: relative;
63
+ border-bottom: 1px solid #e5e5e5;
64
+ }
65
+ .notification_list.unopened {
66
+ background-color: #eeeff4;
67
+ }
68
+ .notification_list:hover {
69
+ background-color: #f8f9fb;
70
+ }
71
+ .notification_list:last-child {
72
+ border-bottom: none;
73
+ }
74
+ .notification_list:after{
75
+ content: "";
76
+ clear: both;
77
+ display: block;
78
+ }
79
+ .notification_list .notification_list_cover{
80
+ position: absolute;
81
+ opacity: 0;
82
+ top: 0;
83
+ left: 0;
84
+ width: 100%;
85
+ height: 100%;
86
+ z-index: 1;
87
+
88
+ }
89
+ .notification_list .list_image {
90
+ float: left;
91
+ width: 40px;
92
+ height: 40px;
93
+ background-position: center;
94
+ background-repeat: no-repeat;
95
+ background-size: cover;
96
+ background-color: #979797;
97
+ }
98
+ .notification_list .list_text_wrapper {
99
+ float: left;
100
+ width: calc(100% - 60px);
101
+ margin-left: 20px;
102
+ }
103
+ .notification_list .list_text_wrapper .list_text {
104
+ color: #4f4f4f;
105
+ font-size: 14px;
106
+ line-height: 1.4;
107
+ margin-top: 0;
108
+ height: auto;
109
+ font-weight: normal;
110
+ }
111
+ .notification_list .list_text_wrapper .list_text span {
112
+ color: #4f4f4f;
113
+ font-size: 14px;
114
+ }
115
+ .notification_list .list_text_wrapper .list_text strong{
116
+ font-weight: bold;
117
+ }
118
+ .notification_list .list_text_wrapper .list_text span.created_at {
119
+ color: #979797;
120
+ font-size: 13px;
121
+ }
122
+ </style>