lesli_view 1.1.4 → 1.1.6
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/Rakefile +8 -0
- data/app/assets/stylesheets/lesli_view/view.css +4446 -0
- data/lib/lesli_view/components/header.html.erb +1 -1
- data/lib/lesli_view/components/timeline.html.erb +38 -25
- data/lib/lesli_view/components/timeline.rb +18 -5
- data/lib/lesli_view/forms/builder_horizontal.rb +4 -0
- data/lib/lesli_view/forms/fields.rb +14 -0
- data/lib/lesli_view/forms/inputs.rb +0 -1
- data/lib/lesli_view/items/activities.html.erb +5 -1
- data/lib/lesli_view/items/activities.rb +111 -11
- data/lib/lesli_view/items/attachment.html.erb +45 -0
- data/lib/lesli_view/items/attachment.rb +63 -0
- data/lib/lesli_view/items/attachments.html.erb +69 -34
- data/lib/lesli_view/items/attachments.rb +38 -2
- data/lib/lesli_view/items/discussion.html.erb +7 -5
- data/lib/lesli_view/items/discussion.rb +26 -0
- data/lib/lesli_view/items/discussions.html.erb +32 -17
- data/lib/lesli_view/items/discussions.rb +27 -5
- data/lib/lesli_view/items/task.html.erb +15 -6
- data/lib/lesli_view/items/task.rb +14 -0
- data/lib/lesli_view/items/tasks.html.erb +28 -15
- data/lib/lesli_view/items/tasks.rb +27 -2
- data/lib/lesli_view/version.rb +2 -2
- data/lib/lesli_view.rb +1 -0
- data/readme.md +3 -3
- metadata +18 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
<section
|
|
3
|
-
class="mx-auto
|
|
3
|
+
class="mx-auto mt-14 mb-10 grid w-full grid-cols-1 gap-5 md:grid-cols-[minmax(0,1fr)_auto] md:items-start"
|
|
4
4
|
<% if title.present? %>aria-labelledby="<%= title_id %>"<% end %>>
|
|
5
5
|
|
|
6
6
|
<div class="min-w-0">
|
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
<div class="lesli-timelines py-6">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
<
|
|
7
|
-
|
|
2
|
+
<% if activities.any? %>
|
|
3
|
+
<ul class="m-0 w-full list-none p-0">
|
|
4
|
+
<% activities.each do |activity| %>
|
|
5
|
+
<li class="group grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 md:grid-cols-[minmax(8rem,auto)_1.5rem_minmax(0,1fr)] md:gap-x-6">
|
|
6
|
+
<div class="col-start-2 mb-2 min-w-0 text-xs font-bold uppercase tracking-[0.2em] text-slate-500 md:col-start-1 md:row-start-1 md:mb-0 md:pt-1 md:text-right">
|
|
7
|
+
<time><%= activity["date"] %></time>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
</
|
|
15
|
-
<span class="absolute top-7 bottom-0 left-1/2 w-px -translate-x-1/2 bg-slate-300 group-last:hidden" aria-hidden="true"></span>
|
|
16
|
-
</div>
|
|
9
|
+
<% if activity["actor"].present? %>
|
|
10
|
+
<span class="mt-1 block font-normal normal-case tracking-normal text-slate-400">
|
|
11
|
+
<%= activity["actor"] %>
|
|
12
|
+
</span>
|
|
13
|
+
<% end %>
|
|
14
|
+
</div>
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
<div class="relative col-start-1 row-span-2 row-start-1 flex justify-center md:col-start-2">
|
|
17
|
+
<span
|
|
18
|
+
class="material-symbols-outlined relative z-10 bg-white text-xl leading-none text-[var(--lesli-color-primary)]"
|
|
19
|
+
aria-hidden="true">
|
|
20
|
+
<%= icon_for(activity) %>
|
|
21
|
+
</span>
|
|
22
|
+
<span class="absolute top-7 bottom-0 left-1/2 w-px -translate-x-1/2 bg-slate-300 group-last:hidden" aria-hidden="true"></span>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div class="col-start-2 row-start-2 min-w-0 pb-10 md:col-start-3 md:row-start-1">
|
|
26
|
+
<h6 class="text-base font-semibold text-slate-800">
|
|
27
|
+
<%= activity["operation"] %>
|
|
28
|
+
</h6>
|
|
29
|
+
|
|
30
|
+
<% if activity["description"].present? %>
|
|
31
|
+
<p class="mt-1 text-sm leading-6 text-slate-600">
|
|
32
|
+
<%= activity["description"] %>
|
|
33
|
+
</p>
|
|
34
|
+
<% end %>
|
|
35
|
+
</div>
|
|
36
|
+
</li>
|
|
37
|
+
<% end %>
|
|
38
|
+
</ul>
|
|
39
|
+
<% else %>
|
|
40
|
+
<%= render LesliView::Elements::Empty.new(text: empty_text) %>
|
|
41
|
+
<% end %>
|
|
29
42
|
</div>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "lesli_view/elements/empty"
|
|
4
|
+
|
|
3
5
|
=begin
|
|
4
6
|
|
|
5
7
|
Lesli
|
|
@@ -35,12 +37,23 @@ Building a better future, one line of code at a time.
|
|
|
35
37
|
module LesliView
|
|
36
38
|
module Components
|
|
37
39
|
class Timeline < ViewComponent::Base
|
|
38
|
-
|
|
40
|
+
DEFAULT_ICON = "radio_button_checked"
|
|
41
|
+
|
|
42
|
+
attr_reader :activities, :empty_text, :icons
|
|
43
|
+
|
|
44
|
+
def initialize(
|
|
45
|
+
activities: [],
|
|
46
|
+
icons: {},
|
|
47
|
+
empty_text: "No activities have been recorded yet."
|
|
48
|
+
)
|
|
49
|
+
@activities = Array(activities)
|
|
50
|
+
@icons = icons.transform_keys(&:to_sym)
|
|
51
|
+
@empty_text = empty_text
|
|
52
|
+
end
|
|
39
53
|
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
@activities = activities
|
|
54
|
+
def icon_for(activity)
|
|
55
|
+
icons.fetch(activity["icon"]&.to_sym, DEFAULT_ICON)
|
|
43
56
|
end
|
|
44
|
-
end
|
|
57
|
+
end
|
|
45
58
|
end
|
|
46
59
|
end
|
|
@@ -25,6 +25,10 @@ module LesliView
|
|
|
25
25
|
super(attribute, label: label, message: message, category: category, icon: icon, horizontal: true, **options)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def field_control_textarea_rich(attribute, label: nil, message: nil, category: nil, icon: nil, **options)
|
|
29
|
+
super(attribute, label: label, message: message, category: category, icon: icon, horizontal: true, **options)
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def field_textarea(attribute, **options)
|
|
29
33
|
field_control_textarea(attribute, **options)
|
|
30
34
|
end
|
|
@@ -81,6 +81,20 @@ module LesliView
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def field_control_textarea(attribute, label: nil, message: nil, category: nil, icon: nil, horizontal: false, **options)
|
|
84
|
+
label_html = label == false ? nil : label(attribute, label)
|
|
85
|
+
control_html = text_area(attribute, options)
|
|
86
|
+
|
|
87
|
+
field_control_builder(
|
|
88
|
+
label_html: label_html,
|
|
89
|
+
control_html: control_html,
|
|
90
|
+
message_text: message,
|
|
91
|
+
category: category,
|
|
92
|
+
horizontal: horizontal,
|
|
93
|
+
icon: icon
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def field_control_textarea_rich(attribute, label: nil, message: nil, category: nil, icon: nil, horizontal: false, **options)
|
|
84
98
|
label_html = label == false ? nil : label(attribute, label)
|
|
85
99
|
control_html = rich_textarea(attribute, options)
|
|
86
100
|
|
|
@@ -38,7 +38,6 @@ module LesliView
|
|
|
38
38
|
def password_field(method, options = {})
|
|
39
39
|
options = options.symbolize_keys
|
|
40
40
|
options[:class] = merge_css_classes("lesli-form-input", options[:class])
|
|
41
|
-
options[:value] = @object.public_send(method) if @object && !options.key?(:value)
|
|
42
41
|
super(method, options)
|
|
43
42
|
end
|
|
44
43
|
|
|
@@ -32,5 +32,9 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
<article
|
|
33
33
|
class="lesli-items-activities bg-white p-4 sm:p-8"
|
|
34
34
|
id="lesli-items-activities">
|
|
35
|
-
<%= render
|
|
35
|
+
<%= render LesliView::Components::Timeline.new(
|
|
36
|
+
activities: activities,
|
|
37
|
+
empty_text: empty_text,
|
|
38
|
+
icons: icons
|
|
39
|
+
) %>
|
|
36
40
|
</article>
|
|
@@ -32,17 +32,117 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
module LesliView
|
|
33
33
|
module Items
|
|
34
34
|
class Activities < ViewComponent::Base
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
DEFAULT_LIMIT = 25
|
|
36
|
+
I18N_SCOPE = "lesli.items.activities"
|
|
37
|
+
DATE_FORMAT = "%Y-%m-%d · %H:%M"
|
|
38
|
+
|
|
39
|
+
attr_reader :activities, :empty_text, :icons, :i18n_scope
|
|
40
|
+
|
|
41
|
+
def initialize(
|
|
42
|
+
resource,
|
|
43
|
+
icons: {},
|
|
44
|
+
i18n_scope: I18N_SCOPE,
|
|
45
|
+
limit: DEFAULT_LIMIT,
|
|
46
|
+
empty_text: nil
|
|
47
|
+
)
|
|
48
|
+
@icons = icons
|
|
49
|
+
@i18n_scope = i18n_scope
|
|
50
|
+
@activities = activity_scope(resource, limit).map do |activity|
|
|
51
|
+
activity_to_timeline(activity)
|
|
52
|
+
end
|
|
53
|
+
@empty_text = empty_text || I18n.t(
|
|
54
|
+
"#{i18n_scope}.empty",
|
|
55
|
+
default: "No activities have been recorded yet."
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def activity_to_timeline(activity)
|
|
62
|
+
metadata = activity.metadata.is_a?(Hash) ? activity.metadata : {}
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
"actor" => actor_name(activity.actor),
|
|
66
|
+
"date" => I18n.l(activity.created_at, format: DATE_FORMAT),
|
|
67
|
+
"description" => activity_description(activity, metadata),
|
|
68
|
+
"icon" => activity.activity_code.to_s,
|
|
69
|
+
"operation" => activity_operation(activity)
|
|
70
|
+
}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def activity_description(activity, metadata)
|
|
74
|
+
I18n.t(
|
|
75
|
+
"#{activity_i18n_key(activity)}.#{description_key(metadata)}",
|
|
76
|
+
from: snapshot_name(metadata_value(metadata, :from)),
|
|
77
|
+
to: snapshot_name(metadata_value(metadata, :to)),
|
|
78
|
+
default: activity.description.to_s
|
|
79
|
+
).presence
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def activity_i18n_key(activity)
|
|
83
|
+
"#{i18n_scope}.events.#{activity.activity_code}"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def activity_operation(activity)
|
|
87
|
+
I18n.t(
|
|
88
|
+
"#{activity_i18n_key(activity)}.operation",
|
|
89
|
+
default: activity.activity_code.to_s.humanize
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def activity_scope(resource, limit)
|
|
94
|
+
resource.activities
|
|
95
|
+
.includes(:actor)
|
|
96
|
+
.reorder(created_at: :desc, id: :desc)
|
|
97
|
+
.limit(normalize_limit(limit))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def actor_name(actor)
|
|
101
|
+
full_name = actor.full_name if actor.respond_to?(:full_name)
|
|
102
|
+
name = actor.name if actor.respond_to?(:name)
|
|
103
|
+
|
|
104
|
+
full_name.presence || name.presence || I18n.t(
|
|
105
|
+
"#{i18n_scope}.unknown_actor",
|
|
106
|
+
default: "Unknown user"
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def description_key(metadata)
|
|
111
|
+
has_change = metadata.key?(:from) || metadata.key?("from") ||
|
|
112
|
+
metadata.key?(:to) || metadata.key?("to")
|
|
113
|
+
|
|
114
|
+
return "description" unless has_change
|
|
115
|
+
return "set" if metadata_value(metadata, :from).nil?
|
|
116
|
+
return "removed" if metadata_value(metadata, :to).nil?
|
|
117
|
+
|
|
118
|
+
"changed"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def metadata_value(metadata, key)
|
|
122
|
+
return metadata[key] if metadata.key?(key)
|
|
123
|
+
|
|
124
|
+
metadata[key.to_s]
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def normalize_limit(limit)
|
|
128
|
+
normalized_limit = Integer(limit)
|
|
129
|
+
return normalized_limit if normalized_limit.positive?
|
|
130
|
+
|
|
131
|
+
raise ArgumentError, "limit must be a positive integer"
|
|
132
|
+
rescue TypeError, ArgumentError
|
|
133
|
+
raise ArgumentError, "limit must be a positive integer"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def snapshot_name(snapshot)
|
|
137
|
+
return "" if snapshot.nil?
|
|
138
|
+
return snapshot.to_s unless snapshot.is_a?(Hash)
|
|
139
|
+
|
|
140
|
+
[:name, :subject, :uid, :id].each do |key|
|
|
141
|
+
value = metadata_value(snapshot, key)
|
|
142
|
+
return value.to_s if value.present?
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
""
|
|
46
146
|
end
|
|
47
147
|
end
|
|
48
148
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<li
|
|
2
|
+
id="<%= dom_id(resource) %>"
|
|
3
|
+
class="flex flex-col gap-4 rounded-xl border border-slate-200 bg-white p-4 sm:flex-row sm:items-center sm:justify-between">
|
|
4
|
+
<div class="flex min-w-0 items-center gap-3">
|
|
5
|
+
<span
|
|
6
|
+
class="material-symbols-outlined shrink-0 text-3xl text-[var(--lesli-color-primary)]"
|
|
7
|
+
aria-hidden="true">
|
|
8
|
+
attach_file
|
|
9
|
+
</span>
|
|
10
|
+
|
|
11
|
+
<div class="min-w-0">
|
|
12
|
+
<p class="truncate text-sm font-medium text-slate-900" title="<%= filename %>">
|
|
13
|
+
<%= display_name %>
|
|
14
|
+
</p>
|
|
15
|
+
<p class="mt-1 text-xs text-slate-500">
|
|
16
|
+
<%= details %>
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
22
|
+
<%= link_to(
|
|
23
|
+
I18n.t("lesli.items.attachments.download", default: "Download"),
|
|
24
|
+
path,
|
|
25
|
+
class: "inline-flex items-center gap-2 rounded-lg border border-slate-300 px-3 py-2 text-sm font-medium text-slate-700 transition-colors hover:border-slate-400 hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--lesli-color-primary)]",
|
|
26
|
+
data: { turbo: false }
|
|
27
|
+
) %>
|
|
28
|
+
|
|
29
|
+
<%= button_to(
|
|
30
|
+
I18n.t("lesli.items.attachments.remove", default: "Remove"),
|
|
31
|
+
path,
|
|
32
|
+
method: :delete,
|
|
33
|
+
class: "inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-500/40",
|
|
34
|
+
form: {
|
|
35
|
+
class: "inline-flex",
|
|
36
|
+
data: {
|
|
37
|
+
turbo_confirm: I18n.t(
|
|
38
|
+
"lesli.items.attachments.confirm_remove",
|
|
39
|
+
default: "Remove this file?"
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
) %>
|
|
44
|
+
</div>
|
|
45
|
+
</li>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
Lesli
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026, Lesli Technologies, S. A.
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
This program is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
|
19
|
+
|
|
20
|
+
Lesli · Ruby on Rails SaaS Development Framework.
|
|
21
|
+
|
|
22
|
+
Made with ♥ by LesliTech
|
|
23
|
+
Building a better future, one line of code at a time.
|
|
24
|
+
|
|
25
|
+
@contact hello@lesli.tech
|
|
26
|
+
@website https://www.lesli.tech
|
|
27
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
28
|
+
|
|
29
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
|
+
// ·
|
|
31
|
+
=end
|
|
32
|
+
|
|
33
|
+
module LesliView
|
|
34
|
+
module Items
|
|
35
|
+
class Attachment < ViewComponent::Base
|
|
36
|
+
attr_reader :resource
|
|
37
|
+
|
|
38
|
+
def initialize(attachment, path: nil)
|
|
39
|
+
@resource = attachment
|
|
40
|
+
@path = path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def path
|
|
44
|
+
@path || helpers.polymorphic_path(resource)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def filename
|
|
48
|
+
resource.file.filename.to_s
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def display_name
|
|
52
|
+
resource.respond_to?(:display_name) ? resource.display_name : filename
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def details
|
|
56
|
+
[
|
|
57
|
+
resource.file.blob.content_type,
|
|
58
|
+
helpers.number_to_human_size(resource.file.blob.byte_size)
|
|
59
|
+
].compact.join(" · ")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -29,40 +29,75 @@ Building a better future, one line of code at a time.
|
|
|
29
29
|
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
30
|
// ·
|
|
31
31
|
%>
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<% ['file-word-2-line','file-excel-2-line','file-pdf-2-line'].each do |file| %>
|
|
61
|
-
<div class="file-list">
|
|
62
|
-
<span class="ri-<%= file %>"></span>
|
|
63
|
-
<p><%= file %></p>
|
|
32
|
+
<article
|
|
33
|
+
class="lesli-items-attachments rounded-2xl border border-slate-200 bg-white p-6 shadow-sm"
|
|
34
|
+
id="<%= dom_id(resource, :attachments) %>">
|
|
35
|
+
<%= form_with(
|
|
36
|
+
scope: scope_key,
|
|
37
|
+
model: attachment,
|
|
38
|
+
builder: LesliView::Forms::Builder,
|
|
39
|
+
url: create_path,
|
|
40
|
+
multipart: true
|
|
41
|
+
) do |form| %>
|
|
42
|
+
<div class="grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(12rem,0.35fr)_auto] lg:items-end">
|
|
43
|
+
<div>
|
|
44
|
+
<%= form.label(
|
|
45
|
+
:file,
|
|
46
|
+
I18n.t("lesli.items.attachments.choose_file", default: "Choose a file"),
|
|
47
|
+
class: "mb-2 block text-sm font-medium text-slate-700"
|
|
48
|
+
) %>
|
|
49
|
+
<%= form.file_field(
|
|
50
|
+
:file,
|
|
51
|
+
required: true,
|
|
52
|
+
accept: accepted_content_types,
|
|
53
|
+
class: "block w-full cursor-pointer rounded-lg border border-slate-300 bg-white text-sm text-slate-700 file:mr-4 file:border-0 file:bg-slate-100 file:px-4 file:py-2.5 file:text-sm file:font-medium file:text-slate-700 hover:file:bg-slate-200 focus:outline-none focus:ring-2 focus:ring-[var(--lesli-color-primary)]"
|
|
54
|
+
) %>
|
|
55
|
+
<% if attachment.errors[:file].any? %>
|
|
56
|
+
<p class="mt-2 text-sm text-red-600">
|
|
57
|
+
<%= attachment.errors[:file].to_sentence %>
|
|
58
|
+
</p>
|
|
59
|
+
<% end %>
|
|
64
60
|
</div>
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
|
|
62
|
+
<%= form.field_control_text(
|
|
63
|
+
:label,
|
|
64
|
+
label: I18n.t("lesli.items.attachments.label", default: "Label"),
|
|
65
|
+
maxlength: 255
|
|
66
|
+
) %>
|
|
67
|
+
|
|
68
|
+
<%= form.field_control_button(
|
|
69
|
+
I18n.t("lesli.items.attachments.add", default: "Add file"),
|
|
70
|
+
{
|
|
71
|
+
data: {
|
|
72
|
+
turbo_submits_with: I18n.t(
|
|
73
|
+
"lesli.items.attachments.uploading",
|
|
74
|
+
default: "Uploading..."
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
icon: "upload_file"
|
|
79
|
+
) %>
|
|
80
|
+
</div>
|
|
81
|
+
<% end %>
|
|
82
|
+
|
|
83
|
+
<hr class="my-6 border-0 border-t border-slate-200">
|
|
84
|
+
|
|
85
|
+
<% if attachments.any? %>
|
|
86
|
+
<ul class="m-0 list-none space-y-3 p-0">
|
|
87
|
+
<% attachments.each do |item| %>
|
|
88
|
+
<%= render LesliView::Items::Attachment.new(
|
|
89
|
+
item,
|
|
90
|
+
path: attachment_path(item)
|
|
91
|
+
) %>
|
|
92
|
+
<% end %>
|
|
93
|
+
</ul>
|
|
94
|
+
<% else %>
|
|
95
|
+
<p class="py-6 text-center text-sm text-slate-500">
|
|
96
|
+
<%= I18n.t(
|
|
97
|
+
"lesli.items.attachments.empty",
|
|
98
|
+
default: "No files have been attached yet."
|
|
99
|
+
) %>
|
|
100
|
+
</p>
|
|
101
|
+
<% end %>
|
|
67
102
|
</article>
|
|
68
103
|
|
|
@@ -33,12 +33,48 @@ Building a better future, one line of code at a time.
|
|
|
33
33
|
module LesliView
|
|
34
34
|
module Items
|
|
35
35
|
class Attachments < ViewComponent::Base
|
|
36
|
-
attr_reader :resource, :
|
|
36
|
+
attr_reader :resource, :attachment
|
|
37
37
|
|
|
38
|
-
def initialize(
|
|
38
|
+
def initialize(
|
|
39
|
+
resource,
|
|
40
|
+
attachment: nil,
|
|
41
|
+
path_to_create: nil,
|
|
42
|
+
path_to_update: nil
|
|
43
|
+
)
|
|
39
44
|
@resource = resource
|
|
40
45
|
@path_to_create = path_to_create
|
|
41
46
|
@path_to_update = path_to_update
|
|
47
|
+
@attachment = attachment || attachment_class.new
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def attachment_class
|
|
51
|
+
resource.class.lesli_attachments_class
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def attachments
|
|
55
|
+
resource.attachments.with_attached_file
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def create_path
|
|
59
|
+
@path_to_create || helpers.polymorphic_path(
|
|
60
|
+
[:items, :attachments],
|
|
61
|
+
attachable_type: resource.class.name,
|
|
62
|
+
attachable_id: resource.id
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def attachment_path(item)
|
|
67
|
+
return @path_to_update.call(item) if @path_to_update.respond_to?(:call)
|
|
68
|
+
|
|
69
|
+
helpers.polymorphic_path(item)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def scope_key
|
|
73
|
+
ActiveSupport::Inflector.underscore(attachment_class.name).tr("/", "_")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def accepted_content_types
|
|
77
|
+
attachment_class.lesli_attachment_content_types.join(",")
|
|
42
78
|
end
|
|
43
79
|
end
|
|
44
80
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<li class="lesli-items-discussions-comments-comment flex flex-col gap-3 border-b border-slate-200 pb-6 last:border-b-0 last:pb-0 sm:flex-row sm:gap-4">
|
|
2
2
|
<div class="shrink-0 text-sm leading-5 text-slate-500 sm:w-40 sm:text-right">
|
|
3
|
-
<strong class="block font-semibold text-slate-800">
|
|
4
|
-
|
|
3
|
+
<strong class="block font-semibold text-slate-800">
|
|
4
|
+
<%= author_name %>
|
|
5
|
+
</strong>
|
|
6
|
+
<time datetime="<%= created_at_iso8601 %>">
|
|
7
|
+
<%= created_at_label %>
|
|
8
|
+
</time>
|
|
5
9
|
</div>
|
|
6
10
|
|
|
7
|
-
<div class="
|
|
8
|
-
<%== discussion.message %>
|
|
9
|
-
</div>
|
|
11
|
+
<div class="min-w-0 flex-1 whitespace-pre-wrap break-words text-slate-700"><%= discussion.message %></div>
|
|
10
12
|
</li>
|
|
@@ -37,6 +37,32 @@ module LesliView
|
|
|
37
37
|
def initialize(discussion)
|
|
38
38
|
@discussion = discussion
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
def author_name
|
|
42
|
+
author = discussion.author
|
|
43
|
+
full_name = author.full_name if author.respond_to?(:full_name)
|
|
44
|
+
name = author.name if author.respond_to?(:name)
|
|
45
|
+
|
|
46
|
+
full_name.presence || name.presence || I18n.t(
|
|
47
|
+
"lesli.items.discussions.unknown_author",
|
|
48
|
+
default: "Unknown user"
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def created_at_label
|
|
53
|
+
return if discussion.created_at.blank?
|
|
54
|
+
|
|
55
|
+
I18n.l(
|
|
56
|
+
discussion.created_at,
|
|
57
|
+
format: "%Y-%m-%d · %H:%M"
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def created_at_iso8601
|
|
62
|
+
return if discussion.created_at.blank?
|
|
63
|
+
|
|
64
|
+
discussion.created_at.strftime("%Y-%m-%dT%H:%M:%S%:z")
|
|
65
|
+
end
|
|
40
66
|
end
|
|
41
67
|
end
|
|
42
68
|
end
|