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
refresh only a single element of the list view
Klaus Zanders5360342ec28e
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.tsindex 05fc48fd619..f09e48fac92 100644--- a/frontend/src/app/core/path-helper/path-helper.service.ts+++ b/frontend/src/app/core/path-helper/path-helper.service.ts@@ -373,4 +373,8 @@ export class PathHelperService {public timeEntryUpdate(timeEntryId:string) {return `${this.staticBase}/time_entries/${timeEntryId}`;}++ public myTimeTrackingRefresh(date:string, viewMode:string, mode:string) {+ return `${this.staticBase}/my/time-tracking/refresh?date=${date}&view_mode=${viewMode}&mode=${mode}`;+ }}diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.tsindex 7a012a6a71f..54af2962088 100644--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts@@ -1,4 +1,4 @@-import { Controller } from '@hotwired/stimulus';+import { ActionEvent, Controller } from '@hotwired/stimulus';import { Calendar } from '@fullcalendar/core';import timeGridPlugin from '@fullcalendar/timegrid';import dayGridPlugin from '@fullcalendar/daygrid';@@ -17,6 +17,7 @@ export default class MyTimeTrackingController extends Controller {static values = {mode: String,+ viewMode: String,timeEntries: Array,initialDate: String,canCreate: Boolean,@@ -26,6 +27,7 @@ export default class MyTimeTrackingController extends Controller {};declare readonly calendarTarget:HTMLElement;+ declare readonly hasCalendarTarget:boolean;declare readonly modeValue:string;declare readonly timeEntriesValue:object[];declare readonly initialDateValue:string;@@ -33,19 +35,36 @@ export default class MyTimeTrackingController extends Controller {declare readonly canEditValue:boolean;declare readonly forceTimesValue:boolean;declare readonly localeValue:string;+ declare readonly viewModeValue:string;private calendar:Calendar;+ private DEFAULT_TIMED_EVENT_DURATION = '01:00';+ private updatingDate:string|null = null;+ private boundListener = this.dialogCloseListener.bind(this);async connect() {const context = await window.OpenProject.getPluginContext();this.turboRequests = context.services.turboRequests;this.pathHelper = context.services.pathHelperService;+ if (this.hasCalendarTarget && this.viewModeValue === 'calendar') {+ this.initializeCalendar();+ }+// handle dialog close event- document.addEventListener('dialog:close', this.dialogCloseListener);+ document.addEventListener('dialog:close', this.boundListener);+ }- const DEFAULT_TIMED_EVENT_DURATION = '01:00';+ disconnect():void {+ document.removeEventListener('dialog:close', this.boundListener);+ // Clean up calendar when controller disconnects+ if (this.calendar) {+ this.calendar.destroy();+ }+ }++ initializeCalendar() {this.calendar = new Calendar(this.calendarTarget, {plugins: [timeGridPlugin, dayGridPlugin, interactionPlugin],initialView: this.calendarView(),@@ -58,7 +77,7 @@ export default class MyTimeTrackingController extends Controller {selectable: this.canCreateValue,editable: this.canEditValue,eventResizableFromStart: true,- defaultTimedEventDuration: DEFAULT_TIMED_EVENT_DURATION,+ defaultTimedEventDuration: this.DEFAULT_TIMED_EVENT_DURATION,allDayContent: '',dayMaxEventRows: 4, // 3 + more linkeventMinHeight: 30,@@ -172,7 +191,7 @@ export default class MyTimeTrackingController extends Controller {);}- this.calendar.setOption('defaultTimedEventDuration', DEFAULT_TIMED_EVENT_DURATION);+ this.calendar.setOption('defaultTimedEventDuration', this.DEFAULT_TIMED_EVENT_DURATION);},eventClick: (info) => {// check if we clicked on a link tag, if so exit early as we don't want to show the modal@@ -193,15 +212,6 @@ export default class MyTimeTrackingController extends Controller {this.calendar.render();}- disconnect():void {- document.removeEventListener('dialog:close', this.dialogCloseListener);-- // Clean up calendar when controller disconnects- if (this.calendar) {- this.calendar.destroy();- }- }-addTotalFooter() {if (!this.calendar) return;const calendarScrollGridWrapper = document.querySelector('.fc-timegrid .fc-scrollgrid tbody');@@ -368,10 +378,35 @@ export default class MyTimeTrackingController extends Controller {}}- dialogCloseListener(this:void, event:CustomEvent):void {+ newTimeEntry(event:ActionEvent) {+ const dialogParams = `onlyMe=true&date=${event.params.date}`;+ this.updatingDate = event.params.date as string;++ void this.turboRequests.request(+ `${this.pathHelper.timeEntryDialog()}?${dialogParams}`,+ { method: 'GET' },+ );+ }++ dialogCloseListener(event:CustomEvent):void {const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean } };- if (dialog.id === 'time-entry-dialog' && submitted) {+ if (dialog.id !== 'time-entry-dialog' || !submitted) { return; }++ // we simply refresh the calendar page+ if (this.viewModeValue === 'calendar') {window.location.reload();+ return;+ }++ // list view replaces only the updated date+ if (this.viewModeValue === 'list') {+ // we don't know what date we clicked, so we need to reload the whole page+ if (this.updatingDate) {+ void this.turboRequests.request(this.pathHelper.myTimeTrackingRefresh(this.updatingDate, this.viewModeValue, this.modeValue), { method: 'GET' });+ this.updatingDate = null;+ } else {+ window.location.reload();+ }}}}diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.rb b/modules/costs/app/components/my/time_tracking/calendar_component.rbindex f502d4d1ef7..c5276e6f2cf 100644--- a/modules/costs/app/components/my/time_tracking/calendar_component.rb+++ b/modules/costs/app/components/my/time_tracking/calendar_component.rb@@ -45,6 +45,7 @@ module My"controller" => "my--time-tracking","application-target" => "dynamic","my--time-tracking-mode-value" => mode,+ "my--time-tracking-view-mode-value" => "calendar","my--time-tracking-time-entries-value" => time_entries_json,"my--time-tracking-initial-date-value" => date.iso8601,"my--time-tracking-can-create-value" => User.current.allowed_in_any_project?(:log_own_time),diff --git a/modules/costs/app/components/my/time_tracking/list_component.html.erb b/modules/costs/app/components/my/time_tracking/list_component.html.erbindex 64d1123ab1e..bf0a724566c 100644--- a/modules/costs/app/components/my/time_tracking/list_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/list_component.html.erb@@ -7,13 +7,10 @@<% section.with_title { date_title(date) } %><% section.with_caption { date_caption(date) } %><% section.with_additional_information do %>- <%=- render(Primer::Beta::Text.new(color: :muted, id: "time-entries-count-#{date.iso8601}")) { "#{entry_count_for(date)} - " } +- render(Primer::Beta::Text.new(id: "time-entries-total-#{date.iso8601}")) { total_hours_for(date) }- %>+ <%= render(My::TimeTracking::ListStatsComponent.new(time_entries: grouped_time_entries[date], date: date)) %><% end %><% section.with_collapsible_content do %>- <%= render(My::TimeTracking::DailyEntriesTable.new(rows: grouped_time_entries[date], date: date, mode: mode)) %>+ <%= render(My::TimeTracking::ListWrapperComponent.new(time_entries: grouped_time_entries[date], date: date, mode: mode)) %><% end %><% end %><% end %>diff --git a/modules/costs/app/components/my/time_tracking/list_component.rb b/modules/costs/app/components/my/time_tracking/list_component.rbindex 048481c8006..848dc4f7f64 100644--- a/modules/costs/app/components/my/time_tracking/list_component.rb+++ b/modules/costs/app/components/my/time_tracking/list_component.rb@@ -41,8 +41,10 @@ module Mydef wrapper_data{- "controller" => "generic-dialog-close",- "application-target" => "dynamic"+ "controller" => "my--time-tracking",+ "application-target" => "dynamic",+ "my--time-tracking-mode-value" => mode,+ "my--time-tracking-view-mode-value" => "list"}end@@ -62,11 +64,6 @@ module Myendend- def total_hours_for(date)- total_hours = grouped_time_entries[date].sum(&:hours).round(2)- DurationConverter.output(total_hours, format: :hours_and_minutes).presence || "0h"- end-def date_title(date)if mode == :monthI18n.t(:label_specific_week, week: date.strftime("%W"))@@ -75,11 +72,6 @@ module Myendend- def entry_count_for(date)- entries_count = grouped_time_entries[date].size- "#{entries_count} #{TimeEntry.model_name.human(count: entries_count)}"- end-def collapsed?(date)date.past?enddiff --git a/modules/costs/app/components/my/time_tracking/list_stats_component.rb b/modules/costs/app/components/my/time_tracking/list_stats_component.rbnew file mode 100644index 00000000000..9082a81643d--- /dev/null+++ b/modules/costs/app/components/my/time_tracking/list_stats_component.rb@@ -0,0 +1,60 @@+# 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 My+ module TimeTracking+ class ListStatsComponent < OpPrimer::BorderBoxTableComponent+ include OpTurbo::Streamable++ options :time_entries, :date++ def wrapper_key+ "time-entries-list-stats-#{date.iso8601}"+ end++ def call+ component_wrapper do+ render(Primer::Beta::Text.new(color: :muted)) { "#{entry_count} - " } ++ render(Primer::Beta::Text.new) { total_hours }+ end+ end++ def total_hours+ total_hours = time_entries.sum(&:hours).round(2)+ DurationConverter.output(total_hours, format: :hours_and_minutes).presence || "0h"+ end++ def entry_count+ entries_count = time_entries.size+ "#{entries_count} #{TimeEntry.model_name.human(count: entries_count)}"+ end+ end+ end+enddiff --git a/modules/costs/app/components/my/time_tracking/list_wrapper_component.rb b/modules/costs/app/components/my/time_tracking/list_wrapper_component.rbnew file mode 100644index 00000000000..e56700131b9--- /dev/null+++ b/modules/costs/app/components/my/time_tracking/list_wrapper_component.rb@@ -0,0 +1,49 @@+# 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 My+ module TimeTracking+ class ListWrapperComponent < OpPrimer::BorderBoxTableComponent+ include OpTurbo::Streamable++ options :time_entries, :date, :mode++ def wrapper_key+ "time-entries-list-#{options[:date].iso8601}"+ end++ def call+ component_wrapper do+ render(My::TimeTracking::TimeEntriesListComponent.new(rows: time_entries, date: date, mode: mode))+ end+ end+ end+ end+enddiff --git a/modules/costs/app/components/my/time_tracking/daily_entries_table.rb b/modules/costs/app/components/my/time_tracking/time_entries_list_component.rbsimilarity index 90%rename from modules/costs/app/components/my/time_tracking/daily_entries_table.rbrename to modules/costs/app/components/my/time_tracking/time_entries_list_component.rbindex 7839842cd05..62375e62a41 100644--- a/modules/costs/app/components/my/time_tracking/daily_entries_table.rb+++ b/modules/costs/app/components/my/time_tracking/time_entries_list_component.rb@@ -30,7 +30,8 @@module Mymodule TimeTracking- class DailyEntriesTable < OpPrimer::BorderBoxTableComponent+ class TimeEntriesListComponent < OpPrimer::BorderBoxTableComponent+ include OpTurbo::Streamablecolumns :spent_on, :time, :hours, :subject, :project, :activity, :commentsmain_column :time, :subject, :project@@ -38,10 +39,6 @@ module MyTimeEntryRowend- def container_id- "time-entries-table-#{options[:date].iso8601}"- end-def mobile_titleTimeEntry.model_name.human(count: 2)end@@ -57,8 +54,11 @@ module Mysize: :small,tag: :a,tooltip_direction: :e,- href: dialog_time_entries_path(onlyMe: true, date: options[:date]),- data: { "turbo-stream" => true },+ href: "#",+ data: {+ action: "my--time-tracking#newTimeEntry",+ "my--time-tracking-date-param" => options[:date]+ },label: t("button_log_time"),aria: { label: t("button_log_time") }))diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rbindex 8b559a5390c..acd1a945dfb 100644--- a/modules/costs/app/controllers/my/time_tracking_controller.rb+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb@@ -51,11 +51,20 @@ module Myenddef refresh- if mode == :month+ if mode == :month # for the month we have the whole week in the table, for the rest it's the dayload_time_entries(date.all_week)elseload_time_entries(date)end++ update_via_turbo_stream(+ component: My::TimeTracking::ListWrapperComponent.new(time_entries: @time_entries, date: date, mode: mode)+ )+ update_via_turbo_stream(+ component: My::TimeTracking::ListStatsComponent.new(time_entries: @time_entries, date: date)+ )++ respond_with_turbo_streamsendprivate