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

employ stimulus controller on journal history pages

ulferts3731b7a32911
diff --git a/app/views/wiki/history.html.erb b/app/views/wiki/history.html.erb
index 2cef6827b3a..075626ef7fc 100644
--- a/app/views/wiki/history.html.erb
+++ b/app/views/wiki/history.html.erb
@@ -31,7 +31,9 @@ See COPYRIGHT and LICENSE files for more details.
<% breadcrumb_paths(*(@page.ancestors.reverse.collect { |parent| link_to h(parent.breadcrumb_title), {id: parent, project_id: parent.project}} + [h(@page.breadcrumb_title)] )) %>
<h3><%= t(:label_history) %></h3>
<%= form_tag({action: "diff"}, method: :get) do %>
- <div class="generic-table--container">
+ <div class="generic-table--container"
+ data-application-target="dynamic"
+ data-controller="journal-history">
<div class="generic-table--results-container">
<table class="generic-table wiki-page-versions">
<colgroup>
@@ -120,18 +122,28 @@ See COPYRIGHT and LICENSE files for more details.
<td class="checkbox">
<% if show_diff && (line_num < @versions.size) %>
<label for="<%="cb-#{line_num}"%>" class="hidden-for-sighted"><%= t(:description_compare_from) + ' ' + t(:label_version) + " " + h(ver.version.to_s) %></label>
- <%= radio_button_tag 'version',
+ <%= radio_button_tag('version_from',
ver.version,
(line_num==1),
class: 'history-cb-from',
- data: { 'select-to': "#cbto-#{line_num + 1}" },
- id: "cb-#{line_num}" %>
+ id: "cb-#{line_num}",
+ data: {
+ 'journal-history-target': 'fromVersion',
+ action: 'journal-history#selectToVersion'
+ }) %>
<% end %>
</td>
<td class="checkbox">
<% if show_diff && (line_num > 1) %>
<label for="<%="cbto-#{line_num}"%>" class="hidden-for-sighted"><%= t(:description_compare_to) + ' ' + t(:label_version) + " " + h(ver.version.to_s) %></label>
- <%= radio_button_tag('version_from', ver.version, (line_num==2), id: "cbto-#{line_num}") %>
+ <%= radio_button_tag('version_to',
+ ver.version,
+ (line_num==2),
+ id: "cbto-#{line_num}",
+ data: {
+ 'journal-history-target': 'toVersion',
+ action: 'journal-history#selectFromVersion'
+ }) %>
<% end %>
</td>
<td class="updated_at"><%= format_time(ver.created_at) %></td>
@@ -149,13 +161,5 @@ See COPYRIGHT and LICENSE files for more details.
<div class="generic-table--action-buttons">
<%= submit_tag t(:label_view_diff), class: 'button -highlight -small' if show_diff %>
</div>
-
- <%= nonced_javascript_tag do -%>
- jQuery(function($) {
- $('.history-cb-from').click(function() {
- var target = $($(this).data('selectTo')).prop('checked', true);
- });
- });
- <% end -%>
<%= pagination_links_full @versions %>
<% end %>
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js b/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js
index b4f869b3de8..ba6a77dd82f 100644
--- a/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js
+++ b/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js
@@ -23,9 +23,4 @@ jQuery(function($) {
return false;
});
-
- $('.meetings--checkbox-version-to').click(function() {
- var target = $(this).data('target');
- $(target).prop('checked', true);
- });
});
diff --git a/frontend/src/stimulus/controllers/dynamic/journal-history.controller.ts b/frontend/src/stimulus/controllers/dynamic/journal-history.controller.ts
new file mode 100644
index 00000000000..9493754b7f6
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/journal-history.controller.ts
@@ -0,0 +1,65 @@
+/*
+ * -- 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 JournalHistoryController extends Controller {
+ static targets = [
+ 'fromVersion',
+ 'toVersion',
+ ];
+
+ declare readonly fromVersionTargets:HTMLInputElement[];
+
+ declare readonly toVersionTargets:HTMLInputElement[];
+
+ // Automatically selects the to version when the from version is selected.
+ // The version chosen is the one above the selected version.
+ selectToVersion(event:Event) {
+ const clickedVersion = (event.target || this.fromVersionTargets[0]) as HTMLInputElement;
+
+ const index = this.fromVersionTargets.indexOf(clickedVersion);
+
+ this.toVersionTargets[index].checked = true;
+ }
+
+ // Automatically corrects the from version when the to version is selected.
+ // In case from and to version are the same after the selection, the from version is corrected to the version above.
+ // Otherwise, nothing is changed.
+ selectFromVersion(event:Event) {
+ const clickedVersion = (event.target || this.toVersionTargets[0]) as HTMLInputElement;
+
+ const index = this.toVersionTargets.indexOf(clickedVersion);
+
+ if (this.fromVersionTargets[index + 1].checked) {
+ this.fromVersionTargets[index].checked = true;
+ }
+ }
+}
diff --git a/modules/meeting/app/views/meeting_contents/_show.html.erb b/modules/meeting/app/views/meeting_contents/_show.html.erb
index 7a2f768df2e..cc1f7caa61d 100644
--- a/modules/meeting/app/views/meeting_contents/_show.html.erb
+++ b/modules/meeting/app/views/meeting_contents/_show.html.erb
@@ -32,11 +32,10 @@ See COPYRIGHT and LICENSE files for more details.
content, content_type = tab[:content], tab[:content_type] if tab && tab.present?
-%>
-<% content_for :header_tags do %>
- <meta name="required_script" content="custom_fields" />
-<% end %>
-
-<div class="meeting_content <%= content_type %>">
+<div class="meeting_content
+ <%= content_type %>"
+ data-application-target="dynamic"
+ data-controller="meetings">
<div>
<%= toolbar title: t(:"label_#{content_type}") do %>
<%=raw meeting_content_context_menu content, content_type %>
@@ -54,7 +53,8 @@ See COPYRIGHT and LICENSE files for more details.
<% if saved_meeting_content_text_present?(content) -%>
<div id="<%= content_type %>-text"
style="<%= 'display: none' if show_meeting_content_editor?(content, content_type) %>"
- class="wiki show-<%= content_type %> op-uc-container">
+ class="wiki show-<%= content_type %> op-uc-container"
+ data>
<%= format_text(content.text, :object => @meeting) %>
</div>
<% else -%>
diff --git a/modules/meeting/app/views/meeting_contents/history.html.erb b/modules/meeting/app/views/meeting_contents/history.html.erb
index d9458bd97fb..8cf69b092ce 100644
--- a/modules/meeting/app/views/meeting_contents/history.html.erb
+++ b/modules/meeting/app/views/meeting_contents/history.html.erb
@@ -39,7 +39,9 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<%= form_tag({:action => "diff"}, :method => :get) do %>
-<div class="generic-table--container">
+<div class="generic-table--container"
+ data-application-target="dynamic"
+ data-controller="journal-history">
<div class="generic-table--results-container">
<table class="generic-table">
<colgroup>
@@ -106,18 +108,26 @@ See COPYRIGHT and LICENSE files for more details.
</td>
<td class="checkbox -short">
<% if show_diff && (index < @content_versions.size-1) %>
- <%= radio_button_tag('version_to',
+ <%= radio_button_tag('version_from',
content_version.version,
(index==0),
- id: "checkbox-from-#{index}",
class: 'meetings--checkbox-version-to',
- data: { target: ".checkbox-to-#{index+1}" }) %>
+ data: {
+ 'journal-history-target': 'fromVersion',
+ action: 'journal-history#selectToVersion'
+ }) %>
<label class="hidden-for-sighted" for="checkbox-from-<%= index %>"><%= t(:description_compare_from) %> <%= index %></label>
<% end %>
</td>
<td class="checkbox -short">
<% if show_diff && (index > 0) %>
- <%= radio_button_tag('version_from', content_version.version, (index==1), :id => "checkbox-to-#{index}") %>
+ <%= radio_button_tag('version_to',
+ content_version.version,
+ (index==1),
+ data: {
+ 'journal-history-target': 'toVersion',
+ action: 'journal-history#selectFromVersion'
+ }) %>
<label class="hidden-for-sighted" for="checkbox-to-<%= index %>"><%= t(:description_compare_to) %> <%= index %></label>
<% end %>
</td>