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

make drag, drop & resize work nicely in the calendar

Klaus Zanders6d9821cbd0ad
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.ts
index 447be9d3ecc..05fc48fd619 100644
--- a/frontend/src/app/core/path-helper/path-helper.service.ts
+++ b/frontend/src/app/core/path-helper/path-helper.service.ts
@@ -369,4 +369,8 @@ export class PathHelperService {
public timeEntryProjectDialog(projectId:string) {
return `${this.projectPath(projectId)}/time_entries/dialog`;
}
+
+ public timeEntryUpdate(timeEntryId:string) {
+ return `${this.staticBase}/time_entries/${timeEntryId}`;
+ }
}
diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
index 892af3b9f2d..bba9a5b039d 100644
--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
@@ -5,6 +5,8 @@ import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import moment from 'moment';
+import { renderStreamMessage } from '@hotwired/turbo';
export default class MyTimeTrackingController extends Controller {
private turboRequests:TurboRequestsService;
@@ -64,8 +66,8 @@ export default class MyTimeTrackingController extends Controller {
'__hl_border_top',
];
},
- eventDidMount(info) {
- console.log(info.event);
+ eventDidMount(_info) {
+ // console.log(info.event);
//eslint-disable-next-line
// info.el.innerHTML = info.event.extendedProps.customEventView;
},
@@ -84,42 +86,66 @@ export default class MyTimeTrackingController extends Controller {
);
},
eventResize: (info) => {
- let dialogParams = 'onlyMe=true';
-
- if (info.event.allDay) {
- dialogParams = `${dialogParams}&date=${info.event.startStr}&removeTime=true`;
- } else {
- dialogParams = `${dialogParams}&startTime=${info.event.start?.toISOString()}&endTime=${info.event.end?.toISOString()}`;
- }
-
- void this.turboRequests.request(
- `${this.pathHelper.timeEntryEditDialog(info.event.id)}?${dialogParams}`,
- { method: 'GET' },
+ const startMoment = moment(info.event.startStr);
+ const endMoment = moment(info.event.endStr);
+
+ this.updateTimeEntry(
+ info.event.id,
+ startMoment.format('YYYY-MM-DD'),
+ info.event.allDay ? null : startMoment.format('HH:mm'),
+ info.event.allDay ? info.event.extendedProps.hours as number : moment.duration(endMoment.diff(startMoment)).asHours(),
+ info.revert,
);
-
- info.revert(); // revert back to old position, when modal succeeds, we reload anyways
},
- eventDrop: (info) => {
- let dialogParams = 'onlyMe=true';
- if (info.event.allDay) {
- dialogParams = `${dialogParams}&date=${info.event.startStr}&removeTime=true`;
- } else {
- dialogParams = `${dialogParams}&startTime=${info.event.start?.toISOString()}&endTime=${info.event.end?.toISOString()}`;
- }
+ // TODO: When dragging from all day to the calendar, we need to set the hours
- void this.turboRequests.request(
- `${this.pathHelper.timeEntryEditDialog(info.event.id)}?${dialogParams}`,
- { method: 'GET' },
+ eventDrop: (info) => {
+ const startMoment = moment(info.event.startStr);
+ const endMoment = moment(info.event.endStr);
+
+ this.updateTimeEntry(
+ info.event.id,
+ startMoment.format('YYYY-MM-DD'),
+ info.event.allDay ? null : startMoment.format('HH:mm'),
+ info.event.allDay ? info.event.extendedProps.hours as number : moment.duration(endMoment.diff(startMoment)).asHours(),
+ info.revert,
);
-
- info.revert(); // revert back to old position, when modal succeeds, we reload anyways
},
});
this.calendar.render();
}
+ updateTimeEntry(timeEntryId:string, spentOn:string, startTime:string | null, hours:number, revertFunction:() => void) {
+ const csrfToken = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content || '';
+ fetch(
+ this.pathHelper.timeEntryUpdate(timeEntryId),
+ {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-CSRF-Token': csrfToken,
+ },
+ body: JSON.stringify({
+ time_entry: {
+ spent_on: spentOn,
+ start_time: startTime,
+ hours,
+ },
+ }),
+ },
+ ).then((response) => {
+ if (response.ok) {
+ void response.text().then((html) => {
+ renderStreamMessage(html);
+ });
+ } else if (!response.ok && revertFunction) { revertFunction(); }
+ }).catch(() => {
+ if (revertFunction) { revertFunction(); }
+ });
+ }
+
calendarView():string {
switch (this.modeValue) {
case 'week':
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index 4ec3067a90c..370801d2eca 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -128,12 +128,14 @@ class TimeEntriesController < ApplicationController
@time_entry = call.result
- unless call.success?
+ if call.success?
+ render_success_flash_message_via_turbo_stream(message: "Event successfully changed")
+ else
form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)
update_via_turbo_stream(component: form_component, status: :bad_request)
-
- respond_with_turbo_streams
end
+
+ respond_with_turbo_streams
end
def destroy