thredded-workgroup 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +9 -8
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +1 -1
  6. data/README.md +7 -6
  7. data/app/controllers/concerns/thredded/workgroup/application_controller_retaining.rb +19 -0
  8. data/app/controllers/concerns/thredded/workgroup/posts_controller_which_redirects.rb +48 -0
  9. data/app/view_hooks/thredded/workgroup/view_hooks.rb +2 -5
  10. data/app/view_models/thredded/workgroup/topics_page_view_with_last_post.rb +13 -0
  11. data/app/views/thredded/workgroup/topics/_topics_with_last_post.html.erb +1 -1
  12. data/lib/overrides/thredded/all_view_hooks_override.rb +5 -0
  13. data/lib/overrides/thredded/application_controller_override.rb +8 -0
  14. data/lib/overrides/thredded/posts_controller_override.rb +5 -0
  15. data/lib/overrides/thredded/topic_view_override.rb +29 -0
  16. data/lib/overrides/thredded/topics_page_view_override.rb +5 -0
  17. data/lib/thredded/workgroup/engine.rb +9 -6
  18. data/lib/thredded/workgroup/version.rb +1 -1
  19. data/shared.gemfile +3 -1
  20. metadata +11 -12
  21. data/app/controllers/thredded/application_controller.rb +0 -23
  22. data/app/controllers/thredded/posts_controller.rb +0 -51
  23. data/app/helpers/thredded/application_helper.rb +0 -10
  24. data/app/helpers/thredded/workgroup/application_helper.rb +0 -8
  25. data/app/view_hooks/thredded/all_view_hooks.rb +0 -9
  26. data/app/view_models/thredded/topic_view.rb +0 -32
  27. data/app/view_models/thredded/topics_page_view.rb +0 -16
  28. data/lib/thredded/workgroup/route_delegator.rb +0 -25
  29. data/lib/thredded/workgroup/thredded_route_delegator.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5efefc1d7010c94166f28b7c5eef2f1068aed1e7695b7b322e39a51456b6b46b
4
- data.tar.gz: 7557fd4b245b16ccabfc6e2c1bacd5d93e2688ba222ddb424330774cbe38d9a8
3
+ metadata.gz: e900db2dd2e7b571e3d3fcb4fac889dbdb8d40d96902a2952b97cbf6bb09704f
4
+ data.tar.gz: 22794ff545fa54b6e0b26680ee53dacb5a472ccbe8658413534ea327344ddf47
5
5
  SHA512:
6
- metadata.gz: b7c4da998f27f48915f3cc3c55fb85d34f62d754d9adb14e579faa9a88cf24b5932a2d270521955968a8557e3bb33f573f9f75f8fadce867248040a699075ec5
7
- data.tar.gz: 4f596f4e2fe49ac827056557a7ec902f7686684ccde0db38c21470726118d12d6ecada6d0857e8906aaad26f00e66c59c4e29a8775b8aef21f726579c5de5342
6
+ metadata.gz: 67d6def354e8949bf6cff37ddbd360a96a6a9a40a01260ebb7691e400d806796815ab017355ce778de415c368edb7eecefc2fe34f4fbb8b50127b68917e9fc91
7
+ data.tar.gz: dc65476c53d44b297f13e5c1ca62309c6ec6436d9cfa90ee7f62e43d75b1b300226cae7b79a6be21f55617adaafea15192d6cab60943aeb7f41954161c62b08d
data/.gitignore CHANGED
@@ -8,6 +8,8 @@
8
8
  /pkg/
9
9
  /spec/reports/
10
10
  /tmp/
