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
DRY up RemindersController methods plus minor touch ups
Kabiru Mwenja92f162fcb2b9
diff --git a/app/controllers/work_packages/reminders_controller.rb b/app/controllers/work_packages/reminders_controller.rbindex 3fcaf9fc5f5..250390be0e6 100644--- a/app/controllers/work_packages/reminders_controller.rb+++ b/app/controllers/work_packages/reminders_controller.rb@@ -32,13 +32,13 @@ class WorkPackages::RemindersController < ApplicationControllerinclude OpTurbo::ComponentStreamlayout falsebefore_action :find_work_package- before_action :build_or_find_reminder, only: %i[modal_body create]+ before_action :find_or_build_reminder, only: %i[modal_body create]before_action :find_reminder, only: %i[update destroy]before_action :authorizedef modal_body- render modal_component_class.new(+ render WorkPackages::Reminder::ModalBodyComponent.new(remindable: @work_package,reminder: @reminder,preset: params[:preset]@@ -50,20 +50,9 @@ class WorkPackages::RemindersController < ApplicationController.call(reminder_params)if service_result.success?- render_success_flash_message_via_turbo_stream(message: I18n.t("work_package.reminders.success_creation_message"))- respond_with_turbo_streams+ respond_with_success_flash_message(message: I18n.t("work_package.reminders.success_creation_message"))else- replace_via_turbo_stream(- component: modal_component_class.new(- remindable: @work_package,- reminder: service_result.result,- errors: service_result.errors,- remind_at_date:,- remind_at_time:- )- )-- respond_with_turbo_streams(status: :unprocessable_entity)+ respond_with_error_modal_component(service_result)endend@@ -73,20 +62,9 @@ class WorkPackages::RemindersController < ApplicationController.call(reminder_params)if service_result.success?- render_success_flash_message_via_turbo_stream(message: I18n.t("work_package.reminders.success_update_message"))- respond_with_turbo_streams+ respond_with_success_flash_message(message: I18n.t("work_package.reminders.success_update_message"))else- replace_via_turbo_stream(- component: modal_component_class.new(- remindable: @work_package,- reminder: service_result.result,- errors: service_result.errors,- remind_at_date:,- remind_at_time:- )- )-- respond_with_turbo_streams(status: :unprocessable_entity)+ respond_with_error_modal_component(service_result)endend@@ -96,8 +74,7 @@ class WorkPackages::RemindersController < ApplicationController.callif service_result.success?- render_success_flash_message_via_turbo_stream(message: I18n.t("work_package.reminders.success_deletion_message"))- respond_with_turbo_streams+ respond_with_success_flash_message(message: I18n.t("work_package.reminders.success_deletion_message"))elserender_error_flash_message_via_turbo_stream(message: service_result.errors.full_messages)respond_with_turbo_streams(status: :unprocessable_entity)@@ -106,8 +83,23 @@ class WorkPackages::RemindersController < ApplicationControllerprivate- def modal_component_class- WorkPackages::Reminder::ModalBodyComponent+ def respond_with_success_flash_message(message:)+ render_success_flash_message_via_turbo_stream(message:)+ respond_with_turbo_streams+ end++ def respond_with_error_modal_component(service_result)+ replace_via_turbo_stream(+ component: WorkPackages::Reminder::ModalBodyComponent.new(+ remindable: @work_package,+ reminder: service_result.result,+ errors: service_result.errors,+ remind_at_date: reminder_params[:remind_at_date],+ remind_at_time: reminder_params[:remind_at_time]+ )+ )++ respond_with_turbo_streams(status: :unprocessable_entity)enddef find_work_package@@ -115,32 +107,24 @@ class WorkPackages::RemindersController < ApplicationControllerend# We assume for now that there is only one reminder per work package- def build_or_find_reminder- @reminder = @work_package.reminders- .upcoming_and_visible_to(User.current)- .last || @work_package.reminders.build+ def find_or_build_reminder+ @reminder = reminders.last || @work_package.reminders.buildenddef find_reminder- @reminder = @work_package.reminders- .upcoming_and_visible_to(User.current)- .find(params[:id])+ @reminder = reminders.find(params[:id])rescue ActiveRecord::RecordNotFoundrender_error_flash_message_via_turbo_stream(message: I18n.t(:error_reminder_not_found))respond_with_turbo_streams(status: :not_found)falseend+ def reminders+ @work_package.reminders.upcoming_and_visible_to(User.current)+ end+def reminder_paramsparams.expect(reminder: %i[remind_at_date remind_at_time note]).merge(remindable: @work_package, creator: User.current)end-- def remind_at_date- params[:reminder][:remind_at_date]- end-- def remind_at_time- params[:reminder][:remind_at_time]- endend