elabs 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/CHANGELOG.md +83 -0
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +9 -2
  6. data/ROADMAP.md +6 -11
  7. data/app/assets/stylesheets/elabs/_icons.scss +8 -4
  8. data/app/assets/stylesheets/elabs/app/_badges.scss +11 -0
  9. data/app/assets/stylesheets/elabs/app/_layout.scss +10 -2
  10. data/app/assets/stylesheets/elabs/app/_users.scss +7 -0
  11. data/app/assets/stylesheets/elabs/app/admin-members/_indexes.scss +2 -1
  12. data/app/assets/stylesheets/elabs/app/mixins/_content-card.scss +4 -0
  13. data/app/assets/stylesheets/elabs/app/mixins/_content-full.scss +17 -5
  14. data/app/assets/stylesheets/elabs/lib/knacss/_knacss-variables.scss +16 -15
  15. data/app/assets/stylesheets/elabs/lib/knacss/_knacss.scss +1 -1
  16. data/app/assets/stylesheets/elabs/style.scss +1 -0
  17. data/app/controllers/elabs/acts_controller.rb +1 -1
  18. data/app/controllers/elabs/admin/admin_content_application_controller.rb +13 -6
  19. data/app/controllers/elabs/admin/languages_controller.rb +4 -4
  20. data/app/controllers/elabs/admin/licenses_controller.rb +2 -2
  21. data/app/controllers/elabs/admin/tags_controller.rb +3 -3
  22. data/app/controllers/elabs/concerns/elabs_controller.rb +1 -0
  23. data/app/controllers/elabs/content_application_controller.rb +1 -1
  24. data/app/controllers/elabs/elabs_application_controller.rb +0 -73
  25. data/app/controllers/elabs/elabs_public_controller.rb +80 -0
  26. data/app/controllers/elabs/languages_controller.rb +3 -3
  27. data/app/controllers/elabs/licenses_controller.rb +3 -3
  28. data/app/controllers/elabs/member/member_content_application_controller.rb +24 -14
  29. data/app/controllers/elabs/member/notifications_controller.rb +30 -0
  30. data/app/controllers/elabs/member/preferences_controller.rb +1 -1
  31. data/app/controllers/elabs/member/users_controller.rb +8 -5
  32. data/app/controllers/elabs/reports_controller.rb +2 -2
  33. data/app/controllers/elabs/tags_controller.rb +2 -2
  34. data/app/controllers/elabs/users_controller.rb +3 -3
  35. data/app/helpers/elabs/admin_content_helper.rb +8 -24
  36. data/app/helpers/elabs/application_helper.rb +1 -1
  37. data/app/helpers/elabs/content_helper.rb +39 -0
  38. data/app/helpers/elabs/form_helper.rb +22 -10
  39. data/app/helpers/elabs/member_content_helper.rb +5 -22
  40. data/app/helpers/elabs/notification_helper.rb +69 -0
  41. data/app/helpers/elabs/thumbnails_helper.rb +15 -0
  42. data/app/helpers/elabs/time_helper.rb +7 -0
  43. data/app/models/elabs/application_content_record.rb +1 -0
  44. data/app/models/elabs/application_record.rb +2 -0
  45. data/app/models/elabs/comment.rb +14 -0
  46. data/app/models/elabs/concerns/actable_entity.rb +0 -12
  47. data/app/models/elabs/concerns/content_entity.rb +23 -0
  48. data/app/models/elabs/concerns/notifiable_entity.rb +46 -0
  49. data/app/models/elabs/notification.rb +10 -0
  50. data/app/models/elabs/preference.rb +2 -0
  51. data/app/models/elabs/report.rb +10 -0
  52. data/app/models/elabs/user.rb +26 -6
  53. data/app/views/elabs/acts/_act.json.jbuilder +7 -2
  54. data/app/views/elabs/acts/index.json.jbuilder +1 -1
  55. data/app/views/elabs/admin/albums/_album.json.jbuilder +15 -2
  56. data/app/views/elabs/admin/albums/index.html.haml +1 -1
  57. data/app/views/elabs/admin/albums/index.json.jbuilder +1 -1
  58. data/app/views/elabs/admin/articles/_article.json.jbuilder +15 -2
  59. data/app/views/elabs/admin/articles/index.html.haml +1 -1
  60. data/app/views/elabs/admin/articles/index.json.jbuilder +1 -1
  61. data/app/views/elabs/admin/languages/_language.json.jbuilder +9 -2
  62. data/app/views/elabs/admin/languages/index.html.haml +1 -1
  63. data/app/views/elabs/admin/languages/index.json.jbuilder +1 -1
  64. data/app/views/elabs/admin/licenses/_license.json.jbuilder +10 -2
  65. data/app/views/elabs/admin/licenses/index.html.haml +1 -1
  66. data/app/views/elabs/admin/licenses/index.json.jbuilder +1 -1
  67. data/app/views/elabs/admin/notes/_note.json.jbuilder +13 -2
  68. data/app/views/elabs/admin/notes/index.html.haml +1 -1
  69. data/app/views/elabs/admin/notes/index.json.jbuilder +1 -1
  70. data/app/views/elabs/admin/projects/_project.json.jbuilder +20 -2
  71. data/app/views/elabs/admin/projects/index.html.haml +1 -1
  72. data/app/views/elabs/admin/projects/index.json.jbuilder +1 -1
  73. data/app/views/elabs/admin/reports/_report.json.jbuilder +10 -0
  74. data/app/views/elabs/admin/reports/index.html.haml +1 -1
  75. data/app/views/elabs/admin/reports/index.json.jbuilder +1 -1
  76. data/app/views/elabs/admin/tags/_tag.json.jbuilder +8 -2
  77. data/app/views/elabs/admin/tags/index.html.haml +1 -1
  78. data/app/views/elabs/admin/tags/index.json.jbuilder +1 -1
  79. data/app/views/elabs/admin/uploads/_upload.json.jbuilder +17 -2
  80. data/app/views/elabs/admin/uploads/index.html.haml +1 -1
  81. data/app/views/elabs/admin/uploads/index.json.jbuilder +1 -1
  82. data/app/views/elabs/admin/users/_user.json.jbuilder +14 -0
  83. data/app/views/elabs/admin/users/index.html.haml +6 -2
  84. data/app/views/elabs/admin/users/index.json.jbuilder +1 -1
  85. data/app/views/elabs/admin/users/show.html.haml +1 -1
  86. data/app/views/elabs/admin/users/show.json.jbuilder +1 -1
  87. data/app/views/elabs/albums/_album.html.haml +2 -2
  88. data/app/views/elabs/albums/_album.json.jbuilder +12 -2
  89. data/app/views/elabs/albums/index.json.jbuilder +1 -1
  90. data/app/views/elabs/albums/show.html.haml +7 -7
  91. data/app/views/elabs/albums/show.json.jbuilder +1 -1
  92. data/app/views/elabs/articles/_article.html.haml +2 -2
  93. data/app/views/elabs/articles/_article.json.jbuilder +12 -2
  94. data/app/views/elabs/articles/index.json.jbuilder +1 -1
  95. data/app/views/elabs/articles/show.html.haml +6 -6
  96. data/app/views/elabs/articles/show.json.jbuilder +1 -1
  97. data/app/views/elabs/auth/registrations/edit.html.haml +8 -5
  98. data/app/views/elabs/comments/_comment.json.jbuilder +10 -2
  99. data/app/views/elabs/comments/_comments.html.haml +2 -2
  100. data/app/views/elabs/languages/_language.json.jbuilder +9 -2
  101. data/app/views/elabs/languages/index.json.jbuilder +1 -1
  102. data/app/views/elabs/languages/show.html.haml +1 -1
  103. data/app/views/elabs/languages/show.json.jbuilder +1 -1
  104. data/app/views/elabs/layouts/_menu.html.haml +10 -5
  105. data/app/views/elabs/licenses/_license.json.jbuilder +10 -2
  106. data/app/views/elabs/licenses/index.json.jbuilder +1 -1
  107. data/app/views/elabs/licenses/show.html.haml +2 -6
  108. data/app/views/elabs/member/albums/_album.json.jbuilder +15 -2
  109. data/app/views/elabs/member/albums/index.html.haml +1 -1
  110. data/app/views/elabs/member/albums/index.json.jbuilder +1 -1
  111. data/app/views/elabs/member/articles/_article.json.jbuilder +15 -2
  112. data/app/views/elabs/member/articles/index.html.haml +1 -1
  113. data/app/views/elabs/member/articles/index.json.jbuilder +1 -1
  114. data/app/views/elabs/member/layouts/_empty.html.haml +3 -2
  115. data/app/views/elabs/member/notes/_note.json.jbuilder +13 -2
  116. data/app/views/elabs/member/notes/index.html.haml +1 -1
  117. data/app/views/elabs/member/notes/index.json.jbuilder +1 -1
  118. data/app/views/elabs/member/notifications/_notification.json.jbuilder +8 -0
  119. data/app/views/elabs/member/notifications/index.html.haml +21 -0
  120. data/app/views/elabs/member/notifications/index.json.jbuilder +1 -0
  121. data/app/views/elabs/member/preferences/_form.html.haml +6 -0
  122. data/app/views/elabs/member/preferences/edit.html.haml +2 -1
  123. data/app/views/elabs/member/projects/_project.json.jbuilder +20 -2
  124. data/app/views/elabs/member/projects/index.html.haml +1 -1
  125. data/app/views/elabs/member/projects/index.json.jbuilder +1 -1
  126. data/app/views/elabs/member/uploads/_upload.json.jbuilder +17 -2
  127. data/app/views/elabs/member/uploads/index.html.haml +1 -1
  128. data/app/views/elabs/member/uploads/index.json.jbuilder +1 -1
  129. data/app/views/elabs/member/users/_form.html.haml +14 -9
  130. data/app/views/elabs/member/users/edit.html.haml +7 -0
  131. data/app/views/elabs/notes/_note.html.haml +2 -2
  132. data/app/views/elabs/notes/_note.json.jbuilder +10 -2
  133. data/app/views/elabs/notes/index.json.jbuilder +1 -1
  134. data/app/views/elabs/notes/show.html.haml +5 -5
  135. data/app/views/elabs/notes/show.json.jbuilder +1 -1
  136. data/app/views/elabs/projects/_project.html.haml +2 -2
  137. data/app/views/elabs/projects/_project.json.jbuilder +17 -0
  138. data/app/views/elabs/projects/index.json.jbuilder +1 -1
  139. data/app/views/elabs/projects/show.html.haml +14 -11
  140. data/app/views/elabs/projects/show.json.jbuilder +1 -1
  141. data/app/views/elabs/tags/_tag.json.jbuilder +8 -2
  142. data/app/views/elabs/tags/index.json.jbuilder +1 -1
  143. data/app/views/elabs/tags/show.json.jbuilder +1 -1
  144. data/app/views/elabs/uploads/_upload.html.haml +1 -1
  145. data/app/views/elabs/uploads/_upload.json.jbuilder +14 -2
  146. data/app/views/elabs/uploads/index.json.jbuilder +1 -1
  147. data/app/views/elabs/uploads/show.html.haml +12 -3
  148. data/app/views/elabs/uploads/show.json.jbuilder +1 -1
  149. data/app/views/elabs/users/_user.html.haml +10 -3
  150. data/app/views/elabs/users/_user.json.jbuilder +14 -2
  151. data/app/views/elabs/users/index.json.jbuilder +1 -1
  152. data/app/views/elabs/users/show.html.haml +15 -10
  153. data/app/views/elabs/users/show.json.jbuilder +1 -1
  154. data/config/routes.rb +21 -16
  155. data/db/migrate/20180910000015_remove_license_timestamps.rb +6 -0
  156. data/db/migrate/20180910175012_create_notifications.rb +13 -0
  157. data/db/migrate/20180913093027_add_fields_in_preferences.rb +6 -0
  158. data/docs/migrating.md +14 -0
  159. data/docs/setup.md +1 -0
  160. data/lib/elabs.rb +3 -0
  161. data/lib/elabs/version.rb +1 -1
  162. data/lib/generators/elabs/required_assets_generator.rb +1 -1
  163. data/lib/generators/templates/elabs.rb +6 -0
  164. data/locale/app.pot +73 -14
  165. data/locale/en/app.edit.po +71 -12
  166. data/locale/en/app.po +71 -12
  167. data/locale/fr/app.edit.po +76 -17
  168. data/locale/fr/app.po +75 -16
  169. data/package.json +4 -4
  170. metadata +19 -5
  171. data/app/assets/images/elabs/preview_placeholder.png +0 -0
  172. data/app/assets/images/elabs/preview_placeholder_nsfw.png +0 -0
  173. data/app/views/elabs/admin/users/_admin_user.json.jbuilder +0 -2
