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

avoid calling the te form unnecessarily

ulfertsd5905d178dfc
diff --git a/frontend/src/app/shared/components/time_entries/create/create.service.ts b/frontend/src/app/shared/components/time_entries/create/create.service.ts
index 53021101da2..c9bcc7f8fb5 100644
--- a/frontend/src/app/shared/components/time_entries/create/create.service.ts
+++ b/frontend/src/app/shared/components/time_entries/create/create.service.ts
@@ -5,22 +5,16 @@ import {
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import {
- map,
- take,
-} from 'rxjs/operators';
import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { Moment } from 'moment';
-import { TimeEntryCreateModalComponent } from 'core-app/shared/components/time_entries/create/create.modal';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
-import { TimeEntryModalOptions } from 'core-app/shared/components/time_entries/edit/edit.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { Observable } from 'rxjs';
+import { Observable, of } from 'rxjs';
@Injectable()
export class TimeEntryCreateService {
@@ -35,59 +29,24 @@ export class TimeEntryCreateService {
) {
}
- public create(
- date:Moment,
- wp?:WorkPackageResource,
- options:TimeEntryModalOptions = {},
- ):Promise<{ entry:TimeEntryResource, action:'create' }> {
- return new Promise<{ entry:TimeEntryResource, action:'create' }>((resolve, reject) => {
- void this
- .createNewTimeEntry(date, wp)
- .subscribe((changeset) => {
- this.opModalService.show(
- TimeEntryCreateModalComponent,
- this.injector,
- { ...options, changeset },
- ).subscribe((modal) => {
- modal
- .closingEvent
- .pipe(take(1))
- .subscribe(() => {
- if (modal.createdEntry) {
- resolve({ entry: modal.createdEntry, action: 'create' });
- } else {
- reject();
- }
- });
- });
- });
- });
- }
-
- public createNewTimeEntry(date:Moment, wp?:WorkPackageResource, ongoing = false):Observable<ResourceChangeset> {
- const payload:any = {
- spentOn: date.format('YYYY-MM-DD'),
- hours: null,
- ongoing,
- };
-
- if (wp) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- payload._links = {
- workPackage: {
- href: wp.href,
+ public createNewTimeEntry(date:Moment, wp:WorkPackageResource, ongoing:boolean):Observable<ResourceChangeset> {
+ const resource:FormResource = this.halResource.createHalResourceOfType(
+ 'Form',
+ {
+ payload: {
+ spentOn: date.format('YYYY-MM-DD'),
+ hours: null,
+ ongoing,
+ _links: {
+ workPackage: {
+ href: wp.href,
+ },
+ },
},
- };
- }
+ },
+ );
- return this
- .apiV3Service
- .time_entries
- .form
- .post(payload)
- .pipe(
- map((form) => this.fromCreateForm(form)),
- );
+ return of(this.fromCreateForm(resource));
}
public fromCreateForm(form:FormResource):ResourceChangeset {
@@ -109,9 +68,6 @@ export class TimeEntryCreateService {
entry.id = 'new';
entry.hours = 'PT1H';
- // Set update link to form
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,no-multi-assign
- entry.update = entry.$links.update = form.$links.self;
// Use POST /work_packages for saving link
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,no-multi-assign
entry.updateImmediately = entry.$links.updateImmediately = (payload:Record<string, unknown>) => this
@@ -121,10 +77,6 @@ export class TimeEntryCreateService {
.toPromise();
entry.state.putValue(entry);
- // We need to provide the schema to the cache so that it is available in the html form to e.g. determine
- // the editability.
- // It would be better if the edit field could simply rely on the changeset if it exists.
- this.schemaCache.update(entry, form.schema);
return entry;
}
diff --git a/modules/costs/app/models/time_entries/scopes/ongoing_for_user_other_than.rb b/modules/costs/app/models/time_entries/scopes/ongoing_for_user_other_than.rb
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/modules/costs/spec/models/time_entries/scopes/ongoing_for_user_other_than_spec.rb b/modules/costs/spec/models/time_entries/scopes/ongoing_for_user_other_than_spec.rb
new file mode 100644
index 00000000000..e69de29bb2d