11
+ /node_modules
12
+ yarn.lock
11
13
  log/*.log
12
14
  spec/dummy/db/*.sqlite3
13
15
  spec/dummy/log/*.log
data/.travis.yml CHANGED
@@ -2,11 +2,9 @@ dist: bionic
2
2
 
3
3
  language: ruby
4
4
  rvm:
5
- - 2.6
5
+ - 2.7
6
6
  cache: bundler
7
7
  bundler_args: --path ../../vendor/bundle --without debug
8
- gemfile:
9
- - spec/gemfiles/rails_5_2.gemfile
10
8
 
11
9
  jobs:
12
10
  fast_finish: true
@@ -14,21 +12,24 @@ jobs:
14
12
  - env: DB=sqlite3 DBC_VERBOSE=true
15
13
  include:
16
14
  - name: audit
17
- gemfile: spec/gemfiles/rails_5_2.gemfile
15
+ gemfile: spec/gemfiles/rails_6_0.gemfile
18
16
  before_script: ""
19
17
  script:
20
18
  - bundle show rubocop
21
19
  - bundle exec rubocop
22
20
  - cp $BUNDLE_GEMFILE Gemfile.lock
23
21
  - bundle exec bundle-audit check --update -v
24
- - gemfile: spec/gemfiles/rails_5_2.gemfile
25
- rvm: 2.6
22
+ - gemfile: spec/gemfiles/rails_6_0.gemfile
23
+ rvm: 2.7
26
24
  env: DB=postgresql DB_USERNAME=postgres DB_PASSWORD=""
27
25
  services: postgresql
28
- - gemfile: spec/gemfiles/rails_5_2.gemfile
29
- rvm: 2.6
26
+ - gemfile: spec/gemfiles/rails_6_0.gemfile
27
+ rvm: 2.7
30
28
  env: DB=sqlite3 DBC_VERBOSE=true
31
29
 
30
+ env:
31
+ global:
32
+ - THREDDED_TESTAPP_SPROCKETS_JS=1
32
33
 
33
34
  before_script:
34
35
  - RAILS_ENV=test bundle exec rake db:create db:migrate
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.4.0
2
+
3
+ This version supports:
4
+
5
+ * thredded v1.0 +
6
+ * rails 6.0 (with zeitwerk)
7
+
1
8
  # v0.3.0, v0.3.1
2
9
 
3
10
  This version supports:
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  # if you switch rails version gemfile:
6
6
  # bundle update rails json rails-i18n
7
- eval_gemfile File.expand_path("spec/gemfiles/rails_5_2.gemfile", File.dirname(__FILE__))
7
+ eval_gemfile File.expand_path("spec/gemfiles/rails_6_0.gemfile", File.dirname(__FILE__))
data/README.md CHANGED
@@ -38,7 +38,7 @@ So you need to include jquery and its ujs file, for example in your Gemfile:
38
38
  gem "jquery-rails"
39
39
  ```
40
40
 
41
- __NB: (see below for using master vs a released version)__
41
+ __NB: (see below for using main branch vs a released version)__
42
42
 
43
43
  And then execute:
44
44
 
@@ -89,15 +89,16 @@ To see the extra view hooks provided by Thredded::Workgroup (with their argument
89
89
  ```bash
90
90
  grep view_hooks -R --include '*.html.erb' "$(bundle show thredded-workgroup)"
91
91
  ```
92
- ## Master vs Released versions
93
92
 
94
- NB: if you are using the master version rather than a release version
93
+ ## Main vs Released versions
94
+
95
+ NB: if you are using the main branch rather than a release version
95
96
  (and as no release has been made yet you must be! :) ) then you may well need
96
- also to use the latest master release of thredded. So your gem file may need to say:
97
+ also to use the latest main branch of thredded. So your gem file may need to say:
97
98
 
98
99
  ```ruby
99
- gem 'thredded', github: 'thredded/thredded', branch: 'master'
100
- gem 'thredded-workgroup', github: 'red56/thredded-workgroup', branch: 'master'
100
+ gem 'thredded', github: 'thredded/thredded', branch: 'main'
101
+ gem 'thredded-workgroup', github: 'red56/thredded-workgroup', branch: 'main'
101
102
  ```
102
103
 
103
104
  and you need to update both at the same time: `gem update thredded thredded-workgroup`
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thredded
4
+ module Workgroup
5
+ module ApplicationControllerRetaining
6
+ def topics_scope
7
+ return super if messageboard_or_nil
8
+
9
+ all_topics_scope
10
+ end
11
+
12
+ def unread_followed_topics_count
13
+ return super if messageboard_or_nil
14
+
15
+ all_unread_followed_topics_count
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thredded
4
+ module Workgroup
5
+ module PostsControllerWhichRedirects
6
+ def create
7
+ @post_form = Thredded::PostForm.new(
8
+ user: thredded_current_user, topic: parent_topic, post_params: new_post_params
9
+ )
10
+ authorize_creating @post_form.post
11
+
12
+ if @post_form.save
13
+ # TODO: extract as a hook on thredded#posts_controller `after_create(post)`
14
+ redirect_after_create(@post_form.post)
15
+ else
16
+ render :new
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def after_mark_as_unread
23
+ if post.private_topic_post?
24
+ redirect_to private_topics_path
25
+ else
26
+ redirect_to thredded_workgroup.unread_nav_path
27
+ end
28
+ end
29
+
30
+ def redirect_after_create(post)
31
+ UserTopicReadState.touch!(thredded_current_user.id, post)
32
+ if params[:post_referer].present?
33
+ redirect_to params[:post_referer], notice: generate_flash_for(post)
34
+ else
35
+ redirect_to thredded_workgroup.unread_nav_path, notice: generate_flash_for(post)
36
+ end
37
+ end
38
+
39
+ def generate_flash_for(post)
40
+ path_to_post = thredded.messageboard_topic_path(parent_topic.messageboard, parent_topic,
41
+ anchor: "post_#{post.id}")
42
+ # rubocop:disable Rails/OutputSafety
43
+ "Successfully replied to #{view_context.link_to(parent_topic.title, path_to_post)}".html_safe
44
+ # rubocop:enable Rails/OutputSafety
45
+ end
46
+ end
47
+ end
48
+ end
@@ -3,11 +3,8 @@
3
3
  module Thredded
4
4
  module Workgroup
5
5
  module ViewHooks
6
- attr_reader :topic_with_last_post
7
-
8
- def initialize
9
- super
10
- @topic_with_last_post = TopicWithLastPost.new
6
+ def topic_with_last_post
7
+ @topic_with_last_post ||= TopicWithLastPost.new
11
8
  end
12
9
 
13
10
  # View hooks for a Topic when displaying last post.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thredded
4
+ module Workgroup
5
+ module TopicsPageViewWithLastPost
6
+ protected
7
+
8
+ def refine_scope(topics_page_scope)
9
+ super.includes(:last_post)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -6,7 +6,7 @@
6
6
  <% end %>
7
7
 
8
8
  <%= button_to t("thredded.nav.mark_all_read"),
9
- mark_all_topics_read_path,
9
+ thredded_workgroup.mark_all_topics_read_path,
10
10
  class: 'thredded--button thredded--button-light thredded--button-wide',
11
11
  method: :put -%>
12
12
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Thredded::AllViewHooks.class_eval do
4
+ include Thredded::Workgroup::ViewHooks
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ Thredded::ApplicationController.class_eval do
4
+ Rails.logger.debug "I am being evaled Thredded::ApplicationController"
5
+ include Thredded::Workgroup::AllUnreadFollowedTopics
6
+
7
+ prepend ::Thredded::Workgroup::ApplicationControllerRetaining
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Thredded::PostsController.class_eval do
4
+ prepend ::Thredded::Workgroup::PostsControllerWhichRedirects
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ Thredded::TopicView.class_eval do
4
+ def path
5
+ anchor = if @read_state.first_unread_post_page
6
+ "unread"
7
+ elsif @topic.last_post
8
+ "post_#{@topic.last_post.id}"
9
+ end
10
+ page = @read_state.first_unread_post_page || @read_state.last_read_post_page
11
+ Thredded::UrlsHelper.topic_path(@topic, page: page, anchor: anchor)
12
+ end
13
+
14
+ def reply_path
15
+ Thredded::UrlsHelper.topic_path(@topic, page: last_page, anchor: "new_post")
16
+ end
17
+
18
+ def mark_as_unread_path
19
+ Thredded::UrlsHelper.mark_as_unread_post_path(id: last_post.id, format: :json)
20
+ end
21
+
22
+ def mark_as_read_path
23
+ Thredded::UrlsHelper.mark_as_read_post_path(id: last_post.id, format: :json)
24
+ end
25
+
26
+ def last_page
27
+ (@topic.posts_count / Thredded.posts_per_page.to_f).ceil # TODO: doesn't account for visibility
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Thredded::TopicsPageView.class_eval do
4
+ prepend ::Thredded::Workgroup::TopicsPageViewWithLastPost
5
+ end
@@ -1,21 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thredded/engine"
4
- require "thredded/workgroup/thredded_route_delegator"
5
- require "thredded/workgroup/route_delegator"
4
+
6
5
  module Thredded
7
6
  module Workgroup
8
7
  class Engine < ::Rails::Engine
9
8
  isolate_namespace Thredded::Workgroup
10
9
 
11
- %w(app/controllers app/jobs app/view_models lib).each do |path|
12
- config.autoload_paths << File.expand_path("../../#{path}", File.dirname(__FILE__))
10
+ # https://guides.rubyonrails.org/engines.html#overriding-models-and-controllers
11
+ overrides = root.join("lib/overrides")
12
+ # Rails::autoloaders.main.ignore(overrides)
13
+ config.to_prepare do
14
+ Dir.glob("#{overrides}/**/*_override.rb").each do |override|
15
+ Rails.logger.debug { "overriding: #{override}" }
16
+ load override
17
+ end
13
18
  end