@@ -1,5 +1,5 @@
1
1
  module Elabs
2
- class ReportsController < ElabsApplicationController
2
+ class ReportsController < ElabsPublicController
3
3
  # POST /reports
4
4
  # POST /reports.json
5
5
  # rubocop:disable Metrics/AbcSize
@@ -9,7 +9,7 @@ module Elabs
9
9
  respond_to do |format|
10
10
  if report.save
11
11
  format.html { redirect_to request.referer, notice: _('Report was successfully created.') }
12
- format.json { render json: { message: 'ok' }, status: :created, location: report }
12
+ format.json { render json: { message: 'ok' }, status: :created }
13
13
  else
14
14
  format.html { redirect_to request.referer, notice: { error: report.errors } }
15
15
  format.json { render json: report.errors, status: :unprocessable_entity }
@@ -1,5 +1,5 @@
1
1
  module Elabs
2
- class TagsController < ElabsApplicationController
2
+ class TagsController < ElabsPublicController
3
3
  ALLOWED_ORDER_FROM = %w[name].freeze
4
4
  DEFAULT_ORDER = { name: :desc }.freeze
5
5
 
@@ -8,7 +8,7 @@ module Elabs
8
8
  # GET /tags
9
9
  # GET /tags.json
10
10
  def index
11
- @tags = Tag.all
11
+ @tags = scope_request Tag.all
12
12
  end
