Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement completions from url #156

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class extends Controller {

connect() {
this.listenForInput()
this.fetchIssuesFromURL()
}

private listenForInput() {
Expand All @@ -42,6 +43,26 @@ export default class extends Controller {
)
}

private fetchIssuesFromURL() {
const urlParams = new URLSearchParams(window.location.search)
const issueIds = urlParams.getAll('issue_ids[]')

issueIds.forEach(id => {
const url = window.RedmineTracky.issueCompletionPath
const data = { term: id, scope: 'all' }
console.log(`Fetching issue with ID: ${id}`)

$.get(url, data, null, 'json')
.done((results: CompletionResult[]) => {
const [result] = results
this.addIssue({ item: result })
})
.fail(() => {
console.error(`Failed to fetch issue with ID: ${id}`)
})
})
}

private addIssue(issue: { item: CompletionResult }) {
const listController =
this.application.getControllerForElementAndIdentifier(
Expand Down
22 changes: 20 additions & 2 deletions assets/javascripts/redmine-tracky.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions test/system/timer_management_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,12 @@ class TimerManagementTest < ApplicationSystemTestCase
assert_equal(time_in_user_time_zone.strftime(I18n.t('timer_sessions.formats.datetime_format')),
TimerSession.last.timer_end.strftime(I18n.t('timer_sessions.formats.datetime_format')))
end

test 'loading timer with issues from url' do
timer_session = FactoryBot.create(:timer_session, :with_issues, finished: false, user: User.current)
visit timer_sessions_path("issue_ids[]=#{Issue.first.id}&issue_ids[]=#{Issue.second.id}")
assert has_content?(timer_session.comments)
assert has_content?(Issue.first.subject)
assert has_content?(Issue.second.subject)
end
end
Loading