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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Show timelogging modal when logging time via the context menu of a WP view (#8320)
Henriette Darge828688ab4b40
diff --git a/frontend/src/app/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts b/frontend/src/app/components/op-context-menu/wp-context-menu/wp-single-context-menu.tsindex 614db8717c8..9e878525398 100644--- a/frontend/src/app/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts+++ b/frontend/src/app/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts@@ -13,6 +13,8 @@ import {PERMITTED_CONTEXT_MENU_ACTIONS} from 'core-components/op-context-menu/wpimport {OpModalService} from 'core-components/op-modals/op-modal.service';import {WorkPackageAuthorization} from 'core-components/work-packages/work-package-authorization.service';import {WorkPackageAction} from 'core-components/wp-table/context-menu-helper/wp-context-menu-helper.service';+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {TimeEntryCreateService} from "core-app/modules/time_entries/create/create.service";@Directive({selector: '[wpSingleContextMenu]'@@ -20,6 +22,8 @@ import {WorkPackageAction} from 'core-components/wp-table/context-menu-helper/wpexport class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger {@Input('wpSingleContextMenu-workPackage') public workPackage:WorkPackageResource;+ @InjectField() public timeEntryCreateService:TimeEntryCreateService;+constructor(readonly HookService:HookService,readonly $state:StateService,readonly injector:Injector,@@ -53,6 +57,13 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTriggercase 'delete':this.opModalService.show(WpDestroyModal, this.injector, { workPackages: [this.workPackage] });break;+ case 'log_time':+ this.timeEntryCreateService+ .create(moment(new Date()), this.workPackage, false)+ .catch(() => {+ // do nothing, the user closed without changes+ });+ break;default:window.location.href = link!;diff --git a/frontend/src/app/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts b/frontend/src/app/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.tsindex 3281fd46014..1dbb541f32f 100644--- a/frontend/src/app/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts+++ b/frontend/src/app/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts@@ -15,6 +15,7 @@ import {OpModalService} from "core-components/op-modals/op-modal.service";import {WpDestroyModal} from "core-components/modals/wp-destroy-modal/wp-destroy.modal";import {StateService} from "@uirouter/core";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {TimeEntryCreateService} from "core-app/modules/time_entries/create/create.service";export class WorkPackageViewContextMenu extends OpContextMenuHandler {@@ -24,6 +25,7 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {@InjectField() protected $state:StateService;@InjectField() protected wpTableSelection:WorkPackageViewSelectionService;@InjectField() protected WorkPackageContextMenuHelper:WorkPackageContextMenuHelperService;+ @InjectField() protected timeEntryCreateService:TimeEntryCreateService;protected workPackage = this.states.workPackages.get(this.workPackageId).value!;protected selectedWorkPackages = this.getSelectedWorkPackages();@@ -77,6 +79,10 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {this.wpRelationsHierarchyService.addNewChildWp(this.baseRoute, this.workPackage);break;+ case 'log_time':+ this.logTimeForSelectedWorkPackage();+ break;+default:window.location.href = link!;break;@@ -112,6 +118,14 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {this.$state.go(this.baseRoute + '.copy', params);}+ private logTimeForSelectedWorkPackage() {+ this.timeEntryCreateService+ .create(moment(new Date()), this.workPackage)+ .catch(() => {+ // do nothing, the user closed without changes+ });+ }+private getSelectedWorkPackages() {let selectedWorkPackages = this.wpTableSelection.getSelectedWorkPackages();diff --git a/spec/features/work_packages/spent_time_display_spec.rb b/spec/features/work_packages/spent_time_display_spec.rbindex 386d8d850cc..12f27ae5f01 100644--- a/spec/features/work_packages/spent_time_display_spec.rb+++ b/spec/features/work_packages/spent_time_display_spec.rb@@ -39,38 +39,50 @@ describe 'Logging time within the work package view', type: :feature, js: true dlet!(:activity) { FactoryBot.create :time_entry_activity, project: project }let(:spent_time_field) { ::SpentTimeEditField.new(page, 'spentTime') }- let(:time_logging_modal) { ::Components::TimeLoggingModal.new }let(:work_package) { FactoryBot.create :work_package, project: project }let(:wp_page) { Pages::FullWorkPackage.new(work_package, project) }+ let(:time_logging_modal) { ::Components::TimeLoggingModal.new }++ def log_time_via_modal+ time_logging_modal.is_visible true++ # the fields are visible+ time_logging_modal.has_field_with_value 'spent_on', Date.today.strftime("%Y-%m-%d")+ time_logging_modal.shows_field 'work_package', false++ time_logging_modal.update_field 'activity', activity.name++ # 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'+ endcontext 'as an admin' dobefore dologin_as(admin)wp_page.visit!loading_indicator_saveguard+ spent_time_field.timeLogIconVisible trueendit 'shows a logging button within the display field and can log time via a modal' do- spent_time_field.timeLogIconVisible true-# click on button opens modalspent_time_field.openTimeLogModal- time_logging_modal.is_visible true-- # the fields are visible- time_logging_modal.has_field_with_value 'spent_on', Date.today.strftime("%Y-%m-%d")- time_logging_modal.shows_field 'work_package', false- time_logging_modal.update_field 'activity', activity.name+ log_time_via_modal+ end- # a click on save creates a time entry- time_logging_modal.perform_action 'Create'- wp_page.expect_and_dismiss_notification message: 'Successful creation.'+ it 'the context menu entry to log time leads to the modal' do+ # click on context menu opens the modal+ find('#action-show-more-dropdown-menu .button').click+ find('.menu-item', text: 'Log time').click- # the value is updated automatically- spent_time_field.expect_display_value '1 h'+ log_time_via_modalendenddiff --git a/spec/features/work_packages/table/context_menu_spec.rb b/spec/features/work_packages/table/context_menu_spec.rbindex 4adeb12913a..cdda73663e1 100644--- a/spec/features/work_packages/table/context_menu_spec.rb+++ b/spec/features/work_packages/table/context_menu_spec.rb@@ -8,6 +8,7 @@ describe 'Work package table context menu', js: true dolet(:wp_timeline) { Pages::WorkPackagesTimeline.new(work_package.project) }let(:menu) { Components::WorkPackages::ContextMenu.new }let(:destroy_modal) { Components::WorkPackages::DestroyModal.new }+ let(:time_logging_modal) { Components::TimeLoggingModal.new }let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new }def goto_context_menu list_view = true@@ -43,7 +44,9 @@ describe 'Work package table context menu', js: true do# Open log timegoto_context_menu list_viewmenu.choose('Log time')- expect(page).to have_selector('h2', text: I18n.t(:label_spent_time))+ time_logging_modal.is_visible true+ time_logging_modal.work_package_is_missing false+ time_logging_modal.perform_action 'Cancel'# Open Movegoto_context_menu list_view