13
13
 
14
14
  # GET /tags/1
@@ -1,14 +1,14 @@
1
1
  module Elabs
2
- class UsersController < ElabsApplicationController
2
+ class UsersController < ElabsPublicController
3
3
  ALLOWED_ORDER_FROM = %w[username created_at].freeze
4
- DEFAULT_ORDER = { username: :desc }.freeze
4
+ DEFAULT_ORDER = { username: :asc }.freeze
5
5
 
6
6
  before_action :set_user, only: %i[show edit update destroy]
7
7
 
8
8
  # GET /users
9
9
  # GET /users.json
10
10
  def index
11
- @users = User.page(params[:page]).per(self.class::MAX_ITEMS_PER_PAGE)
11
+ @users = scope_request User.page(params[:page]).per(self.class::MAX_ITEMS_PER_PAGE)
12
12
  end
13
13
 
14
14
  # GET /users/1
@@ -2,27 +2,20 @@ module Elabs
2
2
  module AdminContentHelper
3
3
  def admin_action_links(singular_model, entity)
4
4
  out = []
5
- out.push(admin_show_online_link(entity))
5
+ out.push(show_online_link(entity))
6
6
  out.push(admin_lock_link(singular_model, entity))
7
7
  out.push(admin_destroy_link(singular_model, entity))