14
19
 
15
20
  config.to_prepare do
16
21
  Rails.application.reload_routes!
17
- ::Thredded::Workgroup::ThreddedRouteDelegator.add_thredded_proxies
18
- ::Thredded::Workgroup::RouteDelegator.add_my_proxies_to_thredded
19
22
 
20
23
  Thredded::ApplicationController.module_eval do
21
24
  Thredded.view_hooks.post_form.content_text_area.config.before do |form:, **_args|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Thredded
4
4
  module Workgroup
5
- VERSION = "0.3.1"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/shared.gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  gem "rake"
4
- gem "thredded", github: "thredded/thredded", branch: "master"
4
+ gem "thredded", github: "thredded/thredded", branch: "main"
5
5
 
6
6
  unless ENV["TRAVIS"]
7
7
  group :development do
@@ -9,6 +9,8 @@ unless ENV["TRAVIS"]
9
9
  gem "guard-rails"
10
10
  gem "guard-livereload"
11
11
  gem "rack-livereload"
12
+ # TODO: drop this when launchy 2.5.2 is released (needed to get to Addressable 2.8)
13
+ gem "launchy", github: "copiousfreetime/launchy", branch: "main"
12
14
  end
13
15
  end
14
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded-workgroup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Diggins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-26 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thredded
@@ -440,19 +440,15 @@ files:
440
440
  - app/assets/stylesheets/thredded/workgroup/_overflow.scss
