annotate plugins/redmine_checkout/init.rb @ 1458:b1f4c9a2af24 bug_794

Makes the default radio button checked by default -- this should fix bug #794.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 11 Nov 2013 18:25:22 +0000
parents 22ab16c93c1c
children
rev   line source
Chris@16 1 require 'redmine'
Chris@16 2
luis@1122 3 ActionDispatch::Callbacks.to_prepare do
Chris@16 4 # Patches
Chris@16 5 require_dependency 'checkout/settings_controller_patch'
luis@1122 6
Chris@16 7 require_dependency 'checkout/repositories_helper_patch'
Chris@16 8 require_dependency 'checkout/repository_patch'
luis@1122 9
Chris@16 10 require_dependency 'checkout/settings_helper_patch'
Chris@16 11 require_dependency 'checkout/setting_patch'
Chris@16 12 end
Chris@16 13
Chris@16 14 # Hooks
Chris@16 15 require 'checkout/repository_hooks'
Chris@16 16
Chris@16 17 Redmine::Plugin.register :redmine_checkout do
Chris@16 18 name 'Redmine Checkout plugin'
Chris@16 19 url 'http://dev.holgerjust.de/projects/redmine-checkout'
Chris@16 20 author 'Holger Just'
Chris@16 21 author_url 'http://meine-er.de'
Chris@16 22 description 'Add links to the actual repository to the repository view.'
Chris@16 23 version '0.5'
luis@1122 24
Chris@16 25 requires_redmine :version_or_higher => '0.9'
luis@1122 26
Chris@16 27 settings_defaults = HashWithIndifferentAccess.new({
Chris@16 28 'display_login' => nil,
Chris@16 29 'use_zero_clipboard' => '1',
luis@1122 30
Chris@16 31 'display_checkout_info' => '1',
Chris@16 32 'description_Abstract' => <<-EOF
Chris@16 33 The data contained in this repository can be downloaded to your computer using one of several clients.
Chris@16 34 Please see the documentation of your version control software client for more information.
Chris@16 35
Chris@16 36 Please select the desired protocol below to get the URL.
Chris@16 37 EOF
Chris@16 38 })
luis@1122 39
Chris@16 40 # this is needed for setting the defaults
Chris@16 41 require 'checkout/repository_patch'
luis@1122 42
Chris@16 43 CheckoutHelper.supported_scm.each do |scm|
Chris@16 44 klazz = "Repository::#{scm}".constantize
luis@1122 45
Chris@16 46 settings_defaults["description_#{scm}"] = ''
Chris@16 47 settings_defaults["overwrite_description_#{scm}"] = '0'
Chris@16 48 settings_defaults["display_command_#{scm}"] = '0'
luis@1122 49
Chris@16 50 # access can be one of
Chris@16 51 # read+write => this protocol always allows read/write access
Chris@16 52 # read-only => this protocol always allows read access only
Chris@16 53 # permission => Access depends on redmine permissions
Chris@16 54 settings_defaults["protocols_#{scm}"] = [HashWithIndifferentAccess.new({
Chris@16 55 :protocol => scm,
Chris@16 56 :command => klazz.checkout_default_command,
Chris@16 57 :regex => '',
Chris@16 58 :regex_replacement => '',
Chris@16 59 :fixed_url => '',
Chris@16 60 :access => 'permission',
Chris@16 61 :append_path => (klazz.allow_subtree_checkout? ? '1' : '0'),
Chris@16 62 :is_default => '1'
Chris@16 63 })]
Chris@16 64 end
luis@1122 65
Chris@16 66 settings :default => settings_defaults, :partial => 'settings/redmine_checkout'
luis@1122 67
Chris@16 68 Redmine::WikiFormatting::Macros.register do
Chris@16 69 desc <<-EOF
Chris@16 70 Creates a checkout link to the actual repository. Example:
Chris@16 71
Chris@16 72 use the default checkout protocol !{{repository}}
Chris@16 73 or use a specific protocol !{{repository(SVN)}}
Chris@16 74 or use the checkout protocol of a specific specific project: !{{repository(projectname:SVN)}}"
Chris@16 75 EOF
Chris@16 76
Chris@16 77 macro :repository do |obj, args|
Chris@16 78 proto = args.first
Chris@16 79 if proto.to_s =~ %r{^([^\:]+)\:(.*)$}
Chris@16 80 project_identifier, proto = $1, $2
Chris@16 81 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
Chris@16 82 else
Chris@16 83 project = @project
Chris@16 84 end
luis@1122 85
Chris@16 86 if project && project.repository
Chris@16 87 protocols = project.repository.checkout_protocols.select{|p| p.access_rw(User.current)}
luis@1122 88
Chris@16 89 if proto.present?
Chris@16 90 proto_obj = protocols.find{|p| p.protocol.downcase == proto.downcase}
Chris@16 91 else
Chris@16 92 proto_obj = protocols.find(&:default?) || protocols.first
Chris@16 93 end
Chris@16 94 end
Chris@16 95 raise "Checkout protocol #{proto} not found" unless proto_obj
luis@1122 96
Chris@16 97 cmd = (project.repository.checkout_display_command? && proto_obj.command.present?) ? proto_obj.command.strip + " " : ""
Chris@16 98 cmd + link_to(proto_obj.url, proto_obj.url)
Chris@16 99 end
Chris@16 100 end
Chris@16 101 end