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

extract time entry form into component

ulferts281be1ef51f0
diff --git a/frontend/src/app/modules/time_entries/create/create.modal.html b/frontend/src/app/modules/time_entries/create/create.modal.html
index 0476c3a8f6d..65cf3c73567 100644
--- a/frontend/src/app/modules/time_entries/create/create.modal.html
+++ b/frontend/src/app/modules/time_entries/create/create.modal.html
@@ -14,62 +14,10 @@
</div>
<div class="ngdialog-body op-modal--modal-body">
- <edit-form
- #editForm
- [resource]="entry"
- [inEditMode]="true"
- (onSaved)="setModifiedEntry($event)">
- <div class="attributes-map">
-
- <div class="attributes-map--key" [textContent]="text.attributes.spentOn"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'spentOn'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.hours"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'hours'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.workPackage"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'workPackage'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.activity"></div>
- <div class="attributes-map--value">
- <editable-attribute-field *ngIf="workPackageSelected"
- [resource]="entry"
- [fieldName]="'activity'">
- </editable-attribute-field>
- <i *ngIf="!workPackageSelected"
- [textContent]="text.wpRequired">
- </i>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.comment"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'comment'">
- </editable-attribute-field>
- </div>
-
- <ng-container *ngFor="let cf of customFields">
- <div class="attributes-map--key" [textContent]="cf.label"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="cf.key">
- </editable-attribute-field>
- </div>
- </ng-container>
- </div>
- </edit-form>
+ <te-form #editForm
+ [entry]="entry"
+ (modifiedEntry)="setModifiedEntry($event)">
+ </te-form>
</div>
<div class="op-modal--modal-footer">
diff --git a/frontend/src/app/modules/time_entries/create/create.modal.ts b/frontend/src/app/modules/time_entries/create/create.modal.ts
index eb9c1f4b55c..8177fda4950 100644
--- a/frontend/src/app/modules/time_entries/create/create.modal.ts
+++ b/frontend/src/app/modules/time_entries/create/create.modal.ts
@@ -6,9 +6,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";
import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
-import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
-import {EditFormComponent} from "core-app/modules/fields/edit/edit-form/edit-form.component";
-import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
+import {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";
@Component({
templateUrl: './create.modal.html',
@@ -19,26 +17,16 @@ import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
})
export class TimeEntryCreateModal extends OpModalComponent {
- @ViewChild('editForm', { static: true }) editForm:EditFormComponent;
+ @ViewChild('editForm', { static: true }) editForm:TimeEntryFormComponent;
text = {
title: this.i18n.t('js.time_entry.edit'),
- attributes: {
- comment: this.i18n.t('js.time_entry.comment'),
- hours: this.i18n.t('js.time_entry.hours'),
- activity: this.i18n.t('js.time_entry.activity'),
- workPackage: this.i18n.t('js.time_entry.work_package'),
- spentOn: this.i18n.t('js.time_entry.spent_on'),
- },
- wpRequired: this.i18n.t('js.time_entry.work_package_required'),
create: this.i18n.t('js.label_create'),
close: this.i18n.t('js.button_close')
};
public closeOnEscape = false;
public closeOnOutsideClick = false;
- public customFields:{key:string, label:string}[] = [];
- public workPackageSelected:boolean = false;
public createdEntry:TimeEntryResource;
@@ -48,18 +36,6 @@ export class TimeEntryCreateModal extends OpModalComponent {
readonly i18n:I18nService,
readonly halEditing:HalResourceEditingService) {
super(locals, cdRef, elementRef);
-
- halEditing
- .temporaryEditResource(this.entry)
- .values$()
- .pipe(
- untilComponentDestroyed(this)
- )
- .subscribe(changeset => {
- if (changeset && changeset.workPackage) {
- this.workPackageSelected = true;
- }
- });
}
public get entry() {
@@ -76,17 +52,4 @@ export class TimeEntryCreateModal extends OpModalComponent {
public setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}) {
this.createdEntry = $event.savedResource as TimeEntryResource;
}
-
- ngOnInit() {
- super.ngOnInit();
- this.setCustomFields(this.entry.schema);
- }
-
- private setCustomFields(schema:SchemaResource) {
- Object.entries(schema).forEach(([key, keySchema]) => {
- if (key.match(/customField\d+/)) {
- this.customFields.push({key: key, label: keySchema.name });
- }
- });
- }
}
diff --git a/frontend/src/app/modules/time_entries/edit/edit.modal.html b/frontend/src/app/modules/time_entries/edit/edit.modal.html
index c2cce63a3e1..57cbe12f05a 100644
--- a/frontend/src/app/modules/time_entries/edit/edit.modal.html
+++ b/frontend/src/app/modules/time_entries/edit/edit.modal.html
@@ -14,56 +14,9 @@
</div>
<div class="ngdialog-body op-modal--modal-body">
- <edit-form
- [resource]="entry"
- (onSaved)="setModifiedEntry($event)">
- <div class="attributes-map">
-
- <div class="attributes-map--key" [textContent]="text.attributes.spentOn"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'spentOn'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.hours"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'hours'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.workPackage"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'workPackage'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.activity"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'activity'">
- </editable-attribute-field>
- </div>
-
- <div class="attributes-map--key" [textContent]="text.attributes.comment"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="'comment'">
- </editable-attribute-field>
- </div>
-
- <ng-container *ngFor="let cf of customFields">
- <div class="attributes-map--key" [textContent]="cf.label"></div>
- <div class="attributes-map--value">
- <editable-attribute-field [resource]="entry"
- [fieldName]="cf.key">
- </editable-attribute-field>
- </div>
- </ng-container>
- </div>
- </edit-form>
+ <te-form [entry]="entry"
+ (modifiedEntry)="setModifiedEntry($event)">
+ </te-form>
</div>
<div class="op-modal--modal-footer">
diff --git a/frontend/src/app/modules/time_entries/edit/edit.modal.ts b/frontend/src/app/modules/time_entries/edit/edit.modal.ts
index 725d0af455a..2de16f141a7 100644
--- a/frontend/src/app/modules/time_entries/edit/edit.modal.ts
+++ b/frontend/src/app/modules/time_entries/edit/edit.modal.ts
@@ -19,20 +19,12 @@ export class TimeEntryEditModal extends OpModalComponent {
text = {
title: this.i18n.t('js.time_entry.edit'),
- attributes: {
- comment: this.i18n.t('js.time_entry.comment'),
- hours: this.i18n.t('js.time_entry.hours'),
- activity: this.i18n.t('js.time_entry.activity'),
- workPackage: this.i18n.t('js.time_entry.work_package'),
- spentOn: this.i18n.t('js.time_entry.spent_on'),
- },
close: this.i18n.t('js.button_close'),
delete: this.i18n.t('js.button_delete')
};
public closeOnEscape = false;
public closeOnOutsideClick = false;
- public customFields:{key:string, label:string}[] = [];
public modifiedEntry:TimeEntryResource;
public destroyedEntry:TimeEntryResource;
@@ -60,17 +52,4 @@ export class TimeEntryEditModal extends OpModalComponent {
this.destroyedEntry = this.entry;
this.service.close();
}
-
- ngOnInit() {
- super.ngOnInit();
- this.setCustomFields(this.entry.schema);
- }
-
- private setCustomFields(schema:SchemaResource) {
- Object.entries(schema).forEach(([key, keySchema]) => {
- if (key.match(/customField\d+/)) {
- this.customFields.push({key: key, label: keySchema.name });
- }
- });
- }
}
diff --git a/frontend/src/app/modules/time_entries/form/form.component.html b/frontend/src/app/modules/time_entries/form/form.component.html
new file mode 100644
index 00000000000..0ec1d2ff398
--- /dev/null
+++ b/frontend/src/app/modules/time_entries/form/form.component.html
@@ -0,0 +1,56 @@
+<edit-form
+ #editForm
+ [resource]="entry"
+ [inEditMode]="inEditMode"
+ (onSaved)="signalModifiedEntry($event)">
+ <div class="attributes-map">
+
+ <div class="attributes-map--key" [textContent]="text.attributes.spentOn"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'spentOn'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.hours"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'hours'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.workPackage"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'workPackage'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.activity"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field *ngIf="workPackageSelected"
+ [resource]="entry"
+ [fieldName]="'activity'">
+ </editable-attribute-field>
+ <i *ngIf="!workPackageSelected"
+ [textContent]="text.wpRequired">
+ </i>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.comment"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'comment'">
+ </editable-attribute-field>
+ </div>
+
+ <ng-container *ngFor="let cf of customFields">
+ <div class="attributes-map--key" [textContent]="cf.label"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="cf.key">
+ </editable-attribute-field>
+ </div>
+ </ng-container>
+ </div>
+</edit-form>
diff --git a/frontend/src/app/modules/time_entries/form/form.component.ts b/frontend/src/app/modules/time_entries/form/form.component.ts
new file mode 100644
index 00000000000..65cf62fd69d
--- /dev/null
+++ b/frontend/src/app/modules/time_entries/form/form.component.ts
@@ -0,0 +1,78 @@
+import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";
+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import { ViewEncapsulation, Component, Input, EventEmitter, Output, OnInit, OnDestroy, ViewChild } from '@angular/core';
+import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
+import {HalResource} from "core-app/modules/hal/resources/hal-resource";
+import { EditFormComponent } from 'core-app/modules/fields/edit/edit-form/edit-form.component';
+
+@Component({
+ templateUrl: './form.component.html',
+ selector: 'te-form',
+ encapsulation: ViewEncapsulation.None
+})
+export class TimeEntryFormComponent implements OnInit, OnDestroy {
+ @Input() entry:TimeEntryResource;
+
+ @Output() modifiedEntry = new EventEmitter<{savedResource:TimeEntryResource, isInital:boolean}>();
+
+ @ViewChild('editForm', { static: true }) editForm:EditFormComponent;
+
+ text = {
+ attributes: {
+ comment: this.i18n.t('js.time_entry.comment'),
+ hours: this.i18n.t('js.time_entry.hours'),
+ activity: this.i18n.t('js.time_entry.activity'),
+ workPackage: this.i18n.t('js.time_entry.work_package'),
+ spentOn: this.i18n.t('js.time_entry.spent_on'),
+ },
+ wpRequired: this.i18n.t('js.time_entry.work_package_required')
+ };
+
+ public workPackageSelected:boolean = false;
+ public customFields:{key:string, label:string}[] = [];
+
+ constructor(readonly halEditing:HalResourceEditingService,
+ readonly i18n:I18nService) {
+ }
+
+ ngOnInit() {
+ this.halEditing
+ .temporaryEditResource(this.entry)
+ .values$()
+ .pipe(
+ untilComponentDestroyed(this)
+ )
+ .subscribe(changeset => {
+ if (changeset && changeset.workPackage) {
+ this.workPackageSelected = true;
+ }
+ });
+
+ this.setCustomFields(this.entry.schema);
+ }
+
+ ngOnDestroy() {
+ // nothing to do
+ }
+
+ public signalModifiedEntry($event:{savedResource:HalResource, isInital:boolean}) {
+ this.modifiedEntry.emit($event as {savedResource:TimeEntryResource, isInital:boolean});
+ }
+ public save() {
+ return this.editForm.save();
+ }
+
+ public get inEditMode() {
+ return this.entry.isNew;
+ }
+
+ private setCustomFields(schema:SchemaResource) {
+ Object.entries(schema).forEach(([key, keySchema]) => {
+ if (key.match(/customField\d+/)) {
+ this.customFields.push({key: key, label: keySchema.name });
+ }
+ });
+ }
+}
diff --git a/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts b/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts
index 79d79778676..e8d52016188 100644
--- a/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts
+++ b/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts
@@ -32,6 +32,7 @@ import {OpenprojectFieldsModule} from "core-app/modules/fields/openproject-field
import {TimeEntryEditService} from "core-app/modules/time_entries/edit/edit.service";
import {TimeEntryCreateModal} from "core-app/modules/time_entries/create/create.modal";
import {TimeEntryEditModal} from "core-app/modules/time_entries/edit/edit.modal";
+import {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";
@NgModule({
imports: [
@@ -46,6 +47,7 @@ import {TimeEntryEditModal} from "core-app/modules/time_entries/edit/edit.modal"
declarations: [
TimeEntryEditModal,
TimeEntryCreateModal,
+ TimeEntryFormComponent
],
entryComponents: [
TimeEntryEditModal,