Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Replace repository-settings

Oliver Günther9424ed38034e
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index 9f3f25b96c1..423feb32543 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -240,13 +240,17 @@ module RepositoriesHelper
end
def scm_vendor_tag(repository)
+ # rubocop:disable Rails/HelperInstanceVariable
+ url = url_for(controller: '/projects/settings/repository', action: 'show', id: @project.id)
+ # rubocop:enable Rails/HelperInstanceVariable
+ #
select_tag('scm_vendor',
scm_options(repository),
- class: 'form--select repositories--remote-select',
+ class: 'form--select',
data: {
- url: url_for(controller: '/projects/settings/repository',
- action: 'show',
- id: @project.id)
+ url:,
+ action: 'repository-settings#updateSelectedType',
+ 'repository-settings-target': 'scmVendor'
},
disabled: (repository && !repository.new_record?))
end
diff --git a/app/views/projects/settings/repository/_vendor_attribute_groups.html.erb b/app/views/projects/settings/repository/_vendor_attribute_groups.html.erb
index 40932f8c02a..bc02643759a 100644
--- a/app/views/projects/settings/repository/_vendor_attribute_groups.html.erb
+++ b/app/views/projects/settings/repository/_vendor_attribute_groups.html.erb
@@ -1,4 +1,10 @@
-<div class="description attributes-group" id="<%= vendor %>-<%= type %>" style="<%=existing ? 'display: block' : 'display: none' %> ">
+<%= content_tag :fieldset,
+ class: 'form--fieldset description attributes-group',
+ id: "#{vendor}-#{type}",
+ hidden: !existing,
+ data: {
+ 'repository-settings-target': 'scmTypeOptions'
+ } do %>
<div class="attributes-group--header">
<div class="attributes-group--header-container">
<span class="attributes-group--header-text">
@@ -6,18 +12,18 @@
</span>
</div>
<% unless repository.new_record? %>
- <div class="attributes-group--header-control">
- <%= render partial: 'projects/settings/repository/repository_committers_link', locals: { repository: repository } %>
- <% if type === 'managed' %>
- <%= link_to t(:button_delete), destroy_info_project_repository_path(repository.project),
- method: :get,
- class: 'icon icon-delete' %>
- <% else %>
- <%= link_to t(:button_remove), destroy_info_project_repository_path(repository.project),
- method: :get,
- class: 'icon icon-remove' %>
- <% end %>
- </div>
+ <div class="attributes-group--header-control">
+ <%= render partial: 'projects/settings/repository/repository_committers_link', locals: { repository: repository } %>
+ <% if type === 'managed' %>
+ <%= link_to t(:button_delete), destroy_info_project_repository_path(repository.project),
+ method: :get,
+ class: 'icon icon-delete' %>
+ <% else %>
+ <%= link_to t(:button_remove), destroy_info_project_repository_path(repository.project),
+ method: :get,
+ class: 'icon icon-remove' %>
+ <% end %>
+ </div>
<% end %>
</div>
@@ -28,4 +34,4 @@
<%= render partial: "projects/settings/repository/#{vendor}/#{type}",
locals: { form: form, repository: repository } %>
</div>
-</div>
+<% end %>
diff --git a/app/views/projects/settings/repository/_vendor_form.html.erb b/app/views/projects/settings/repository/_vendor_form.html.erb
index fd2149ceadc..f94e0003f89 100644
--- a/app/views/projects/settings/repository/_vendor_form.html.erb
+++ b/app/views/projects/settings/repository/_vendor_form.html.erb
@@ -29,12 +29,22 @@ See COPYRIGHT and LICENSE files for more details.
<% if repository.new_record? %>
<% scm_types = repository.class.available_types %>
- <div class="attributes-group -toggleable" data-switch="scm_type">
+ <div class="form--fieldset attributes-group -toggleable"
+ data-repository-settings-target="scmTypeSwitch"
+ >
<% scm_types.each do |type|%>
<div class="form--field">
<%= styled_label_tag type, t("repositories.#{@repository.vendor}.#{type}_title") %>
<div class="form--field-container">
- <%= styled_radio_button_tag 'scm_type', type, scm_types.length == 1 ? true : false, id: type, autofocus: true %>
+ <%= styled_radio_button_tag 'scm_type',
+ type,
+ scm_types.length == 1 ? true : false,
+ id: type,
+ autofocus: true,
+ data: {
+ action: 'repository-settings#toggleContent'
+ }
+ %>
</div>
</div>
<% end %>
diff --git a/app/views/projects/settings/repository/show.html.erb b/app/views/projects/settings/repository/show.html.erb
index a76c6baeb66..355464314cd 100644
--- a/app/views/projects/settings/repository/show.html.erb
+++ b/app/views/projects/settings/repository/show.html.erb
@@ -27,10 +27,6 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<% content_for :header_tags do %>
- <meta name="required_script" content="repository_settings" />
-<% end %>
-
<%= toolbar title: t(:label_repository) %>
<% is_creation_form = @repository.nil? || @repository.new_record? %>
@@ -42,34 +38,38 @@ See COPYRIGHT and LICENSE files for more details.
builder: TabularFormBuilder,
html: { class: 'form' } do |f| %>
-<fieldset class="form--fieldset -with-control">
- <legend class="form--fieldset-legend">
- <%= t(:label_available_project_repositories) %>
- </legend>
+ <fieldset
+ class="form--fieldset -with-control"
+ data-controller="repository-settings"
+ data-application-target="dynamic"
+ >
+ <legend class="form--fieldset-legend">
+ <%= t(:label_available_project_repositories) %>
+ </legend>
- <%= error_messages_for 'repository' %>
- <div class="form--field -required">
- <%= label_tag('scm_vendor', t('repositories.scm_vendor'), class: "form--label") %>
- <div class="form--field-container">
- <div class="form--select-container -middle">
- <%= scm_vendor_tag(@repository) %>
+ <%= error_messages_for 'repository' %>
+ <div class="form--field -required">
+ <%= label_tag('scm_vendor', t('repositories.scm_vendor'), class: "form--label") %>
+ <div class="form--field-container">
+ <div class="form--select-container -middle">
+ <%= scm_vendor_tag(@repository) %>
+ </div>
</div>
</div>
- </div>
- <%# Show (selected) type options %>
- <% unless @repository.nil? %>
+ <%# Show (selected) type options %>
+ <% unless @repository.nil? %>
<%= render partial: "projects/settings/repository/vendor_form",
locals: { form: f, repository: @repository } %>
- <% end %>
+ <% end %>
- <%# Allow plugins to add additional information %>
- <%= call_hook :repository_settings_fields, repository: @repository, form: f %>
+ <%# Allow plugins to add additional information %>
+ <%= call_hook :repository_settings_fields, repository: @repository, form: f %>
- <%# Hide the save button for existing managed repositories %>
- <% if show_settings_save_button?(@repository) %>
- <%= render partial: "projects/settings/repository/submit",
- locals: { form: f, is_creation_form: is_creation_form, project: @project } %>
- <% end %>
-</fieldset>
+ <%# Hide the save button for existing managed repositories %>
+ <% if show_settings_save_button?(@repository) %>
+ <%= render partial: "projects/settings/repository/submit",
+ locals: { form: f, is_creation_form: is_creation_form, project: @project } %>
+ <% end %>
+ </fieldset>
<% end %>
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/repository_settings.js b/frontend/src/app/core/augmenting/dynamic-scripts/repository_settings.js
deleted file mode 100644
index 82a62921c70..00000000000
--- a/frontend/src/app/core/augmenting/dynamic-scripts/repository_settings.js
+++ /dev/null
@@ -1,92 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2023 the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// 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.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-jQuery(function($){
- var toggleContent = function(content,selected) {
- var vendor = $('#scm_vendor').val(),
- targetName = '#' + vendor + '-' + selected,
- oldTargets = content.find('.attributes-group').not(targetName);
- var newTarget = jQuery(targetName);
-
- // would work with fieldset#disabled, but that's bugged up unto IE11
- // https://connect.microsoft.com/IE/feedbackdetail/view/962368/
- //
- // Ugly workaround: disable all inputs manually, but
- // spare enabling inputs marked with `aria-disabled`
- oldTargets
- .find('input,select')
- .prop('disabled', true);
- oldTargets.hide();
-
- newTarget
- .find('input,select')
- .not('[aria-disabled="true"]')
- .prop('disabled', false);
- newTarget.show();
- };
-
- // Submit form when
- $('.repositories--remote-select').change(function() {
- var select = $(this);
- var url = URI(select.data('url')).search({ scm_vendor: select.val() });
-
- window.location.href = url.toString();
- });
-
- $("[data-switch='scm_type']")
- .each(function(_i, el) {
-
- var fs = $(el),
- name = fs.attr('data-switch'),
- switches = fs.find('[name="' + name + '"]'),
- headers = fs.find('.attributes-group--header-text'),
- content = $(el);
-
- // Focus on first header
- headers.first().focus();
-
- // Open content if there is only one possible selection
- var checkedInput = jQuery('input[name=scm_type]:checked');
- if(checkedInput.length > 0) {
- toggleContent(content, checkedInput.val());
- }
-
- // Necessary for accessibility purpose
- jQuery('#scm_vendor').on('change', function(){
- window.setTimeout(function(){
- document.getElementsByName('scm_type')[0].focus();
- }, 500);
- });
-
- // Toggle content
- switches.on('change', function() {
- toggleContent(content, this.value);
- });
- });
-});
-
diff --git a/frontend/src/stimulus/controllers/dynamic/repository-settings.controller.ts b/frontend/src/stimulus/controllers/dynamic/repository-settings.controller.ts
new file mode 100644
index 00000000000..1542bca1687
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/repository-settings.controller.ts
@@ -0,0 +1,96 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 the OpenProject GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+ * Copyright (C) 2006-2013 Jean-Philippe Lang
+ * Copyright (C) 2010-2013 the ChiliProject Team
+ *
+ * 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.
+ *
+ * See COPYRIGHT and LICENSE files for more details.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+import * as URI from 'urijs';
+
+export default class RepositorySettingsController extends Controller {
+ static targets = [
+ 'scmVendor',
+ 'scmTypeSwitch',
+ 'scmTypeOptions',
+ ];
+
+ declare readonly scmVendorTarget:HTMLSelectElement;
+
+ declare readonly scmTypeOptionsTargets:HTMLFieldSetElement[];
+
+ scmTypeSwitchTargetConnected(el:HTMLFieldSetElement) {
+ // Open content if there is only one possible selection
+ const checkedInput = el.querySelector<HTMLInputElement>('input[name=scm_type]:checked');
+ if (checkedInput) {
+ this.selectFieldset(checkedInput.value);
+ }
+ }
+
+ updateSelectedType(event:InputEvent) {
+ const select = event.target as HTMLSelectElement;
+ const url = URI(select.dataset.url as string)
+ .search({ scm_vendor: select.value });
+
+ window.location.href = url.toString();
+ }
+
+ toggleContent(event:InputEvent) {
+ this.selectFieldset((event.target as HTMLInputElement).value);
+ }
+
+ private selectFieldset(selected:string) {
+ const vendor = this.scmVendorTarget.value;
+ const targetName = `${vendor}-${selected}`;
+ const selectedFieldset = document.getElementById(targetName) as HTMLFieldSetElement;
+
+ this
+ .scmTypeOptionsTargets
+ .forEach((fieldset:HTMLFieldSetElement) => {
+ if (fieldset === selectedFieldset) {
+ return;
+ }
+
+ fieldset.hidden = fieldset !== selectedFieldset;
+ fieldset.disabled = fieldset !== selectedFieldset;
+
+ fieldset
+ .querySelectorAll('input,select')
+ .forEach((el:HTMLInputElement) => {
+ el.disabled = true;
+ });
+ });
+
+ selectedFieldset.hidden = false;
+ selectedFieldset
+ .querySelectorAll('input,select')
+ .forEach((el:HTMLInputElement) => {
+ if (!el.matches('[aria-disabled="true"]')) {
+ el.disabled = false;
+ }
+ });
+ }
+}
diff --git a/spec/features/repositories/create_repository_spec.rb b/spec/features/repositories/create_repository_spec.rb
index 32c9d96eadb..724036ceb90 100644
--- a/spec/features/repositories/create_repository_spec.rb
+++ b/spec/features/repositories/create_repository_spec.rb
@@ -116,7 +116,7 @@ describe 'Create repository', js: true, selenium: true do
content = find("##{vendor}-#{type}", visible: false)
expect(content).not_to be_nil
- expect(content[:style]).to match("display: none")
+ expect(content[:hidden]).to eq 'true'
end
end
@@ -131,7 +131,7 @@ describe 'Create repository', js: true, selenium: true do
expect(content[:hidden]).to eql 'false'
content = find("##{vendor}-#{type}", visible: false)
expect(content).not_to be_nil
- expect(content[:style]).not_to match("display: none")
+ expect(content[:hidden]).to eql 'false'
find('input[type="radio"][value="managed"]').set(true)
content = find_by_id('attributes-group--content-managed')
@@ -139,7 +139,7 @@ describe 'Create repository', js: true, selenium: true do
expect(content[:hidden]).to eql 'false'
content = find("##{vendor}-managed", visible: false)
expect(content).not_to be_nil
- expect(content[:style]).not_to match("display: none")
+ expect(content[:hidden]).to eql 'false'
end
end