Redmine 3.4.4

This commit is contained in:
Manuel Cillero 2018-02-02 22:19:29 +01:00
commit 64924a6376
2112 changed files with 259028 additions and 0 deletions

View file

@ -0,0 +1,26 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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 Redmine
module Views
class ApiTemplateHandler
def self.call(template)
"Redmine::Views::Builders.for(params[:format], request, response) do |api|; #{template.source}; self.output_buffer = api.output; end"
end
end
end
end

View file

@ -0,0 +1,38 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
require 'redmine/views/builders/json'
require 'redmine/views/builders/xml'
module Redmine
module Views
module Builders
def self.for(format, request, response, &block)
builder = case format
when 'xml', :xml; Builders::Xml.new(request, response)
when 'json', :json; Builders::Json.new(request, response)
else; raise "No builder for format #{format}"
end
if block
block.call(builder)
else
builder
end
end
end
end
end

View file

@ -0,0 +1,45 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
require 'redmine/views/builders/structure'
module Redmine
module Views
module Builders
class Json < Structure
attr_accessor :jsonp
def initialize(request, response)
super
callback = request.params[:callback] || request.params[:jsonp]
if callback && Setting.jsonp_enabled?
self.jsonp = callback.to_s.gsub(/[^a-zA-Z0-9_.]/, '')
end
end
def output
json = @struct.first.to_json
if jsonp.present?
json = "#{jsonp}(#{json})"
response.content_type = 'application/javascript'
end
json
end
end
end
end
end

View file

@ -0,0 +1,94 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
require 'blankslate'
module Redmine
module Views
module Builders
class Structure < BlankSlate
attr_accessor :request, :response
def initialize(request, response)
@struct = [{}]
self.request = request
self.response = response
end
def array(tag, options={}, &block)
@struct << []
block.call(self)
ret = @struct.pop
@struct.last[tag] = ret
@struct.last.merge!(options) if options
end
def encode_value(value)
if value.is_a?(Time)
# Rails uses a global setting to format JSON times
# Don't rely on it for the API as it could have been changed
value.xmlschema(0)
else
value
end
end
def method_missing(sym, *args, &block)
if args.any?
if args.first.is_a?(Hash)
if @struct.last.is_a?(Array)
@struct.last << args.first unless block
else
@struct.last[sym] = args.first
end
else
value = encode_value(args.first)
if @struct.last.is_a?(Array)
if args.size == 1 && !block_given?
@struct.last << value
else
@struct.last << (args.last || {}).merge(:value => value)
end
else
@struct.last[sym] = value
end
end
end
if block
@struct << (args.first.is_a?(Hash) ? args.first : {})
block.call(self)
ret = @struct.pop
if @struct.last.is_a?(Array)
@struct.last << ret
else
if @struct.last.has_key?(sym) && @struct.last[sym].is_a?(Hash)
@struct.last[sym].merge! ret
else
@struct.last[sym] = ret
end
end
end
end
def output
raise "Need to implement #{self.class.name}#output"
end
end
end
end
end

View file

@ -0,0 +1,48 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
require 'builder'
module Redmine
module Views
module Builders
class Xml < ::Builder::XmlMarkup
def initialize(request, response)
super()
instruct!
end
def output
target!
end
# Overrides Builder::XmlBase#tag! to format timestamps in ISO 8601
def tag!(sym, *args, &block)
if args.size == 1 && args.first.is_a?(::Time)
tag! sym, args.first.xmlschema, &block
else
super
end
end
def array(name, options={}, &block)
__send__ name, (options || {}).merge(:type => 'array'), &block
end
end
end
end
end

View file

@ -0,0 +1,64 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
require 'action_view/helpers/form_helper'
class Redmine::Views::LabelledFormBuilder < ActionView::Helpers::FormBuilder
include Redmine::I18n
(field_helpers.map(&:to_s) - %w(radio_button hidden_field fields_for check_box label) +
%w(date_select)).each do |selector|
src = <<-END_SRC
def #{selector}(field, options = {})
label_for_field(field, options) + super(field, options.except(:label)).html_safe
end
END_SRC
class_eval src, __FILE__, __LINE__
end
def check_box(field, options={}, checked_value="1", unchecked_value="0")
label_for_field(field, options) + super(field, options.except(:label), checked_value, unchecked_value).html_safe
end
def select(field, choices, options = {}, html_options = {})
label_for_field(field, options) + super(field, choices, options, html_options.except(:label)).html_safe
end
def time_zone_select(field, priority_zones = nil, options = {}, html_options = {})
label_for_field(field, options) + super(field, priority_zones, options, html_options.except(:label)).html_safe
end
# A field for entering hours value
def hours_field(field, options={})
# display the value before type cast when the entered value is not valid
if @object.errors[field].blank?
options = options.merge(:value => format_hours(@object.send field))
end
text_field field, options
end
# Returns a label tag for the given field
def label_for_field(field, options = {})
return ''.html_safe if options.delete(:no_label)
text = options[:label].is_a?(Symbol) ? l(options[:label]) : options[:label]
text ||= l(("field_" + field.to_s.gsub(/\_id$/, "")).to_sym)
text += @template.content_tag("span", " *", :class => "required") if options.delete(:required)
@template.content_tag("label", text.html_safe,
:class => (@object && @object.errors[field].present? ? "error" : nil),
:for => (@object_name.to_s + "_" + field.to_s))
end
end

View file

@ -0,0 +1,43 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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 Redmine
module Views
class OtherFormatsBuilder
def initialize(view)
@view = view
end
def link_to(name, options={})
url = { :format => name.to_s.downcase }.merge(options.delete(:url) || {}).except('page')
caption = options.delete(:caption) || name
html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
@view.content_tag('span', @view.link_to(caption, url, html_options))
end
# Preserves query parameters
def link_to_with_query_parameters(name, url={}, options={})
params = @view.request.query_parameters.except(:page, :format).except(*url.keys)
url = {:params => params, :page => nil, :format => name.to_s.downcase}.merge(url)
caption = options.delete(:caption) || name
html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
@view.content_tag('span', @view.link_to(caption, url, html_options))
end
end
end
end