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

Pass the correct WP to the spent time widget when starting it from the table

Henriette Dargefd520f0150dc
diff --git a/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts
index e715a7fe9bd..690dd029c53 100644
--- a/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts
+++ b/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts
@@ -33,6 +33,7 @@ import { ProjectResource } from "core-app/modules/hal/resources/project-resource
import { InjectField } from "core-app/helpers/angular/inject-field.decorator";
import * as URI from 'urijs';
import { TimeEntryCreateService } from 'core-app/modules/time_entries/create/create.service';
+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";
export class WorkPackageSpentTimeDisplayField extends DurationDisplayField {
public text = {
@@ -81,16 +82,13 @@ export class WorkPackageSpentTimeDisplayField extends DurationDisplayField {
element.appendChild(timelogElement);
- let classContext = this;
- timelogElement.addEventListener('click', function() {
- classContext.showTimelogWidget();
- });
+ timelogElement.addEventListener('click', this.showTimelogWidget.bind(this, this.resource));
}
}
- private showTimelogWidget() {
+ private showTimelogWidget(wp:WorkPackageResource) {
this.timeEntryCreateService
- .create(moment(new Date()), this.resource, false)
+ .create(moment(new Date()), wp, false)
.catch(() => {
// do nothing, the user closed without changes
});
diff --git a/spec/features/work_packages/spent_time_display_spec.rb b/spec/features/work_packages/spent_time_display_spec.rb
index ae676ffb778..c491f073733 100644
--- a/spec/features/work_packages/spent_time_display_spec.rb
+++ b/spec/features/work_packages/spent_time_display_spec.rb
@@ -57,9 +57,6 @@ describe 'Logging time within the work package view', type: :feature, js: true d
# a click on save creates a time entry
time_logging_modal.perform_action 'Create'
wp_page.expect_and_dismiss_notification message: 'Successful creation.'
-
- # the value is updated automatically
- spent_time_field.expect_display_value '1 h'
end
context 'as an admin' do
@@ -75,6 +72,9 @@ describe 'Logging time within the work package view', type: :feature, js: true d
spent_time_field.open_time_log_modal
log_time_via_modal
+
+ # the value is updated automatically
+ spent_time_field.expect_display_value '1 h'
end
it 'the context menu entry to log time leads to the modal' do
@@ -83,6 +83,9 @@ describe 'Logging time within the work package view', type: :feature, js: true d
find('.menu-item', text: 'Log time').click
log_time_via_modal
+
+ # the value is updated automatically
+ spent_time_field.expect_display_value '1 h'
end
end
@@ -98,4 +101,30 @@ describe 'Logging time within the work package view', type: :feature, js: true d
spent_time_field.expect_display_value '-'
end
end
+
+ context 'within the table' do
+ let(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let(:second_work_package) { FactoryBot.create :work_package, project: project }
+ let(:query) { FactoryBot.create :public_query, project: project, column_names: ['subject', 'spent_hours'] }
+
+ before do
+ work_package
+ second_work_package
+ login_as(admin)
+
+ wp_table.visit_query query
+ loading_indicator_saveguard
+ end
+
+ it 'shows no logging button within the display field' do
+ wp_table.expect_work_package_listed work_package, second_work_package
+
+ find('tr:nth-of-type(1) .wp-table--cell-td.spentTime .icon-time').click
+
+ log_time_via_modal
+
+ expect(page).to have_selector('tr:nth-of-type(1) .wp-table--cell-td.spentTime', text: '1 h')
+ expect(page).to have_selector('tr:nth-of-type(2) .wp-table--cell-td.spentTime', text: '-')
+ end
+ end
end