collavre_plan 0.1.1 → 0.1.3
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/app/assets/stylesheets/collavre_plan/timeline.css +183 -0
- data/app/components/collavre/plans_timeline_component.html.erb +8 -2
- data/app/components/collavre/plans_timeline_component.rb +10 -39
- data/app/controllers/collavre_plan/plans_controller.rb +86 -54
- data/app/javascript/controllers/__tests__/index.test.js +22 -0
- data/app/javascript/controllers/creatives/__tests__/set_plan_button_controller.test.js +55 -0
- data/app/javascript/controllers/creatives/__tests__/set_plan_modal_controller.test.js +102 -0
- data/app/javascript/controllers/creatives/set_plan_button_controller.js +11 -0
- data/app/javascript/controllers/creatives/set_plan_modal_controller.js +12 -24
- data/app/javascript/controllers/index.js +2 -0
- data/app/javascript/modules/__tests__/plans_menu.test.js +101 -0
- data/app/javascript/modules/plans_menu.js +34 -44
- data/app/javascript/modules/plans_timeline.js +63 -5
- data/app/services/collavre_plan/timeline_items.rb +74 -0
- data/app/views/collavre_plan/creatives/_set_plan_button.html.erb +1 -1
- data/app/views/collavre_plan/shared/navigation/_panels.html.erb +1 -0
- data/config/locales/plans.en.yml +4 -0
- data/config/locales/plans.ko.yml +4 -0
- data/lib/collavre_plan/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4010d48c48d0b49b8a455b19033e00fb4f5b4c76cba4d3b80f158b9c9a2cfa3
|
|
4
|
+
data.tar.gz: bbf626b7803939f57c3763d72e156980a1e06ebc9b3fcddbb378ebd64cec0b63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c94480962005879853538886b6f63463a14d758a6c62f388232b61d3d461891ba7dc5862796f8dc82151a72283795ad65d648cb90cfadb707955b5a836c0b383
|
|
7
|
+
data.tar.gz: b69cba6b19cd352b45718900f6a7add74d41b2a6402f81fb72194d3284f6873f905f4d4b7bf0e8dae5b668f777c220323e429a0184f9c00c470789e22582069a
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Plans timeline panel styles.
|
|
3
|
+
*
|
|
4
|
+
* Owned by the collavre_plan engine (not the host application.css) so the
|
|
5
|
+
* engine ships its own CSS. Loaded via stylesheet_link_tag in the engine's
|
|
6
|
+
* navigation panel partial. Design tokens (--color-*, --surface-*, --ease-*)
|
|
7
|
+
* are provided globally by collavre/design_tokens.css.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#plans-list-area {
|
|
11
|
+
max-width: var(--max-width);
|
|
12
|
+
width: min(100%, var(--max-width));
|
|
13
|
+
margin: 0.5em auto;
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#plans-list-area hr {
|
|
18
|
+
border: 0;
|
|
19
|
+
border-top: 1px solid var(--color-border);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.horizontal-timeline {
|
|
23
|
+
overflow-x: auto;
|
|
24
|
+
position: relative;
|
|
25
|
+
padding-bottom: 1em;
|
|
26
|
+
width: 100%;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.plans-timeline-wrapper {
|
|
30
|
+
position: relative;
|
|
31
|
+
width: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.plans-timeline-wrapper #timeline-today-btn {
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 0;
|
|
37
|
+
right: 0;
|
|
38
|
+
z-index: 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.horizontal-timeline .timeline-scroll {
|
|
42
|
+
position: relative;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
height: 120px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.horizontal-timeline .timeline-day {
|
|
48
|
+
display: inline-block;
|
|
49
|
+
width: 80px;
|
|
50
|
+
box-sizing: border-box;
|
|
51
|
+
border-right: 1px solid var(--color-border);
|
|
52
|
+
text-align: center;
|
|
53
|
+
font-size: 0.8em;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.plan-form-container {
|
|
57
|
+
padding: 0.5em;
|
|
58
|
+
display: flex;
|
|
59
|
+
justify-content: flex-end;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.plan-form-container form {
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
gap: var(--paragraph-space-1);
|
|
66
|
+
max-width: min(28rem, 100%);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.plan-bar {
|
|
70
|
+
position: absolute;
|
|
71
|
+
height: 20px;
|
|
72
|
+
background: var(--color-border);
|
|
73
|
+
border-radius: var(--radius-2);
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.plan-bar .plan-progress {
|
|
79
|
+
background: var(--color-complete);
|
|
80
|
+
height: 100%;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.plan-bar .plan-label {
|
|
84
|
+
position: absolute;
|
|
85
|
+
left: 2px;
|
|
86
|
+
top: 2px;
|
|
87
|
+
font-size: 0.75em;
|
|
88
|
+
color: var(--color-text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.plan-bar .delete-plan-btn {
|
|
92
|
+
position: absolute;
|
|
93
|
+
top: 2px;
|
|
94
|
+
right: 2px;
|
|
95
|
+
border: none;
|
|
96
|
+
background: none;
|
|
97
|
+
font-weight: bold;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
color: var(--color-bg);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Registration markers: creatives drawn at their created_at (single day). */
|
|
103
|
+
.plan-bar--registration {
|
|
104
|
+
background: var(--color-link);
|
|
105
|
+
opacity: 0.85;
|
|
106
|
+
min-width: 6px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.plan-bar--registration .plan-progress {
|
|
110
|
+
background: transparent;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Modification markers: creatives drawn at their updated_at (single day).
|
|
114
|
+
Amber to read as distinct from the blue registration markers. */
|
|
115
|
+
.plan-bar--modification {
|
|
116
|
+
background: var(--color-warning);
|
|
117
|
+
opacity: 0.85;
|
|
118
|
+
min-width: 6px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.plan-bar--modification .plan-progress {
|
|
122
|
+
background: transparent;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Timeline chip filters (Registered, ...) — default-off toggles. */
|
|
126
|
+
.timeline-controls {
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
gap: 0.5em;
|
|
130
|
+
margin-bottom: 0.25em;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.timeline-chips {
|
|
134
|
+
display: flex;
|
|
135
|
+
gap: 0.25em;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.timeline-chip {
|
|
139
|
+
/* Inactive chips sit on a neutral surface (not transparent) so the off-state
|
|
140
|
+
still reads as a toggle against the timeline background, without looking
|
|
141
|
+
active. */
|
|
142
|
+
border: 1px solid var(--color-border);
|
|
143
|
+
background: var(--surface-secondary);
|
|
144
|
+
color: var(--color-text);
|
|
145
|
+
border-radius: var(--radius-round);
|
|
146
|
+
padding: 0.1em 0.7em;
|
|
147
|
+
font-size: 0.75em;
|
|
148
|
+
line-height: 1.6;
|
|
149
|
+
cursor: pointer;
|
|
150
|
+
transition: background-color 0.15s var(--ease-2), color 0.15s var(--ease-2), border-color 0.15s var(--ease-2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.timeline-chip:hover {
|
|
154
|
+
background: var(--surface-hover);
|
|
155
|
+
color: var(--color-text);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.timeline-chip:focus-visible {
|
|
159
|
+
outline: 2px solid var(--color-link);
|
|
160
|
+
outline-offset: 1px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.timeline-chip--active {
|
|
164
|
+
background: var(--color-link);
|
|
165
|
+
border-color: var(--color-link);
|
|
166
|
+
color: var(--color-bg);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Keep the active chip filled on hover — don't fall back to the inactive surface. */
|
|
170
|
+
.timeline-chip--active:hover {
|
|
171
|
+
background: var(--color-link);
|
|
172
|
+
color: var(--color-bg);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* The Modified chip's active fill matches its amber timeline markers
|
|
176
|
+
(.plan-bar--modification) so the filter color maps to the dots it controls.
|
|
177
|
+
--text-on-badge is the codebase convention for text over --color-warning. */
|
|
178
|
+
#chip-modifications.timeline-chip--active,
|
|
179
|
+
#chip-modifications.timeline-chip--active:hover {
|
|
180
|
+
background: var(--color-warning);
|
|
181
|
+
border-color: var(--color-warning);
|
|
182
|
+
color: var(--text-on-badge);
|
|
183
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<div class="plans-timeline-wrapper">
|
|
2
|
-
<
|
|
3
|
-
|
|
2
|
+
<div class="timeline-controls">
|
|
3
|
+
<button id="timeline-today-btn" class="btn btn-xs" type="button"><%= t('collavre.plans.today', default: '오늘') %></button>
|
|
4
|
+
<div class="timeline-chips">
|
|
5
|
+
<button type="button" id="chip-registrations" class="timeline-chip<%= ' timeline-chip--active' if show_registrations %>" data-chip="registrations" aria-pressed="<%= show_registrations %>"><%= t('collavre.plans.chip_registrations', default: 'Registered') %></button>
|
|
6
|
+
<button type="button" id="chip-modifications" class="timeline-chip<%= ' timeline-chip--active' if show_modifications %>" data-chip="modifications" aria-pressed="<%= show_modifications %>"><%= t('collavre.plans.chip_modifications', default: 'Modified') %></button>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
<div id="plans-timeline" class="horizontal-timeline" data-plans='<%= raw plan_data.to_json %>' data-start-date="<%= @start_date %>" data-end-date="<%= @end_date %>" data-registrations="<%= show_registrations %>" data-modifications="<%= show_modifications %>" data-delete-confirm="<%= t('collavre.plans.delete_confirm', default: 'Are you sure?') %>"></div>
|
|
4
10
|
</div>
|
|
5
11
|
<hr>
|
|
6
12
|
<div class="plan-form-container">
|
|
@@ -1,53 +1,24 @@
|
|
|
1
1
|
module Collavre
|
|
2
2
|
class PlansTimelineComponent < ViewComponent::Base
|
|
3
|
-
# Accepts pre-filtered plans and
|
|
4
|
-
def initialize(plans:, calendar_events: Collavre::CalendarEvent.none)
|
|
3
|
+
# Accepts pre-filtered plans, calendar_events, registrations and modifications from the controller
|
|
4
|
+
def initialize(plans:, calendar_events: Collavre::CalendarEvent.none, registrations: [], show_registrations: false, modifications: [], show_modifications: false)
|
|
5
5
|
@start_date = Date.current - 30
|
|
6
6
|
@end_date = Date.current + 30
|
|
7
7
|
@plans = plans
|
|
8
8
|
@calendar_events = calendar_events
|
|
9
|
+
@registrations = registrations
|
|
10
|
+
@show_registrations = show_registrations
|
|
11
|
+
@modifications = modifications
|
|
12
|
+
@show_modifications = show_modifications
|
|
9
13
|
end
|
|
10
14
|
|
|
11
|
-
attr_reader :plans, :calendar_events, :start_date, :end_date
|
|
15
|
+
attr_reader :plans, :calendar_events, :registrations, :start_date, :end_date, :show_registrations, :modifications, :show_modifications
|
|
12
16
|
|
|
13
17
|
# Called after component enters render context - safe to use helpers here
|
|
14
18
|
def plan_data
|
|
15
|
-
@plan_data ||=
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def plan_item(plan)
|
|
21
|
-
{
|
|
22
|
-
id: plan.id,
|
|
23
|
-
name: (plan.creative&.effective_description(nil, false) || plan.name.presence || I18n.l(plan.target_date)),
|
|
24
|
-
created_at: plan.created_at.to_date,
|
|
25
|
-
start_date: plan.start_date,
|
|
26
|
-
target_date: plan.target_date,
|
|
27
|
-
progress: plan.progress,
|
|
28
|
-
path: plan_creatives_path(plan),
|
|
29
|
-
deletable: plan.owner_id == Current.user&.id
|
|
30
|
-
}
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def calendar_item(event)
|
|
34
|
-
{
|
|
35
|
-
id: "calendar_event_#{event.id}",
|
|
36
|
-
name: event.summary.presence || I18n.l(event.start_time.to_date),
|
|
37
|
-
created_at: event.start_time.to_date,
|
|
38
|
-
target_date: event.end_time.to_date,
|
|
39
|
-
progress: event.creative&.progress || 0,
|
|
40
|
-
path: event.creative ? helpers.collavre.creative_path(event.creative) : event.html_link,
|
|
41
|
-
deletable: event.user_id == Current.user&.id
|
|
42
|
-
}
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def plan_creatives_path(plan)
|
|
46
|
-
if helpers.params[:id].present?
|
|
47
|
-
helpers.collavre.creative_path(helpers.params[:id], tags: [ plan.id ])
|
|
48
|
-
else
|
|
49
|
-
helpers.collavre.creatives_path(tags: [ plan.id ])
|
|
50
|
-
end
|
|
19
|
+
@plan_data ||= CollavrePlan::TimelineItems.new(creative_id: helpers.params[:id], routes: helpers.collavre).all(
|
|
20
|
+
plans: @plans, calendar_events: @calendar_events, registrations: @registrations, modifications: @modifications
|
|
21
|
+
)
|
|
51
22
|
end
|
|
52
23
|
end
|
|
53
24
|
end
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
module CollavrePlan
|
|
2
2
|
class PlansController < ApplicationController
|
|
3
|
+
# Cap how many registration/modification markers we draw so a busy window
|
|
4
|
+
# never floods the timeline (or the JSON payload). Most recent within the
|
|
5
|
+
# window win.
|
|
6
|
+
REGISTRATION_LIMIT = 300
|
|
7
|
+
MODIFICATION_LIMIT = 300
|
|
8
|
+
|
|
3
9
|
def index
|
|
4
10
|
center = if params[:date].present?
|
|
5
11
|
Date.parse(params[:date]) rescue Date.current
|
|
@@ -20,14 +26,21 @@ module CollavrePlan
|
|
|
20
26
|
shared_events = events_in_scope.reject { |event| event.user_id == Current.user.id }
|
|
21
27
|
.select { |event| event.creative&.has_permission?(Current.user, :write) }
|
|
22
28
|
@calendar_events = (own_events + shared_events).uniq.sort_by(&:start_time)
|
|
29
|
+
|
|
30
|
+
# "Registered"/"Modified" chips are default-off, so their creatives are
|
|
31
|
+
# only gathered when the client explicitly asks (lazy, zero cost normally).
|
|
32
|
+
@show_registrations = ActiveModel::Type::Boolean.new.cast(params[:registrations]) == true
|
|
33
|
+
@registrations = @show_registrations ? registration_creatives(start_date, end_date) : []
|
|
34
|
+
@show_modifications = ActiveModel::Type::Boolean.new.cast(params[:modifications]) == true
|
|
35
|
+
@modifications = @show_modifications ? modification_creatives(start_date, end_date) : []
|
|
36
|
+
|
|
23
37
|
respond_to do |format|
|
|
24
38
|
format.html do
|
|
25
|
-
render html: render_to_string(Collavre::PlansTimelineComponent.new(plans: @plans, calendar_events: @calendar_events), layout: false)
|
|
39
|
+
render html: render_to_string(Collavre::PlansTimelineComponent.new(plans: @plans, calendar_events: @calendar_events, registrations: @registrations, show_registrations: @show_registrations, modifications: @modifications, show_modifications: @show_modifications), layout: false)
|
|
26
40
|
end
|
|
27
41
|
format.json do
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
render json: plan_jsons + event_jsons
|
|
42
|
+
render json: timeline_items.all(plans: @plans, calendar_events: @calendar_events,
|
|
43
|
+
registrations: @registrations, modifications: @modifications)
|
|
31
44
|
end
|
|
32
45
|
end
|
|
33
46
|
end
|
|
@@ -41,19 +54,11 @@ module CollavrePlan
|
|
|
41
54
|
redirect_back fallback_location: main_app.root_path, notice: t("collavre.plans.created")
|
|
42
55
|
end
|
|
43
56
|
format.json do
|
|
44
|
-
render json:
|
|
57
|
+
render json: timeline_items.plan(@plan), status: :created
|
|
45
58
|
end
|
|
46
59
|
end
|
|
47
60
|
else
|
|
48
|
-
|
|
49
|
-
format.html do
|
|
50
|
-
flash[:alert] = @plan.errors.full_messages.join(", ")
|
|
51
|
-
redirect_back fallback_location: main_app.root_path
|
|
52
|
-
end
|
|
53
|
-
format.json do
|
|
54
|
-
render json: { errors: @plan.errors.full_messages }, status: :unprocessable_entity
|
|
55
|
-
end
|
|
56
|
-
end
|
|
61
|
+
respond_with_plan_errors
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
|
|
@@ -82,24 +87,32 @@ module CollavrePlan
|
|
|
82
87
|
notice: t("collavre.plans.updated", default: "Plan updated.")
|
|
83
88
|
end
|
|
84
89
|
format.json do
|
|
85
|
-
render json:
|
|
90
|
+
render json: timeline_items(params[:creative_id] || @plan.creative_id).plan(@plan), status: :ok
|
|
86
91
|
end
|
|
87
92
|
end
|
|
88
93
|
else
|
|
89
|
-
|
|
90
|
-
format.html do
|
|
91
|
-
flash[:alert] = @plan.errors.full_messages.join(", ")
|
|
92
|
-
redirect_back fallback_location: main_app.root_path
|
|
93
|
-
end
|
|
94
|
-
format.json do
|
|
95
|
-
render json: { errors: @plan.errors.full_messages }, status: :unprocessable_entity
|
|
96
|
-
end
|
|
97
|
-
end
|
|
94
|
+
respond_with_plan_errors
|
|
98
95
|
end
|
|
99
96
|
end
|
|
100
97
|
|
|
101
98
|
private
|
|
102
99
|
|
|
100
|
+
def timeline_items(creative_id = nil)
|
|
101
|
+
TimelineItems.new(creative_id: creative_id.presence || params[:id])
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def respond_with_plan_errors
|
|
105
|
+
respond_to do |format|
|
|
106
|
+
format.html do
|
|
107
|
+
flash[:alert] = @plan.errors.full_messages.join(", ")
|
|
108
|
+
redirect_back fallback_location: main_app.root_path
|
|
109
|
+
end
|
|
110
|
+
format.json do
|
|
111
|
+
render json: { errors: @plan.errors.full_messages }, status: :unprocessable_entity
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
103
116
|
def plan_params
|
|
104
117
|
params.require(:plan).permit(:target_date, :start_date, :creative_id)
|
|
105
118
|
end
|
|
@@ -119,40 +132,59 @@ module CollavrePlan
|
|
|
119
132
|
tagged_creative.has_permission?(Current.user, :write)
|
|
120
133
|
end
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
# Registered creatives owned by the current user, drawn at their created_at.
|
|
136
|
+
# Owner-scoped (cheap, indexed) and capped — readable-but-shared creatives are
|
|
137
|
+
# intentionally a follow-up to avoid a per-creative permission fan-out here.
|
|
138
|
+
def registration_creatives(start_date, end_date)
|
|
139
|
+
# Range-compare in the user's zone (set_time_zone wraps the request in
|
|
140
|
+
# Time.use_zone) so day-edge creatives match the local created_at.to_date
|
|
141
|
+
# we render the marker at; also stays sargable (no DATE() cast on the column).
|
|
142
|
+
Collavre::Creative.active
|
|
143
|
+
.where(user_id: Current.user.id)
|
|
144
|
+
.where(created_at: start_date.beginning_of_day..end_date.end_of_day)
|
|
145
|
+
.where.not(id: plan_anchor_creative_ids)
|
|
146
|
+
.order(created_at: :desc)
|
|
147
|
+
.limit(REGISTRATION_LIMIT)
|
|
148
|
+
.to_a
|
|
133
149
|
end
|
|
134
150
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
deletable: event.user_id == Current.user&.id
|
|
144
|
-
}
|
|
151
|
+
# Plan#start_date= overwrites the anchor creative's created_at (via
|
|
152
|
+
# update_column), repurposing it as the plan start date — so these creatives
|
|
153
|
+
# already render as plan bars at that date and their created_at is not a true
|
|
154
|
+
# registration. Exclude them from the Registered chip to avoid a duplicate,
|
|
155
|
+
# mislabeled marker. (The Modified chip handles anchors via the immutable
|
|
156
|
+
# plan-label created_at instead; see modification_creatives.)
|
|
157
|
+
def plan_anchor_creative_ids
|
|
158
|
+
Collavre::Plan.where.not(creative_id: nil).select(:creative_id)
|
|
145
159
|
end
|
|
146
160
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
# Modified creatives owned by the current user, drawn at their updated_at.
|
|
162
|
+
# We only include creatives genuinely edited after they came into being, so
|
|
163
|
+
# the "Modified" chip stays distinct from "Registered" rather than duplicating
|
|
164
|
+
# it. Owner-scoped and capped, mirroring registration_creatives.
|
|
165
|
+
#
|
|
166
|
+
# Plan#start_date= rewrites an anchor creative's created_at to the chosen plan
|
|
167
|
+
# start date (via update_column, leaving updated_at untouched), so for anchors
|
|
168
|
+
# created_at is the plan start, not a creation time, and updated_at > created_at
|
|
169
|
+
# can't signal a real edit (it's true for almost every anchor). The plan
|
|
170
|
+
# label's own created_at is immutable, so we measure "edited since setup"
|
|
171
|
+
# against the earliest plan's created_at for anchors; COALESCE falls back to
|
|
172
|
+
# created_at for ordinary creatives. This surfaces genuine post-setup edits to
|
|
173
|
+
# planned creatives while still suppressing the setup-only false positive.
|
|
174
|
+
def modification_creatives(start_date, end_date)
|
|
175
|
+
Collavre::Creative.active
|
|
176
|
+
.where(user_id: Current.user.id)
|
|
177
|
+
.where(updated_at: start_date.beginning_of_day..end_date.end_of_day)
|
|
178
|
+
.where(
|
|
179
|
+
"creatives.updated_at > COALESCE(" \
|
|
180
|
+
"(SELECT MIN(plan_labels.created_at) FROM labels plan_labels " \
|
|
181
|
+
"WHERE plan_labels.creative_id = creatives.id " \
|
|
182
|
+
"AND plan_labels.type = ?), creatives.created_at)",
|
|
183
|
+
Collavre::Plan.sti_name
|
|
184
|
+
)
|
|
185
|
+
.order(updated_at: :desc)
|
|
186
|
+
.limit(MODIFICATION_LIMIT)
|
|
187
|
+
.to_a
|
|
156
188
|
end
|
|
157
189
|
end
|
|
158
190
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { jest } from '@jest/globals'
|
|
6
|
+
|
|
7
|
+
jest.unstable_mockModule('collavre/lib/utils/dialog', () => ({ alertDialog: jest.fn() }))
|
|
8
|
+
|
|
9
|
+
const { registerControllers } = await import('../index')
|
|
10
|
+
const { default: SetPlanButtonController } = await import('../creatives/set_plan_button_controller')
|
|
11
|
+
const { default: SetPlanModalController } = await import('../creatives/set_plan_modal_controller')
|
|
12
|
+
|
|
13
|
+
describe('registerControllers', () => {
|
|
14
|
+
test('registers the set plan button and modal controllers', () => {
|
|
15
|
+
const application = { register: jest.fn() }
|
|
16
|
+
|
|
17
|
+
registerControllers(application)
|
|
18
|
+
|
|
19
|
+
expect(application.register).toHaveBeenCalledWith('creatives--set-plan-button', SetPlanButtonController)
|
|
20
|
+
expect(application.register).toHaveBeenCalledWith('creatives--set-plan-modal', SetPlanModalController)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { jest } from '@jest/globals'
|
|
5
|
+
import { Application } from '@hotwired/stimulus'
|
|
6
|
+
|
|
7
|
+
jest.unstable_mockModule('collavre/lib/utils/dialog', () => ({ alertDialog: jest.fn() }))
|
|
8
|
+
|
|
9
|
+
const { default: SetPlanButtonController } = await import('../set_plan_button_controller')
|
|
10
|
+
const { default: SetPlanModalController } = await import('../set_plan_modal_controller')
|
|
11
|
+
|
|
12
|
+
describe('SetPlanButtonController', () => {
|
|
13
|
+
let application
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
document.body.innerHTML = `
|
|
17
|
+
<form id="toolbar-form">
|
|
18
|
+
<button id="set-plan-btn"
|
|
19
|
+
data-controller="creatives--set-plan-button"
|
|
20
|
+
data-action="click->creatives--set-plan-button#open">Set Plan</button>
|
|
21
|
+
</form>
|
|
22
|
+
<div data-controller="creatives--set-plan-modal">
|
|
23
|
+
<div data-creatives--set-plan-modal-target="modal" style="display:none"></div>
|
|
24
|
+
</div>
|
|
25
|
+
`
|
|
26
|
+
application = Application.start()
|
|
27
|
+
application.register('creatives--set-plan-button', SetPlanButtonController)
|
|
28
|
+
application.register('creatives--set-plan-modal', SetPlanModalController)
|
|
29
|
+
await Promise.resolve()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
application.stop()
|
|
34
|
+
document.body.innerHTML = ''
|
|
35
|
+
document.body.classList.remove('no-scroll')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('opens the set-plan modal that lives outside the button scope', () => {
|
|
39
|
+
document.getElementById('set-plan-btn').click()
|
|
40
|
+
|
|
41
|
+
expect(document.querySelector('[data-creatives--set-plan-modal-target="modal"]').style.display).toBe('flex')
|
|
42
|
+
expect(document.body.classList.contains('no-scroll')).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('prevents the default button action', () => {
|
|
46
|
+
const submitted = jest.fn((event) => event.preventDefault())
|
|
47
|
+
document.getElementById('toolbar-form').addEventListener('submit', submitted)
|
|
48
|
+
const event = new MouseEvent('click', { bubbles: true, cancelable: true })
|
|
49
|
+
|
|
50
|
+
document.getElementById('set-plan-btn').dispatchEvent(event)
|
|
51
|
+
|
|
52
|
+
expect(event.defaultPrevented).toBe(true)
|
|
53
|
+
expect(submitted).not.toHaveBeenCalled()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { jest } from '@jest/globals'
|
|
5
|
+
import { Application } from '@hotwired/stimulus'
|
|
6
|
+
|
|
7
|
+
const alertDialog = jest.fn()
|
|
8
|
+
jest.unstable_mockModule('collavre/lib/utils/dialog', () => ({ alertDialog }))
|
|
9
|
+
|
|
10
|
+
const { default: SetPlanModalController } = await import('../set_plan_modal_controller')
|
|
11
|
+
|
|
12
|
+
describe('SetPlanModalController plan requests', () => {
|
|
13
|
+
let application
|
|
14
|
+
const originalFetch = global.fetch
|
|
15
|
+
|
|
16
|
+
async function mount({ checked = ['3', '5'], planId = '9' } = {}) {
|
|
17
|
+
document.head.innerHTML = '<meta name="csrf-token" content="token-1">'
|
|
18
|
+
document.body.innerHTML = `
|
|
19
|
+
<input type="checkbox" class="select-creative-checkbox" value="3">
|
|
20
|
+
<input type="checkbox" class="select-creative-checkbox" value="4">
|
|
21
|
+
<input type="checkbox" class="select-creative-checkbox" value="5">
|
|
22
|
+
<div data-controller="set-plan-modal"
|
|
23
|
+
data-set-plan-modal-select-one-value="Select a creative"
|
|
24
|
+
data-set-plan-modal-select-plan-value="Select a plan">
|
|
25
|
+
<div data-set-plan-modal-target="modal" style="display:flex">
|
|
26
|
+
<form data-set-plan-modal-target="form" action="/plans/assign"
|
|
27
|
+
data-action="submit->set-plan-modal#submit">
|
|
28
|
+
<input type="hidden" data-set-plan-modal-target="idsInput">
|
|
29
|
+
<select data-set-plan-modal-target="planSelect">
|
|
30
|
+
<option value=""></option>
|
|
31
|
+
<option value="9">Plan</option>
|
|
32
|
+
</select>
|
|
33
|
+
<button type="button" id="remove" data-remove-path="/plans/unassign"
|
|
34
|
+
data-action="click->set-plan-modal#remove"></button>
|
|
35
|
+
</form>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
`
|
|
39
|
+
document.querySelectorAll('.select-creative-checkbox').forEach((checkbox) => {
|
|
40
|
+
checkbox.checked = checked.includes(checkbox.value)
|
|
41
|
+
})
|
|
42
|
+
document.querySelector('select').value = planId
|
|
43
|
+
application = Application.start()
|
|
44
|
+
application.register('set-plan-modal', SetPlanModalController)
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function act(trigger) {
|
|
49
|
+
trigger()
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const submit = () => document.querySelector('form').dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
|
|
54
|
+
const remove = () => document.getElementById('remove').click()
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
global.fetch = jest.fn().mockResolvedValue({ ok: true, json: () => Promise.resolve({ message: 'Done' }) })
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
application.stop()
|
|
62
|
+
global.fetch = originalFetch
|
|
63
|
+
document.head.innerHTML = ''
|
|
64
|
+
document.body.innerHTML = ''
|
|
65
|
+
jest.clearAllMocks()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test.each([
|
|
69
|
+
['submit', submit, 'http://localhost/plans/assign', 'POST'],
|
|
70
|
+
['remove', remove, '/plans/unassign', 'DELETE'],
|
|
71
|
+
])('%s sends the selected creatives and plan, then closes the modal', async (_name, trigger, url, method) => {
|
|
72
|
+
await mount()
|
|
73
|
+
|
|
74
|
+
await act(trigger)
|
|
75
|
+
|
|
76
|
+
expect(global.fetch).toHaveBeenCalledWith(url, {
|
|
77
|
+
method,
|
|
78
|
+
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-CSRF-Token': 'token-1' },
|
|
79
|
+
body: JSON.stringify({ plan_id: '9', creative_ids: '3,5' }),
|
|
80
|
+
})
|
|
81
|
+
expect(alertDialog).toHaveBeenCalledWith('Done')
|
|
82
|
+
expect(document.querySelector('[data-set-plan-modal-target="modal"]').style.display).toBe('none')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test.each([['submit', submit], ['remove', remove]])('%s asks for a creative when none is selected', async (_name, trigger) => {
|
|
86
|
+
await mount({ checked: [] })
|
|
87
|
+
|
|
88
|
+
await act(trigger)
|
|
89
|
+
|
|
90
|
+
expect(alertDialog).toHaveBeenCalledWith('Select a creative')
|
|
91
|
+
expect(global.fetch).not.toHaveBeenCalled()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test.each([['submit', submit], ['remove', remove]])('%s asks for a plan when none is chosen', async (_name, trigger) => {
|
|
95
|
+
await mount({ planId: '' })
|
|
96
|
+
|
|
97
|
+
await act(trigger)
|
|
98
|
+
|
|
99
|
+
expect(alertDialog).toHaveBeenCalledWith('Select a plan')
|
|
100
|
+
expect(global.fetch).not.toHaveBeenCalled()
|
|
101
|
+
})
|
|
102
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
|
|
3
|
+
// Opens the set-plan modal from the creative toolbar button. The button lives
|
|
4
|
+
// outside the modal controller's scope, so it signals via a document event
|
|
5
|
+
// instead of an inline onclick (blocked by the CSP script-src policy).
|
|
6
|
+
export default class extends Controller {
|
|
7
|
+
open(event) {
|
|
8
|
+
event.preventDefault()
|
|
9
|
+
document.dispatchEvent(new CustomEvent('plan:open-modal'))
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
import { alertDialog } from 'collavre/lib/utils/dialog'
|
|
2
3
|
|
|
3
4
|
// Self-contained controller: attaches to the modal wrapper element
|
|
4
5
|
// and listens for 'plan:open-modal' on document for cross-element communication.
|
|
@@ -47,43 +48,30 @@ export default class extends Controller {
|
|
|
47
48
|
async submit(event) {
|
|
48
49
|
event.preventDefault()
|
|
49
50
|
if (!this.hasFormTarget || !this.hasIdsInputTarget) return
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (ids.length === 0) {
|
|
53
|
-
this.alert(this.selectOneValue)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const planId = this.planSelectTarget.value
|
|
58
|
-
if (!planId) {
|
|
59
|
-
this.alert(this.selectPlanValue)
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
await this.performRequest(this.formTarget.action, 'POST', {
|
|
64
|
-
plan_id: planId,
|
|
65
|
-
creative_ids: ids.join(',')
|
|
66
|
-
})
|
|
51
|
+
const body = this.selectionPayload()
|
|
52
|
+
if (body) await this.performRequest(this.formTarget.action, 'POST', body)
|
|
67
53
|
}
|
|
68
54
|
|
|
69
55
|
async remove(event) {
|
|
70
56
|
event.preventDefault()
|
|
57
|
+
const body = this.selectionPayload()
|
|
58
|
+
if (body) await this.performRequest(event.currentTarget.dataset.removePath, 'DELETE', body)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
selectionPayload() {
|
|
71
62
|
const ids = this.selectedIds()
|
|
72
63
|
if (ids.length === 0) {
|
|
73
64
|
this.alert(this.selectOneValue)
|
|
74
|
-
return
|
|
65
|
+
return null
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
const planId = this.planSelectTarget.value
|
|
78
69
|
if (!planId) {
|
|
79
70
|
this.alert(this.selectPlanValue)
|
|
80
|
-
return
|
|
71
|
+
return null
|
|
81
72
|
}
|
|
82
73
|
|
|
83
|
-
|
|
84
|
-
plan_id: planId,
|
|
85
|
-
creative_ids: ids.join(',')
|
|
86
|
-
})
|
|
74
|
+
return { plan_id: planId, creative_ids: ids.join(',') }
|
|
87
75
|
}
|
|
88
76
|
|
|
89
77
|
async performRequest(url, method, body) {
|
|
@@ -119,6 +107,6 @@ export default class extends Controller {
|
|
|
119
107
|
|
|
120
108
|
alert(message) {
|
|
121
109
|
if (!message) return
|
|
122
|
-
|
|
110
|
+
alertDialog(message)
|
|
123
111
|
}
|
|
124
112
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// CollavrePlan Engine Controllers
|
|
2
|
+
import CreativesSetPlanButtonController from "./creatives/set_plan_button_controller"
|
|
2
3
|
import CreativesSetPlanModalController from "./creatives/set_plan_modal_controller"
|
|
3
4
|
|
|
4
5
|
export function registerControllers(application) {
|
|
6
|
+
application.register("creatives--set-plan-button", CreativesSetPlanButtonController)
|
|
5
7
|
application.register("creatives--set-plan-modal", CreativesSetPlanModalController)
|
|
6
8
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
const notifyPopupOpen = jest.fn()
|
|
4
|
+
const onOtherPopupOpen = jest.fn()
|
|
5
|
+
jest.unstable_mockModule('collavre/lib/gnb_popup_manager', () => ({
|
|
6
|
+
notifyPopupOpen, onOtherPopupOpen
|
|
7
|
+
}), { virtual: true })
|
|
8
|
+
|
|
9
|
+
await import('../plans_menu.js')
|
|
10
|
+
|
|
11
|
+
function renderMenu() {
|
|
12
|
+
document.body.innerHTML = `
|
|
13
|
+
<button class="plans-menu-btn"><span>Plans</span></button>
|
|
14
|
+
<button class="plans-menu-btn" id="mobile-plans">Plans</button>
|
|
15
|
+
<div id="plans-list-area" style="display:none" data-plans-url="/mounted/plans.json">
|
|
16
|
+
<div id="plans-timeline"></div>
|
|
17
|
+
</div>`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function navigate() {
|
|
21
|
+
document.dispatchEvent(new window.Event('turbo:load'))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function click(selector = '.plans-menu-btn span') {
|
|
25
|
+
document.querySelector(selector).click()
|
|
26
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
renderMenu()
|
|
31
|
+
global.fetch = jest.fn().mockResolvedValue({ json: async () => [{ id: 1 }] })
|
|
32
|
+
window.initPlansTimeline = jest.fn()
|
|
33
|
+
notifyPopupOpen.mockClear()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('opens once after repeated navigation with the GNB preserved', async () => {
|
|
37
|
+
navigate()
|
|
38
|
+
navigate()
|
|
39
|
+
await click()
|
|
40
|
+
expect(document.getElementById('plans-list-area').style.display).toBe('block')
|
|
41
|
+
expect(fetch).toHaveBeenCalledTimes(1)
|
|
42
|
+
expect(fetch).toHaveBeenCalledWith('/mounted/plans.json')
|
|
43
|
+
expect(notifyPopupOpen).toHaveBeenCalledTimes(1)
|
|
44
|
+
expect(window.initPlansTimeline).toHaveBeenCalledWith(document.getElementById('plans-timeline'))
|
|
45
|
+
expect(document.getElementById('plans-timeline').dataset.plans).toBe('[{"id":1}]')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('desktop and mobile toggle the same panel and reuse loaded plans', async () => {
|
|
49
|
+
navigate()
|
|
50
|
+
await click()
|
|
51
|
+
await click('#mobile-plans')
|
|
52
|
+
expect(document.getElementById('plans-list-area').style.display).toBe('none')
|
|
53
|
+
await click('#mobile-plans')
|
|
54
|
+
expect(document.getElementById('plans-list-area').style.display).toBe('block')
|
|
55
|
+
expect(fetch).toHaveBeenCalledTimes(1)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('loads the new panel after full page replacement', async () => {
|
|
59
|
+
navigate()
|
|
60
|
+
await click()
|
|
61
|
+
renderMenu()
|
|
62
|
+
navigate()
|
|
63
|
+
await click()
|
|
64
|
+
expect(document.getElementById('plans-list-area').style.display).toBe('block')
|
|
65
|
+
expect(fetch).toHaveBeenCalledTimes(2)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('other popups close the current panel after replacement', async () => {
|
|
69
|
+
navigate()
|
|
70
|
+
renderMenu()
|
|
71
|
+
navigate()
|
|
72
|
+
await click()
|
|
73
|
+
onOtherPopupOpen.mock.calls.at(-1)[1]()
|
|
74
|
+
expect(document.getElementById('plans-list-area').style.display).toBe('none')
|
|
75
|
+
document.body.innerHTML = ''
|
|
76
|
+
expect(() => onOtherPopupOpen.mock.calls.at(-1)[1]()).not.toThrow()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('ignores unrelated clicks and pages without a plans panel', async () => {
|
|
80
|
+
navigate()
|
|
81
|
+
await click('#plans-timeline')
|
|
82
|
+
document.getElementById('plans-list-area').remove()
|
|
83
|
+
await click()
|
|
84
|
+
expect(fetch).not.toHaveBeenCalled()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('supports the fallback endpoint and an absent timeline', async () => {
|
|
88
|
+
document.getElementById('plans-list-area').removeAttribute('data-plans-url')
|
|
89
|
+
document.getElementById('plans-timeline').remove()
|
|
90
|
+
navigate()
|
|
91
|
+
await click()
|
|
92
|
+
expect(fetch).toHaveBeenCalledWith('/plans.json')
|
|
93
|
+
expect(window.initPlansTimeline).not.toHaveBeenCalled()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('stores plans when the timeline initializer is unavailable', async () => {
|
|
97
|
+
delete window.initPlansTimeline
|
|
98
|
+
navigate()
|
|
99
|
+
await click()
|
|
100
|
+
expect(document.getElementById('plans-timeline').dataset.plans).toBe('[{"id":1}]')
|
|
101
|
+
})
|
|
@@ -1,50 +1,40 @@
|
|
|
1
1
|
// Plans menu functionality
|
|
2
|
-
//
|
|
2
|
+
// Delegate clicks once: workspace navigation preserves the GNB across turbo:load.
|
|
3
3
|
|
|
4
4
|
import { notifyPopupOpen, onOtherPopupOpen } from 'collavre/lib/gnb_popup_manager'
|
|
5
5
|
|
|
6
6
|
const POPUP_ID = 'plans-menu'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
loaded = true
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
area.style.display = 'none'
|
|
44
|
-
}
|
|
45
|
-
})
|
|
7
|
+
const loadedAreas = new WeakSet()
|
|
8
|
+
|
|
9
|
+
onOtherPopupOpen(POPUP_ID, function() {
|
|
10
|
+
const area = document.getElementById('plans-list-area')
|
|
11
|
+
if (area) area.style.display = 'none'
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
document.addEventListener('click', function(event) {
|
|
15
|
+
if (!event.target.closest('.plans-menu-btn')) return
|
|
16
|
+
|
|
17
|
+
const area = document.getElementById('plans-list-area')
|
|
18
|
+
if (!area) return
|
|
19
|
+
|
|
20
|
+
if (area.style.display !== 'none') {
|
|
21
|
+
area.style.display = 'none'
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
notifyPopupOpen(POPUP_ID)
|
|
26
|
+
area.style.display = 'block'
|
|
27
|
+
if (loadedAreas.has(area)) return
|
|
28
|
+
|
|
29
|
+
const timeline = document.getElementById('plans-timeline')
|
|
30
|
+
const plansUrl = area.dataset.plansUrl || '/plans.json'
|
|
31
|
+
fetch(plansUrl)
|
|
32
|
+
.then(function(r) { return r.json() })
|
|
33
|
+
.then(function(plans) {
|
|
34
|
+
if (timeline) { timeline.dataset.plans = JSON.stringify(plans) }
|
|
35
|
+
if (window.initPlansTimeline && timeline) {
|
|
36
|
+
window.initPlansTimeline(timeline)
|
|
37
|
+
}
|
|
38
|
+
loadedAreas.add(area)
|
|
46
39
|
})
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
initPlansMenu()
|
|
40
|
+
})
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { alertDialog, confirmDialog } from "collavre/lib/utils/dialog";
|
|
2
|
+
|
|
1
3
|
let plansTimelineScriptInitialized = false;
|
|
2
4
|
|
|
3
5
|
if (!plansTimelineScriptInitialized) {
|
|
@@ -24,6 +26,12 @@ if (!plansTimelineScriptInitialized) {
|
|
|
24
26
|
var endDate = new Date(container.dataset.endDate || new Date());
|
|
25
27
|
container.dataset.lastLoadedDate = new Date().toISOString().slice(0, 10);
|
|
26
28
|
|
|
29
|
+
// "Registered" chip: when on, the timeline also draws creatives at their
|
|
30
|
+
// created_at. Default-off, so registrations are fetched lazily on toggle.
|
|
31
|
+
var registrationsEnabled = container.dataset.registrations === 'true';
|
|
32
|
+
// "Modified" chip: same idea, drawing modified creatives at their updated_at.
|
|
33
|
+
var modificationsEnabled = container.dataset.modifications === 'true';
|
|
34
|
+
|
|
27
35
|
var scroll = document.createElement('div');
|
|
28
36
|
scroll.className = 'timeline-scroll';
|
|
29
37
|
container.appendChild(scroll);
|
|
@@ -65,6 +73,8 @@ if (!plansTimelineScriptInitialized) {
|
|
|
65
73
|
function createPlanBar(plan, idx) {
|
|
66
74
|
var el = document.createElement('div');
|
|
67
75
|
el.className = 'plan-bar';
|
|
76
|
+
if (plan.type === 'registration') el.className += ' plan-bar--registration';
|
|
77
|
+
else if (plan.type === 'modification') el.className += ' plan-bar--modification';
|
|
68
78
|
el.dataset.path = plan.path;
|
|
69
79
|
el.dataset.id = plan.id;
|
|
70
80
|
var startDateValue = plan.start_date || plan.created_at;
|
|
@@ -90,9 +100,9 @@ if (!plansTimelineScriptInitialized) {
|
|
|
90
100
|
del.textContent = '×';
|
|
91
101
|
del.className = 'delete-plan-btn';
|
|
92
102
|
el.appendChild(del);
|
|
93
|
-
del.addEventListener('click', function (e) {
|
|
103
|
+
del.addEventListener('click', async function (e) {
|
|
94
104
|
e.stopPropagation();
|
|
95
|
-
if (!
|
|
105
|
+
if (!(await confirmDialog(container.dataset.deleteConfirm, { danger: true }))) return;
|
|
96
106
|
var deleteUrl;
|
|
97
107
|
if (String(plan.id).indexOf('calendar_event_') === 0) {
|
|
98
108
|
deleteUrl = '/calendar_events/' + String(plan.id).replace('calendar_event_', '');
|
|
@@ -190,6 +200,7 @@ if (!plansTimelineScriptInitialized) {
|
|
|
190
200
|
renderPlans();
|
|
191
201
|
updatePlanPositions();
|
|
192
202
|
|
|
203
|
+
var loadSeq = 0;
|
|
193
204
|
function loadPlans(centerDate) {
|
|
194
205
|
var dateStr = centerDate.toISOString().slice(0, 10);
|
|
195
206
|
if (container.dataset.lastLoadedDate === dateStr) return;
|
|
@@ -197,9 +208,16 @@ if (!plansTimelineScriptInitialized) {
|
|
|
197
208
|
var listArea = document.getElementById('plans-list-area')
|
|
198
209
|
var basePlansUrl = (listArea && listArea.dataset.plansUrl) || '/plans.json'
|
|
199
210
|
var separator = basePlansUrl.indexOf('?') >= 0 ? '&' : '?'
|
|
200
|
-
|
|
211
|
+
var requestUrl = basePlansUrl + separator + 'date=' + dateStr
|
|
212
|
+
if (registrationsEnabled) requestUrl += '®istrations=1'
|
|
213
|
+
if (modificationsEnabled) requestUrl += '&modifications=1'
|
|
214
|
+
// Discard out-of-order responses: a slower registrations fetch must not
|
|
215
|
+
// overwrite the result of a later request (e.g. rapid chip on/off).
|
|
216
|
+
var seq = ++loadSeq;
|
|
217
|
+
fetch(requestUrl)
|
|
201
218
|
.then(function (r) { return r.json(); })
|
|
202
219
|
.then(function (newPlans) {
|
|
220
|
+
if (seq !== loadSeq) return;
|
|
203
221
|
plans = newPlans.map(function (p) {
|
|
204
222
|
if (p.start_date) {
|
|
205
223
|
p.start_date = new Date(p.start_date);
|
|
@@ -235,6 +253,38 @@ if (!plansTimelineScriptInitialized) {
|
|
|
235
253
|
todayBtn.addEventListener('click', function () { scrollToDate(new Date()); });
|
|
236
254
|
}
|
|
237
255
|
|
|
256
|
+
// Re-fetch the currently centered window, bypassing the lastLoadedDate guard
|
|
257
|
+
// (used when toggling a chip changes WHAT we request for the same date).
|
|
258
|
+
function reloadCurrentView() {
|
|
259
|
+
var centerOffset = container.scrollLeft + container.clientWidth / 2;
|
|
260
|
+
var daysFromStart = centerOffset / dayWidth;
|
|
261
|
+
var centerDate = new Date(startDate.getTime() + Math.round(daysFromStart) * 86400000);
|
|
262
|
+
container.dataset.lastLoadedDate = '';
|
|
263
|
+
loadPlans(centerDate);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var registrationsChip = document.getElementById('chip-registrations');
|
|
267
|
+
if (registrationsChip) {
|
|
268
|
+
registrationsChip.addEventListener('click', function () {
|
|
269
|
+
registrationsEnabled = !registrationsEnabled;
|
|
270
|
+
container.dataset.registrations = registrationsEnabled ? 'true' : 'false';
|
|
271
|
+
registrationsChip.classList.toggle('timeline-chip--active', registrationsEnabled);
|
|
272
|
+
registrationsChip.setAttribute('aria-pressed', registrationsEnabled ? 'true' : 'false');
|
|
273
|
+
reloadCurrentView();
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
var modificationsChip = document.getElementById('chip-modifications');
|
|
278
|
+
if (modificationsChip) {
|
|
279
|
+
modificationsChip.addEventListener('click', function () {
|
|
280
|
+
modificationsEnabled = !modificationsEnabled;
|
|
281
|
+
container.dataset.modifications = modificationsEnabled ? 'true' : 'false';
|
|
282
|
+
modificationsChip.classList.toggle('timeline-chip--active', modificationsEnabled);
|
|
283
|
+
modificationsChip.setAttribute('aria-pressed', modificationsEnabled ? 'true' : 'false');
|
|
284
|
+
reloadCurrentView();
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
238
288
|
scrollToDate(new Date());
|
|
239
289
|
|
|
240
290
|
var scrollTimer;
|
|
@@ -257,7 +307,15 @@ if (!plansTimelineScriptInitialized) {
|
|
|
257
307
|
|
|
258
308
|
// Listen for plan creation from delegated handler
|
|
259
309
|
const onPlanCreated = function (e) {
|
|
260
|
-
|
|
310
|
+
// While a chip is active, the planned creative's derived
|
|
311
|
+
// registration/modification marker stops being eligible (plan anchors
|
|
312
|
+
// are excluded server-side), so re-fetch the authoritative view to drop
|
|
313
|
+
// the now-stale marker. Appending alone would leave it as a duplicate.
|
|
314
|
+
if (registrationsEnabled || modificationsEnabled) {
|
|
315
|
+
reloadCurrentView();
|
|
316
|
+
} else {
|
|
317
|
+
addPlan(e.detail);
|
|
318
|
+
}
|
|
261
319
|
};
|
|
262
320
|
document.addEventListener('plan:created', onPlanCreated);
|
|
263
321
|
|
|
@@ -398,7 +456,7 @@ if (!plansTimelineScriptInitialized) {
|
|
|
398
456
|
if (addPlanBtn) addPlanBtn.disabled = true;
|
|
399
457
|
}).catch(function (err) {
|
|
400
458
|
if (err && err.errors) {
|
|
401
|
-
|
|
459
|
+
alertDialog(err.errors.join(', '));
|
|
402
460
|
} else {
|
|
403
461
|
console.error(err);
|
|
404
462
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module CollavrePlan
|
|
2
|
+
class TimelineItems
|
|
3
|
+
# routes: pass a request-aware proxy (e.g. helpers.collavre) to keep the caller's script name.
|
|
4
|
+
def initialize(creative_id: nil, routes: Collavre::Engine.routes.url_helpers)
|
|
5
|
+
@creative_id = creative_id
|
|
6
|
+
@routes = routes
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def all(plans:, calendar_events:, registrations:, modifications:)
|
|
10
|
+
plans.map { |record| plan(record) } +
|
|
11
|
+
calendar_events.map { |event| calendar_event(event) } +
|
|
12
|
+
registrations.map { |creative| registration(creative) } +
|
|
13
|
+
modifications.map { |creative| modification(creative) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def plan(plan)
|
|
17
|
+
{
|
|
18
|
+
id: plan.id,
|
|
19
|
+
name: (plan.creative&.effective_description(nil, false) || plan.name.presence || I18n.l(plan.target_date)),
|
|
20
|
+
created_at: plan.created_at.to_date,
|
|
21
|
+
start_date: plan.start_date,
|
|
22
|
+
target_date: plan.target_date,
|
|
23
|
+
progress: plan.progress,
|
|
24
|
+
path: plan_creatives_path(plan),
|
|
25
|
+
deletable: plan.owner_id == Collavre::Current.user&.id
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def calendar_event(event)
|
|
30
|
+
{
|
|
31
|
+
id: "calendar_event_#{event.id}",
|
|
32
|
+
name: event.summary.presence || I18n.l(event.start_time.to_date),
|
|
33
|
+
created_at: event.start_time.to_date,
|
|
34
|
+
target_date: event.end_time.to_date,
|
|
35
|
+
progress: event.creative&.progress || 0,
|
|
36
|
+
path: event.creative ? @routes.creative_path(event.creative) : event.html_link,
|
|
37
|
+
deletable: event.user_id == Collavre::Current.user&.id
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def registration(creative)
|
|
42
|
+
marker(creative, "registration", creative.created_at.to_date,
|
|
43
|
+
I18n.t("collavre.plans.registration_fallback", id: creative.id))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def modification(creative)
|
|
47
|
+
marker(creative, "modification", creative.updated_at.to_date,
|
|
48
|
+
I18n.t("collavre.plans.modification_fallback", id: creative.id))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def marker(creative, type, date, fallback_name)
|
|
54
|
+
{
|
|
55
|
+
id: "#{type}_#{creative.id}",
|
|
56
|
+
type: type,
|
|
57
|
+
name: creative.effective_description(nil, false).presence || fallback_name,
|
|
58
|
+
created_at: date,
|
|
59
|
+
target_date: date,
|
|
60
|
+
progress: creative.progress,
|
|
61
|
+
path: @routes.creative_path(creative),
|
|
62
|
+
deletable: false
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def plan_creatives_path(plan)
|
|
67
|
+
if @creative_id.present?
|
|
68
|
+
@routes.creative_path(@creative_id, tags: [ plan.id ])
|
|
69
|
+
else
|
|
70
|
+
@routes.creatives_path(tags: [ plan.id ])
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<button id="set-plan-btn" class="set-plan-btn" style="display:none;" data-creatives--
|
|
1
|
+
<button type="button" id="set-plan-btn" class="set-plan-btn" style="display:none;" data-controller="creatives--set-plan-button" data-action="click->creatives--set-plan-button#open" data-creatives--select-mode-target="setPlan"><%= t('app.set_plan') %></button>
|
data/config/locales/plans.en.yml
CHANGED
|
@@ -14,3 +14,7 @@ en:
|
|
|
14
14
|
delete_confirm: Are you sure you want to delete this plan?
|
|
15
15
|
today: Today
|
|
16
16
|
select_creative: Select Creative
|
|
17
|
+
chip_registrations: Registered
|
|
18
|
+
chip_modifications: Modified
|
|
19
|
+
registration_fallback: 'Creative #%{id}'
|
|
20
|
+
modification_fallback: 'Creative #%{id}'
|
data/config/locales/plans.ko.yml
CHANGED
|
@@ -14,6 +14,10 @@ ko:
|
|
|
14
14
|
delete_confirm: 이 계획을 삭제하시겠습니까?
|
|
15
15
|
today: 오늘
|
|
16
16
|
select_creative: 크리에이티브 선택
|
|
17
|
+
chip_registrations: 등록
|
|
18
|
+
chip_modifications: 수정
|
|
19
|
+
registration_fallback: '크리에이티브 #%{id}'
|
|
20
|
+
modification_fallback: '크리에이티브 #%{id}'
|
|
17
21
|
activerecord:
|
|
18
22
|
errors:
|
|
19
23
|
models:
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: collavre_plan
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collavre
|
|
@@ -45,18 +45,25 @@ extensions: []
|
|
|
45
45
|
extra_rdoc_files: []
|
|
46
46
|
files:
|
|
47
47
|
- Rakefile
|
|
48
|
+
- app/assets/stylesheets/collavre_plan/timeline.css
|
|
48
49
|
- app/components/collavre/plans_timeline_component.html.erb
|
|
49
50
|
- app/components/collavre/plans_timeline_component.rb
|
|
50
51
|
- app/controllers/collavre_plan/application_controller.rb
|
|
51
52
|
- app/controllers/collavre_plan/creative_plans_controller.rb
|
|
52
53
|
- app/controllers/collavre_plan/plans_controller.rb
|
|
53
54
|
- app/javascript/collavre_plan.js
|
|
55
|
+
- app/javascript/controllers/__tests__/index.test.js
|
|
56
|
+
- app/javascript/controllers/creatives/__tests__/set_plan_button_controller.test.js
|
|
57
|
+
- app/javascript/controllers/creatives/__tests__/set_plan_modal_controller.test.js
|
|
58
|
+
- app/javascript/controllers/creatives/set_plan_button_controller.js
|
|
54
59
|
- app/javascript/controllers/creatives/set_plan_modal_controller.js
|
|
55
60
|
- app/javascript/controllers/index.js
|
|
61
|
+
- app/javascript/modules/__tests__/plans_menu.test.js
|
|
56
62
|
- app/javascript/modules/plans_menu.js
|
|
57
63
|
- app/javascript/modules/plans_timeline.js
|
|
58
64
|
- app/models/collavre/plan.rb
|
|
59
65
|
- app/services/collavre/creatives/plan_tagger.rb
|
|
66
|
+
- app/services/collavre_plan/timeline_items.rb
|
|
60
67
|
- app/views/collavre/creatives/_set_plan_modal.html.erb
|
|
61
68
|
- app/views/collavre/labels/_plan_extra.html.erb
|
|
62
69
|
- app/views/collavre/labels/_plan_suffix.html.erb
|
|
@@ -90,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
97
|
- !ruby/object:Gem::Version
|
|
91
98
|
version: '0'
|
|
92
99
|
requirements: []
|
|
93
|
-
rubygems_version: 3.6.
|
|
100
|
+
rubygems_version: 3.6.9
|
|
94
101
|
specification_version: 4
|
|
95
102
|
summary: Plan feature for Collavre
|
|
96
103
|
test_files: []
|