Skip to content

Commit 09c2529

Browse files
authored
Merge pull request #2394 from tf/commenting-badge
Support rendering commenting badges on elements in preview
2 parents 1015876 + f004fa4 commit 09c2529

41 files changed

Lines changed: 865 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/assets/stylesheets/pageflow/ui/properties.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
--ui-box-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
5858
--ui-box-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
5959

60+
--ui-accent-color: #ffd24d;
61+
--ui-accent-color-glow: #ffd24d3d;
62+
--ui-on-accent-color: #795f0f;
63+
6064
--ui-on-button-color: var(--ui-primary-color);
6165
--ui-button-border-color: var(--ui-primary-color-light);
6266
--ui-button-hover-border-color: var(--ui-primary-color);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Pageflow
2+
module Review
3+
# @api private
4+
class CommentThreadsController < Pageflow::ApplicationController
5+
respond_to :json
6+
before_action :authenticate_user!
7+
8+
def index
9+
entry = DraftEntry.find(params[:entry_id])
10+
authorize!(:read, entry.to_model)
11+
12+
@comment_threads = entry.comment_threads.includes(comments: :creator)
13+
end
14+
end
15+
end
16+
end

app/models/pageflow/comment.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Pageflow
2+
# @api private
3+
class Comment < ApplicationRecord
4+
include NestedRevisionComponent
5+
6+
belongs_to :comment_thread
7+
belongs_to :creator, class_name: 'User'
8+
9+
validates :body, presence: true
10+
11+
def entry_for_auto_generated_perma_id
12+
comment_thread.revision.entry
13+
end
14+
end
15+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Pageflow
2+
# @api private
3+
class CommentThread < ApplicationRecord
4+
include RevisionComponent
5+
6+
belongs_to :creator, class_name: 'User'
7+
has_many :comments, dependent: :destroy
8+
9+
nested_revision_components :comments
10+
11+
validates :subject_type, :subject_id, presence: true
12+
end
13+
end

app/models/pageflow/entry_at_revision.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def initialize(entry, revision, theme: nil)
3838
:author, :publisher, :keywords,
3939
:published_at,
4040
:noindex?,
41+
:comment_threads,
4142
:configuration,
4243
:structured_data_type_name,
4344
to: :revision)

app/models/pageflow/revision.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Revision < ApplicationRecord # rubocop:todo Style/Documentation
2727
has_many :chapters, -> { order(CHAPTER_ORDER) }, through: :storylines
2828
has_many :pages, -> { reorder(PAGE_ORDER) }, through: :storylines
2929

30+
has_many :comment_threads, dependent: :destroy
31+
3032
has_many :file_usages, dependent: :destroy
3133

3234
has_many :image_files, -> { extending WithFileUsageExtension },
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
json.key_format!(camelize: :lower)
2+
3+
json.call(comment_thread,
4+
:id,
5+
:perma_id,
6+
:subject_type,
7+
:subject_id,
8+
:creator_id,
9+
:resolved_at,
10+
:created_at,
11+
:updated_at)
12+
13+
json.comments(comment_thread.comments) do |comment|
14+
json.partial!('pageflow/review/comments/comment', comment:)
15+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
json.key_format!(camelize: :lower)
2+
3+
json.current_user do
4+
json.id current_user.id
5+
json.name current_user.full_name
6+
end
7+
8+
json.comment_threads(@comment_threads) do |comment_thread|
9+
json.partial!('pageflow/review/comment_threads/comment_thread', comment_thread:)
10+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
json.key_format!(camelize: :lower)
2+
3+
json.call(comment,
4+
:id,
5+
:perma_id,
6+
:creator_id,
7+
:body,
8+
:created_at,
9+
:updated_at)
10+
11+
json.creator_name comment.creator.full_name

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
resource :oembed, only: [:show]
7878
end
7979

80+
namespace :review do
81+
resources :entries, only: [] do
82+
resources :comment_threads, only: [:index]
83+
end
84+
end
85+
8086
root to: redirect('/admin')
8187
end
8288

0 commit comments

Comments
 (0)