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

[OP#65504] Show ongoing timer in calendar

Klaus Zanderse8d84a6aa11e
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 bcac37be9b6..dd96e6122c2 100644
--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
@@ -10,6 +10,7 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.service
import moment from 'moment';
import allLocales from '@fullcalendar/core/locales-all';
import { renderStreamMessage } from '@hotwired/turbo';
+import { opStopwatchStopIconData, toDOMString } from '@openproject/octicons-angular';
export default class MyTimeTrackingController extends Controller {
private turboRequests:TurboRequestsService;
@@ -98,15 +99,22 @@ export default class MyTimeTrackingController extends Controller {
hiddenDays: this.hiddenDays(),
firstDay: this.startOfWeekValue,
eventClassNames(info) {
- return [
+ const classes = [
'calendar-time-entry-event',
`__hl_type_${info.event.extendedProps.typeId}`,
'__hl_border_top',
'ellipsis',
];
+
+ if (info.event.extendedProps.ongoing) {
+ classes.push('calendar-time-entry-event-ongoing');
+ }
+
+ return classes;
},
eventContent: (info) => {
let timeDetails = '';
+ let stopTimerButton = '';
let duration = info.event.extendedProps.hours as number;
if (info.isResizing && info.event.start && info.event.end) {
@@ -118,10 +126,22 @@ export default class MyTimeTrackingController extends Controller {
timeDetails = `<div class="fc-event-times" title="${time}">${time}</div>`;
}
+ if (info.event.extendedProps.ongoing) {
+ stopTimerButton = toDOMString(
+ opStopwatchStopIconData,
+ 'small',
+ { 'aria-hidden': 'true', class: 'octicon stop-timer-button' },
+ );
+ }
+
return {
html: `
<div class="fc-event-main-frame">
- <div class="fc-event-time">${this.displayDuration(duration)}</div>
+ <div class="fc-event-time">
+ ${stopTimerButton}
+
+ ${this.displayDuration(duration)}
+ </div>
<div class="fc-event-title-container">
<div class="fc-event-title fc-event-wp" title="${info.event.extendedProps.workPackageSubject}">
<a class="Link--primary Link" href="${this.pathHelper.workPackageShortPath(info.event.extendedProps.workPackageId as string)}">
@@ -188,6 +208,10 @@ export default class MyTimeTrackingController extends Controller {
return false;
}
+ if (draggedEvent?.extendedProps.ongoing) {
+ return false;
+ }
+
return true;
},
diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.rb b/modules/costs/app/components/my/time_tracking/calendar_component.rb
index bffcc324c00..2645208a2b3 100644
--- a/modules/costs/app/components/my/time_tracking/calendar_component.rb
+++ b/modules/costs/app/components/my/time_tracking/calendar_component.rb
@@ -65,7 +65,7 @@ module My
end
def total_hours
- total_hours = time_entries.sum(&:hours).round(2)
+ total_hours = time_entries.sum(&:hours_for_calculation).round(2)
total_str = DurationConverter.output(total_hours, format: :hours_and_minutes).presence || t("label_no_time")
I18n.t(mode, scope: "total_times", hours: total_str)
diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.sass b/modules/costs/app/components/my/time_tracking/calendar_component.sass
index 1890e6fdec6..10df325f46b 100644
--- a/modules/costs/app/components/my/time_tracking/calendar_component.sass
+++ b/modules/costs/app/components/my/time_tracking/calendar_component.sass
@@ -20,6 +20,12 @@
line-height: var(--text-body-lineHeight-small)
font-size: var(--text-body-size-small)
+ &-ongoing
+ background: var(--bgColor-accent-muted)
+
+ .stop-timer-button
+ color: var(--fgColor-accent)
+
.fc-event-time
font-size: var(--text-body-size-small) !important
diff --git a/modules/costs/lib/full_calendar/time_entry_event.rb b/modules/costs/lib/full_calendar/time_entry_event.rb
index 22f31827b02..6d2be1f8fae 100644
--- a/modules/costs/lib/full_calendar/time_entry_event.rb
+++ b/modules/costs/lib/full_calendar/time_entry_event.rb
@@ -34,11 +34,19 @@ module FullCalendar
class << self
def from_time_entry(time_entry)
+ starts_at = time_entry.start_timestamp || time_entry.spent_on
+ ends_at = time_entry.end_timestamp || time_entry.spent_on
+
+ if time_entry.ongoing?
+ starts_at = time_entry.created_at
+ ends_at = Time.current
+ end
+
event = new(
id: time_entry.id,
- starts_at: time_entry.start_timestamp || time_entry.spent_on,
- ends_at: time_entry.end_timestamp || time_entry.spent_on,
- all_day: time_entry.start_time.blank?,
+ starts_at: starts_at,
+ ends_at: ends_at,
+ all_day: !time_entry.ongoing? && time_entry.start_time.blank?,
title: "#{time_entry.project.name}: ##{time_entry.work_package.id} #{time_entry.work_package.subject}"
)
event.time_entry = time_entry
@@ -50,12 +58,13 @@ module FullCalendar
def additional_attributes # rubocop:disable Metrics/AbcSize
{
durationEditable: time_entry.start_time.present?,
- hours: time_entry.hours,
+ hours: time_entry.hours_for_calculation,
typeId: time_entry.work_package.type_id,
workPackageId: time_entry.work_package.id,
workPackageSubject: time_entry.work_package.subject,
projectId: time_entry.project.id,
- projectName: time_entry.project.name
+ projectName: time_entry.project.name,
+ ongoing: time_entry.ongoing?
}
end
end