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
remove some duplication in My Time Tracking Controller
Klaus Zanders8ee31ce054e3
diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.tsindex 0018bbe2114..13c0360db87 100644--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts@@ -1,5 +1,5 @@import { ActionEvent, Controller } from '@hotwired/stimulus';-import { Calendar } from '@fullcalendar/core';+import { Calendar, EventApi } from '@fullcalendar/core';import timeGridPlugin from '@fullcalendar/timegrid';import dayGridPlugin from '@fullcalendar/daygrid';import interactionPlugin from '@fullcalendar/interaction';@@ -99,27 +99,24 @@ export default class MyTimeTrackingController extends Controller {businessHours: { daysOfWeek: this.workingDaysValue, startTime: '00:00', endTime: '24:00' },hiddenDays: this.hiddenDays(),firstDay: this.startOfWeekValue,- eventClassNames(arg) {+ eventClassNames(info) {return ['calendar-time-entry-event',- `__hl_type_${arg.event.extendedProps.typeId}`,+ `__hl_type_${info.event.extendedProps.typeId}`,'__hl_border_top','ellipsis',];},- eventContent: (arg) => {+ eventContent: (info) => {let timeDetails = '';- let duration = arg.event.extendedProps.hours as number;+ let duration = info.event.extendedProps.hours as number;- if (arg.isResizing && arg.event.start && arg.event.end) {- const startMoment = toMoment(arg.event.start, this.calendar);- const endMoment = toMoment(arg.event.end, this.calendar);-- duration = moment.duration(endMoment.diff(startMoment)).asHours();+ if (info.isResizing && info.event.start && info.event.end) {+ duration = this.calculateHours(info.event);}- if (!arg.event.allDay) {- const time = `${toMoment(arg.event.start!, this.calendar).format('LT')} - ${toMoment(arg.event.end!, this.calendar).format('LT')}`;+ if (!info.event.allDay) {+ const time = `${toMoment(info.event.start!, this.calendar).format('LT')} - ${toMoment(info.event.end!, this.calendar).format('LT')}`;timeDetails = `<div class="fc-entry-time color-fg-muted mt-2" title="${time}">${time}</div>`;}@@ -128,12 +125,12 @@ export default class MyTimeTrackingController extends Controller {<div class="fc-event-main-frame"><div class="fc-event-time mb-1">${this.displayDuration(duration)}</div><div class="fc-event-title-container">- <div class="fc-event-title mb-2" title="${arg.event.extendedProps.workPackageSubject}">- <a class="Link--primary Link" href="${this.pathHelper.workPackageShortPath(arg.event.extendedProps.workPackageId as string)}">- ${arg.event.extendedProps.workPackageSubject}+ <div class="fc-event-title mb-2" title="${info.event.extendedProps.workPackageSubject}">+ <a class="Link--primary Link" href="${this.pathHelper.workPackageShortPath(info.event.extendedProps.workPackageId as string)}">+ ${info.event.extendedProps.workPackageSubject}</a></div>- <div class="fc-project-name color-fg-muted" title="${arg.event.extendedProps.projectName}">${arg.event.extendedProps.projectName}</div>+ <div class="fc-project-name color-fg-muted" title="${info.event.extendedProps.projectName}">${info.event.extendedProps.projectName}</div>${timeDetails}</div></div>`,@@ -163,9 +160,7 @@ export default class MyTimeTrackingController extends Controller {}const startMoment = toMoment(info.event.start, this.calendar);- const endMoment = toMoment(info.event.end, this.calendar);-- const newEventHours = moment.duration(endMoment.diff(startMoment)).asHours();+ const newEventHours = this.calculateHours(info.event);info.event.setExtendedProp('hours', newEventHours);@@ -391,6 +386,20 @@ export default class MyTimeTrackingController extends Controller {return `${hours}h ${minutes}m`;}+ calculateHours(event:EventApi):number {+ const start = event.start;+ const end = event.end;++ if (!start || !end) {+ return 0;+ }++ const startMoment = toMoment(start, this.calendar);+ const endMoment = toMoment(end, this.calendar);++ return moment.duration(endMoment.diff(startMoment)).asHours();+ }+calendarView():string {switch (this.modeValue) {case 'week':