Feature #44552 » 0001-Add-a-link-from-each-issue-attachment-to-the-note-in.patch
| app/assets/images/icons.svg | ||
|---|---|---|
|
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--checked">
|
||
|
<path d="M5 12l5 5l10 -10"/>
|
||
|
</symbol>
|
||
|
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--chevrons-down">
|
||
|
<path d="M7 7l5 5l5 -5"/>
|
||
|
<path d="M7 13l5 5l5 -5"/>
|
||
|
</symbol>
|
||
|
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--chevrons-left">
|
||
|
<path d="M11 7l-5 5l5 5"/>
|
||
|
<path d="M17 7l-5 5l5 5"/>
|
||
| app/assets/stylesheets/application.css | ||
|---|---|---|
|
div.attachments img { vertical-align: middle; }
|
||
|
div.attachments span.author { font-size: 0.9em; color: var(--oc-gray-6); }
|
||
|
div.attachments span.attachment-journal { display: inline-flex; inline-size: 18px; block-size: 18px; vertical-align: text-bottom; }
|
||
|
div.thumbnails {margin:0.6em;}
|
||
|
div.thumbnail {
|
||
| app/helpers/attachments_helper.rb | ||
|---|---|---|
|
# Options:
|
||
|
# :author -- author names are not displayed if set to false
|
||
|
# :thumbails -- display thumbnails if enabled in settings
|
||
|
# :journals -- hash of journals keyed by attachment id, used to display
|
||
|
# a link to the journal that added each attachment
|
||
|
def link_to_attachments(container, options = {})
|
||
|
options.assert_valid_keys(:author, :thumbnails)
|
||
|
options.assert_valid_keys(:author, :thumbnails, :journals)
|
||
|
attachments =
|
||
|
if container.attachments.loaded?
|
||
|
container.attachments
|
||
| app/helpers/issues_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
# Returns a hash of the journals that added an attachment,
|
||
|
# keyed by attachment id
|
||
|
def journals_by_attachment_id(journals)
|
||
|
journals.to_a.each_with_object({}) do |journal, h|
|
||
|
journal.details.each do |detail|
|
||
|
next unless detail.property == 'attachment' && detail.value.present?
|
||
|
h[detail.prop_key.to_i] = journal
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Issue history tabs
|
||
|
def issue_history_tabs
|
||
|
tabs = []
|
||
| app/views/attachments/_links.html.erb | ||
|---|---|---|
|
</td>
|
||
|
<td><%= attachment.description unless attachment.description.blank? %></td>
|
||
|
<td>
|
||
|
<% if options[:journals].present? %>
|
||
|
<span class="attachment-journal">
|
||
|
<% if journal = options[:journals][attachment.id] %>
|
||
|
<% anchor = "#note-#{journal.indice}" %>
|
||
|
<%= link_to sprite_icon('chevrons-down', anchor), anchor,
|
||
|
:title => anchor,
|
||
|
:class => 'icon-only icon-chevrons-down' %>
|
||
|
<% end %>
|
||
|
</span>
|
||
|
<% end %>
|
||
|
<% if options[:author] %>
|
||
|
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
|
||
|
<% end %>
|
||
| app/views/issues/show.html.erb | ||
|---|---|---|
|
<% if @issue.attachments.any? %>
|
||
|
<hr />
|
||
|
<p><strong><%=l(:label_attachment_plural)%></strong></p>
|
||
|
<%= link_to_attachments @issue, :thumbnails => true %>
|
||
|
<%= link_to_attachments @issue, :thumbnails => true, :journals => journals_by_attachment_id(@journals) %>
|
||
|
<% end %>
|
||
|
<%= render_full_width_custom_fields_rows(@issue) %>
|
||
| config/icon_source.yml | ||
|---|---|---|
|
svg: chevrons-right
|
||
|
- name: chevrons-left
|
||
|
svg: chevrons-left
|
||
|
- name: chevrons-down
|
||
|
svg: chevrons-down
|
||
|
- name: key
|
||
|
svg: key
|
||
|
- name: search
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
assert_select 'div#relations div.contextual a.icon.icon-link-add', :text => /Add/
|
||
|
end
|
||
|
def test_show_should_link_attachments_to_the_journal_that_added_them
|
||
|
@request.session[:user_id] = 2
|
||
|
get(:show, :params => {:id => 2})
|
||
|
assert_response :success
|
||
|
# Attachment 4 was added by journal 3, which is the first journal of the issue
|
||
|
assert_select 'div.attachments a.icon-attachment[href=?]', '/attachments/4'
|
||
|
assert_select 'div.attachments span.attachment-journal a', 1
|
||
|
assert_select 'div.attachments span.attachment-journal a[href=?][title=?]', '#note-1', '#note-1' do
|
||
|
assert_select "svg.icon-svg use:match('href', ?)", /assets\/icons-\w+.svg#icon--chevrons-down/
|
||
|
end
|
||
|
end
|
||
|
def test_show_should_not_link_attachments_to_invisible_private_notes
|
||
|
journal = Journal.find(3)
|
||
|
journal.update_columns(:private_notes => true, :user_id => 1)
|
||
|
@request.session[:user_id] = 2
|
||
|
get(:show, :params => {:id => 2})
|
||
|
assert_response :success
|
||
|
assert_select 'div.attachments span.attachment-journal a[href=?]', '#note-1'
|
||
|
Role.find(1).remove_permission! :view_private_notes
|
||
|
get(:show, :params => {:id => 2})
|
||
|
assert_response :success
|
||
|
assert_select 'div.attachments a.icon-attachment[href=?]', '/attachments/4'
|
||
|
assert_select 'div.attachments span.attachment-journal', 0
|
||
|
end
|
||
|
def test_show_should_display_attachment_icons_by_mime_type
|
||
|
@request.session[:user_id] = 2
|
||
|
get(:show, :params => {:id => 3})
|
||
| test/helpers/issues_helper_test.rb | ||
|---|---|---|
|
assert_include "<a href=\"/issues?issue_id=#{open_issue.id}%2C#{closed_issue.id}&set_filter=true&status_id=o\">1 open</a>", html
|
||
|
assert_include "<a href=\"/issues?issue_id=#{open_issue.id}%2C#{closed_issue.id}&set_filter=true&status_id=c\">1 closed</a>", html
|
||
|
end
|
||
|
def test_journals_by_attachment_id
|
||
|
issue = Issue.find(2)
|
||
|
# Detail of a removed attachment
|
||
|
JournalDetail.create!(:journal => issue.journals.last, :property => 'attachment',
|
||
|
:prop_key => '99', :old_value => 'removed.txt')
|
||
|
journals = issue.visible_journals_with_index(User.find(2))
|
||
|
result = journals_by_attachment_id(journals)
|
||
|
assert_equal [4], result.keys
|
||
|
assert_equal 3, result[4].id
|
||
|
assert_equal 1, result[4].indice
|
||
|
end
|
||
|
end
|
||