Rework instruction display

- Defaults to localized instruction when none is provided in the
settings
- Make readonly input visually clickable, not disabled
- Renamed `permission?` to `permissions?`
pull/3394/head
Oliver Günther 9 years ago
parent ef322e89dd
commit 7e7386f3b6
  1. 2
      app/assets/javascripts/settings.js.erb
  2. 4
      app/assets/stylesheets/content/_forms.sass
  3. 11
      app/services/scm/checkout_instructions_service.rb
  4. 5
      app/views/repositories/_checkout_instructions.html.erb
  5. 3
      app/views/settings/_repositories_checkout.html.erb
  6. 9
      config/locales/en.yml
  7. 6
      config/settings.yml
  8. 22
      spec/app/services/scm/checkout_instructions_service_spec.rb

@ -59,7 +59,7 @@ See doc/COPYRIGHT.rdoc for more details.
fieldset = $(this).closest('fieldset');
fieldset
.find('input,select,textarea')
.find('input,select')
.filter(':not([type=checkbox])')
.filter(':not([type=hidden])')
.removeAttr('required') // Rails 4.0 still seems to use attribute

@ -386,6 +386,10 @@ fieldset.form--fieldset
.form--text-field
@extend %input-style
&[readonly].-clickable
cursor: pointer
background: white
.form--text-field,
#{$text-input-selectors}
line-height: 1.5

@ -60,7 +60,8 @@ class Scm::CheckoutInstructionsService
##
# Returns the instructions defined in the settings.
def instructions
checkout_settings['text']
checkout_settings['text'].presence ||
I18n.t("repositories.checkout.default_instructions.#{repository.vendor}")
end
##
@ -85,7 +86,7 @@ class Scm::CheckoutInstructionsService
##
# Determines whether permissions for the given repository
# are available.
def permission?
def manages_permissions?
repository.managed?
end
@ -98,7 +99,7 @@ class Scm::CheckoutInstructionsService
#
# Note that this information is only applicable when the repository is managed,
# because otherwise OpenProject does not control the repository permissions.
# Use +permission?+ to check whether this is the case.
# Use +manages_permissions?+ to check whether this is the case.
#
def permission
project = repository.project
@ -116,7 +117,7 @@ class Scm::CheckoutInstructionsService
#
# Note that this information is only applicable when the repository is managed,
# because otherwise OpenProject does not control the repository permissions.
# Use +permission?+ to check whether this is the case.
# Use +manages_permissions?+ to check whether this is the case.
def may_checkout?
[:readwrite, :read].include?(permission)
end
@ -126,7 +127,7 @@ class Scm::CheckoutInstructionsService
#
# Note that this information is only applicable when the repository is managed,
# because otherwise OpenProject does not control the repository permissions.
# Use +permission?+ to check whether this is the case.
# Use +manages_permissions?+ to check whether this is the case.
def may_commit?
permission == :readwrite
end

@ -10,17 +10,18 @@
<%= instructions.checkout_command %>
</div>
<div class="form--text-field-container -xwide">
<input type="text" class="form--text-field"
<input type="text" class="form--text-field -clickable"
onclick="this.focus(); this.select()"
readonly="readonly" value="<%= instructions.checkout_url %>">
</div>
</div>
<div class="form--field-instructions -no-italic">
<%= simple_format instructions.instructions %>
<% if instructions.permission? %>
<% if instructions.manages_permissions? %>
<p>
<span><%= l('repositories.checkout.access_permission') %></span>
<strong><%= l("repositories.checkout.access.#{instructions.permission}") %></strong>
</p>
<% end %>
</div>
</div>

@ -7,7 +7,6 @@
<fieldset class="form--fieldset -collapsible collapsed">
<legend class="form--fieldset-legend" title="<%= klass.vendor_name %>" onclick="toggleFieldset(this);">
<a href="javascript:"><%= klass.vendor_name %>
<span class="fieldset-toggle-state-label hidden-for-sighted">expanded</span>
</a>
</legend>
<div class="form--field">
@ -28,7 +27,7 @@
<% key = "#{setting_base}[text]" %>
<%= setting_label key, label: :setting_repository_checkout_text %>
<%= styled_text_area_tag key, Setting.repository_checkout_data[vendor]['text'],
required: enabled %>
placeholder: l("repositories.checkout.default_instructions.#{vendor}") %>
<div class="form--field-instructions"><%= l('repositories.checkout.text_instructions') %></div>
</div>
</fieldset>

@ -1293,7 +1293,14 @@ en:
none: 'No checkout access, you may only view the repository through this application.'
access_permission: 'Your permissions on this repository:'
url: "Checkout URL"
base_url_text: "The base URL to use for generating checkout URLs (e.g., https://myserver.example.org/repos/).\nNote: The base URL is only used for rewriting checkout URLs in managed repositories. Other repositories are not altered"
base_url_text: "The base URL to use for generating checkout URLs (e.g., https://myserver.example.org/repos/).\nNote: The base URL is only used for rewriting checkout URLs in managed repositories. Other repositories are not altered."
default_instructions:
git: |-
The data contained in this repository can be downloaded to your computer with Git using the checkout information below.
Please consult the documentation of Git if you need more information on the checkout procedure and available clients.
subversion: |-
The data contained in this repository can be downloaded to your computer with Subversion using the checkout information below.
Please consult the documentation of Subversion if you need more information on the checkout procedure and available clients.
enable_instructions_text: "Displays checkout instructions defined below on all repository-related pages."
instructions: "Checkout instructions"
text_instructions: "This text is displayed alongside the checkout URL for guidance on how to check out the repository."

@ -285,14 +285,8 @@ repository_checkout_data:
default:
git:
enabled: 0
text: |-
The data contained in this repository can be downloaded to your computer with Git using the checkout information below.
Please consult the documentation of Git if you need more information on the checkout procedure and available clients.
subversion:
enabled: 0
text: |-
The data contained in this repository can be downloaded to your computer with Subversion using the checkout information below.
Please consult the documentation of Subversion if you need more information on the checkout procedure and available clients.
api_max_page_size:
format: int
default: 500

@ -40,11 +40,12 @@ describe Scm::CheckoutInstructionsService do
}
let(:base_url) { 'http://example.org/svn/' }
let(:text) { 'foo' }
let(:checkout_hash) {
{
'git' => { 'enabled' => '0' },
'subversion' => { 'enabled' => '1',
'text' => 'foo',
'text' => text,
'base_url' => base_url
}
}
@ -82,6 +83,21 @@ describe Scm::CheckoutInstructionsService do
end
end
describe '#instructions' do
it 'returns the setting when defined' do
expect(service.instructions).to eq('foo')
end
context 'no setting defined' do
let(:text) { nil }
it 'returns the default translated instructions' do
expect(service.instructions)
.to eq(I18n.t("repositories.checkout.default_instructions.subversion"))
end
end
end
describe '#settings' do
it 'svn is available for checkout' do
expect(service.available?).to be true
@ -117,7 +133,7 @@ describe Scm::CheckoutInstructionsService do
describe '#permission' do
context 'with no managed repository' do
it 'is not applicable' do
expect(service.permission?).to be false
expect(service.manages_permissions?).to be false
end
end
@ -127,7 +143,7 @@ describe Scm::CheckoutInstructionsService do
end
it 'is applicable' do
expect(service.permission?).to be true
expect(service.manages_permissions?).to be true
end
it 'returns the correct permissions' do

Loading…
Cancel
Save