Skip to content

Commit

Permalink
#1563 file icons
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Nov 22, 2024
1 parent fa62c09 commit d5312ae
Show file tree
Hide file tree
Showing 49 changed files with 94 additions and 106 deletions.
13 changes: 0 additions & 13 deletions app/helpers/dmsf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ def self.sanitize_filename(filename)
just_filename
end

def self.filetype_css(filename)
extension = File.extname(filename)
extension = extension[1, extension.length - 1]
path = File.join(Redmine::Plugin.public_directory, ['redmine_dmsf', 'images', 'filetypes', "#{extension}.png"])
cls = if File.exist?(path)
"filetype-#{extension}"
else
Redmine::MimeType.css_class_of filename
end
cls << ' dmsf-icon-file' if cls
cls
end

def plugin_asset_path(plugin, asset_type, source)
File.join('/plugin_assets', plugin.to_s, asset_type, source)
end
Expand Down
64 changes: 33 additions & 31 deletions app/helpers/dmsf_queries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,21 @@ def column_value(column, item, value)
when 'file'
file = DmsfFile.find_by(id: item.id)
if file&.locked?
return content_tag(:span, val) +
content_tag(:span,
'',
title: l(:title_locked_by_user, user: file.locked_by),
class: 'icon icon-unlock dmsf-icon-unlock')
return content_tag(:span, val) + content_tag('span',
sprite_icon('unlock', ''),
title: l(:title_locked_by_user, user: file.locked_by),
class: 'icon icon-unlock dmsf-icon-unlock')
end
when 'folder'
folder = DmsfFolder.find_by(id: item.id)
if folder&.locked?
return content_tag(:span, val) +
content_tag(:span,
'',
title: l(:title_locked_by_user, user: folder.locked_by),
class: 'icon icon-unlock dmsf-icon-unlock')
return content_tag(:span, val) + content_tag('span',
sprite_icon('unlock', ''),
title: l(:title_locked_by_user, user: folder.locked_by),
class: 'icon icon-unlock dmsf-icon-unlock')
end
end
content_tag(:span, val) +
content_tag(:span, '', class: 'icon icon-none')
content_tag(:span, val) + content_tag(:span, '', class: 'icon icon-none')
when :id
case item.type
when 'file'
Expand Down Expand Up @@ -109,9 +106,9 @@ def column_value(column, item, value)
when 'project'
tag = h("[#{value}]")
tag = if item.project.module_enabled?(:dmsf)
link_to tag, dmsf_folder_path(id: item.project), class: 'icon icon-folder'
link_to sprite_icon('folder', tag), dmsf_folder_path(id: item.project)
else
content_tag 'span', tag, class: 'icon icon-folder'
sprite_icon 'folder', tag
end
unless filter_any?
path = expand_folder_dmsf_path
Expand All @@ -130,7 +127,7 @@ def column_value(column, item, value)
end
tag += content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download))
if item.project.watched_by?(User.current)
tag += link_to('',
tag += link_to(sprite_icon('unlock', ''),
watch_path(object_type: 'project', object_id: item.project.id),
title: l(:button_unwatch),
method: 'delete',
Expand All @@ -139,9 +136,10 @@ def column_value(column, item, value)
tag
when 'folder'
if item&.deleted?
tag = content_tag('span', value, class: 'icon icon-folder')
tag = sprite_icon('folder', h(value))
else
tag = link_to(h(value), dmsf_folder_path(id: item.project, folder_id: item.id), class: 'icon icon-folder')
tag = link_to(sprite_icon('folder', h(value)),
dmsf_folder_path(id: item.project, folder_id: item.id))
unless filter_any?
path = expand_folder_dmsf_path
columns = params['c']
Expand All @@ -160,7 +158,7 @@ def column_value(column, item, value)
end
tag += content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download))
if !item&.deleted? && item.watched_by?(User.current)
tag += link_to('',
tag += link_to(sprite_icon('fav', ''),
watch_path(object_type: 'dmsf_folder', object_id: item.id),
title: l(:button_unwatch),
method: 'delete',
Expand All @@ -169,40 +167,40 @@ def column_value(column, item, value)
tag
when 'folder-link'
if item&.deleted?
tag = content_tag('span', value, class: 'icon icon-folder')
tag = sprite_icon('folder', h(value))
else
# For links we use revision_id containing dmsf_folder.id in fact
tag = link_to(h(value),
dmsf_folder_path(id: item.project, folder_id: item.revision_id),
class: 'icon icon-folder')
# For links, we use revision_id containing dmsf_folder.id in fact
tag = link_to(sprite_icon('folder', h(value)), dmsf_folder_path(id: item.project,
folder_id: item.revision_id))
tag = content_tag('span', '', class: 'dmsf-expander') + tag unless filter_any?
end
tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:label_target_folder))
when 'file', 'file-link'
icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(item.filename))
if item&.deleted?
tag = content_tag('span', value, class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}")
tag = sprite_icon(icon_name, h(value), css_class: 'icon icon-file')
else
# For links we use revision_id containing dmsf_file.id in fact
# For links, we use revision_id containing dmsf_file.id in fact
file_view_url = url_for(
{ controller: :dmsf_files, action: 'view', id: item.type == 'file' ? item.id : item.revision_id }
)
content_type = Redmine::MimeType.of(item.filename)
content_type = 'application/octet-stream' if content_type.blank?
options = { class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}",
'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}" }
options = { class: 'icon icon-file', 'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}" }
unless previewable?(item.filename, content_type)
options[:target] = '_blank'
options[:rel] = 'noopener'
end
tag = link_to h(value), file_view_url, options
tag = link_to(sprite_icon(icon_name, h(value)), file_view_url, options)

tag = content_tag('span', '', class: 'dmsf-expander') + tag unless filter_any?
end
member = Member.find_by(user_id: User.current.id, project_id: item.project_id)
revision = DmsfFileRevision.find_by(id: item.customized_id)
filename = revision ? revision.formatted_name(member) : item.filename
tag += content_tag('div', filename, class: 'dmsf-filename', title: l(:title_filename_for_download))
if (item.type == 'file') && !item&.deleted? && revision.dmsf_file&.watched_by?(User.current)
tag += link_to('',
tag += link_to(sprite_icon('fav', ''),
watch_path(object_type: 'dmsf_file', object_id: item.id),
title: l(:button_unwatch),
method: 'delete',
Expand All @@ -211,9 +209,13 @@ def column_value(column, item, value)
tag
when 'url-link'
if item&.deleted?
tag = content_tag('span', value, class: 'icon dmsf-icon-link')
tag = sprite_icon('link', h(value))
else
tag = link_to(h(value), item.filename, target: '_blank', rel: 'noopener', class: 'icon dmsf-icon-link')
tag = link_to(sprite_icon('link', h(value)),
item.filename,
target: '_blank',
rel: 'noopener',
class: 'icon dmsf-icon-link')
tag = content_tag('span', '', class: 'dmsf-expander') + tag unless filter_any?
end
tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:field_url))
Expand Down
4 changes: 2 additions & 2 deletions app/views/dmsf_context_menus/_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
<% end %>
<% url << dmsf_file.name %>
<% end %>
<%= context_menu_link sprite_icon('edit', l(:button_edit_content)), url,
class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}",
<% icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(dmsf_file.name)) %>
<%= context_menu_link sprite_icon(icon_name, l(:button_edit_content)), url, class: 'icon icon-file',
disabled: url.blank? || (locked && !unlockable) ||
(Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] != 'WEBDAV_READ_WRITE') %>
</li>
Expand Down
50 changes: 25 additions & 25 deletions app/views/dmsf_files/_link.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

