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
replace form when work package has changed
Klaus Zanders19bfa60c781a
diff --git a/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts b/frontend/src/stimulus/controllers/dynamic/time-entry.controller.tsindex 3f77f5325c0..536c425e700 100644--- a/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts@@ -37,8 +37,9 @@ import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.serviceimport { PathHelperService } from 'core-app/core/path-helper/path-helper.service';export default class TimeEntryController extends Controller {- static targets = ['startTimeInput', 'endTimeInput', 'hoursInput'];+ static targets = ['startTimeInput', 'endTimeInput', 'hoursInput', 'form'];+ declare readonly formTarget:HTMLFormElement;declare readonly startTimeInputTarget:HTMLInputElement;declare readonly hasStartTimeInputTarget:boolean;declare readonly endTimeInputTarget:HTMLInputElement;@@ -62,12 +63,16 @@ export default class TimeEntryController extends Controller {);}- workPackageChanged(event:InputEvent) {- const workPackageId = (event.currentTarget as HTMLInputElement).value;- void this.turboRequests.request(- this.pathHelper.timeEntriesWorkPackageActivity(workPackageId),- { method: 'GET' },- );+ workPackageChanged() {+ const url = this.formTarget.dataset.refreshFormUrl as string;+ const csrfToken = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content || '';+ void this.turboRequests.request(url, {+ method: 'post',+ body: new FormData(this.formTarget),+ headers: {+ 'X-CSRF-Token': csrfToken,+ },+ });}timeInputChanged(event:InputEvent) {@@ -89,11 +94,7 @@ export default class TimeEntryController extends Controller {// We calculate the hours field if:// - We have start & end time and no hours// - We have start & end time and we have triggered the change from the end time field- if (- startTimeInMinutes- && endTimeInMinutes- && (hoursInMinutes === 0 || initiatedBy === this.endTimeInputTarget)- ) {+ if (startTimeInMinutes && endTimeInMinutes && (hoursInMinutes === 0 || initiatedBy === this.endTimeInputTarget)) {hoursInMinutes = endTimeInMinutes - startTimeInMinutes;if (hoursInMinutes <= 0) {hoursInMinutes += 24 * 60;diff --git a/modules/costs/app/components/time_entries/time_entry_form_component.rb b/modules/costs/app/components/time_entries/time_entry_form_component.rbindex 0069b5b3186..f7ba69bff05 100644--- a/modules/costs/app/components/time_entries/time_entry_form_component.rb+++ b/modules/costs/app/components/time_entries/time_entry_form_component.rb@@ -47,7 +47,11 @@ module TimeEntriesdef form_optionsbase = {model: time_entry,- data: { turbo: true },+ data: {+ turbo: true,+ "time-entry-target" => "form",+ refresh_form_url: refresh_form_time_entries_path+ },id: "time-entry-form"}diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 5fe18175e28..e5400770b07 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -38,7 +38,7 @@ class TimeEntriesController < ApplicationControllerbefore_action :load_or_build_and_authorize_time_entryend- authorization_checked! :dialog, :create, :update, :user_tz_caption, :time_entry_activities+ authorization_checked! :dialog, :create, :update, :user_tz_caption, :refresh_formdef dialogif params[:date].present?@@ -60,27 +60,19 @@ class TimeEntriesController < ApplicationControllerrespond_with_turbo_streamsend- def time_entry_activities- work_package = WorkPackage.visible.find_by(id: params[:work_package_id])-- time_entry = TimeEntry.new(project: work_package&.project, work_package: work_package)-- form = Primer::Forms::Builder.new(- TimeEntry.model_name.param_key,- time_entry,- TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry),- {- allow_method_names_outside_object: true,- skip_default_ids: false,- data: { turbo: true },- id: "time-entry-form",- method: :post,- builder: Primer::Forms::Builder- }- )+ def refresh_form+ call = TimeEntries::SetAttributesService.new(+ user: current_user,+ model: TimeEntry.new,+ contract_class: EmptyContract+ ).call(permitted_params.time_entries)++ time_entry = call.result++ # TODO Some logic to figure out what fields we want to show (user, etc)replace_via_turbo_stream(- component: TimeEntries::ActivityForm.new(form)+ component: TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry))respond_with_turbo_streamsdiff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex 6e8716ce941..7123fbd316b 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -30,7 +30,7 @@ Rails.application.routes.draw doresources :time_entries, only: %i[create update] doget :dialog, on: :collectionget "/users/:user_id/tz_caption", action: :user_tz_caption, on: :collection- get "/work_packages/:work_package_id/time_entry_activities", action: :time_entry_activities, on: :collection+ post :refresh_form, on: :collectionendscope "projects/:project_id", as: "projects" do