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
refactor: move progress `new` action to the collection level
Christophe Bliardbf7c2536a881
diff --git a/config/routes.rb b/config/routes.rbindex 03bb86cacd1..0c6b8047890 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -664,10 +664,10 @@ Rails.application.routes.draw doresources :children_relations, only: %i[new create destroy], controller: "work_package_children_relations"- resource :progress, only: %i[new edit update], controller: "work_packages/progress"+ resource :progress, only: %i[edit update], controller: "work_packages/progress"collection doresource :progress,- only: :create,+ only: %i[create new],controller: "work_packages/progress",as: :work_package_progressenddiff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.tsindex c0c532d924b..7bc36958726 100644--- a/frontend/src/app/core/path-helper/path-helper.service.ts+++ b/frontend/src/app/core/path-helper/path-helper.service.ts@@ -298,7 +298,7 @@ export class PathHelperService {public workPackageProgressModalPath(workPackageId:string|number) {if (workPackageId === 'new') {- return `${this.workPackagePath(workPackageId)}/progress/new`;+ return `${this.workPackagesPath()}/progress/new`;}return `${this.workPackagePath(workPackageId)}/progress/edit`;diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.tsindex 0b56555dc65..b5aa327ba05 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts@@ -309,14 +309,6 @@ export default class PreviewController extends DialogPreviewController {this.updateFlatpickrCalendar();}- ensureValidPathname(formAction:string):string {- return formAction;- }-- ensureValidWpAction(wpPath:string):string {- return wpPath.endsWith('/work_packages/date_picker') ? 'new' : 'edit';- }-afterRendering() {this.readCurrentValues();this.updateFlatpickrCalendar();diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.tsindex 23e44c6e80d..f8d885bc4c2 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts@@ -138,17 +138,20 @@ export abstract class DialogPreviewController extends Controller {});}- const wpPath = this.ensureValidPathname(form.action);- const wpAction = this.ensureValidWpAction(wpPath);-- const editUrl = `${wpPath}/${wpAction}?${new URLSearchParams(wpParams).toString()}`;+ const wpAction = this.isUpdatingWorkPackage(form.action) ? 'edit' : 'new';+ const previewUrl = `${form.action}/${wpAction}?${new URLSearchParams(wpParams).toString()}`;const turboFrame = this.formTarget.closest('turbo-frame') as HTMLTurboFrameElement;if (turboFrame) {- turboFrame.src = editUrl;+ turboFrame.src = previewUrl;}}+ private isUpdatingWorkPackage(formPath:string):boolean {+ const workPackagePathRegex = /\/work_packages\/\d+\//;+ return workPackagePathRegex.test(formPath);+ }+protected focusAndSetCursorPositionToEndOfInput(field:HTMLInputElement) {field.focus();if (field.type === 'text') {@@ -159,10 +162,6 @@ export abstract class DialogPreviewController extends Controller {}}- abstract ensureValidPathname(formAction:string):string;-- abstract ensureValidWpAction(path:string):string;-abstract afterRendering():void;protected isBeingEdited(fieldName:string) {diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.tsindex 912f5192c97..23e6053f55a 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview.controller.ts@@ -59,23 +59,6 @@ export default class PreviewController extends DialogPreviewController {// Do nothing;}- // Ensures that on create forms, there is an "id" for the un-persisted- // work package when sending requests to the edit action for previews.- ensureValidPathname(formAction:string):string {- const wpPath = new URL(formAction);-- if (wpPath.pathname.endsWith('/work_packages/progress')) {- // Replace /work_packages/progress with /work_packages/new/progress- wpPath.pathname = wpPath.pathname.replace('/work_packages/progress', '/work_packages/new/progress');- }-- return wpPath.toString();- }-- ensureValidWpAction(wpPath:string):string {- return wpPath.endsWith('/work_packages/new/progress') ? 'new' : 'edit';- }-markFieldAsTouched(event:{ target:HTMLInputElement }) {this.targetFieldName = event.target.name.replace(/^work_package\[([^\]]+)\]$/, '$1');this.markTouched(this.targetFieldName);diff --git a/spec/controllers/work_packages/progress_controller_spec.rb b/spec/controllers/work_packages/progress_controller_spec.rbindex 1a2e48ee849..98a9eaa8a2b 100644--- a/spec/controllers/work_packages/progress_controller_spec.rb+++ b/spec/controllers/work_packages/progress_controller_spec.rb@@ -45,7 +45,7 @@ RSpec.describe WorkPackages::ProgressController dowork_package.errors.group_by_attribute.slice(:estimated_hours, :remaining_hours, :done_ratio)end- describe "GET /work_packages/new/progress/new" do+ describe "GET /work_packages/progress/new" dolet(:params) do{"work_package_id" => work_package.id,