From e6abd839bdc4be084aed870b9a9658dfd0fc0c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 7 Mar 2016 15:12:26 +0100 Subject: [PATCH 1/3] Extend quick info with path_info option WorkPackageHelper#quick_info by default only output path links, which won't work when formatting mail references. --- app/helpers/work_packages_helper.rb | 21 +++++++++++++++------ lib/open_project/text_formatting.rb | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/helpers/work_packages_helper.rb b/app/helpers/work_packages_helper.rb index 30f8b5611f..1b722c68e9 100644 --- a/app/helpers/work_packages_helper.rb +++ b/app/helpers/work_packages_helper.rb @@ -44,6 +44,7 @@ module WorkPackagesHelper # link_to_work_package(package, subject_only: true) # => This is the subject (as link) # link_to_work_package(package, status: true) # => #6 New (if #id => true) def link_to_work_package(package, options = {}) + only_path = options.fetch(:only_path) { true } if options[:subject_only] options.merge!(type: false, subject: true, @@ -119,20 +120,28 @@ def link_to_work_package(package, options = {}) title = parts[:title].join(' ') css_class = parts[:css_class].join(' ') + # Determine path or url + work_package_link = + if only_path + work_package_path(package) + else + work_package_url(package) + end + text = if options[:all_link] link_text = [prefix, link].reject(&:empty?).join(' - ') link_text = [link_text, suffix].reject(&:empty?).join(': ') link_text = [hidden_link, link_text].reject(&:empty?).join('') link_to(link_text.html_safe, - work_package_path(package), + work_package_link, title: title, class: css_class) else link_text = [hidden_link, link].reject(&:empty?).join('') html_link = link_to(link_text.html_safe, - work_package_path(package), + work_package_link, title: title, class: css_class) @@ -141,7 +150,7 @@ def link_to_work_package(package, options = {}) end.html_safe end - def work_package_quick_info(work_package) + def work_package_quick_info(work_package, only_path: true) changed_dates = {} journals = work_package.journals.where(['created_at >= ?', Date.today.to_time - 7.day]) @@ -159,7 +168,7 @@ def work_package_quick_info(work_package) end end - link = link_to_work_package(work_package, status: true) + link = link_to_work_package(work_package, status: true, only_path: only_path) link += " #{work_package.start_date.nil? ? '[?]' : work_package.start_date.to_s}" link += changed_dates['start_date'] link += " – #{work_package.due_date.nil? ? '[?]' : work_package.due_date.to_s}" @@ -168,10 +177,10 @@ def work_package_quick_info(work_package) link end - def work_package_quick_info_with_description(work_package, lines = 3) + def work_package_quick_info_with_description(work_package, lines = 3, only_path: true) description = truncated_work_package_description(work_package, lines) - link = work_package_quick_info(work_package) + link = work_package_quick_info(work_package, only_path: only_path) attributes = info_user_attributes(work_package) diff --git a/lib/open_project/text_formatting.rb b/lib/open_project/text_formatting.rb index a4e5014ef6..fdacd7b2a7 100644 --- a/lib/open_project/text_formatting.rb +++ b/lib/open_project/text_formatting.rb @@ -341,7 +341,7 @@ def parse_redmine_links(text, project, obj, attr, only_path, options) .includes(:status) .references(:statuses) .find_by(id: oid) - link = work_package_quick_info(work_package) + link = work_package_quick_info(work_package, only_path: only_path) end elsif sep == '###' oid = identifier.to_i @@ -350,7 +350,7 @@ def parse_redmine_links(text, project, obj, attr, only_path, options) .references(:statuses) .find_by(id: oid) if work_package && obj && !(attr == :description && obj.id == work_package.id) - link = work_package_quick_info_with_description(work_package) + link = work_package_quick_info_with_description(work_package, only_path: only_path) end elsif sep == ':' # removes the double quotes if any From 396dcdd8595340e321c7c070db362b669920031b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 7 Mar 2016 10:30:39 +0100 Subject: [PATCH 2/3] Add path-based checkout for SVN --- app/controllers/repositories_controller.rb | 4 +-- .../scm/checkout_instructions_service.rb | 11 +++++--- .../repositories/_repository_header.html.erb | 2 +- .../repositories_controller_spec.rb | 27 +++++++++++++++++++ .../scm/checkout_instructions_service_spec.rb | 12 ++++++--- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 698f67db17..0142dc64af 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -310,12 +310,12 @@ def find_repository # Prepare checkout instructions # available on all pages (even empty!) - @instructions = ::Scm::CheckoutInstructionsService.new(@repository) + @path = params[:path] || '' + @instructions = ::Scm::CheckoutInstructionsService.new(@repository, path: @path) # Asserts repository availability, or renders an appropriate error @repository.scm.check_availability! - @path = params[:path] || '' @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip @rev_to = params[:rev_to] diff --git a/app/services/scm/checkout_instructions_service.rb b/app/services/scm/checkout_instructions_service.rb index 5a3da2ff32..47e2700907 100644 --- a/app/services/scm/checkout_instructions_service.rb +++ b/app/services/scm/checkout_instructions_service.rb @@ -30,18 +30,21 @@ ## # Implements a repository service for building checkout instructions if supported class Scm::CheckoutInstructionsService - attr_reader :repository, :user + attr_reader :repository, :user, :path - def initialize(repository, user: User.current) + def initialize(repository, path: nil, user: User.current) @repository = repository @user = user + @path = path end ## # Retrieve the checkout URL using the repository vendor information # It may additionally set a path parameter, if the repository supports subtree checkout - def checkout_url(path = nil) - repository.scm.checkout_url(repository, checkout_base_url, path) + def checkout_url(with_path = false) + repository.scm.checkout_url(repository, + checkout_base_url, + with_path ? @path : nil) end ## diff --git a/app/views/repositories/_repository_header.html.erb b/app/views/repositories/_repository_header.html.erb index d77fde15c3..b68a82fb7f 100644 --- a/app/views/repositories/_repository_header.html.erb +++ b/app/views/repositories/_repository_header.html.erb @@ -40,7 +40,7 @@ See doc/COPYRIGHT.rdoc for more details.