Skip to content

Commit df3336e

Browse files
committed
Update prefil notice
1 parent c5d3346 commit df3336e

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

app/views/timer_sessions/_timer_container.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="box" data-controller="form timer" data-timer-timezone-value="<%= offset_for_time_zone %>"
22
data-form-share-copied-value="<%= t('timer_sessions.timer.share_copied') %>"
3+
data-form-share-prefilled-value="<%= t('timer_sessions.timer.share_prefilled') %>"
34
data-form-share-ignored-value="<%= t('timer_sessions.timer.share_ignored') %>"
45
data-form-session-active-value="<%= timer_session.persisted? %>">
56
<div class="timer-container">

assets.src/src/redmine-tracky/controllers/form-controller.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class extends Controller {
1010
declare readonly descriptionTarget: HTMLInputElement
1111
declare readonly issueTargets: Element[]
1212
declare readonly shareCopiedValue: string
13+
declare readonly sharePrefilledValue: string
1314
declare readonly shareIgnoredValue: string
1415
declare readonly sessionActiveValue: boolean
1516

@@ -26,14 +27,18 @@ export default class extends Controller {
2627

2728
static values = {
2829
shareCopied: String,
30+
sharePrefilled: String,
2931
shareIgnored: String,
3032
sessionActive: Boolean,
3133
}
3234

3335
public connect() {
3436
this.connected = true
35-
this.prefillFieldsFromURL()
36-
this.showShareIgnoredNotice()
37+
if (this.sessionActiveValue) {
38+
this.showShareIgnoredNotice()
39+
} else {
40+
this.prefillFieldsFromURL()
41+
}
3742
}
3843

3944
public disconnect() {
@@ -95,24 +100,31 @@ export default class extends Controller {
95100
const url = `${window.location.origin}${window.location.pathname}${query}`
96101

97102
navigator.clipboard.writeText(url).then(() => {
98-
this.showFlashNotice(this.shareCopiedValue)
103+
this.showFlash(this.shareCopiedValue, 'notice')
99104
})
100105
}
101106

102107
private prefillFieldsFromURL() {
103108
const urlParams = new URLSearchParams(window.location.search)
104109

105-
this.prefillField(urlParams, 'comments', this.descriptionTarget)
106-
this.prefillField(urlParams, 'timer_start', this.startTarget)
107-
this.prefillField(urlParams, 'timer_end', this.endTarget)
110+
const prefilled = [
111+
this.prefillField(urlParams, 'comments', this.descriptionTarget),
112+
this.prefillField(urlParams, 'timer_start', this.startTarget),
113+
this.prefillField(urlParams, 'timer_end', this.endTarget),
114+
].some(Boolean)
115+
116+
if (prefilled) {
117+
this.showFlash(this.sharePrefilledValue, 'notice')
118+
}
108119
}
109120

110-
private prefillField(urlParams: URLSearchParams, param: string, target: HTMLInputElement) {
121+
private prefillField(urlParams: URLSearchParams, param: string, target: HTMLInputElement): boolean {
111122
const value = urlParams.get(param)
112-
if (!value) return
123+
if (!value) return false
113124

114125
target.value = value
115126
target.dispatchEvent(new Event('change'))
127+
return true
116128
}
117129

118130
private showShareIgnoredNotice() {
@@ -125,26 +137,27 @@ export default class extends Controller {
125137
urlParams.getAll('issue_ids[]').some((v) => v !== '')
126138

127139
if (hasShareParams) {
128-
this.showFlashNotice(this.shareIgnoredValue)
140+
this.showFlash(this.shareIgnoredValue, 'warning')
129141
}
130142
}
131143

132-
private showFlashNotice(message: string) {
133-
const flash = document.getElementById('flash_notice')
134-
if (flash) {
135-
flash.textContent = message
136-
flash.style.display = ''
144+
private showFlash(message: string, type: 'notice' | 'warning') {
145+
const flashId = `flash_${type}`
146+
const existing = document.getElementById(flashId)
147+
if (existing) {
148+
existing.textContent = message
149+
existing.style.display = ''
137150
return
138151
}
139152

140153
const container = document.getElementById('content')
141154
if (!container) return
142155

143-
const notice = document.createElement('div')
144-
notice.id = 'flash_notice'
145-
notice.className = 'flash notice'
146-
notice.textContent = message
147-
container.prepend(notice)
156+
const flash = document.createElement('div')
157+
flash.id = flashId
158+
flash.className = `flash ${type}`
159+
flash.textContent = message
160+
container.prepend(flash)
148161
}
149162

150163
private extractIssueIds(): string[] {

assets/javascripts/redmine-tracky.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/locales/de.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ de:
7575
continue_last_session: Anschliessend Starten
7676
share: Teilen
7777
share_copied: Link in die Zwischenablage kopiert
78+
share_prefilled: Session wurde von einem geteilten Link vorausgefüllt
7879
share_ignored: Ein Timer läuft bereits. Die geteilten Parameter wurden ignoriert.
7980
stop: Stop
8081
cancel: Abbrechen

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ en:
7979
continue_last_session: Start on end of last session
8080
share: Share
8181
share_copied: Link copied to clipboard
82+
share_prefilled: Session was prefilled from a shared link
8283
share_ignored: A timer is already running. Shared session parameters were ignored.
8384
stop: Stop
8485
cancel: Cancel

test/system/timer_management_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class TimerManagementTest < ApplicationSystemTestCase
145145
timer_end: '01.01.2026 10:00'
146146
)
147147

148+
assert_text I18n.t('timer_sessions.timer.share_prefilled')
148149
assert_text Issue.first.subject
149150
assert_equal 'Sprint planning', find('#timer_session_comments').value
150151
assert_equal '01.01.2026 09:00', find('#timer_session_timer_start').value
@@ -168,11 +169,19 @@ class TimerManagementTest < ApplicationSystemTestCase
168169
assert_no_selector('[data-name="timer-share"]')
169170
end
170171

171-
test 'shows prefill notice when active session exists and url has params' do
172+
test 'shows only ignored notice when active session exists and url has params' do
172173
FactoryBot.create(:timer_session, finished: false, user: User.current)
173174
visit timer_sessions_path(comments: 'Meeting', issue_ids: [Issue.first.id])
174175

175176
assert_text I18n.t('timer_sessions.timer.share_ignored')
177+
assert_no_text I18n.t('timer_sessions.timer.share_prefilled')
178+
end
179+
180+
test 'shows only prefilled notice when no active session and url has params' do
181+
visit timer_sessions_path(comments: 'Sprint planning', timer_start: '01.01.2026 09:00')
182+
183+
assert_text I18n.t('timer_sessions.timer.share_prefilled')
184+
assert_no_text I18n.t('timer_sessions.timer.share_ignored')
176185
end
177186

178187
test 'preserves filter parameters when stopping a timer' do

0 commit comments

Comments
 (0)