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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Create a duration_property helper in the API::Decorators::DateProperty
Dombi Attila40688d6304e7
diff --git a/lib/api/decorators/date_property.rb b/lib/api/decorators/date_property.rbindex a37381460b2..a2b5f716b90 100644--- a/lib/api/decorators/date_property.rb+++ b/lib/api/decorators/date_property.rb@@ -66,6 +66,19 @@ module APIattributes.merge(args)end+ def duration_property(name,+ getter: default_duration_getter(name),+ setter: default_duration_setter(name),+ **args)+ attributes = {+ getter:,+ setter:+ }++ property name,+ attributes.merge(args)+ end+privatedef default_date_getter(name)@@ -91,6 +104,23 @@ module APIdecorator.datetime_formatter.format_datetime(represented.send(name), allow_nil: true)}end++ def default_duration_getter(name)+ ->(represented:, decorator:, **) {+ decorator.datetime_formatter.format_duration_from_hours(represented.send(name), allow_nil: true)+ }+ end++ def default_duration_setter(name)+ ->(fragment:, decorator:, **) {+ hours = decorator+ .datetime_formatter+ .parse_duration_to_hours(fragment,+ name.to_s.camelize(:lower),+ allow_nil: true)+ send(:"#{name}=", hours)+ }+ endendendenddiff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rbindex 44ac5df6f61..5aa77e2177d 100644--- a/lib/api/v3/user_preferences/notification_setting_representer.rb+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb@@ -31,30 +31,13 @@ module APImodule UserPreferencesclass NotificationSettingRepresenter < ::API::Decorators::Singleinclude API::Decorators::LinkedResource+ include API::Decorators::DatePropertyNotificationSetting.all_settings.each do |setting|- setting_configuration = {}if setting.in?(NotificationSetting.duration_settings)- setting_configuration = {- exec_context: :decorator,- getter: ->(*) do- datetime_formatter.format_duration_from_hours(represented.send(setting),- allow_nil: true)- end,- setter: ->(fragment:, **) {- hours = datetime_formatter.parse_duration_to_hours(fragment, setting, allow_nil: true)-- send(:"#{setting}=", hours)- }- }- end-- property setting, **setting_configuration- end-- NotificationSetting.duration_settings.each do |setting|- define_method "#{setting}=" do |value|- represented[setting] = value+ duration_property setting+ else+ property settingendend