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

Fix spent time widget

Klaus Zanders3568a50acc21
diff --git a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
index d7ea932a681..18babf14424 100644
--- a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
@@ -1,13 +1,14 @@
import {
+ AfterViewInit,
ChangeDetectorRef,
Directive,
Injector,
+ OnDestroy,
OnInit,
} from '@angular/core';
import { AbstractWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-widget.component';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { TimeEntryEditService } from 'core-app/shared/components/time_entries/edit/edit.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { FilterOperator } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
@@ -20,9 +21,10 @@ import {
firstValueFrom,
Observable,
} from 'rxjs';
+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
@Directive()
-export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetComponent implements OnInit {
+export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetComponent implements OnInit, AfterViewInit, OnDestroy {
public text = {
edit: this.i18n.t('js.button_edit'),
delete: this.i18n.t('js.button_delete'),
@@ -42,20 +44,35 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
public rows:{ date:string, sum?:string, entry?:TimeEntryResource }[] = [];
- @InjectField() public readonly timeEntryEditService:TimeEntryEditService;
+ private closeDialogHandler:EventListener = this.handleDialogClose.bind(this);
@InjectField() public readonly apiV3Service:ApiV3Service;
+ @InjectField() public readonly turboRequests:TurboRequestsService;
- constructor(readonly injector:Injector,
+ constructor(
+ readonly injector:Injector,
readonly timezone:TimezoneService,
readonly i18n:I18nService,
readonly pathHelper:PathHelperService,
readonly confirmDialog:ConfirmDialogService,
- protected readonly cdr:ChangeDetectorRef) {
+ protected readonly cdr:ChangeDetectorRef,
+ ) {
super(i18n, injector);
}
ngOnInit():void {
+ this.loadTimeEntries();
+ }
+
+ ngAfterViewInit():void {
+ document.addEventListener('dialog:close', this.closeDialogHandler);
+ }
+
+ ngOnDestroy():void {
+ document.removeEventListener('dialog:close', this.closeDialogHandler);
+ }
+
+ public loadTimeEntries() {
this
.apiV3Service
.time_entries
@@ -100,7 +117,7 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
return entry.workPackage.id as string;
}
- public comment(entry:TimeEntryResource):string|undefined {
+ public comment(entry:TimeEntryResource):string | undefined {
return entry.comment && entry.comment.raw;
}
@@ -117,25 +134,10 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
}
public editTimeEntry(entry:TimeEntryResource):void {
- this
- .apiV3Service
- .time_entries
- .id(entry.id as string)
- .get()
- .subscribe((loadedEntry) => {
- this.timeEntryEditService
- .edit(loadedEntry)
- .then((changedEntry) => {
- const oldEntryIndex:number = this.entries.findIndex((el) => el.id === changedEntry.entry.id);
- const newEntries = this.entries;
- newEntries[oldEntryIndex] = changedEntry.entry;
-
- this.buildEntries(newEntries);
- })
- .catch(() => {
- // User canceled the modal
- });
- });
+ void this.turboRequests.request(
+ `${this.pathHelper.timeEntryEditDialog(entry.id as string)}`,
+ { method: 'GET' },
+ );
}
public deleteIfConfirmed(event:Event, entry:TimeEntryResource):void {
@@ -184,7 +186,7 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
const sortedEntries = entries.sort((a, b) => b.spentOn.localeCompare(a.spentOn));
this.rows = [];
- let currentDate:string|null = null;
+ let currentDate:string | null = null;
sortedEntries.forEach((entry) => {
if (entry.spentOn !== currentDate) {
currentDate = entry.spentOn;
@@ -214,4 +216,11 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
.schema
.get();
}
+
+ private handleDialogClose(event:CustomEvent):void {
+ const { detail: { dialog, submitted } } = event as { detail:{ dialog:HTMLDialogElement; submitted:boolean } };
+ if (dialog.id === 'time-entry-dialog' && submitted) {
+ this.loadTimeEntries();
+ }
+ }
}
diff --git a/modules/dashboards/spec/features/time_entries_spec.rb b/modules/dashboards/spec/features/time_entries_spec.rb
index 5f223fa9405..fd16372ef43 100644
--- a/modules/dashboards/spec/features/time_entries_spec.rb
+++ b/modules/dashboards/spec/features/time_entries_spec.rb
@@ -30,7 +30,7 @@ require "spec_helper"
require_relative "../support/pages/dashboard"
-RSpec.describe "Time entries widget on dashboard", :js do
+RSpec.describe "Time entries widget on dashboard", :js, :with_cuprite do
let!(:type) { create(:type) }
let!(:project) { create(:project, types: [type]) }
let!(:other_project) { create(:project, types: [type]) }
@@ -102,30 +102,19 @@ RSpec.describe "Time entries widget on dashboard", :js do
spent_time_widget = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(1)")
within spent_time_widget.area do
- expect(page)
- .to have_content "Total: 11 h"
-
- expect(page)
- .to have_content Date.today.strftime("%m/%d/%Y")
- expect(page)
- .to have_css(".activity", text: visible_time_entry.activity.name)
- expect(page)
- .to have_css(".subject", text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
- expect(page)
- .to have_css(".comments", text: visible_time_entry.comments)
- expect(page)
- .to have_css(".hours", text: visible_time_entry.hours)
-
- expect(page)
- .to have_content((Date.today - 1.day).strftime("%m/%d/%Y"))
- expect(page)
- .to have_css(".activity", text: other_visible_time_entry.activity.name)
- expect(page)
- .to have_css(".subject", text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
- expect(page)
- .to have_css(".comments", text: other_visible_time_entry.comments)
- expect(page)
- .to have_css(".hours", text: other_visible_time_entry.hours)
+ expect(page).to have_content "Total: 11 h"
+
+ expect(page).to have_content Time.zone.today.strftime("%m/%d/%Y")
+ expect(page).to have_css(".activity", text: visible_time_entry.activity.name)
+ expect(page).to have_css(".subject", text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
+ expect(page).to have_css(".comments", text: visible_time_entry.comments)
+ expect(page).to have_css(".hours", text: visible_time_entry.hours)
+
+ expect(page).to have_content(1.day.ago.strftime("%m/%d/%Y"))
+ expect(page).to have_css(".activity", text: other_visible_time_entry.activity.name)
+ expect(page).to have_css(".subject", text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
+ expect(page).to have_css(".comments", text: other_visible_time_entry.comments)
+ expect(page).to have_css(".hours", text: other_visible_time_entry.hours)
# Allows to edit
page.find_test_selector("edit-time-entry-#{visible_time_entry.id}").click
@@ -139,7 +128,7 @@ RSpec.describe "Time entries widget on dashboard", :js do
sleep(0.1)
- time_logging_modal.perform_action "Save"
+ time_logging_modal.submit
time_logging_modal.is_visible false
within spent_time_widget.area do