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
add reload to the table view when adding new time entry
Klaus Zanders5acf95c16df7
diff --git a/frontend/src/stimulus/controllers/dynamic/generic-dialog-close.controller.ts b/frontend/src/stimulus/controllers/dynamic/generic-dialog-close.controller.tsnew file mode 100644index 00000000000..f8c9e08edb8--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/generic-dialog-close.controller.ts@@ -0,0 +1,51 @@+/*+ * -- 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.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class GenericDialogCloseController extends Controller<HTMLElement> {+ // TODO: Add something that we can only refresh a certain turbo frame, etc+ connect():void {+ // handle dialog close event+ document.addEventListener('dialog:close', this.dialogCloseListener);+ }++ disconnect():void {+ document.removeEventListener('dialog:close', this.dialogCloseListener);+ }++ dialogCloseListener(this:void, event:CustomEvent):void {+ const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean } };++ if (dialog.id === 'time-entry-dialog' && submitted) {+ window.location.reload();+ }+ }+}diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.tsindex 52004d6d3e6..972b4f49802 100644--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts@@ -39,16 +39,7 @@ export default class MyTimeTrackingController extends Controller {this.pathHelper = context.services.pathHelperService;// handle dialog close event- document.addEventListener('dialog:close', (event:CustomEvent) => {- const {- detail: { dialog, submitted },- } = event as {- detail:{ dialog:HTMLDialogElement; submitted:boolean };- };- if (dialog.id === 'time-entry-dialog' && submitted) {- window.location.reload();- }- });+ document.addEventListener('dialog:close', this.dialogCloseListener);const DEFAULT_TIMED_EVENT_DURATION = '01:00';@@ -194,15 +185,13 @@ export default class MyTimeTrackingController extends Controller {this.calendar.render();}- updateTimeEntry(- timeEntryId:string,- spentOn:string,- startTime:string | null,- hours:number,- revertFunction:() => void,- ) {- const csrfToken = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')- ?.content || '';+ disconnect():void {+ document.removeEventListener('dialog:close', this.dialogCloseListener);+ }++ updateTimeEntry(timeEntryId:string, spentOn:string, startTime:string | null, hours:number, revertFunction:() => void) {+ const csrfToken = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content || '';+fetch(this.pathHelper.timeEntryUpdate(timeEntryId), {method: 'PATCH',headers: {@@ -255,4 +244,11 @@ export default class MyTimeTrackingController extends Controller {return 'timeGridWeek';}}++ dialogCloseListener(this:void, event:CustomEvent):void {+ const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean }; };+ if (dialog.id === 'time-entry-dialog' && submitted) {+ window.location.reload();+ }+ }}diff --git a/modules/costs/app/components/my/time_tracking/table_component.html.erb b/modules/costs/app/components/my/time_tracking/table_component.html.erbindex cd7bb90c3fe..1a3d8a8f6e7 100644--- a/modules/costs/app/components/my/time_tracking/table_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/table_component.html.erb@@ -1,4 +1,4 @@-<%= component_wrapper(tag: "div") do %>+<%= component_wrapper(tag: "div", data: wrapper_data) do %><%= render(Primer::OpenProject::SubHeader.new) do |component|component.with_text { title }@@ -22,7 +22,7 @@end %><%- range.each do |date| %>- <h2><%= date %></h2>+ <%= render(Primer::OpenProject::Heading.new(tag: :h2)) { date.strftime("%A %d") } %><%= render(My::TimeTracking::DailyEntriesTable.new(rows: time_entries_by_day[date])) %><%- end %><%- end %>diff --git a/modules/costs/app/components/my/time_tracking/table_component.rb b/modules/costs/app/components/my/time_tracking/table_component.rbindex 4e5375789d2..fa4056bd8a5 100644--- a/modules/costs/app/components/my/time_tracking/table_component.rb+++ b/modules/costs/app/components/my/time_tracking/table_component.rb@@ -40,6 +40,13 @@ module Myprivate+ def wrapper_data+ {+ "controller" => "generic-dialog-close",+ "application-target" => "dynamic"+ }+ end+def rangecase modewhen :day then [date]