8
8
 
9
9
  raw out.join('')
10
10
  end
11
11
 
12
- def admin_show_link(singular_model, entity)
13
- link_to send("admin_#{singular_model}_path".to_sym, entity),
14
- title: _('Show'),
15
- class: 'btn btn--small btn--show' do
16
- icon('eye', ['fw'])
17
- end
12
+ # @deprecated This will be deprecated in 4.0
13
+ def admin_show_online_link(singular_model, entity)
14
+ admin_show_link(singular_model, entity)
18
15
  end
19
16
 
20
- def admin_show_online_link(entity)
21
- link_to entity,
22
- title: _('View online'),
23
- class: 'btn btn--small btn--show' do
24
- icon('globe', ['fw'])
25
- end
17
+ def admin_show_link(singular_model, entity)
18
+ namespace_show_link('admin', singular_model, entity)
26
19
  end
27
20
 
28
21
  def admin_lock_link(singular_model, entity)
@@ -35,20 +28,11 @@ module Elabs
35
28
  end
36
29
 
37
30
  def admin_destroy_link(singular_model, entity)
38
- link_to send("admin_#{singular_model}_path".to_sym, entity),
39
- title: _('Destroy'),
40
- class: 'btn btn--small btn--destroy',
41
- method: :delete, data: { confirm: _('Are you sure?') } do
42
- icon('trash', ['fw'])
43
- end
31
+ namespace_destroy_link('admin', singular_model, entity)
44
32
  end
45
33
 
46
34
  def admin_edit_link(singular_model, entity)