441
441
  - app/assets/stylesheets/thredded/workgroup/_topics.scss
442
442
  - app/controllers/concerns/thredded/workgroup/all_unread_followed_topics.rb
443
- - app/controllers/thredded/application_controller.rb
444
- - app/controllers/thredded/posts_controller.rb
443
+ - app/controllers/concerns/thredded/workgroup/application_controller_retaining.rb
444
+ - app/controllers/concerns/thredded/workgroup/posts_controller_which_redirects.rb
445
445
  - app/controllers/thredded/workgroup/application_controller.rb
446
446
  - app/controllers/thredded/workgroup/navs_controller.rb
447
447
  - app/controllers/thredded/workgroup/read_states_controller.rb
448
448
  - app/controllers/thredded/workgroup/topics_controller.rb
449
- - app/helpers/thredded/application_helper.rb
450
- - app/helpers/thredded/workgroup/application_helper.rb
451
449
  - app/jobs/thredded/workgroup/mark_all_topics_read_job.rb
452
- - app/view_hooks/thredded/all_view_hooks.rb
453
450
  - app/view_hooks/thredded/workgroup/view_hooks.rb
454
- - app/view_models/thredded/topic_view.rb
455
- - app/view_models/thredded/topics_page_view.rb
451
+ - app/view_models/thredded/workgroup/topics_page_view_with_last_post.rb
456
452
  - app/views/layouts/thredded/workgroup/application.html.erb
