context_drop 0.2.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.md +149 -12
- data/Rakefile +110 -1
- data/app/assets/javascripts/context_drop/context_drop.js +1759 -105
- data/app/controllers/context_drop/application_controller.rb +52 -3
- data/app/controllers/context_drop/configs_controller.rb +10 -1
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +99 -14
- data/app/controllers/context_drop/feedbacks_controller.rb +536 -17
- data/app/helpers/context_drop/dashboard_helper.rb +4 -0
- data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +355 -1
- data/app/javascript/context_drop/api-client.ts +343 -22
- data/app/javascript/context_drop/element-picker.ts +1 -1
- data/app/javascript/context_drop/icons.ts +6 -0
- data/app/javascript/context_drop/screenshot.ts +1 -1
- data/app/javascript/context_drop/styles.ts +311 -0
- data/app/javascript/context_drop/types.ts +141 -6
- data/app/javascript/context_drop/widget.ts +1072 -35
- data/app/models/context_drop/attachment.rb +5 -0
- data/app/models/context_drop/comment.rb +50 -0
- data/app/models/context_drop/feedback.rb +81 -11
- data/app/services/context_drop/ownership_token.rb +114 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +14 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +169 -2
- data/app/views/layouts/context_drop/application.html.erb +131 -7
- data/config/routes.rb +16 -1
- data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
- data/db/migrate/20261116000001_create_context_drop_comments_and_update_statuses.rb +44 -0
- data/lib/context_drop/agent/orchestrator.rb +1 -1
- data/lib/context_drop/configuration.rb +26 -0
- data/lib/context_drop/mcp/dispatcher.rb +2 -1
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +5 -3
- data/lib/context_drop/mcp/server.rb +1 -0
- data/lib/context_drop/mcp/tools/add_feedback_comment.rb +139 -0
- data/lib/context_drop/mcp/tools/get_feedback.rb +45 -6
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +3 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +23 -3
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +5 -3
- data/lib/context_drop/version.rb +1 -1
- metadata +7 -2
|
@@ -10,6 +10,11 @@ module ContextDrop
|
|
|
10
10
|
class_name: "ContextDrop::Feedback",
|
|
11
11
|
inverse_of: :attachments
|
|
12
12
|
|
|
13
|
+
belongs_to :comment,
|
|
14
|
+
class_name: "ContextDrop::Comment",
|
|
15
|
+
optional: true,
|
|
16
|
+
inverse_of: :attachments
|
|
17
|
+
|
|
13
18
|
belongs_to :element_reference,
|
|
14
19
|
class_name: "ContextDrop::ElementReference",
|
|
15
20
|
optional: true,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
class Comment < ApplicationRecord
|
|
5
|
+
self.table_name = "context_drop_comments"
|
|
6
|
+
|
|
7
|
+
belongs_to :feedback,
|
|
8
|
+
class_name: "ContextDrop::Feedback",
|
|
9
|
+
inverse_of: :comments
|
|
10
|
+
|
|
11
|
+
has_many :attachments,
|
|
12
|
+
class_name: "ContextDrop::Attachment",
|
|
13
|
+
foreign_key: :comment_id,
|
|
14
|
+
inverse_of: :comment,
|
|
15
|
+
dependent: :destroy
|
|
16
|
+
|
|
17
|
+
validate :ensure_body_or_attachments_present
|
|
18
|
+
validate :ensure_attachments_limit
|
|
19
|
+
|
|
20
|
+
before_validation :normalize_metadata
|
|
21
|
+
|
|
22
|
+
def display_author_label
|
|
23
|
+
return author_label.to_s if author_label.present?
|
|
24
|
+
return "#{author_type}##{author_id}" if author_type.present? && author_id.present?
|
|
25
|
+
|
|
26
|
+
"Submitter"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def normalize_metadata
|
|
32
|
+
self.metadata = {} unless metadata.is_a?(Hash)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def ensure_body_or_attachments_present
|
|
36
|
+
has_body = body.to_s.strip != ""
|
|
37
|
+
has_attachments = attachments.reject(&:marked_for_destruction?).any?
|
|
38
|
+
return if has_body || has_attachments
|
|
39
|
+
|
|
40
|
+
errors.add(:base, "Comment must include text or an image attachment")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def ensure_attachments_limit
|
|
44
|
+
max_att = ContextDrop.config.max_attachments.to_i
|
|
45
|
+
return unless attachments.reject(&:marked_for_destruction?).size > max_att
|
|
46
|
+
|
|
47
|
+
errors.add(:attachments, "exceeds maximum allowed (#{max_att})")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -4,26 +4,41 @@ module ContextDrop
|
|
|
4
4
|
class Feedback < ApplicationRecord
|
|
5
5
|
self.table_name = "context_drop_feedbacks"
|
|
6
6
|
|
|
7
|
-
STATUSES = %w[new reviewed
|
|
7
|
+
STATUSES = %w[new updated fixed reviewed dismissed].freeze
|
|
8
8
|
|
|
9
9
|
belongs_to :submitter, polymorphic: true, optional: true
|
|
10
10
|
|
|
11
|
+
has_many :element_references,
|
|
12
|
+
class_name: "ContextDrop::ElementReference",
|
|
13
|
+
foreign_key: :feedback_id,
|
|
14
|
+
inverse_of: :feedback,
|
|
15
|
+
dependent: :destroy
|
|
16
|
+
|
|
11
17
|
has_many :attachments,
|
|
18
|
+
-> { where(comment_id: nil) },
|
|
12
19
|
class_name: "ContextDrop::Attachment",
|
|
13
20
|
foreign_key: :feedback_id,
|
|
14
21
|
inverse_of: :feedback,
|
|
15
22
|
dependent: :destroy
|
|
16
23
|
|
|
17
|
-
has_many :
|
|
18
|
-
|
|
24
|
+
has_many :comments,
|
|
25
|
+
-> { order(created_at: :asc, id: :asc) },
|
|
26
|
+
class_name: "ContextDrop::Comment",
|
|
19
27
|
foreign_key: :feedback_id,
|
|
20
28
|
inverse_of: :feedback,
|
|
21
29
|
dependent: :destroy
|
|
22
30
|
|
|
23
|
-
scope :
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
scope :
|
|
31
|
+
scope :active, lambda {
|
|
32
|
+
column_names.include?("deleted_at") ? where(deleted_at: nil) : all
|
|
33
|
+
}
|
|
34
|
+
scope :deleted, lambda {
|
|
35
|
+
column_names.include?("deleted_at") ? where.not(deleted_at: nil) : none
|
|
36
|
+
}
|
|
37
|
+
scope :new_records, -> { active.where(status: "new") }
|
|
38
|
+
scope :updated_records, -> { active.where(status: "updated") }
|
|
39
|
+
scope :fixed, -> { active.where(status: "fixed") }
|
|
40
|
+
scope :reviewed, -> { active.where(status: "reviewed") }
|
|
41
|
+
scope :dismissed, -> { active.where(status: "dismissed") }
|
|
27
42
|
scope :recent, -> { order(created_at: :desc, id: :desc) }
|
|
28
43
|
scope :for_environment, lambda { |env|
|
|
29
44
|
normalized = env.to_s.strip.downcase
|
|
@@ -41,18 +56,73 @@ module ContextDrop
|
|
|
41
56
|
|
|
42
57
|
before_validation :normalize_defaults
|
|
43
58
|
|
|
44
|
-
def
|
|
45
|
-
update!(status: "
|
|
59
|
+
def mark_updated!
|
|
60
|
+
update!(status: "updated")
|
|
46
61
|
end
|
|
47
62
|
|
|
48
|
-
def
|
|
49
|
-
update!(status: "
|
|
63
|
+
def mark_fixed!
|
|
64
|
+
update!(status: "fixed")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def mark_reviewed!
|
|
68
|
+
update!(status: "reviewed")
|
|
50
69
|
end
|
|
51
70
|
|
|
52
71
|
def mark_dismissed!
|
|
53
72
|
update!(status: "dismissed")
|
|
54
73
|
end
|
|
55
74
|
|
|
75
|
+
def deleted?
|
|
76
|
+
if has_attribute?(:deleted_at)
|
|
77
|
+
!self[:deleted_at].nil?
|
|
78
|
+
elsif metadata.is_a?(Hash)
|
|
79
|
+
metadata["deleted_at"].present?
|
|
80
|
+
else
|
|
81
|
+
false
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def deleted_at_value
|
|
86
|
+
if has_attribute?(:deleted_at)
|
|
87
|
+
self[:deleted_at]
|
|
88
|
+
elsif metadata.is_a?(Hash) && metadata["deleted_at"].present?
|
|
89
|
+
begin
|
|
90
|
+
Time.iso8601(metadata["deleted_at"].to_s)
|
|
91
|
+
rescue ArgumentError
|
|
92
|
+
nil
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def soft_delete!(timestamp = Time.current)
|
|
98
|
+
if has_attribute?(:deleted_at)
|
|
99
|
+
update_columns(deleted_at: timestamp, updated_at: timestamp)
|
|
100
|
+
self[:deleted_at] = timestamp
|
|
101
|
+
self[:updated_at] = timestamp
|
|
102
|
+
else
|
|
103
|
+
next_meta = (metadata.is_a?(Hash) ? metadata.dup : {}).merge("deleted_at" => timestamp.utc.iso8601)
|
|
104
|
+
update_columns(metadata: next_meta, updated_at: timestamp)
|
|
105
|
+
self[:metadata] = next_meta
|
|
106
|
+
self[:updated_at] = timestamp
|
|
107
|
+
end
|
|
108
|
+
true
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def restore!
|
|
112
|
+
now = Time.current
|
|
113
|
+
if has_attribute?(:deleted_at)
|
|
114
|
+
update_columns(deleted_at: nil, updated_at: now)
|
|
115
|
+
self[:deleted_at] = nil
|
|
116
|
+
self[:updated_at] = now
|
|
117
|
+
elsif metadata.is_a?(Hash)
|
|
118
|
+
next_meta = metadata.except("deleted_at")
|
|
119
|
+
update_columns(metadata: next_meta, updated_at: now)
|
|
120
|
+
self[:metadata] = next_meta
|
|
121
|
+
self[:updated_at] = now
|
|
122
|
+
end
|
|
123
|
+
true
|
|
124
|
+
end
|
|
125
|
+
|
|
56
126
|
def environment_name
|
|
57
127
|
if has_attribute?(:environment) && self[:environment].present?
|
|
58
128
|
self[:environment].to_s
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "openssl"
|
|
4
|
+
require "securerandom"
|
|
5
|
+
|
|
6
|
+
module ContextDrop
|
|
7
|
+
module OwnershipToken
|
|
8
|
+
MAX_TOKENS_HEADER_COUNT = 50
|
|
9
|
+
TOKEN_DOMAIN = "cd_own:v1"
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def generate(feedback_id, secret: nil)
|
|
13
|
+
id_str = feedback_id.to_s.strip
|
|
14
|
+
raise ArgumentError, "feedback_id cannot be blank" if id_str.empty?
|
|
15
|
+
|
|
16
|
+
nonce = SecureRandom.hex(8)
|
|
17
|
+
sig = compute_hmac(id_str, nonce, secret || resolved_secret)
|
|
18
|
+
"#{id_str}.#{nonce}.#{sig}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def valid?(token, feedback_id, secret: nil)
|
|
22
|
+
return false if token.nil? || feedback_id.nil?
|
|
23
|
+
|
|
24
|
+
raw_token = token.to_s.strip
|
|
25
|
+
target_id = feedback_id.to_s.strip
|
|
26
|
+
return false if raw_token.empty? || target_id.empty?
|
|
27
|
+
|
|
28
|
+
id_part, nonce_part, sig_part = raw_token.split(".", 3)
|
|
29
|
+
return false if id_part.nil? || nonce_part.nil? || sig_part.nil?
|
|
30
|
+
return false unless id_part == target_id
|
|
31
|
+
return false if nonce_part.empty? || sig_part.empty?
|
|
32
|
+
|
|
33
|
+
expected = compute_hmac(target_id, nonce_part, secret || resolved_secret)
|
|
34
|
+
ActiveSupport::SecurityUtils.secure_compare(sig_part, expected)
|
|
35
|
+
rescue StandardError
|
|
36
|
+
false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def extract_verified_ids(raw_tokens, secret: nil)
|
|
40
|
+
tokens = case raw_tokens
|
|
41
|
+
when Array
|
|
42
|
+
raw_tokens
|
|
43
|
+
when String
|
|
44
|
+
raw_tokens.split(",")
|
|
45
|
+
else
|
|
46
|
+
[]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
key = secret || resolved_secret
|
|
50
|
+
verified = []
|
|
51
|
+
|
|
52
|
+
tokens.first(MAX_TOKENS_HEADER_COUNT).each do |raw|
|
|
53
|
+
tok = raw.to_s.strip
|
|
54
|
+
next if tok.empty?
|
|
55
|
+
|
|
56
|
+
id_part, nonce_part, sig_part = tok.split(".", 3)
|
|
57
|
+
next if id_part.nil? || nonce_part.nil? || sig_part.nil?
|
|
58
|
+
next if id_part.empty? || nonce_part.empty? || sig_part.empty?
|
|
59
|
+
|
|
60
|
+
expected = compute_hmac(id_part, nonce_part, key)
|
|
61
|
+
verified << id_part if ActiveSupport::SecurityUtils.secure_compare(sig_part, expected)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
verified.uniq
|
|
65
|
+
rescue StandardError
|
|
66
|
+
[]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def find_token_for(raw_tokens, feedback_id, secret: nil)
|
|
70
|
+
tokens = case raw_tokens
|
|
71
|
+
when Array
|
|
72
|
+
raw_tokens
|
|
73
|
+
when String
|
|
74
|
+
raw_tokens.split(",")
|
|
75
|
+
else
|
|
76
|
+
[]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
key = secret || resolved_secret
|
|
80
|
+
tokens.first(MAX_TOKENS_HEADER_COUNT).each do |raw|
|
|
81
|
+
tok = raw.to_s.strip
|
|
82
|
+
return tok if valid?(tok, feedback_id, secret: key)
|
|
83
|
+
end
|
|
84
|
+
nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def resolved_secret
|
|
88
|
+
configured = ContextDrop.config.respond_to?(:ownership_secret) ? ContextDrop.config.ownership_secret.to_s.strip : ""
|
|
89
|
+
return configured unless configured.empty?
|
|
90
|
+
|
|
91
|
+
env_secret = ENV["CONTEXT_DROP_SECRET_KEY"].to_s.strip
|
|
92
|
+
return env_secret unless env_secret.empty?
|
|
93
|
+
|
|
94
|
+
if defined?(Rails) && Rails.respond_to?(:application) && Rails.application
|
|
95
|
+
rails_secret = Rails.application.secret_key_base.to_s.strip rescue ""
|
|
96
|
+
return rails_secret unless rails_secret.empty?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
fallback_secret
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
def compute_hmac(id_str, nonce, secret)
|
|
105
|
+
OpenSSL::HMAC.hexdigest("SHA256", secret.to_s, "#{TOKEN_DOMAIN}:#{id_str}:#{nonce}")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def fallback_secret
|
|
109
|
+
@fallback_secret ||= SecureRandom.hex(32)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
<span class="cd-tab-count"><%= @status_counts[status_name] || 0 %></span>
|
|
12
12
|
</a>
|
|
13
13
|
<% end %>
|
|
14
|
+
<a href="<%= dashboard_feedbacks_path(status: 'deleted', q: @search_query.presence, page_url: @page_url_filter.presence) %>"
|
|
15
|
+
class="cd-tab <%= 'active' if @current_status == 'deleted' %>">
|
|
16
|
+
<span>Deleted</span>
|
|
17
|
+
<span class="cd-tab-count"><%= @status_counts["deleted"] || 0 %></span>
|
|
18
|
+
</a>
|
|
14
19
|
</div>
|
|
15
20
|
|
|
16
21
|
<div class="cd-card cd-card-tight">
|
|
@@ -80,6 +85,9 @@
|
|
|
80
85
|
</td>
|
|
81
86
|
<td>
|
|
82
87
|
<span class="cd-badge cd-badge-<%= fb.status %>"><%= fb.status %></span>
|
|
88
|
+
<% if fb.respond_to?(:deleted?) && fb.deleted? %>
|
|
89
|
+
<span class="cd-badge cd-badge-deleted" style="margin-top: 0.2rem;">deleted</span>
|
|
90
|
+
<% end %>
|
|
83
91
|
</td>
|
|
84
92
|
<td>
|
|
85
93
|
<div style="font-weight: 500; color: var(--cd-text); margin-bottom: 0.25rem; line-height: 1.4;">
|
|
@@ -97,6 +105,12 @@
|
|
|
97
105
|
<span><%= fb.attachments.size %></span>
|
|
98
106
|
</span>
|
|
99
107
|
<% end %>
|
|
108
|
+
<% if fb.comments.size > 0 %>
|
|
109
|
+
<span class="cd-context-chip" title="<%= fb.comments.size %> comment(s)">
|
|
110
|
+
<%= cd_icon_comment(size: 11) %>
|
|
111
|
+
<span><%= fb.comments.size %></span>
|
|
112
|
+
</span>
|
|
113
|
+
<% end %>
|
|
100
114
|
<% if fb.element_references.size > 0 %>
|
|
101
115
|
<span class="cd-context-chip" title="<%= fb.element_references.size %> element reference(s)">
|
|
102
116
|
<%= cd_icon_pin(size: 11) %>
|
|
@@ -53,13 +53,18 @@
|
|
|
53
53
|
Feedback #<%= @feedback.id %>
|
|
54
54
|
</h1>
|
|
55
55
|
<span class="cd-badge cd-badge-<%= @feedback.status %>"><%= @feedback.status %></span>
|
|
56
|
+
<% if @feedback.respond_to?(:deleted?) && @feedback.deleted? %>
|
|
57
|
+
<span class="cd-badge cd-badge-deleted">deleted</span>
|
|
58
|
+
<% end %>
|
|
56
59
|
</div>
|
|
57
60
|
</div>
|
|
58
61
|
|
|
59
62
|
<div style="display: flex; gap: 0.375rem; flex-wrap: wrap; align-items: center;">
|
|
63
|
+
<% primary_status = @feedback.status == "fixed" ? "reviewed" : "fixed" %>
|
|
60
64
|
<% [
|
|
61
|
-
["
|
|
62
|
-
["
|
|
65
|
+
["updated", "Mark Updated", primary_status == "updated" ? "cd-btn-primary" : ""],
|
|
66
|
+
["fixed", "Mark Fixed", primary_status == "fixed" ? "cd-btn-primary" : ""],
|
|
67
|
+
["reviewed", "Mark Reviewed", primary_status == "reviewed" ? "cd-btn-primary" : ""],
|
|
63
68
|
["dismissed", "Dismiss", ""]
|
|
64
69
|
].each do |target_status, label, extra_class| %>
|
|
65
70
|
<%= form_with url: dashboard_feedback_path(@feedback), method: :patch, local: true, style: "display: inline;" do %>
|
|
@@ -109,6 +114,12 @@
|
|
|
109
114
|
<dd style="font-family: var(--cd-font-mono); font-variant-numeric: tabular-nums;">
|
|
110
115
|
<%= @feedback.created_at&.strftime("%Y-%m-%d %H:%M:%S UTC") %>
|
|
111
116
|
</dd>
|
|
117
|
+
<% if @feedback.respond_to?(:deleted?) && @feedback.deleted? %>
|
|
118
|
+
<dt>Deleted At</dt>
|
|
119
|
+
<dd style="font-family: var(--cd-font-mono); font-variant-numeric: tabular-nums; color: #b91c1c;">
|
|
120
|
+
<%= @feedback.deleted_at_value&.strftime("%Y-%m-%d %H:%M:%S UTC") %>
|
|
121
|
+
</dd>
|
|
122
|
+
<% end %>
|
|
112
123
|
<dt>User Agent</dt>
|
|
113
124
|
<dd style="font-size: 0.75rem; color: var(--cd-text-secondary);"><%= @feedback.user_agent.presence || "N/A" %></dd>
|
|
114
125
|
<dt>Metadata</dt>
|
|
@@ -222,8 +233,164 @@
|
|
|
222
233
|
<% end %>
|
|
223
234
|
</div>
|
|
224
235
|
|
|
236
|
+
<div class="cd-card">
|
|
237
|
+
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.875rem;">
|
|
238
|
+
<h2 style="margin: 0; font-size: 0.9375rem; font-weight: 600; display: inline-flex; align-items: center; gap: 0.4rem;">
|
|
239
|
+
<%= cd_icon_comment(size: 14) %>
|
|
240
|
+
<span>Comments</span>
|
|
241
|
+
<span class="cd-tab-count"><%= @feedback.comments.size %></span>
|
|
242
|
+
</h2>
|
|
243
|
+
<span style="font-size: 0.75rem; color: var(--cd-muted);">Adding a comment sets status to <strong>Updated</strong></span>
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
<% if @feedback.comments.empty? %>
|
|
247
|
+
<p style="color: var(--cd-muted); margin: 0 0 1rem 0; font-size: 0.8125rem;">No comments yet. Add a note or screenshot below to follow up.</p>
|
|
248
|
+
<% else %>
|
|
249
|
+
<div class="cd-comment-list">
|
|
250
|
+
<% @feedback.comments.each do |comment| %>
|
|
251
|
+
<div class="cd-comment-item" id="comment-<%= comment.id %>">
|
|
252
|
+
<div class="cd-comment-header">
|
|
253
|
+
<span class="cd-comment-author">
|
|
254
|
+
<%= cd_icon_user(size: 12) %>
|
|
255
|
+
<span><%= comment.display_author_label %></span>
|
|
256
|
+
</span>
|
|
257
|
+
<span class="cd-comment-time"><%= comment.created_at&.strftime("%Y-%m-%d %H:%M:%S UTC") %></span>
|
|
258
|
+
</div>
|
|
259
|
+
<% if comment.body.present? %>
|
|
260
|
+
<p class="cd-comment-body"><%= comment.body %></p>
|
|
261
|
+
<% end %>
|
|
262
|
+
<% if comment.attachments.any? %>
|
|
263
|
+
<div class="cd-comment-images">
|
|
264
|
+
<% comment.attachments.each do |att| %>
|
|
265
|
+
<% if att.respond_to?(:file) && att.file.attached? && main_app.respond_to?(:url_for) %>
|
|
266
|
+
<a href="<%= main_app.url_for(att.file) %>" target="_blank" rel="noopener noreferrer" title="<%= att.file.filename %>">
|
|
267
|
+
<img src="<%= main_app.url_for(att.file) %>"
|
|
268
|
+
alt="Comment attachment #<%= att.id %>"
|
|
269
|
+
class="cd-comment-thumb" />
|
|
270
|
+
</a>
|
|
271
|
+
<% end %>
|
|
272
|
+
<% end %>
|
|
273
|
+
</div>
|
|
274
|
+
<% end %>
|
|
275
|
+
</div>
|
|
276
|
+
<% end %>
|
|
277
|
+
</div>
|
|
278
|
+
<% end %>
|
|
279
|
+
|
|
280
|
+
<%= form_with url: comments_dashboard_feedback_path(@feedback), method: :post, multipart: true, local: true, class: "cd-comment-form", id: "cd-dashboard-comment-form" do %>
|
|
281
|
+
<textarea name="body"
|
|
282
|
+
id="cd-dashboard-comment-body"
|
|
283
|
+
class="cd-comment-textarea"
|
|
284
|
+
placeholder="Write a comment... (You can paste or attach images below)"
|
|
285
|
+
aria-label="Comment body"></textarea>
|
|
286
|
+
<div class="cd-comment-previews" id="cd-dashboard-comment-previews" hidden></div>
|
|
287
|
+
<div class="cd-comment-toolbar">
|
|
288
|
+
<div style="display: flex; align-items: center; gap: 0.5rem;">
|
|
289
|
+
<label for="cd-dashboard-comment-images" class="cd-btn cd-btn-sm" style="cursor: pointer;">
|
|
290
|
+
<%= cd_icon_attachment(size: 13) %>
|
|
291
|
+
<span>Attach Images</span>
|
|
292
|
+
</label>
|
|
293
|
+
<input type="file"
|
|
294
|
+
id="cd-dashboard-comment-images"
|
|
295
|
+
name="images[]"
|
|
296
|
+
multiple
|
|
297
|
+
accept="image/png,image/jpeg,image/webp,image/gif"
|
|
298
|
+
style="display: none;">
|
|
299
|
+
<span style="font-size: 0.75rem; color: var(--cd-muted);" id="cd-dashboard-comment-files-label"></span>
|
|
300
|
+
</div>
|
|
301
|
+
<button type="submit" class="cd-btn cd-btn-sm cd-btn-primary">Post Comment</button>
|
|
302
|
+
</div>
|
|
303
|
+
<% end %>
|
|
304
|
+
</div>
|
|
305
|
+
|
|
225
306
|
<script>
|
|
226
307
|
(function() {
|
|
308
|
+
var form = document.getElementById("cd-dashboard-comment-form");
|
|
309
|
+
var textarea = document.getElementById("cd-dashboard-comment-body");
|
|
310
|
+
var fileInput = document.getElementById("cd-dashboard-comment-images");
|
|
311
|
+
var previews = document.getElementById("cd-dashboard-comment-previews");
|
|
312
|
+
var filesLabel = document.getElementById("cd-dashboard-comment-files-label");
|
|
313
|
+
var selectedFiles = [];
|
|
314
|
+
|
|
315
|
+
function syncFileInput() {
|
|
316
|
+
if (!fileInput || typeof DataTransfer === "undefined") return;
|
|
317
|
+
var dt = new DataTransfer();
|
|
318
|
+
selectedFiles.forEach(function(f) { dt.items.add(f); });
|
|
319
|
+
fileInput.files = dt.files;
|
|
320
|
+
renderPreviews();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function renderPreviews() {
|
|
324
|
+
if (!previews || !filesLabel) return;
|
|
325
|
+
previews.innerHTML = "";
|
|
326
|
+
if (selectedFiles.length === 0) {
|
|
327
|
+
previews.hidden = true;
|
|
328
|
+
filesLabel.textContent = "";
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
previews.hidden = false;
|
|
332
|
+
filesLabel.textContent = selectedFiles.length + " image(s) selected";
|
|
333
|
+
selectedFiles.forEach(function(file, idx) {
|
|
334
|
+
var chip = document.createElement("span");
|
|
335
|
+
chip.className = "cd-comment-preview-chip";
|
|
336
|
+
var img = document.createElement("img");
|
|
337
|
+
img.alt = file.name;
|
|
338
|
+
var reader = new FileReader();
|
|
339
|
+
reader.onload = function(ev) { img.src = ev.target.result; };
|
|
340
|
+
reader.readAsDataURL(file);
|
|
341
|
+
var nameSpan = document.createElement("span");
|
|
342
|
+
nameSpan.textContent = file.name.length > 24 ? file.name.slice(0, 21) + "..." : file.name;
|
|
343
|
+
var rmBtn = document.createElement("button");
|
|
344
|
+
rmBtn.type = "button";
|
|
345
|
+
rmBtn.textContent = "×";
|
|
346
|
+
rmBtn.setAttribute("aria-label", "Remove image");
|
|
347
|
+
rmBtn.style.cssText = "border:none;background:none;cursor:pointer;font-size:14px;color:var(--cd-muted);padding:0 2px;";
|
|
348
|
+
rmBtn.addEventListener("click", function() {
|
|
349
|
+
selectedFiles.splice(idx, 1);
|
|
350
|
+
syncFileInput();
|
|
351
|
+
});
|
|
352
|
+
chip.appendChild(img);
|
|
353
|
+
chip.appendChild(nameSpan);
|
|
354
|
+
chip.appendChild(rmBtn);
|
|
355
|
+
previews.appendChild(chip);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (fileInput) {
|
|
360
|
+
fileInput.addEventListener("change", function() {
|
|
361
|
+
if (fileInput.files && fileInput.files.length > 0) {
|
|
362
|
+
Array.prototype.forEach.call(fileInput.files, function(f) { selectedFiles.push(f); });
|
|
363
|
+
syncFileInput();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (textarea) {
|
|
369
|
+
textarea.addEventListener("keydown", function(e) {
|
|
370
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter" && form) {
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
form.submit();
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
textarea.addEventListener("paste", function(e) {
|
|
376
|
+
var items = e.clipboardData && e.clipboardData.items;
|
|
377
|
+
if (!items) return;
|
|
378
|
+
var added = false;
|
|
379
|
+
for (var i = 0; i < items.length; i++) {
|
|
380
|
+
if (items[i].type && items[i].type.indexOf("image/") === 0) {
|
|
381
|
+
var file = items[i].getAsFile();
|
|
382
|
+
if (file) {
|
|
383
|
+
selectedFiles.push(file);
|
|
384
|
+
added = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (added) {
|
|
389
|
+
syncFileInput();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
227
394
|
window.addEventListener("keydown", function(e) {
|
|
228
395
|
if (e.target && (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA" || e.target.tagName === "SELECT" || e.target.isContentEditable)) {
|
|
229
396
|
return;
|