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

Start with custom view implementation for calendar

Klaus Zanders3a3d3148706d
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 ebeb18459ae..2b2c8baaff5 100644
--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts
@@ -30,6 +30,13 @@ export default class MyTimeTrackingController extends Controller {
events: this.timeEntriesValue,
headerToolbar: false,
initialDate: this.initialDateValue,
+ eventClassNames: ['calendar-time-entry-event'],
+ eventContent: (arg) => {
+ if (arg.event.extendedProps.hasOwnProperty('customEventView')) {
+ return { html: arg.event.extendedProps.customEventView };
+ }
+ return null;
+ },
});
this.calendar.render();
diff --git a/lib/full_calendar/event.rb b/lib/full_calendar/event.rb
index 1505745a156..897d4a7c5de 100644
--- a/lib/full_calendar/event.rb
+++ b/lib/full_calendar/event.rb
@@ -53,12 +53,26 @@ module FullCalendar
"title" => title,
"url" => url,
"classNames" => class_names,
- "editable" => editable
+ "editable" => editable,
+ "customEventView" => rendered_event_content
}.compact_blank.as_json
end
def to_json(*)
as_json.to_json(*)
end
+
+ def event_content_view_component
+ # override in subclasses
+ nil
+ end
+
+ private
+
+ def rendered_event_content
+ if event_content_view_component
+ ApplicationController.render(event_content_view_component, layout: false)
+ end
+ end
end
end
diff --git a/modules/costs/app/components/_index.sass b/modules/costs/app/components/_index.sass
index c2d6cebea24..baf9ffc4943 100644
--- a/modules/costs/app/components/_index.sass
+++ b/modules/costs/app/components/_index.sass
@@ -1 +1,2 @@
@import "time_entries/entry_dialog_component"
+@import "time_tracking/time_entry_event_component"
diff --git a/modules/costs/app/components/time_tracking/time_entry_event_component.html.erb b/modules/costs/app/components/time_tracking/time_entry_event_component.html.erb
new file mode 100644
index 00000000000..38d0d65701f
--- /dev/null
+++ b/modules/costs/app/components/time_tracking/time_entry_event_component.html.erb
@@ -0,0 +1,3 @@
+<div class="calendar-time-entry-event--highlighting __hl_background_status_<%= time_entry.work_package.status_id %>"></div>
+
+<h6><%= time_entry.work_package.subject %></h6>
diff --git a/modules/costs/app/components/time_tracking/time_entry_event_component.rb b/modules/costs/app/components/time_tracking/time_entry_event_component.rb
new file mode 100644
index 00000000000..fa5b74bfdf2
--- /dev/null
+++ b/modules/costs/app/components/time_tracking/time_entry_event_component.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module TimeTracking
+ class TimeEntryEventComponent < ApplicationComponent
+ options :time_entry
+ end
+end
diff --git a/modules/costs/app/components/time_tracking/time_entry_event_component.sass b/modules/costs/app/components/time_tracking/time_entry_event_component.sass
new file mode 100644
index 00000000000..0b5d4f3682d
--- /dev/null
+++ b/modules/costs/app/components/time_tracking/time_entry_event_component.sass
@@ -0,0 +1,24 @@
+@import 'helpers'
+@import '../../app/spot/styles/sass/variables'
+
+.calendar-time-entry-event
+ display: flex
+ user-select: none
+ // Leave space for the shadow to be displayed
+ width: calc(100% - 2px)
+ border: 1px solid var(--borderColor-default)
+ border-radius: 2px
+ padding: 10px
+ position: relative
+ box-shadow: 1px 1px 3px 0px var(--borderColor-default)
+ background: var(--body-background)
+ color: var(--body-font-color)
+ font-size: var(--body-font-size)
+
+ &--highlighting
+ width: 100%
+ height: 2px
+ position: absolute
+ top: 0
+ left: 0
+ border-radius: 2px 2px 0 0
diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rb
index c6f5e00ac4b..d87a65edc67 100644
--- a/modules/costs/app/controllers/my/time_tracking_controller.rb
+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb
@@ -90,13 +90,7 @@ module My
def time_entries_json
@time_entries.map do |time_entry|
- FullCalendar::Event.new(
- id: time_entry.id,
- title: "#{time_entry.project.name}: ##{time_entry.work_package.id} #{time_entry.work_package.subject}",
- 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?
- )
+ FullCalendar::TimeEntryEvent.from_time_entry(time_entry)
end.to_json
end
diff --git a/modules/costs/lib/full_calendar/time_entry_event.rb b/modules/costs/lib/full_calendar/time_entry_event.rb
new file mode 100644
index 00000000000..a65471f8dfd
--- /dev/null
+++ b/modules/costs/lib/full_calendar/time_entry_event.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module FullCalendar
+ class TimeEntryEvent < Event
+ attr_accessor :time_entry
+
+ class << self
+ def from_time_entry(time_entry)
+ 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?,
+ title: "#{time_entry.project.name}: ##{time_entry.work_package.id} #{time_entry.work_package.subject}"
+ )
+ event.time_entry = time_entry
+
+ event
+ end
+ end
+
+ def event_content_view_component
+ TimeTracking::TimeEntryEventComponent.new(time_entry: time_entry)
+ end
+ end
+end