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 modals into common base class

ulferts35c27a770320
diff --git a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
index 0904cc552dc..67330346d8e 100644
--- a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
+++ b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
@@ -533,7 +533,7 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
<span class="tooltip--map--value">${this.sanitizedValue(entry.activity.name)}</span>
</li>
<li class="tooltip--map--item">
- <span class="tooltip--map--key">${this.i18n.t('js.time_entry.duration')}:</span>
+ <span class="tooltip--map--key">${this.i18n.t('js.time_entry.hours')}:</span>
<span class="tooltip--map--value">${this.timezone.formattedDuration(entry.hours)}</span>
</li>
<li class="tooltip--map--item">
diff --git a/frontend/src/app/modules/time_entries/create/create.modal.html b/frontend/src/app/modules/time_entries/create/create.modal.html
deleted file mode 100644
index 8e61b4bfad5..00000000000
--- a/frontend/src/app/modules/time_entries/create/create.modal.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<div class="op-modal--portal ngdialog-theme-openproject">
- <div class="op-modal--modal-container confirm-dialog--modal loading-indicator--location"
- data-indicator-name="modal"
- tabindex="0">
- <div class="op-modal--modal-header">
- <a class="op-modal--modal-close-button">
- <i
- class="icon-close"
- (click)="closeMe($event)"
- [attr.title]="text.close">
- </i>
- </a>
- <h3 class="icon-context icon-log_time" [textContent]="text.title"></h3>
- </div>
-
- <div class="ngdialog-body op-modal--modal-body">
- <te-form #editForm
- [entry]="entry"
- (modifiedEntry)="setModifiedEntry($event)">
- </te-form>
- </div>
-
- <div class="op-modal--modal-footer">
- <button class="button -highlight"
- (click)="createEntry()"
- [attr.title]="text.create">
- <op-icon icon-classes="button--icon icon-checkmark"></op-icon>
- <span class="button--text"
- [textContent]="text.create"
- aria-hidden="true"></span>
- </button>
-
- <button class="button"
- (click)="closeMe($event)"
- [attr.title]="text.cancel">
- <op-icon icon-classes="button--icon icon-close"></op-icon>
- <span class="button--text"
- [textContent]="text.cancel"
- aria-hidden="true"></span>
- </button>
- </div>
- </div>
-</div>
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 364477038ab..c154c678ce6 100644
--- a/frontend/src/app/modules/time_entries/create/create.modal.ts
+++ b/frontend/src/app/modules/time_entries/create/create.modal.ts
@@ -1,57 +1,29 @@
-import {Component, ElementRef, Inject, ChangeDetectorRef, ViewChild, ChangeDetectionStrategy} from "@angular/core";
-import {OpModalComponent} from "app/components/op-modals/op-modal.component";
-import {OpModalLocalsToken} from "app/components/op-modals/op-modal.service";
-import {OpModalLocalsMap} from "app/components/op-modals/op-modal.types";
-import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {Component, ChangeDetectionStrategy} from "@angular/core";
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 {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";
+import { TimeEntryBaseModal } from '../shared/modal/base.modal';
@Component({
- templateUrl: './create.modal.html',
- styleUrls: ['../edit/edit.modal.sass'],
+ templateUrl: '../shared/modal/base.modal.html',
+ styleUrls: ['../shared/modal/base.modal.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
HalResourceEditingService
]
})
-export class TimeEntryCreateModal extends OpModalComponent {
-
- @ViewChild('editForm', { static: true }) editForm:TimeEntryFormComponent;
-
- text = {
- title: this.i18n.t('js.button_log_time'),
- create: this.i18n.t('js.label_create'),
- close: this.i18n.t('js.button_close'),
- cancel: this.i18n.t('js.button_cancel')
- };
-
- public closeOnEscape = false;
- public closeOnOutsideClick = false;
-
+export class TimeEntryCreateModal extends TimeEntryBaseModal {
public createdEntry:TimeEntryResource;
- constructor(readonly elementRef:ElementRef,
- @Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,
- readonly cdRef:ChangeDetectorRef,
- readonly i18n:I18nService,
- readonly halEditing:HalResourceEditingService) {
- super(locals, cdRef, elementRef);
- }
-
- public get entry() {
- return this.locals.entry;
- }
-
- public createEntry() {
- this.editForm.save()
- .then(() => {
- this.service.close();
- });
+ public get deleteAllowed() {
+ return false;
}
public setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}) {
this.createdEntry = $event.savedResource as TimeEntryResource;
}
+
+ public get saveText() {
+ return this.i18n.t('js.label_create');
+ }
}
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 ba09cd52d60..7c9ff9d64e1 100644
--- a/frontend/src/app/modules/time_entries/edit/edit.modal.ts
+++ b/frontend/src/app/modules/time_entries/edit/edit.modal.ts
@@ -1,62 +1,26 @@
-import {Component, ElementRef, Inject, ChangeDetectorRef, ChangeDetectionStrategy, ViewChild} from "@angular/core";
-import {OpModalComponent} from "app/components/op-modals/op-modal.component";
-import {OpModalLocalsToken} from "app/components/op-modals/op-modal.service";
-import {OpModalLocalsMap} from "app/components/op-modals/op-modal.types";
-import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {Component, ChangeDetectionStrategy} from "@angular/core";
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 {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";
+import {TimeEntryBaseModal} from "core-app/modules/time_entries/shared/modal/base.modal";
@Component({
- templateUrl: './edit.modal.html',
- styleUrls: ['./edit.modal.sass'],
+ templateUrl: '../shared/modal/base.modal.html',
+ styleUrls: ['../shared/modal/base.modal.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
HalResourceEditingService
]
})
-export class TimeEntryEditModal extends OpModalComponent {
-
- @ViewChild('editForm', { static: true }) editForm:TimeEntryFormComponent;
-
- text = {
- title: this.i18n.t('js.time_entry.label'),
- save: this.i18n.t('js.button_save'),
- delete: this.i18n.t('js.button_delete'),
- cancel: this.i18n.t('js.button_cancel'),
- close: this.i18n.t('js.button_close')
- };
-
- public closeOnEscape = false;
- public closeOnOutsideClick = false;
-
+export class TimeEntryEditModal extends TimeEntryBaseModal {
public modifiedEntry:TimeEntryResource;
public destroyedEntry:TimeEntryResource;
- constructor(readonly elementRef:ElementRef,
- @Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,
- readonly cdRef:ChangeDetectorRef,
- readonly i18n:I18nService) {
- super(locals, cdRef, elementRef);
- }
-
- public get entry() {
- return this.locals.entry;
- }
-
public setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}) {
this.modifiedEntry = $event.savedResource as TimeEntryResource;
}
- public saveEntry() {
- this.editForm.save()
- .then(() => {
- this.service.close();
- });
- }
-
- public get updateAllowed() {
+ public get saveAllowed() {
return !!this.entry.update;
}
diff --git a/frontend/src/app/modules/time_entries/edit/edit.modal.html b/frontend/src/app/modules/time_entries/shared/modal/base.modal.html
similarity index 91%
rename from frontend/src/app/modules/time_entries/edit/edit.modal.html
rename to frontend/src/app/modules/time_entries/shared/modal/base.modal.html
index d097744d079..f62518b7b50 100644
--- a/frontend/src/app/modules/time_entries/edit/edit.modal.html
+++ b/frontend/src/app/modules/time_entries/shared/modal/base.modal.html
@@ -22,17 +22,17 @@
<div class="op-modal--modal-footer">
<button class="button -highlight"
- *ngIf="updateAllowed"
+ *ngIf="saveAllowed"
(click)="saveEntry()"
- [attr.title]="text.save">
+ [attr.title]="saveText">
<op-icon icon-classes="button--icon icon-checkmark"></op-icon>
<span class="button--text"
- [textContent]="text.save"
+ [textContent]="saveText"
aria-hidden="true"></span>
</button>
<button class="button"
- *ngIf="updateAllowed"
+ *ngIf="saveAllowed"
(click)="closeMe($event)"
[attr.title]="text.cancel">
<op-icon icon-classes="button--icon icon-close"></op-icon>
diff --git a/frontend/src/app/modules/time_entries/edit/edit.modal.sass b/frontend/src/app/modules/time_entries/shared/modal/base.modal.sass
similarity index 100%
rename from frontend/src/app/modules/time_entries/edit/edit.modal.sass
rename to frontend/src/app/modules/time_entries/shared/modal/base.modal.sass
diff --git a/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts b/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts
new file mode 100644
index 00000000000..7d4ff5e324f
--- /dev/null
+++ b/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts
@@ -0,0 +1,53 @@
+import {ElementRef, Inject, ChangeDetectorRef, ViewChild} from "@angular/core";
+import {OpModalComponent} from "app/components/op-modals/op-modal.component";
+import {OpModalLocalsToken} from "app/components/op-modals/op-modal.service";
+import {OpModalLocalsMap} from "app/components/op-modals/op-modal.types";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";
+import {HalResource} from "core-app/modules/hal/resources/hal-resource";
+
+export abstract class TimeEntryBaseModal extends OpModalComponent {
+ @ViewChild('editForm', { static: true }) editForm:TimeEntryFormComponent;
+
+ public text:{ [key:string]:string } = {
+ title: this.i18n.t('js.time_entry.label'),
+ cancel: this.i18n.t('js.button_cancel'),
+ close: this.i18n.t('js.button_close'),
+ delete: this.i18n.t('js.button_delete'),
+ };
+
+ public closeOnEscape = false;
+ public closeOnOutsideClick = false;
+
+ constructor(readonly elementRef:ElementRef,
+ @Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,
+ readonly cdRef:ChangeDetectorRef,
+ readonly i18n:I18nService) {
+ super(locals, cdRef, elementRef);
+ }
+
+ public abstract setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}):void;
+
+ public get entry() {
+ return this.locals.entry;
+ }
+
+ public saveEntry() {
+ this.editForm.save()
+ .then(() => {
+ this.service.close();
+ });
+ }
+
+ public get saveText() {
+ return this.i18n.t('js.button_save');
+ }
+
+ public get saveAllowed() {
+ return true;
+ }
+
+ public get deleteAllowed() {
+ return true;
+ }
+}
diff --git a/modules/my_page/spec/features/my/time_entries_current_user_spec.rb b/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
index 57ab7815f4f..82a99ca2ccf 100644
--- a/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
+++ b/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
@@ -242,7 +242,7 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
.to have_selector('.ui-tooltip', text: "Work package: ##{other_work_package.id}: #{other_work_package.subject}")
expect(page)
- .to have_selector('.ui-tooltip', text: "Duration: 6 h")
+ .to have_selector('.ui-tooltip', text: "Hours: 6 h")
expect(page)
.to have_selector('.ui-tooltip', text: "Activity: #{other_activity.name}")