From 97114d4a2837dd069182f6dd7bba2ea0ff7960ec Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Tue, 11 Jul 2017 13:40:51 +0200 Subject: [PATCH] The parent folder link --- app/views/search/_container.html.erb | 31 ++++++++++++++ lib/redmine_dmsf.rb | 1 + .../hooks/helpers/issues_helper_hooks.rb | 2 +- .../hooks/helpers/search_helper_hooks.rb | 41 +++++++++++++++++++ .../hooks/views/search_view_hooks.rb | 16 +++----- 5 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 app/views/search/_container.html.erb create mode 100644 lib/redmine_dmsf/hooks/helpers/search_helper_hooks.rb diff --git a/app/views/search/_container.html.erb b/app/views/search/_container.html.erb new file mode 100644 index 00000000..3d7fe9ae --- /dev/null +++ b/app/views/search/_container.html.erb @@ -0,0 +1,31 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright (C) 2011-17 Karel Picman + # + # This program is free software; you can redistribute it and/or + # modify it under the terms of the GNU General Public License + # as published by the Free Software Foundation; either version 2 + # of the License, or (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + +<% dmsf_file_or_folder = object %> +<% if dmsf_file_or_folder.dmsf_folder_id %> + <% dmsf_folder = DmsfFolder.find_by_id dmsf_file_or_folder.dmsf_folder_id %> + <% title = dmsf_folder.title if dmsf_folder %> +<% else %> + <% title = dmsf_file_or_folder.project.name %> +<% end %> +<%= link_to(h(title), dmsf_folder_path(:id => dmsf_file_or_folder.project, + :folder_id => dmsf_file_or_folder.dmsf_folder_id), :class => 'icon icon-folder') %> diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 263b8cf3..ba037f86 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -63,6 +63,7 @@ require 'redmine_dmsf/hooks/views/issue_view_hooks' require 'redmine_dmsf/hooks/views/custom_field_view_hooks' require 'redmine_dmsf/hooks/views/search_view_hooks' require 'redmine_dmsf/hooks/helpers/issues_helper_hooks' +require 'redmine_dmsf/hooks/helpers/search_helper_hooks' # Macros require 'redmine_dmsf/macros' diff --git a/lib/redmine_dmsf/hooks/helpers/issues_helper_hooks.rb b/lib/redmine_dmsf/hooks/helpers/issues_helper_hooks.rb index 8a8f9a07..f9a28a5f 100644 --- a/lib/redmine_dmsf/hooks/helpers/issues_helper_hooks.rb +++ b/lib/redmine_dmsf/hooks/helpers/issues_helper_hooks.rb @@ -22,7 +22,7 @@ module RedmineDmsf module Hooks include Redmine::Hook - class HellperIssuesHook < RedmineDmsf::Hooks::Listener + class HelperIssuesHook < RedmineDmsf::Hooks::Listener def helper_issues_show_detail_after_setting(context) if context.is_a?(Hash) diff --git a/lib/redmine_dmsf/hooks/helpers/search_helper_hooks.rb b/lib/redmine_dmsf/hooks/helpers/search_helper_hooks.rb new file mode 100644 index 00000000..d38f859c --- /dev/null +++ b/lib/redmine_dmsf/hooks/helpers/search_helper_hooks.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module RedmineDmsf + module Hooks + include Redmine::Hook + + class SearchHelperHook < RedmineDmsf::Hooks::Listener + + def helper_easy_extensions_search_helper_patch(context={}) + case context[:entity].event_type + when 'dmsf-file', 'dmsf-folder' + str = context[:controller].send(:render_to_string, :partial => 'search/container', + :locals => { :object => context[:entity] }) + if str + context[:additional_result] << str + end + end + end + + end + + end +end \ No newline at end of file diff --git a/lib/redmine_dmsf/hooks/views/search_view_hooks.rb b/lib/redmine_dmsf/hooks/views/search_view_hooks.rb index baed61d0..65a933cd 100644 --- a/lib/redmine_dmsf/hooks/views/search_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/search_view_hooks.rb @@ -22,18 +22,12 @@ module RedmineDmsf class ViewSearchFormHook < Redmine::Hook::ViewListener def view_search_index_container(context={}) - if context && context[:object].is_a?(DmsfFile) - dmsf_file = context[:object] - title = '' - if dmsf_file.dmsf_folder_id - dmsf_folder = DmsfFolder.find_by_id dmsf_file.dmsf_folder_id - title = dmsf_folder.title if dmsf_folder - else - title = dmsf_file.project.name + if context[:object].is_a?(DmsfFile) || context[:object].is_a?(DmsfFolder) + str = context[:controller].send(:render_to_string, :partial => 'search/container', + :locals => { :object => context[:object] }) + if str + " #{str} /" end - link_to(h(title), - dmsf_folder_path(:id => dmsf_file.project, :folder_id => dmsf_file.dmsf_folder_id), - :class => 'icon icon-folder') + ' / ' end end