457
453
  - app/views/thredded/posts_common/form/_after_content.html.erb
458
454
  - app/views/thredded/shared/_header.html.erb
@@ -479,10 +475,13 @@ files:
479
475
  - config/routes.rb
480
476
  - docs/followers-above-post.png
481
477
  - docs/navbar.png
478
+ - lib/overrides/thredded/all_view_hooks_override.rb
479
+ - lib/overrides/thredded/application_controller_override.rb
480
+ - lib/overrides/thredded/posts_controller_override.rb
481
+ - lib/overrides/thredded/topic_view_override.rb
482
+ - lib/overrides/thredded/topics_page_view_override.rb
482
483
  - lib/thredded/workgroup.rb
483
484
  - lib/thredded/workgroup/engine.rb
484
- - lib/thredded/workgroup/route_delegator.rb
485
- - lib/thredded/workgroup/thredded_route_delegator.rb
486
485
  - lib/thredded/workgroup/version.rb
487
486
  - script/create-db-users
488
487
  - script/dummy-console
@@ -507,7 +506,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
507
506
  - !ruby/object:Gem::Version
508
507
  version: '0'
509
508
  requirements: []
510
- rubygems_version: 3.0.9
509
+ rubygems_version: 3.1.6
511
510
  signing_key:
512
511
  specification_version: 4
