Merge branch 'release/4.3' into dev

pull/3168/merge
Florian Kraft 9 years ago
commit c093cd9539
  1. 4
      app/controllers/projects_controller.rb
  2. 14
      app/views/projects/show.html.erb
  3. 7
      config/initializers/menus.rb
  4. 20
      lib/open_project/text_formatting.rb
  5. 6
      lib/redmine/menu_manager/mapper.rb
  6. 6
      lib/redmine/menu_manager/menu_item.rb
  7. 13
      lib/redmine/plugin.rb
  8. 12
      spec/legacy/unit/helpers/application_helper_spec.rb
  9. 46
      spec/lib/open_project/text_formatting_spec.rb

@ -117,10 +117,6 @@ class ProjectsController < ApplicationController
include: [:project, :status, :type],
conditions: cond)
if User.current.allowed_to?(:view_time_entries, @project)
@total_hours = TimeEntry.visible.sum(:hours, include: :project, conditions: cond).to_f
end
respond_to do |format|
format.html
end

@ -89,20 +89,6 @@ See doc/COPYRIGHT.rdoc for more details.
</div>
</div>
<% content_for :sidebar do %>
<% if @total_hours.present? %>
<h3><%= l(:label_spent_time) %></h3>
<p><span class="icon5 icon-time"><%= l_hours(@total_hours) %></span></p>
<p>
<%= link_to(l(:label_details), {:controller => '/timelog', :action => 'index', :project_id => @project}) %> |
<%= link_to(l(:label_report), project_time_entries_report_path(@project)) %>
<% if authorize_for('timelog', 'new') %>
| <%= link_to l(:button_log_time), {:controller => '/timelog', :action => 'new', :project_id => @project} %>
<% end %>
</p>
<% end %>
<%= call_hook(:view_projects_show_sidebar_bottom, :project => @project) %>
<% end %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:controller => '/activities', :action => 'index', :id => @project, :format => 'atom', :key => User.current.rss_key}) %>
<% end %>

@ -236,6 +236,13 @@ Redmine::MenuManager.map :project_menu do |menu|
if: Proc.new { |p| p.repository && !p.repository.new_record? },
html: { class: 'icon2 icon-open-folder' }
menu.push :time_entries,
{ controller: '/timelog', action: 'index' },
param: :project_id,
if: -> (project) { User.current.allowed_to?(:view_time_entries, project) },
caption: :label_time_sheet_menu,
html: { class: 'icon2 icon-stats' }
menu.push :reportings,
{ controller: '/reportings', action: 'index' },
param: :project_id,

@ -379,7 +379,8 @@ module OpenProject
item = strip_tags(content).strip
anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
@parsed_headings << [level, anchor, item]
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
url = full_url(anchor)
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"#{url}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
end
end
@ -408,7 +409,8 @@ module OpenProject
elsif started
out << '</li><li>'
end
out << "<a href=\"##{anchor}\">#{item}</a>"
url = full_url anchor
out << "<a href=\"#{url}\">#{item}</a>"
current = level
started = true
end
@ -418,5 +420,19 @@ module OpenProject
end
end
end
#
# displays the current url plus an optional anchor
#
def full_url(anchor_name = '')
return "##{anchor_name}" if current_request.nil?
current = url_for
return current if anchor_name.blank?
"#{current}##{anchor_name}"
end
def current_request
request rescue nil
end
end
end

@ -97,6 +97,12 @@ class Redmine::MenuManager::Mapper
end
end
def add_condition(name, condition)
if found = find(name)
found.add_condition(condition)
end
end
# Checks if a menu item exists
def exists?(name)
@menu_items.any? { |node| node.name == name }

@ -75,4 +75,10 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode
@html_options
end
end
def add_condition(new_condition)
raise ArgumentError, 'Condition needs to be callable' unless new_condition.respond_to?(:call)
old_condition = @condition
@condition = -> (project) { old_condition.call(project) && new_condition.call(project) }
end
end

@ -263,8 +263,19 @@ module Redmine #:nodoc:
# Removes +item+ from the given +menu+.
def delete_menu_item(menu_name, item)
hide_menu_item(menu_name, item)
end
# N.B.: I could not find any usages of :delete_menu_item in my locally available plugins
deprecate delete_menu_item: 'Use :hide_menu_item instead'
# Allows to hide an existing +item+ in a menu.
#
# +hide_if+ parameter can be a lambda accepting a project, the item will only be hidden if
# the condition evaluates to true.
def hide_menu_item(menu_name, item, hide_if: -> (*) { true })
Redmine::MenuManager.map(menu_name) do |menu|
menu.delete(item)
menu.add_condition(item, -> (project) { !hide_if.call(project) })
end
end

@ -394,14 +394,23 @@ EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), format_text(raw).gsub(%r{[\r\n\t]}, '')
end
it 'should headings' do
it 'should headings without url' do
undef request
raw = 'h1. Some heading'
expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
assert_equal expected, format_text(raw)
end
it 'should headings with url' do
raw = 'h1. Some heading'
expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="/issues#Some-heading" class="wiki-anchor">&para;</a></h1>|
assert_equal expected, format_text(raw)
end
it 'should table of content' do
undef request
@project.wiki.start_page = 'Wiki'
@project.wiki.save!
FactoryGirl.create :wiki_page_with_content, wiki: @project.wiki, title: 'Wiki'
@ -464,6 +473,7 @@ RAW
end
it 'should table of content should contain included page headings' do
undef request
@project.wiki.start_page = 'Wiki'
@project.save!
page = FactoryGirl.create :wiki_page_with_content, wiki: @project.wiki, title: 'Wiki'

@ -573,7 +573,50 @@ WIKI_TEXT
subject(:html) { format_text(wiki_text) }
it 'emits a table of contents for headings h1-h4' do
context 'w/ request present' do
let(:request) { ActionController::TestRequest.new }
let(:url_for) { '/test' }
it 'emits a table of contents for headings h1-h4 with links present' do
expect(html).to be_html_eql(%{
<fieldset class='form--fieldset -collapsible'>
<legend class='form--fieldset-legend' title='Show/Hide table of contents' onclick='toggleFieldset(this);'>
<a href='javascript:'>Table of Contents</a>
</legend>
<div>
<ul class="toc">
<li>
<a href="/test#Orange">Orange</a>
<ul>
<li>
<a href="/test#Varietes">Varietes</a>
<ul>
<li>
<a href="/test#Common-Oranges">Common Oranges</a>
<ul>
<li><a href="/test#Valencia">Valencia</a></li>
<li><a href="/test#Harts-Tardiff-Valencia">Hart's Tardiff Valencia</a></li>
</ul>
</li>
<li><a href="/test#Navel-Oranges">Navel Oranges</a></li>
<li><a href="/test#Blood-Oranges">Blood Oranges</a></li>
<li><a href="/test#Acidless-Oranges">Acidless Oranges</a></li>
</ul>
</li>
<li><a href="/test#Attributes">Attributes</a></li>
</ul>
</li>
</ul>
</div>
</fieldset>
}).at_path('fieldset')
end
end
context 'w/o request present' do
let(:request) { nil }
it 'emits a table of contents for headings h1-h4 with anchors' do
expect(html).to be_html_eql(%{
<fieldset class='form--fieldset -collapsible'>
<legend class='form--fieldset-legend' title='Show/Hide table of contents' onclick='toggleFieldset(this);'>
@ -608,6 +651,7 @@ WIKI_TEXT
}).at_path('fieldset')
end
end
end
context 'deprecated methods' do
subject { self }

Loading…
Cancel
Save