<td class="<%= cls %>">
<% file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: dmsf_file }) %>
<%= link_to h(link ? link.name : dmsf_file.title),
<% icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(dmsf_file.name)) %>
<%= link_to sprite_icon(icon_name, h(link ? link.name : dmsf_file.title)),
file_view_url,
target: '_blank',
rel: 'noopener',
class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}",
class: 'icon icon-file',
title: h(dmsf_file.last_revision.try(:tooltip)),
'data-downloadurl' => "#{dmsf_file.last_revision.detect_content_type}:#{h(dmsf_file.name)}:#{file_view_url}" %>
</td>
Expand All @@ -47,38 +48,37 @@
<span class="dmsf_upload_select">
<% # Details %>
<% if User.current.allowed_to? :file_manipulation, dmsf_file.project %>
<%= link_to '', dmsf_file_path(id: dmsf_file, back_url: issue_path(@issue)),
<%= link_to sprite_icon('edit', ''), dmsf_file_path(id: dmsf_file, back_url: issue_path(@issue)),
title: l(:link_details, title: h(dmsf_file.last_revision.title)),
class: 'icon-only icon-edit' %>
<% else %>
<span class="icon-only"></span>
<% end %>
<% # Email %>
<%= link_to '', entries_operations_dmsf_path(id: dmsf_file.project_id, email_entries: 'email',
ids: ["file-#{dmsf_file.id}"], back_url: issue_path(@issue)), method: :post, title: l(:heading_send_documents_by_email),
class: 'icon-only icon-email-disabled' %>
<%= link_to sprite_icon('email', ''), entries_operations_dmsf_path(id: dmsf_file.project_id, email_entries: 'email',
ids: ["file-#{dmsf_file.id}"],
back_url: issue_path(@issue)),
method: :post, title: l(:heading_send_documents_by_email), class: 'icon-only icon-email-disabled' %>
<% # Lock %>
<% if !dmsf_file.locked? %>
<%= link_to '', lock_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: l(:title_lock_file),
class: 'icon-only icon-lock' %>
<%= link_to sprite_icon('lock', ''), lock_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: l(:title_lock_file), class: 'icon-only icon-lock' %>
<% elsif dmsf_file.unlockable? && (!dmsf_file.locked_for_user? || User.current.allowed_to?(:force_file_unlock, dmsf_file.project)) %>
<%= link_to '', unlock_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: dmsf_file.locked_title,
class: 'icon-only icon-unlock' %>
<%= link_to sprite_icon('unlock', ''), unlock_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: dmsf_file.locked_title, class: 'icon-only icon-unlock' %>
<% else %>
<span class="icon-only icon-unlock" title="<%= dmsf_file.locked_title %>"></span>
<%= content_tag('span', sprite_icon('unlock', ''), title: dmsf_file.locked_title) %>
<% end %>
<% if !dmsf_file.locked? %>
<% # Notifications %>
<% if dmsf_file.notification %>
<%= link_to '', notify_deactivate_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: l(:title_notifications_active_deactivate),
class: 'icon-only icon-email' %>
<%= link_to sprite_icon('email', ''), notify_deactivate_dmsf_files_path(id: dmsf_file,
back_url: issue_path(@issue)),
title: l(:title_notifications_active_deactivate), class: 'icon-only icon-email' %>
<% else %>
<%= link_to '', notify_activate_dmsf_files_path(id: dmsf_file, back_url: issue_path(@issue)),
title: l(:title_notifications_not_active_activate),
class: 'icon-only icon-email-add' %>
<%= link_to sprite_icon('email-disabled', ''), notify_activate_dmsf_files_path(id: dmsf_file,
back_url: issue_path(@issue)),
title: l(:title_notifications_not_active_activate), class: 'icon-only icon-email-add' %>
<% end %>
<% else %>
<span class="icon-only"></span>
Expand All @@ -88,12 +88,12 @@
<% if @issue.attributes_editable? &&
((link && User.current.allowed_to?(:file_manipulation, dmsf_file.project)) ||
(!link && User.current.allowed_to?(:file_delete, dmsf_file.project))) %>
<%= link_to '',
link ? dmsf_link_path(link, commit: 'yes', back_url: issue_path(@issue)) : dmsf_file_path(id: dmsf_file, commit: 'yes', back_url: issue_path(@issue)),
data: { confirm: l(:text_are_you_sure) },
method: :delete,
title: l(:button_delete),
class: 'icon-only icon-del' %>
<% url = if link
dmsf_link_path(link, commit: 'yes', back_url: issue_path(@issue))
else
dmsf_file_path(id: dmsf_file, commit: 'yes', back_url: issue_path(@issue))
end %>
<%= delete_link url %>
<% end %>
<% # Approval workflow %>
<% wf = DmsfWorkflow.find_by(id: dmsf_file.last_revision.dmsf_workflow_id) if dmsf_file.last_revision.dmsf_workflow_id %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/dmsf_workflows/_approval_workflow_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% assignments = wf.next_assignments(file.last_revision.id) %>
<% index = assignments.find_index{|assignment| assignment.user_id == User.current.id} if assignments %>
<% if assignments && index %>
<%= link_to '',
<%= link_to sprite_icon('checked', ''),
action_dmsf_workflow_path(project_id: project.id, id: wf.id,
dmsf_workflow_step_assignment_id: assignments[index].id,
dmsf_file_revision_id: file.last_revision.id,
Expand All @@ -42,7 +42,7 @@
<% end %>
<% when DmsfWorkflow::STATE_ASSIGNED %>
<% if User.current && (file.last_revision.dmsf_workflow_assigned_by_user == User.current) && wf %>
<%= link_to '',
<%= link_to sprite_icon('checked', ''),
start_dmsf_workflow_path(id: file.last_revision.dmsf_workflow_id,
dmsf_file_revision_id: file.last_revision.id,
back_url: back_url),
Expand All @@ -55,7 +55,7 @@
<span class="icon-only"></span>
<% else %>
<% if workflows_available %>
<%= link_to '',
<%= link_to sprite_icon('checked', ''),
dmsf_link_id ?
assign_dmsf_workflow_path(id: project.id, project_id: project.id, dmsf_link_id: dmsf_link_id,
back_url: back_url) :
Expand Down
4 changes: 2 additions & 2 deletions app/views/my/blocks/_locked_documents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
<%= link_to_project file.project %>
</td>
<td class="title">
<%= link_to h(file.title), dmsf_file_path(id: file),
class: "icon icon-file #{DmsfHelper.filetype_css(file.name)}" %>
<% icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(file.name)) %>
<%= link_to sprite_icon(icon_name, h(file.title)), dmsf_file_path(id: file), class: 'icon icon-file' %>
</td>
<td class="title">
<% if file.dmsf_folder %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/my/blocks/_watched_documents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
<%= link_to_project(file.project) if file.project %>
</td>
<td class="title">
<%= link_to h(file.title), dmsf_file_path(id: file),
class: "icon icon-file #{DmsfHelper.filetype_css(file.name)}" %>
<% icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(file.name)) %>
<%= link_to sprite_icon(icon_name, h(file.title)), dmsf_file_path(id: file), class: 'icon icon-file' %>
</td>
<td class="title">
<% if file.dmsf_folder %>
Expand Down
Binary file removed assets/images/filetypes/c_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/csharp_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/css_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/doc.png
Binary file not shown.
Binary file removed assets/images/filetypes/doc_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/docx.png
Binary file not shown.
Binary file removed assets/images/filetypes/html_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/image_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/java_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/js_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/mpp.png
Binary file not shown.
Binary file removed assets/images/filetypes/mpp_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/odg.png
Binary file not shown.
Binary file removed assets/images/filetypes/odg_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/odp.png
Binary file not shown.
Binary file removed assets/images/filetypes/odp_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/ods.png
Binary file not shown.
Binary file removed assets/images/filetypes/ods_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/odt.png
Binary file not shown.
Binary file removed assets/images/filetypes/odt_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/ott.png
Binary file not shown.
Binary file removed assets/images/filetypes/ott_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/pdf_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/php_gray.png
Binary file not shown.
Binary file removed assets/images/filetypes/ppt.png
Binary file not shown.
Binary file removed assets/images/filetypes/ppt_gray.png
Diff not rendered.
Binary file removed assets/images/filetypes/pptx.png
Diff not rendered.
Binary file removed assets/images/filetypes/ruby_gray.png
Diff not rendered.
Binary file removed assets/images/filetypes/vsd.png
Diff not rendered.
Binary file removed assets/images/filetypes/vsd_gray.png
Diff not rendered.
Binary file removed assets/images/filetypes/vsdx.png
Diff not rendered.
Binary file removed assets/images/filetypes/xls.png
Diff not rendered.
Binary file removed assets/images/filetypes/xls_gray.png
Diff not rendered.
Binary file removed assets/images/filetypes/xlsm.png
Diff not rendered.
Binary file removed assets/images/filetypes/xlsx.png
Diff not rendered.
Binary file removed assets/images/filetypes/xml_gray.png
Diff not rendered.
Binary file removed assets/images/filetypes/zip_gray.png
Diff not rendered.
Binary file removed assets/images/folder_gray.png
Diff not rendered.
Binary file removed assets/images/folder_system.png
Diff not rendered.
5 changes: 3 additions & 2 deletions lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def formatted_value(view, _custom_field, value, _customized = nil, _html = false
member = Member.find_by(user_id: User.current.id, project_id: revision.dmsf_file.project.id)
filename = revision.formatted_name(member)
file_view_url = view.static_dmsf_file_path(revision.dmsf_file, download: revision, filename: filename)
icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(revision.dmsf_file.name))
view.link_to(
h(filename),
sprite_icon(icon_name, h(filename)),
file_view_url,
target: '_blank',
rel: 'noopener',
class: "icon icon-file #{DmsfHelper.filetype_css(revision.dmsf_file.name)}",
class: 'icon icon-file',
title: h(revision.try(:tooltip)),
'data-downloadurl' => "#{revision.detect_content_type}:#{h(revision.dmsf_file.name)}:#{file_view_url}"
)
Expand Down
Loading

0 comments on commit d5312ae

Please sign in to comment.