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

Add option to provide controller for entire page with helper

Oliver Güntherf88603d066a7
diff --git a/app/helpers/stimulus_helper.rb b/app/helpers/stimulus_helper.rb
new file mode 100644
index 00000000000..4a2e2dc3a90
--- /dev/null
+++ b/app/helpers/stimulus_helper.rb
@@ -0,0 +1,36 @@
+#-- 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.
+#++
+
+module StimulusHelper
+ def page_controller(name, dynamic: false)
+ # rubocop:disable Rails/HelperInstanceVariable
+ @page_controller = name
+ @page_controller_dynamic = dynamic
+ # rubocop:enable Rails/HelperInstanceVariable
+ end
+end
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 01b9f02ba62..2d921e3b329 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -124,14 +124,20 @@ See COPYRIGHT and LICENSE files for more details.
<%= render partial: '/onboarding/configuration_modal' %>
</section>
<% end %>
- <div id="content" class="<%= initial_classes %>">
+ <%= content_tag :div,
+ id: 'content',
+ class: initial_classes,
+ data: {
+ controller: @page_controller,
+ 'application-target': @page_controller_dynamic ? 'dynamic' : nil,
+ }.compact do %>
<h1 class="hidden-for-sighted"><%= t(:label_content) %></h1>
<%= content_for :content_body %>
<% unless local_assigns[:no_layout_yield] %>
<%= yield %>
<% end %>
<%= call_hook :view_layouts_base_content %>
- </div>
+ <% end %>
</main>
</div>
<div id="ajax-indicator" style="display:none;"><span><%= t(:label_loading) %></span></div>
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/repository_navigation.js b/frontend/src/app/core/augmenting/dynamic-scripts/repository_navigation.js
deleted file mode 100644
index a4f74318ee6..00000000000
--- a/frontend/src/app/core/augmenting/dynamic-scripts/repository_navigation.js
+++ /dev/null
@@ -1,149 +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.
-//++
-
-(function($) {
- $(function() {
- var revision = $('#revision-identifier-input'),
- form = revision.closest('form'),
- tag = $('#revision-tag-select'),
- branch = $('#revision-branch-select'),
- selects = tag.add(branch),
- branch_selected = branch.length > 0 && revision.val() == branch.val(),
- tag_selected = tag.length > 0 && revision.val() == tag.val();
-
- var sendForm = function() {
- selects.prop('disable', true);
- form.submit();
- selects.prop('disable', false);
- };
-
- /*
- If we're viewing a tag or branch, don't display it in the
- revision box
- */
- if (branch_selected || tag_selected) {
- revision.val('');
- }
-
- /*
- Copy the branch/tag value into the revision box, then disable
- the dropdowns before submitting the form
- */
- selects.on('change', function() {
- var select = $(this);
- revision.val(select.val());
- sendForm();
- });
-
- /*
- Disable the branch/tag dropdowns before submitting the revision form
- */
- revision.on('keydown', function(e) {
- if (e.keyCode == 13) {
- sendForm();
- }
- });
-
-
- // Dir expanders
- var repoBrowser = $('#browser');
- repoBrowser.on('click', '.dir-expander', function() {
- var el = $(this),
- id = $(this).data('element'),
- content = $(id);
-
- if (expandDir(content)) {
- content.addClass('loading');
- $.ajax({
- url: el.data('url'),
- success: function(response) {
- content.after(response);
- content.removeClass('loading');
- content.addClass('loaded open');
- content.find('a.dir-expander')[0].title = I18n.t('js.label_collapse');
- }
- });
- }
- });
-
- /**
- * Collapses a directory listing in the repository module
- */
- function collapseScmEntry(content) {
- repoBrowser.find('.' + content.attr('id')).each(function() {
- var el = $(this);
- if (el.hasClass('open')) {
- collapseScmEntry(el);
- }
-
- el.hide();
- el.toggleClass('open collapsed');
- });
-
- content.toggleClass('open collapsed')
- content.find('a.dir-expander')[0].title = I18n.t('js.label_expand');
- }
-
- /**
- * Expands an SCM entry if its loaded
- */
- function expandScmEntry(content) {
- repoBrowser.find('.' + content.attr('id')).each(function() {
- var el = $(this);
- el.show();
- if (el.hasClass('loaded') && !el.hasClass('collapsed')) {
- expandScmEntry(el);
- }
-
- el.toggleClass('open collapsed')
- });
-
- content.toggleClass('open collapsed')
- content.find('a.dir-expander')[0].title = I18n.t('js.label_collapse');
- }
-
- /**
- * Determines whether a dir-expander should load content
- * or simply expand already loaded content.
- */
- function expandDir(content) {
- if (content.hasClass('open')) {
- collapseScmEntry(content);
- return false;
- } else if (content.hasClass('loaded')) {
- expandScmEntry(content);
- return false;
- }
- if (content.hasClass('loading')) {
- return false;
- }
- return true;
- }
- });
-}(jQuery));
-
diff --git a/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts b/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts
new file mode 100644
index 00000000000..6ec29d440b4
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts
@@ -0,0 +1,70 @@
+/*
+ * -- 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';
+
+export default class MeetingContentController extends Controller {
+ static targets = [
+ 'renderedText',
+ 'editor',
+ 'attachments',
+ 'editButton',
+ ];
+
+ static values = {
+ editState: { type: Boolean, default: false },
+ };
+
+ declare editStateValue:boolean;
+
+ declare readonly renderedTextTarget:HTMLElement;
+
+ declare readonly editorTarget:HTMLElement;
+
+ declare readonly attachmentsTarget:HTMLElement;
+
+ declare readonly editButtonTarget:HTMLLinkElement;
+
+ enableEditState() {
+ this.editStateValue = true;
+ }
+
+ cancelEditState() {
+ this.editStateValue = false;
+ window.OpenProject.pageWasEdited = false;
+ }
+
+ editStateValueChanged() {
+ this.renderedTextTarget.hidden = this.editStateValue;
+ this.attachmentsTarget.hidden = this.editStateValue;
+ this.editorTarget.hidden = !this.editStateValue;
+ this.editButtonTarget.classList.toggle('-active', this.editStateValue);
+ }
+}