#236 Documents tagging

This commit is contained in:
Karel Picman 2014-03-19 12:43:11 +01:00
parent 8837ae8f67
commit cd94b958c1
6 changed files with 110 additions and 9 deletions

View File

@ -40,17 +40,70 @@ class DmsfController < ApplicationController
@workflows_available = DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', @project.id]).count > 0
unless @folder
@subfolders = @project.dmsf_folders.visible
@files = @project.dmsf_files.visible
if params[:custom_field_id].present? && params[:custom_value].present?
@subfolders = []
DmsfFolder.where(:project_id => @project.id).visible.each do |f|
f.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@subfolders << f
break
end
end
end
end
@files = []
DmsfFile.where(:project_id => @project.id).visible.each do |f|
r = f.last_revision
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@files << f
break
end
end
end
end
end
@dir_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name).visible.each do |l|
l.target_folder.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@dir_links << l
break
end
end
end
end
@file_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFile.model_name).visible.each do |l|
r = l.target_file.last_revision
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@file_links << l
break
end
end
end
end
end
else
@subfolders = @project.dmsf_folders.visible
@files = @project.dmsf_files.visible
@dir_links = @project.folder_links.visible
@file_links = @project.file_links.visible
end
@locked_for_user = false
@dir_links = @project.folder_links
@file_links = @project.file_links
else
@subfolders = @folder.subfolders.visible
@files = @folder.files.visible
@files = @folder.files.visible
@dir_links = @folder.folder_links.visible
@file_links = @folder.file_links.visible
@locked_for_user = @folder.locked_for_user?
@dir_links = @folder.folder_links
@file_links = @folder.file_links
end
@files.sort! do |a,b|
@ -75,6 +128,15 @@ class DmsfController < ApplicationController
end
def entries_operation
# Tag filter
if params[:dmsf_folder] && params[:dmsf_folder][:custom_field_values].present?
redirect_to dmsf_folder_path(
:id => @project,
:custom_field_id => params[:dmsf_folder][:custom_field_values].first[0],
:custom_value => params[:dmsf_folder][:custom_field_values].first[1])
return
end
# Download/Email
selected_folders = params[:subfolders].present? ? params[:subfolders] : []
selected_files = params[:files].present? ? params[:files] : []
selected_dir_links = params[:dir_links]

View File

@ -76,4 +76,18 @@ module DmsfHelper
return obj
end
# Return custom field html tag corresponding to its format
def custom_field_tag_ex(prefix, custom_value, data)
custom_value.custom_field.format.edit_tag self,
custom_field_tag_id(prefix, custom_value.custom_field),
custom_field_tag_name(prefix, custom_value.custom_field),
custom_value,
{:class => "#{custom_value.custom_field.field_format}_cf}"}.merge(data)
end
# Return custom field tag with its label tag
def custom_field_tag_with_label_ex(name, custom_value, options={}, data={})
custom_field_label_tag(name, custom_value, options) + custom_field_tag_ex(name, custom_value, data)
end
end

View File

@ -44,6 +44,11 @@ class DmsfFile < ActiveRecord::Base
:conditions => {:target_type => DmsfFile.model_name}, :dependent => :destroy
scope :visible, lambda {|*args| where(DmsfFile.visible_condition(args.shift || User.current, *args)).readonly(false)}
scope :by_tag,
lambda { |id, value| {
:joins => 'JOIN custom_values ON dmsf_folders.id = custom_values.customized_id',
:conditions => ["custom_values.custom_field_id = ? AND custom_values.value = ?", id, value]
}}
validates :name, :presence => true
validates_format_of :name, :with => DmsfFolder.invalid_characters,

View File

@ -18,7 +18,17 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class DmsfFileRevisionCustomField < CustomField
def type_name
:menu_dmsf
end
def compare_values?(x, y)
if x.is_a?(Array) && y.is_a?(Array) && !y.empty?
x.include? y[0]
else
x == y
end
end
end

View File

@ -43,7 +43,7 @@ class DmsfFolder < ActiveRecord::Base
:conditions => {:entity_type => 1},
:dependent => :destroy
scope :visible, lambda {|*args| {:conditions => '' }} #For future use, however best to be referenced now
scope :visible, lambda {|*args| {:conditions => '' }} #For future use, however best to be referenced now
acts_as_customizable

View File

@ -109,8 +109,18 @@
<%= submit_tag(l(:submit_email), :title => l(:title_send_checked_by_email), :name => 'email_entries') %>
<% if @file_manipulation_allowed && @folder_manipulation_allowed && !@locked_for_user %>
<button type="button" id="entries_delete_button" title="<%= l(:title_delete_checked) %>"><%= l(:button_delete) %></button>
<% end %>
<% end %>
</div>
<% values = @folder ? @folder.custom_field_values : @parent ? @parent.custom_field_values : DmsfFolder.new(:project => @project).custom_field_values %>
<% unless values.empty? %>
<div class="controls" style="float: right">
<%= custom_field_tag_with_label_ex(
:dmsf_folder,
CustomValue.new(:custom_field_id => params[:custom_field_id].present? ? params[:custom_field_id] : values.first.custom_field_id, :value => params[:custom_value]),
{},
:onchange => 'this.form.submit(); return false;') %>
</div>
<% end %>
<table class="display entries" id="browser">
<thead>
<tr id="root">