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

Load time entries schema to provide translations to frontend

Oliver Günther10f8a8311806
diff --git a/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts b/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts
index 18a14c850c7..448fb6e8d3a 100644
--- a/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts
+++ b/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts
@@ -40,6 +40,8 @@ import {
} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { TimeEntryCacheService } from 'core-app/core/apiv3/endpoints/time-entries/time-entry-cache.service';
import { StateCacheService } from 'core-app/core/apiv3/cache/state-cache.service';
+import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';
+import { ApiV3GettableResource } from 'core-app/core/apiv3/paths/apiv3-resource';
export class ApiV3TimeEntriesPaths
extends ApiV3Collection<TimeEntryResource, ApiV3TimeEntryPaths>
@@ -52,6 +54,9 @@ export class ApiV3TimeEntriesPaths
// Static paths
public readonly form = this.subResource('form', ApiV3FormResource);
+ // /api/v3/time_entries/schema
+ readonly schema = this.subResource<ApiV3GettableResource<SchemaResource>>('schema');
+
/**
* Load a list of time entries with a given list parameter filter
* @param params
diff --git a/frontend/src/app/features/hal/resources/time-entry-resource.ts b/frontend/src/app/features/hal/resources/time-entry-resource.ts
index e0086d71b21..89092887bed 100644
--- a/frontend/src/app/features/hal/resources/time-entry-resource.ts
+++ b/frontend/src/app/features/hal/resources/time-entry-resource.ts
@@ -29,6 +29,7 @@
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
import { InputState } from 'reactivestates';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import Formattable = api.v3.Formattable;
export class TimeEntryResource extends HalResource {
@@ -38,6 +39,10 @@ export class TimeEntryResource extends HalResource {
comment:Formattable;
+ workPackage:WorkPackageResource;
+
+ spentOn:string;
+
public get state():InputState<this> {
return this.states.timeEntries.get(this.id as string) as unknown as InputState<this>;
}
@@ -49,3 +54,7 @@ export class TimeEntryResource extends HalResource {
return _.without(super.$linkableKeys(), 'schema');
}
}
+
+export interface TimeEntryResource {
+ delete():Promise<unknown>;
+}
diff --git a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.html b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.html
index 47275482c4c..340c4be1984 100644
--- a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.html
+++ b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.html
@@ -17,7 +17,7 @@
<p>Total: <span [textContent]="total"></span></p>
</div>
- <div class="generic-table--results-container" *ngIf="anyEntries">
+ <div class="generic-table--results-container" *ngIf="entriesLoaded && anyEntries">
<table class="generic-table time-entries">
<colgroup>
<col opHighlightCol>
@@ -31,28 +31,28 @@
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
- <span [textContent]="text.activity"></span>
+ <span [textContent]="schema.activity.name"></span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
- <span [textContent]="text.workPackage"></span>
+ <span [textContent]="schema.workPackage.name"></span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
- <span [textContent]="text.comment"></span>
+ <span [textContent]="schema.comment.name"></span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
- <span [textContent]="text.hour"></span>
+ <span [textContent]="schema.hours.name"></span>
</div>
</div>
</th>
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 a9b5f095405..84e51c70f04 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,5 +1,8 @@
import {
- ChangeDetectorRef, Directive, Injector, OnInit,
+ ChangeDetectorRef,
+ Directive,
+ Injector,
+ 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';
@@ -12,14 +15,11 @@ import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
+import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';
@Directive()
export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetComponent implements OnInit {
public text = {
- activity: this.i18n.t('js.time_entry.activity'),
- comment: this.i18n.t('js.time_entry.comment'),
- hour: this.i18n.t('js.time_entry.hours'),
- workPackage: this.i18n.t('js.label_work_package'),
edit: this.i18n.t('js.button_edit'),
delete: this.i18n.t('js.button_delete'),
confirmDelete: {
@@ -31,6 +31,8 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
public entries:TimeEntryResource[] = [];
+ public schema:SchemaResource;
+
private entriesLoaded = false;
public rows:{ date:string, sum?:string, entry?:TimeEntryResource }[] = [];
@@ -48,66 +50,72 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
super(i18n, injector);
}
- ngOnInit() {
+ ngOnInit():void {
this
.apiV3Service
.time_entries
.list({ filters: this.dmFilters(), pageSize: 500 })
- .subscribe((collection) => {
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
+ .subscribe(async (collection) => {
this.buildEntries(collection.elements);
+
+ if (collection.count > 0) {
+ this.schema = await this.loadSchema();
+ }
+
this.entriesLoaded = true;
this.cdr.detectChanges();
});
}
- public get total() {
+ public get total():string {
const duration = this.entries.reduce((current, entry) => current + this.timezone.toHours(entry.hours), 0);
return this.i18n.t('js.units.hour', { count: this.formatNumber(duration) });
}
- public get anyEntries() {
+ public get anyEntries():boolean {
return !!this.entries.length;
}
- public activityName(entry:TimeEntryResource) {
+ public activityName(entry:TimeEntryResource):string {
return entry.activity.name;
}
- public projectName(entry:TimeEntryResource) {
+ public projectName(entry:TimeEntryResource):string {
return entry.project.name;
}
- public workPackageName(entry:TimeEntryResource) {
- return `#${entry.workPackage.id}: ${entry.workPackage.name}`;
+ public workPackageName(entry:TimeEntryResource):string {
+ return `#${entry.workPackage.id as string}: ${entry.workPackage.name}`;
}
- public workPackageId(entry:TimeEntryResource) {
- return entry.workPackage.id!;
+ public workPackageId(entry:TimeEntryResource):string {
+ return entry.workPackage.id as string;
}
- public comment(entry:TimeEntryResource) {
+ public comment(entry:TimeEntryResource):string|undefined {
return entry.comment && entry.comment.raw;
}
- public hours(entry:TimeEntryResource) {
+ public hours(entry:TimeEntryResource):string {
return this.formatNumber(this.timezone.toHours(entry.hours));
}
- public workPackagePath(entry:TimeEntryResource) {
+ public workPackagePath(entry:TimeEntryResource):string {
return this.pathHelper.workPackagePath(idFromLink(entry.workPackage.href));
}
- public get isEditable() {
+ public get isEditable():boolean {
return false;
}
- public editTimeEntry(entry:TimeEntryResource) {
+ public editTimeEntry(entry:TimeEntryResource):void {
this
.apiV3Service
.time_entries
- .id(entry.id!)
+ .id(entry.id as string)
.get()
.subscribe((loadedEntry) => {
this.timeEntryEditService
@@ -120,12 +128,12 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
this.buildEntries(newEntries);
})
.catch(() => {
- // User canceled the modal
+ // User canceled the modal
});
});
}
- public deleteIfConfirmed(event:Event, entry:TimeEntryResource) {
+ public deleteIfConfirmed(event:Event, entry:TimeEntryResource):void {
event.preventDefault();
this.confirmDialog.confirm({
text: this.text.confirmDelete,
@@ -141,7 +149,7 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
],
dangerHighlighting: true,
}).then(() => {
- entry.delete().then(() => {
+ void entry.delete().then(() => {
const newEntries = this.entries.filter((anEntry) => entry.id !== anEntry.id);
this.buildEntries(newEntries);
@@ -165,7 +173,7 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
sumsByDateSpent[date] = 0;
}
- sumsByDateSpent[date] = sumsByDateSpent[date] + this.timezone.toHours(entry.hours);
+ sumsByDateSpent[date] += this.timezone.toHours(entry.hours);
});
const sortedEntries = entries.sort((a, b) => b.spentOn.localeCompare(a.spentOn));
@@ -175,10 +183,13 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
sortedEntries.forEach((entry) => {
if (entry.spentOn !== currentDate) {
currentDate = entry.spentOn;
- this.rows.push({ date: this.timezone.formattedDate(currentDate!), sum: this.formatNumber(sumsByDateSpent[currentDate!]) });
+ this.rows.push({
+ date: this.timezone.formattedDate(currentDate),
+ sum: this.formatNumber(sumsByDateSpent[currentDate]),
+ });
}
- this.rows.push({ date: currentDate!, entry });
+ this.rows.push({ date: currentDate, entry });
});
// entries
}
@@ -187,7 +198,16 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
return this.i18n.toNumber(value, { precision: 2 });
}
- public get noEntries() {
+ public get noEntries():boolean {
return !this.entries.length && this.entriesLoaded;
}
+
+ private loadSchema():Promise<SchemaResource> {
+ return this
+ .apiV3Service
+ .time_entries
+ .schema
+ .get()
+ .toPromise();
+ }
}