47
- link_to send("edit_admin_#{singular_model}_path".to_sym, entity),
48
- title: _('Edit'),
49
- class: 'btn btn--small btn--edit' do
50
- icon('pencil-alt', ['fw'])
51
- end
35
+ namespace_edit_link('admin', singular_model, entity)
52
36
  end
53
37
  end
54
38
  end
@@ -29,7 +29,7 @@ module Elabs
29
29
  def icon(name, classes = [], base = 'fas')
30
30
  icon_class = ["#{base} fa-#{name}"]
31
31
  icon_class += classes.map do |c|
32
- if %w[2x 3x 4x].include? c
32
+ if %w[2x 3x 4x fw].include? c
33
33
  "fa-#{c}"
34
34
  else
35
35
  c
@@ -0,0 +1,39 @@
1
+ module Elabs
2
+ module ContentHelper
3
+ def show_online_link(entity)
4
+ link_to entity,
5
+ title: _('View online'),
6
+ class: 'btn btn--small btn--show' do
7
+ icon('eye', ['fw'])
8
+ end
9
+ end
10
+
11
+ def namespace_show_link(namespace, singular_model, entity)
12
+ link_to send("#{namespace}_#{singular_model}_path", entity),
13
+ title: _('View online'),
14
+ class: 'btn btn--small btn--show' do
15
+ icon('eye', ['fw'])
16
+ end
17
+ end
18
+
19
+ def namespace_edit_link(namespace, singular_model, entity)
20
+ link_to send("edit_#{namespace}_#{singular_model}_path", entity),
21
+ title: _('Edit'),
22
+ class: 'btn btn--small btn--edit' do
23
+ icon('pencil-alt', ['fw'])
24
+ end
25
+ end
26
+
27
+ def namespace_destroy_link(namespace, singular_model, entity, confirm = true)
28
+ link_params = {
29
+ title: _('Destroy'),
30
+ method: :delete,
31
+ class: 'btn btn--small btn--destroy'
32
+ }
33
+ link_params[:data] = { confirm: _('Are you sure?') } if confirm
34
+ link_to send("#{namespace}_#{singular_model}_path".to_sym, entity), link_params do
35
+ icon('trash', ['fw'])
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,23 +1,35 @@
1
1
  module Elabs
2
2
  module FormHelper
3
- def album_selector(form)
4
- form.select :album_ids, Elabs::Album.by_member(current_user).for_list, {}, multiple: true
3
+ def album_selector(form, field = :album_ids, multiple: true)
4
+ form.select field, Elabs::Album.by_member(current_user).for_list, {},
5
+ multiple: multiple, id: selector_id(form, field)
5
6
  end
6
7
 
7
- def language_selector(form)
8
- form.select :language_id, Elabs::Language.for_list
8
+ def language_selector(form, field = :language_id, multiple: false)
9
+ form.select field, Elabs::Language.for_list, {},
10
+ multiple: multiple, id: selector_id(form, field)
9
11
  end
10
12
 
11
- def license_selector(form)
12
- form.select :license_id, Elabs::License.for_list
13
+ def license_selector(form, field = :license_id, multiple: false)
14
+ form.select field, Elabs::License.for_list, {},
15
+ multiple: multiple, id: selector_id(form, field)
13
16
  end
14
17
 
15
- def project_selector(form)
16
- form.select :project_ids, Elabs::Project.by_member(current_user).for_list, {}, multiple: true
18
+ def project_selector(form, field = :project_ids, multiple: true)
19
+ form.select field, Elabs::Project.by_member(current_user).for_list, {},
20
+ multiple: multiple, id: selector_id(form, field)
17
21
  end
18
22
 
19
- def uploads_selector(form)
20
- form.select :upload_ids, Elabs::Upload.by_member(current_user).for_list, {}, multiple: true
23
+ def uploads_selector(form, field = :upload_ids, multiple: true)
24
+ form.select field, Elabs::Upload.by_member(current_user).for_list, {},
25
+ multiple: multiple, id: selector_id(form, field)
26
+ end
27
+
28
+ private
29
+
30
+ def selector_id(form, field)
31
+ field_name = field.to_s.sub(/(.*)_id(s?)/, '\1\2')
32
+ "#{form.object_name}_#{field_name}"
21
33
  end
22
34
  end
23
35
  end
@@ -2,7 +2,7 @@ module Elabs
2
2
  module MemberContentHelper
3
3
  def member_action_links(singular_model, entity)
