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
implement stimulus controller to render FullCalendar
Klaus Zanders45da824bdaa7
diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.tsnew file mode 100644index 00000000000..ebeb18459ae--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts@@ -0,0 +1,50 @@+import { Controller } from '@hotwired/stimulus';+import { Calendar } from '@fullcalendar/core';+import timeGridPlugin from '@fullcalendar/timegrid';+import dayGridPlugin from '@fullcalendar/daygrid';++export default class MyTimeTrackingController extends Controller {+ static targets = ['calendar'];++ static values = {+ mode: String,+ timeEntries: Array,+ initialDate: String,+ };++ declare readonly calendarTarget:HTMLElement;+ declare readonly modeValue:string;+ declare readonly timeEntriesValue:object[];+ declare readonly initialDateValue:string;++ private calendar:Calendar;++ connect() {+ // styling for the calendar entries can be stolen from the team planner++ this.calendar = new Calendar(this.calendarTarget, {+ plugins: [timeGridPlugin, dayGridPlugin],+ initialView: this.calendarView(),+ firstDay: 1, // get from settings+ locale: 'de', // also get from settings+ events: this.timeEntriesValue,+ headerToolbar: false,+ initialDate: this.initialDateValue,+ });++ this.calendar.render();+ }++ calendarView():string {+ switch (this.modeValue) {+ case 'week':+ return 'timeGridWeek';+ case 'month':+ return 'dayGridMonth';+ case 'day':+ return 'timeGridDay';+ default:+ return 'timeGridWeek';+ }+ }+}diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rbindex e81b777133c..80c66fb8d09 100644--- a/modules/costs/app/controllers/my/time_tracking_controller.rb+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb@@ -48,16 +48,36 @@ module Mylayout "global"- helper_method :current_day, :today?, :this_week?, :this_month?+ helper_method :current_day, :today?, :this_week?, :this_month?, :time_entries_json- def day; end+ def day+ @time_entries = TimeEntry+ .includes(:project, :activity, :work_package)+ .where(user: User.current, spent_on: current_day)- def week; end+ # TODO: At some point the filters will reduce the list, so we need to load them seperately+ @project_filters = @time_entries.map(&:project).uniq+ @activity_filters = @time_entries.map(&:activity).uniq+ end++ def week+ @time_entries = TimeEntry+ .includes(:project, :activity, :work_package)+ .where(user: User.current, spent_on: current_day.all_week)++ # TODO: At some point the filters will reduce the list, so we need to load them seperately+ @project_filters = @time_entries.map(&:project).uniq+ @activity_filters = @time_entries.map(&:activity).uniq+ end- def month; end+ def month+ @time_entries = TimeEntry+ .includes(:project, :activity, :work_package)+ .where(user: User.current, spent_on: current_day.all_month)- def default_breadcrumb- "my time"+ # TODO: At some point the filters will reduce the list, so we need to load them seperately+ @project_filters = @time_entries.map(&:project).uniq+ @activity_filters = @time_entries.map(&:activity).uniqenddef today?@@ -74,6 +94,19 @@ module Myprivate+ def time_entries_json+ @time_entries.map do |time_entry|+ {+ id: time_entry.id.to_s,+ title: "#{time_entry.project.name}: ##{time_entry.work_package.id} #{time_entry.work_package.subject}",+ start: time_entry.start_timestamp || time_entry.spent_on,+ end: time_entry.end_timestamp || time_entry.spent_on,+ allDay: time_entry.start_time.blank?++ }+ end.to_json+ end+def current_dayreturn @current_day if defined?(@current_day)diff --git a/modules/costs/app/views/my/time_tracking/_calendar.html.erb b/modules/costs/app/views/my/time_tracking/_calendar.html.erbnew file mode 100644index 00000000000..4ee728acd98--- /dev/null+++ b/modules/costs/app/views/my/time_tracking/_calendar.html.erb@@ -0,0 +1,45 @@+<div+ data-controller="my--time-tracking"+ data-application-target="dynamic"+ data-my--time-tracking-mode-value="<%= local_assigns[:mode] %>"+ data-my--time-tracking-time-entries-value="<%= time_entries_json %>"+ data-my--time-tracking-initial-date-value="<%= current_day %>">+<%= render(Primer::OpenProject::SubHeader.new) do |component|+ component.with_filter_component do+ concat(render(Primer::Beta::IconButton.new(icon: "search", aria: { label: "Search" })))++ concat(+ render(Primer::Beta::Button.new) do |button|+ button.with_leading_visual_icon(icon: :project)+ button.with_trailing_action_icon(icon: :"triangle-down")+ "Project"+ end+ )++ concat(+ render(Primer::Beta::Button.new) do |button|+ button.with_leading_visual_icon(icon: :log)+ button.with_trailing_action_icon(icon: :"triangle-down")+ "Activity"+ end+ )+ end++ component.with_text do+ "#{current_day.beginning_of_week.day}-#{current_day.end_of_week.day}. #{current_day.strftime('%B %Y')}"+ end++ component.with_action_component do+ render(Primer::Beta::ButtonGroup.new) do |group|+ group.with_button(icon: "arrow-left", aria: { label: "Previous week" }, tag: :a, href: my_time_tracking_week_path(date: current_day - 1.week))+ group.with_button(icon: "arrow-right", aria: { label: "Next week" }, tag: :a, href: my_time_tracking_week_path(date: current_day + 1.week))+ end+ end++ component.with_action_button(tag: :a, href: my_time_tracking_week_path(date: Time.zone.today)) { "Today" }++ component.with_action_button(scheme: :primary) { "Log Time" }+ end %>++<div data-my--time-tracking-target="calendar"></div>+</div>diff --git a/modules/costs/app/views/my/time_tracking/day.html.erb b/modules/costs/app/views/my/time_tracking/day.html.erbindex 8d731f456fa..f3c7c50cfd3 100644--- a/modules/costs/app/views/my/time_tracking/day.html.erb+++ b/modules/costs/app/views/my/time_tracking/day.html.erb@@ -9,3 +9,5 @@)end%>++<%= render(partial: "calendar", locals: { mode: "day" }) %>diff --git a/modules/costs/app/views/my/time_tracking/month.html.erb b/modules/costs/app/views/my/time_tracking/month.html.erbindex f18bf60a872..d1e4bda3bac 100644--- a/modules/costs/app/views/my/time_tracking/month.html.erb+++ b/modules/costs/app/views/my/time_tracking/month.html.erb@@ -9,3 +9,5 @@)end%>++<%= render(partial: "calendar", locals: { mode: "month" }) %>diff --git a/modules/costs/app/views/my/time_tracking/week.html.erb b/modules/costs/app/views/my/time_tracking/week.html.erbindex 965396b6b34..ce5662e0afc 100644--- a/modules/costs/app/views/my/time_tracking/week.html.erb+++ b/modules/costs/app/views/my/time_tracking/week.html.erb@@ -28,38 +28,4 @@end%>-<%= render(Primer::OpenProject::SubHeader.new) do |component|- component.with_filter_component do- concat(render(Primer::Beta::IconButton.new(icon: "search", aria: { label: "Search" })))-- concat(- render(Primer::Beta::Button.new) do |button|- button.with_leading_visual_icon(icon: :project)- button.with_trailing_action_icon(icon: :"triangle-down")- "Project"- end- )-- concat(- render(Primer::Beta::Button.new) do |button|- button.with_leading_visual_icon(icon: :log)- button.with_trailing_action_icon(icon: :"triangle-down")- "Activity"- end- )- end-- component.with_text do- "#{Time.zone.now.beginning_of_week.day} - #{Time.zone.now.end_of_week.day}, #{Time.zone.now.strftime('%B %Y')}"- end- component.with_action_component do- render(Primer::Beta::ButtonGroup.new) do |group|- group.with_button(icon: "arrow-left", aria: { label: "Previous week" })- group.with_button(icon: "arrow-right", aria: { label: "Next week" })- end- end-- component.with_action_button { "Today" }-- component.with_action_button(scheme: :primary) { "Log Time" }- end %>+<%= render(partial: "calendar", locals: { mode: "week" }) %>