Skip to content

Commit 4decbb1

Browse files
Implement completions from url
1 parent fe471ed commit 4decbb1

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

assets.src/src/redmine-tracky/controllers/issue-completion-controller.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default class extends Controller {
1818

1919
connect() {
2020
this.listenForInput()
21+
this.fetchIssuesFromURL()
2122
}
2223

2324
private listenForInput() {
@@ -42,6 +43,26 @@ export default class extends Controller {
4243
)
4344
}
4445

46+
private fetchIssuesFromURL() {
47+
const urlParams = new URLSearchParams(window.location.search)
48+
const issueIds = urlParams.getAll('issue_ids[]')
49+
50+
issueIds.forEach(id => {
51+
const url = window.RedmineTracky.issueCompletionPath
52+
const data = { term: id, scope: 'all' }
53+
console.log(`Fetching issue with ID: ${id}`)
54+
55+
$.get(url, data, null, 'json')
56+
.done((results: CompletionResult[]) => {
57+
const [result] = results
58+
this.addIssue({ item: result })
59+
})
60+
.fail(() => {
61+
console.error(`Failed to fetch issue with ID: ${id}`)
62+
})
63+
})
64+
}
65+
4566
private addIssue(issue: { item: CompletionResult }) {
4667
const listController =
4768
this.application.getControllerForElementAndIdentifier(

assets/javascripts/redmine-tracky.js

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/system/timer_management_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@ class TimerManagementTest < ApplicationSystemTestCase
103103
assert_equal(time_in_user_time_zone.strftime(I18n.t('timer_sessions.formats.datetime_format')),
104104
TimerSession.last.timer_end.strftime(I18n.t('timer_sessions.formats.datetime_format')))
105105
end
106+
107+
test 'loading timer with issues from url' do
108+
timer_session = FactoryBot.create(:timer_session, :with_issues, finished: false, user: User.current)
109+
visit timer_sessions_path("issue_ids[]=#{Issue.first.id}&issue_ids[]=#{Issue.second.id}")
110+
assert has_content?(timer_session.comments)
111+
assert has_content?(Issue.first.subject)
112+
assert has_content?(Issue.second.subject)
113+
end
106114
end

0 commit comments

Comments
 (0)