4
4
  out = []
5
- out.push member_show_link(entity)
5
+ out.push show_online_link(entity)
6
6
  out.push member_edit_link(singular_model, entity)
7
7
  out.push member_publish_link(singular_model, entity)
8
8
  out.push member_destroy_link(singular_model, entity)
@@ -10,20 +10,12 @@ module Elabs
10
10
  raw out.join('')
11
11
  end
12
12
 
13
- def member_show_link(entity)
14
- link_to entity,
15
- title: _('View online'),
16
- class: 'btn btn--small btn--show' do
17
- icon('eye', ['fw'])
18
- end
13
+ def member_edit_link(singular_model, entity)
14
+ namespace_edit_link('member', singular_model, entity)
19
15
  end
20
16
 
21
- def member_edit_link(singular_model, entity)
22
- link_to send("edit_member_#{singular_model}_path", entity),
23
- title: _('Edit'),
24
- class: 'btn btn--small btn--edit' do
25
- icon('pencil-alt', ['fw'])
26
- end
17
+ def member_destroy_link(singular_model, entity, confirm = true)
18
+ namespace_destroy_link('member', singular_model, entity, confirm)
27
19
  end
28
20
 
29
21
  def member_publish_link(singular_model, entity)
@@ -34,14 +26,5 @@ module Elabs
34
26
  icon(entity.published? ? 'calendar-times' : 'calendar-check', ['fw'])
35
27
  end
36
28
  end
37
-
38
- def member_destroy_link(singular_model, entity)
39
- link_to send("member_#{singular_model}_path".to_sym, entity),
40
- title: _('Destroy'),
41
- method: :delete, data: { confirm: _('Are you sure?') },
42
- class: 'btn btn--small btn--destroy' do
43
- icon('trash', ['fw'])
44
- end
45
- end
46
29
  end
47
30
  end
@@ -0,0 +1,69 @@
1
+ module Elabs
2
+ module NotificationHelper
3
+ def notification_message(notification)
4
+ user = notification_user notification.source_user
5
+ action = notification_action notification.event
6
+ link = notification_link notification
7
+ string = notification_string notification
8
+ format(string, user: user, action: action, link: link).html_safe
9
+ end
10
+
11
+ def notification_icon(event)
12
+ actions = {
13
+ comment: 'comment',
14
+ report: 'flag',
15
+ lock: 'lock',
16
+ unlock: 'unlock',
17
+ delete: 'trash'
18
+ }.freeze
19
+ icon (actions[event.to_sym] || 'question'), ['fw']
20
+ end
21
+
22
+ def notification_count
23
+ Elabs::Notification.for_user(current_user).count
24
+ end
25
+
26
+ private
27
+
28
+ def notification_action(event)
29
+ actions = {
30
+ comment: _('has commented'),
31
+ report: _('has reported'),
32
+ lock: _('has locked'),
33
+ unlock: _('has unlocked'),
34
+ delete: _('has deleted')
35
+ }.freeze
36
+ actions[event.to_sym] || "[missing: #{event}]"
37
+ end
38
+
39
+ def notification_user(user)
40
+ return link_to user.display_name, user if user
41
+
42
+ _('Someone')
43
+ end
44
+
45
+ def notification_link(notification)
46
+ return "##{notification.content_id}" if notification.event == 'delete'
47
+
48
+ link = case notification.content_type
49
+ when 'Elabs::Report'
50
+ admin_reports_path
51
+ else
52
+ notification.content
53
+ end
54
+ link_to("##{notification.content_id}", link).html_safe
55
+ end
56
+
57
+ def notification_string(notification)
58
+ strings = {
59
+ 'Elabs::Album' => _('%<user>s %<action>s your album %<link>s'),
60
+ 'Elabs::Article' => _('%<user>s %<action>s your article %<link>s'),
61
+ 'Elabs::Note' => _('%<user>s %<action>s your note %<link>s'),
62
+ 'Elabs::Project' => _('%<user>s %<action>s your project %<link>s'),
63
+ 'Elabs::Upload' => _('%<user>s %<action>s your file %<link>s'),
64
+ 'Elabs::Report' => _('%<user>s %<action>s %<link>s')
65
+ }.freeze
66
+ strings[notification.content_type] || '%<user> %<action>s something (<%link>)'
67
+ end
68
+ end
69
+ end
@@ -24,5 +24,20 @@ module Elabs
24
24
 
