Searching in multiple revisions #4
This commit is contained in:
parent
151c5c335b
commit
6346b88149
@ -51,22 +51,56 @@ class DmsfFile < ApplicationRecord
|
|||||||
case_sensitive: true
|
case_sensitive: true
|
||||||
}
|
}
|
||||||
|
|
||||||
acts_as_event title: proc { |o| o.name },
|
acts_as_event(
|
||||||
description: proc { |o|
|
title: proc { |o|
|
||||||
desc = Redmine::Search.cache_store.fetch("DmsfFile-#{o.id}")
|
@searched_revision = nil
|
||||||
if desc
|
o.dmsf_file_revisions.visible.each do |r|
|
||||||
Redmine::Search.cache_store.delete("DmsfFile-#{o.id}")
|
key = "DmsfFile-#{o.id}-#{r.id}"
|
||||||
else
|
@desc = Redmine::Search.cache_store.fetch(key)
|
||||||
# Set desc to an empty string if o.description is nil
|
next unless @desc
|
||||||
desc = o.description.nil? ? +'' : +o.description
|
|
||||||
desc += ' / ' if o.description.present? && o.last_revision.comment.present?
|
Redmine::Search.cache_store.delete key
|
||||||
desc += o.last_revision.comment if o.last_revision.comment.present?
|
@searched_revision = r
|
||||||
end
|
break
|
||||||
desc
|
end
|
||||||
},
|
if @searched_revision && (@searched_revision != o.last_revision)
|
||||||
url: proc { |o| { controller: 'dmsf_files', action: 'view', id: o } },
|
"#{o.name} (r#{@searched_revision.id})"
|
||||||
datetime: proc { |o| o.updated_at },
|
else
|
||||||
author: proc { |o| o.last_revision.user }
|
o.name
|
||||||
|
end
|
||||||
|
},
|
||||||
|
description: proc { |o|
|
||||||
|
unless @desc
|
||||||
|
# Set desc to an empty string if o.description is nil
|
||||||
|
@desc = o.description.nil? ? +'' : +o.description
|
||||||
|
@desc += ' / ' if o.description.present? && o.last_revision.comment.present?
|
||||||
|
@desc += o.last_revision.comment if o.last_revision.comment.present?
|
||||||
|
end
|
||||||
|
@desc
|
||||||
|
},
|
||||||
|
url: proc { |o|
|
||||||
|
if @searched_revision
|
||||||
|
{ controller: 'dmsf_files', action: 'view', id: o.id, download: @searched_revision.id,
|
||||||
|
filename: o.name }
|
||||||
|
else
|
||||||
|
{ controller: 'dmsf_files', action: 'view', id: o.id, filename: o.name }
|
||||||
|
end
|
||||||
|
},
|
||||||
|
datetime: proc { |o|
|
||||||
|
if @searched_revision
|
||||||
|
@searched_revision.updated_at
|
||||||
|
else
|
||||||
|
o.updated_at
|
||||||
|
end
|
||||||
|
},
|
||||||
|
author: proc { |o|
|
||||||
|
if @searched_revision
|
||||||
|
@searched_revision.user
|
||||||
|
else
|
||||||
|
o.last_revision.user
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
acts_as_searchable(
|
acts_as_searchable(
|
||||||
columns: [
|
columns: [
|
||||||
@ -415,20 +449,21 @@ class DmsfFile < ApplicationRecord
|
|||||||
filename = dochash['url']
|
filename = dochash['url']
|
||||||
next unless filename
|
next unless filename
|
||||||
|
|
||||||
dmsf_attrs = filename.scan(%r{^([^/]+/[^_]+)_(\d+)_(.*)$})
|
dmsf_attrs = filename.scan(%r{^\d{4}/\d{2}/(\d{12}_(\d+)_.*)$})
|
||||||
id_attribute = 0
|
id_attribute = 0
|
||||||
id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length.positive?
|
id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length.positive?
|
||||||
next if dmsf_attrs.empty? || id_attribute.to_i.zero?
|
next if dmsf_attrs.empty? || id_attribute.to_i.zero?
|
||||||
next unless results.none? { |f| f.id.to_s == id_attribute }
|
|
||||||
|
|
||||||
dmsf_file = DmsfFile.visible.where(limit_options).find_by(id: id_attribute)
|
dmsf_file = DmsfFile.visible.where(limit_options).find_by(id: id_attribute)
|
||||||
|
|
||||||
next unless dmsf_file && DmsfFolder.permissions?(dmsf_file.dmsf_folder) &&
|
next unless dmsf_file && DmsfFolder.permissions?(dmsf_file.dmsf_folder) &&
|
||||||
user.allowed_to?(:view_dmsf_files, dmsf_file.project) &&
|
user.allowed_to?(:view_dmsf_files, dmsf_file.project) &&
|
||||||
(project_ids.blank? || project_ids.include?(dmsf_file.project_id))
|
(project_ids.blank? || project_ids.include?(dmsf_file.project_id))
|
||||||
|
|
||||||
|
rev_id = DmsfFileRevision.where(dmsf_file_id: dmsf_file.id, disk_filename: dmsf_attrs[0][0])
|
||||||
|
.pick(:id)
|
||||||
if dochash['sample']
|
if dochash['sample']
|
||||||
Redmine::Search.cache_store.write("DmsfFile-#{dmsf_file.id}", dochash['sample'].force_encoding('UTF-8'))
|
Redmine::Search.cache_store.write("DmsfFile-#{dmsf_file.id}-#{rev_id}",
|
||||||
|
dochash['sample'].force_encoding('UTF-8'))
|
||||||
end
|
end
|
||||||
break if options[:limit].present? && results.count >= options[:limit]
|
break if options[:limit].present? && results.count >= options[:limit]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user