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

Fix datepicker selections and serialization for backlogs

Oliver Güntherfbbc0e151cca
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/model.js b/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/model.js
index a81f2b645f0..e8ec4f1faee 100644
--- a/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/model.js
+++ b/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/model.js
@@ -406,9 +406,9 @@ RB.Model = (function ($) {
editors.each(function (index) {
var editor, fieldName;
- editor = $(this);
+ editor = $(this).find('input,select').addBack('input,select');
fieldName = editor.attr('name');
- if (this.type.match(/select/)) {
+ if (editor.attr('type').match(/select/)) {
// if the user changes the type and that type does not offer the status
// of the current story, the status field is set to blank
// if the user saves this edit we will receive a validation error
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/sprint.js b/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/sprint.js
index 7cbe98c1dca..672b00789fb 100644
--- a/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/sprint.js
+++ b/frontend/src/app/core/augmenting/dynamic-scripts/backlogs/sprint.js
@@ -59,9 +59,17 @@ RB.Sprint = (function ($) {
},
saveDirectives: function () {
- var j = this.$,
- data = j.find('.editor').serialize() + "&_method=put",
- url = RB.urlFor('update_sprint', { id: this.getID() });
+ const wrapper = this.$;
+ const editor = wrapper.find('.editor');
+ const inputs = editor.map((i, el) => {
+ if (el.matches('op-single-date-picker')) {
+ return Array.from(el.querySelectorAll('input'));
+ }
+
+ return el;
+ });
+ const data = inputs.serialize() + "&_method=put";
+ const url = RB.urlFor('update_sprint', { id: this.getID() });
return {
url : url,
diff --git a/modules/backlogs/spec/support/pages/backlogs.rb b/modules/backlogs/spec/support/pages/backlogs.rb
index 3e97b4627ca..a0270fba3f1 100644
--- a/modules/backlogs/spec/support/pages/backlogs.rb
+++ b/modules/backlogs/spec/support/pages/backlogs.rb
@@ -75,18 +75,18 @@ module Pages
end
def alter_attributes_in_edit_backlog_mode(backlog, attributes)
- within_backlog(backlog) do
- attributes.each do |key, value|
- case key
- when :name
+ attributes.each do |key, value|
+ case key
+ when :name
+ within_backlog(backlog) do
find('input[name=name]').set value
- when :start_date
- find('input[name=start_date]').set value
- when :effective_date
- find('input[name=effective_date]').set value
- else
- raise NotImplementedError
end
+ when :start_date
+ ::Components::Datepicker.update_field("#start_date_#{backlog.id}", value)
+ when :effective_date
+ ::Components::Datepicker.update_field("#effective_date_#{backlog.id}", value)
+ else
+ raise NotImplementedError
end
end
end
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rb
index cc7aa4dc60a..f282bba63b6 100644
--- a/spec/support/components/datepicker/datepicker.rb
+++ b/spec/support/components/datepicker/datepicker.rb
@@ -5,6 +5,25 @@ module Components
include RSpec::Matchers
attr_reader :context_selector
+ ##
+ # Open a datepicker drop field with the trigger,
+ # and set the date to the given date.
+ # @param trigger [String] Selector to click the trigger at
+ # @param date [Date | String] Date or ISO8601 date string to set to
+ def self.update_field(trigger, date)
+ datepicker = Components::Datepicker.new
+
+ datepicker.instance_eval do
+ input = page.find(trigger)
+ input.click
+ end
+
+ date = Date.parse(date) unless date.is_a?(Date)
+ datepicker.set_date(date.strftime('%Y-%m-%d'))
+ datepicker.expect_current_date(date)
+ datepicker.save!
+ end
+
def initialize(context = 'body')
@context_selector = context
end