25
25
  { resize: dimensions }
26
26
  end
27
+
28
+ def avatar_image(avatar, size = :medium)
29
+ x = avatar.blob.metadata[:width].to_f
30
+ y = avatar.blob.metadata[:height].to_f
31
+ bigger_size = x < y ? x : y
32
+ dimensions = case size
33
+ when :large
34
+ '512'
35
+ when :medium
36
+ '256'
37
+ when :small
38
+ '64'
39
+ end
40
+ avatar.variant(combine_options: { gravity: 'center', crop: "#{bigger_size}x#{bigger_size}+0+0", resize: dimensions.to_s }).processed
41
+ end
27
42
  end
28
43
  end
@@ -2,6 +2,7 @@ module Elabs
2
2
  module TimeHelper
3
3
  def same_day?(previous_date_time, current_date_time)
4
4
  return false if previous_date_time.nil?
5
+
5
6
  date1 = Date.parse(previous_date_time.to_s)
6
7
  date2 = Date.parse(current_date_time.to_s)
7
8
 
@@ -15,5 +16,11 @@ module Elabs
15
16
  def date_time_to_time(time)
16
17
  time.strftime(_('%I:%M %p'))
17
18
  end
19
+
20
+ def short_date(date)
21
+ return nil if date.nil?
22
+
23
+ I18n.l date, format: :short
24
+ end
18
25
  end
19
26
  end
@@ -3,6 +3,7 @@ module Elabs
3
3
  include Elabs::Concerns::ContentEntity
4
4
  include Elabs::Concerns::ActableEntity
5
5
  include Elabs::Concerns::CountableEntity
6
+ include Elabs::Concerns::NotifiableEntity
6
7
  include Elabs::Concerns::Taggable
7
8
 
8
9
  self.abstract_class = true
@@ -1,5 +1,7 @@
1
1
  module Elabs
2
2
  class ApplicationRecord < ActiveRecord::Base
3
3
  self.abstract_class = true
4
+
5
+ attr_accessor :changed_by
4
6
  end
5
7
  end
@@ -8,5 +8,19 @@ module Elabs
8
8
 
9
9
  belongs_to :content, polymorphic: true
10
10
  belongs_to :user, optional: true
11
+
12
+ after_save :notify_author, if: :notify_author?
13
+
14
+ def notify_author?
15
+ user_id ? content.user_id != user_id : true
16
+ end
17
+
18
+ def notify_author
19
+ notification = { content: content,
20
+ event: :comment,
21
+ user_id: content.user_id }
22
+ notification[:source_user] = user if user_id
23
+ Elabs::Notification.create! notification
24
+ end
11
25
  end
12
26
  end
@@ -26,18 +26,6 @@ module Elabs
26
26
  end
27
27
  end
28
28
 
29
- def current_publish_action
30
- published? && unlocked? ? :publish : :unpublish
31
- end
32
-
33
- def current_lock_action
34
- published? && locked? ? :lock : :unlock
35
- end
36
-
37
- def current_update_action
38
- published? && unlocked? ? :update : :nothing
39
- end
40
-
41
29
  def update_acts
42
30
  acts.destroy_all if %i[lock unpublish].include? @action
43
31
  Act.create content: self, event: @action unless @action == :nothing || hidden_in_history
@@ -56,6 +56,29 @@ module Elabs
56
56
  self.published_at = nil if changed.include?('published') && !published?
57
57
  end
58
58
 
59
+ # method used by ActableEntity/NotifiableEntity to determine the events.
60
+ def current_publish_action
61
+ return :nothing unless unlocked?
62
+
63
+ published? ? :publish : :unpublish
64
+ end
65
+
66
+ # method used by ActableEntity/NotifiableEntity to determine the events.
67
+ def current_lock_action
68
+ return :nothing unless published?
69
+
70
+ locked? ? :lock : :unlock
71
+ end
72
+
73
+ # method used by ActableEntity/NotifiableEntity to determine the events.
74
+ def current_update_action
75
+ published? && unlocked? ? :update : :nothing
76
+ end
77
+
78
+ def changed_by_someone_else
79
+ changed_by.present? && changed_by.id != user.id
80
+ end
81
+
59
82
  class_methods do
60
83
  def find_publicly_visible(id)
61
84
  entity = where(id: id).published.first