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

Implement functionality to select times in the calendar and prefill the modal

Klaus Zanders39544299dc79
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 67749fbf333..79fa5215496 100644
--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
@@ -2,24 +2,38 @@ import { Controller } from '@hotwired/stimulus';
import { Calendar } from '@fullcalendar/core';
import timeGridPlugin from '@fullcalendar/timegrid';
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';
export default class MyTimeTrackingController extends Controller {
+ private turboRequests:TurboRequestsService;
+ private pathHelper:PathHelperService;
+
static targets = ['calendar'];
static values = {
mode: String,
timeEntries: Array,
initialDate: String,
+ canCreate: Boolean,
+ canEdit: Boolean,
};
declare readonly calendarTarget:HTMLElement;
declare readonly modeValue:string;
declare readonly timeEntriesValue:object[];
declare readonly initialDateValue:string;
+ declare readonly canCreateValue:boolean;
+ declare readonly canEditValue:boolean;
private calendar:Calendar;
- connect() {
+ async connect() {
+ const context = await window.OpenProject.getPluginContext();
+ this.turboRequests = context.services.turboRequests;
+ this.pathHelper = context.services.pathHelperService;
+
// handle dialog close event
document.addEventListener('dialog:close', (event:CustomEvent) => {
const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean }; };
@@ -28,10 +42,8 @@ export default class MyTimeTrackingController extends Controller {
}
});
- // styling for the calendar entries can be stolen from the team planner
-
this.calendar = new Calendar(this.calendarTarget, {
- plugins: [timeGridPlugin, dayGridPlugin],
+ plugins: [timeGridPlugin, dayGridPlugin, interactionPlugin],
initialView: this.calendarView(),
firstDay: 1, // get from settings
locale: 'de', // also get from settings
@@ -41,6 +53,7 @@ export default class MyTimeTrackingController extends Controller {
height: 800,
contentHeight: 780,
aspectRatio: 3,
+ selectable: this.canCreateValue,
allDayContent: I18n.t('js.myTimeTracking.noSpecificTime'),
eventClassNames(arg) {
return [
@@ -53,6 +66,20 @@ export default class MyTimeTrackingController extends Controller {
//eslint-disable-next-line
info.el.innerHTML = info.event.extendedProps.customEventView;
},
+ select: (info) => {
+ let dialogParams = 'onlyMe=true';
+
+ if (info.allDay) {
+ dialogParams = `${dialogParams}&date=${info.startStr}`;
+ } else {
+ dialogParams = `${dialogParams}&startTime=${info.start.toISOString()}&endTime=${info.end.toISOString()}`;
+ }
+
+ void this.turboRequests.request(
+ `${this.pathHelper.timeEntryDialog()}?${dialogParams}`,
+ { method: 'GET' },
+ );
+ },
});
this.calendar.render();