513
512
  summary: Extension to Thredded with features for workgroup messaging (Unread, Unreplied,
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/controllers/thredded/application_controller",
4
- Thredded::Engine.called_from)
5
-
6
- module Thredded
7
- module ApplicationControllerRetaining
8
- def topics_scope
9
- return super if messageboard_or_nil
10
- all_topics_scope
11
- end
12
-
13
- def unread_followed_topics_count
14
- return super if messageboard_or_nil
15
- all_unread_followed_topics_count
16
- end
17
- end
18
- class ApplicationController
19
- include Thredded::Workgroup::AllUnreadFollowedTopics
20
-
21
- prepend ::Thredded::ApplicationControllerRetaining
22
- end
23
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/controllers/thredded/posts_controller", Thredded::Engine.called_from)
4
-
5
- module Thredded
6
- module PostsControllerWhichRedirects
7
- def create
8
- @post_form = Thredded::PostForm.new(
9
- user: thredded_current_user, topic: parent_topic, post_params: new_post_params
10
- )
11
- authorize_creating @post_form.post
12
-
13
- if @post_form.save
14
- # TODO: extract as a hook on thredded#posts_controller `after_create(post)`
15
- redirect_after_create(@post_form.post)
16
- else
17
- render :new
18
- end
19
- end
20
-
21
- private
22
-
23
- def after_mark_as_unread
24
- if post.private_topic_post?
25
- redirect_to private_topics_path
26
- else
27
- redirect_to thredded_workgroup.unread_nav_path
28
- end
29
- end
30
-
31
- def redirect_after_create(post)
32
- UserTopicReadState.touch!(thredded_current_user.id, post)
33
- if params[:post_referer].present?
34
- redirect_to params[:post_referer], notice: generate_flash_for(post)
35
- else
36
- redirect_to unread_nav_path, notice: generate_flash_for(post)
37
- end
38
- end
39
-
40
- def generate_flash_for(post)
41
- path_to_post = messageboard_topic_path(parent_topic.messageboard, parent_topic, anchor: "post_#{post.id}")
42
- # rubocop:disable Rails/OutputSafety
43
- "Successfully replied to #{view_context.link_to(parent_topic.title, path_to_post)}".html_safe
44
- # rubocop:enable Rails/OutputSafety
45
- end
46
- end
47
-
48
- class PostsController
49
- prepend ::Thredded::PostsControllerWhichRedirects
50
- end
51
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/helpers/thredded/application_helper", Thredded::Engine.called_from)
4
- module Thredded
5
- module ApplicationHelper
6
- # include Thredded::Engine.routes.url_helpers
7
- # include Thredded::Workgroup::Engine.routes.url_helpers
8
- #
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thredded
4
- module Workgroup
5
- module ApplicationHelper
6
- end
7
- end
8
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/view_hooks/thredded/all_view_hooks", Thredded::Engine.called_from)
4
-
5
- module Thredded
6
- class AllViewHooks
7
- prepend ::Thredded::Workgroup::ViewHooks
8
- end
9
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/view_models/thredded/topic_view", Thredded::Engine.called_from)
4
- module Thredded
5
- class TopicView < Thredded::BaseTopicView
6
- def path
7
- anchor = if @read_state.first_unread_post_page
8
- "unread"
9
- elsif @topic.last_post
10
- "post_#{@topic.last_post.id}"
11
- end
12
- page = @read_state.first_unread_post_page || @read_state.last_read_post_page
13
- Thredded::UrlsHelper.topic_path(@topic, page: page, anchor: anchor)
14
- end
15
-
16
- def reply_path
17
- Thredded::UrlsHelper.topic_path(@topic, page: last_page, anchor: "new_post")
18
- end
19
-
20
- def mark_as_unread_path
21
- Thredded::UrlsHelper.mark_as_unread_post_path(id: last_post.id, format: :json)
22
- end
23
-
24
- def mark_as_read_path
25
- Thredded::UrlsHelper.mark_as_read_post_path(id: last_post.id, format: :json)
26
- end
27
-
28
- def last_page
29
- (@topic.posts_count / Thredded.posts_per_page.to_f).ceil # TODO: doesn't account for visibility
30
- end
31
- end
32
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency File.expand_path("../../app/view_models/thredded/topics_page_view", Thredded::Engine.called_from)
4
- module Thredded
5
- module TopicsPageViewWithLastPost
6
- protected
7
-
8
- def refine_scope(topics_page_scope)
9
- super.includes(:last_post)
10
- end
11
- end
12
-
13
- class TopicsPageView
14
- prepend ::Thredded::TopicsPageViewWithLastPost
15
- end
16
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This includes this module into Thredded Application Controller so we can use
4
- # url helpers from Thredded PN like unread_nav_path in controllers.
5
- module Thredded
6
- module Workgroup
7
- module RouteDelegator
8
- def self.add_my_proxies_to_thredded
9
- thredded_methods = Thredded::Engine.routes.url_helpers.methods
10
- my_route_helpers = Thredded::Workgroup::Engine.routes.url_helpers
11
- path_methods = my_route_helpers.methods.select { |s| s.to_s.ends_with?("_path", "_url") }
12
- .reject { |s| thredded_methods.include?(s) }
13
- path_methods.each do |method_name|
14
- send(:define_method, method_name) do |*args|
15
- my_route_helpers.send(method_name, *args)
16
- end
17
- end
18
- ::Thredded::ApplicationController.send(:include,
19
- ::Thredded::Workgroup::RouteDelegator)
20
- # if we need to use in views, then we add
21
- # ::Thredded::ApplicationController.helper(::Thredded::Workgroup::RouteDelegator)
22
- end
23
- end
24
- end
25
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thredded
4
- module Workgroup
5
- module ThreddedRouteDelegator
6
- def self.add_thredded_proxies
7
- thredded = Thredded::Engine.routes.url_helpers
8
- path_methods = thredded.methods.select { |s| s.to_s.ends_with?("_path", "_url") }
9
- path_methods.each do |method_name|
10
- send(:define_method, method_name) do |*args|
11
- thredded.send(method_name, *args)
12
- end
13
- end
14
- ::Thredded::Workgroup::ApplicationController.helper(
15
- ::Thredded::Workgroup::ThreddedRouteDelegator
16
- )
17
- end
18
- end
19
- end
20
- end