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

Hide when not on mobile and add spec

Oliver Günther6432338c4b40
diff --git a/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts b/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts
index f8509ee7351..3773e5a6e38 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts
@@ -42,6 +42,7 @@ export type WorkPackageAction = {
indexBy?:(actions:WorkPackageAction[]) => number,
link?:string;
href?:string;
+ hidden?:boolean;
};
@Injectable()
diff --git a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts
index fff4740da6f..d48e510d268 100644
--- a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts
+++ b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts
@@ -23,7 +23,7 @@ import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { TimeEntryTimerService } from 'core-app/shared/components/time_entries/services/time-entry-timer.service';
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
-import { action } from 'ts-action';
+import { DeviceService } from 'core-app/core/browser/device.service';
@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
@@ -47,6 +47,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
readonly authorisationService = inject(AuthorisationService);
readonly timeEntryService = inject(TimeEntryTimerService);
protected copyToClipboardService = inject(CopyToClipboardService);
+ protected deviceService = inject(DeviceService);
private closeDialogHandler:EventListener = this.handleTimeEntryDialogClose.bind(this);
@@ -133,15 +134,21 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
return !!entry && entry.entity.href === this.workPackage.href;
}
- private hasTimerPermission():boolean {
- return Object.prototype.hasOwnProperty.call(this.workPackage, 'logTime');
- }
-
- private getTimerAction():string {
+ private getTimerAction():WorkPackageAction {
if (this.activeForWorkPackage(this.currentTimer)) {
- return 'stop_timer';
+ return {
+ key: 'stop_timer',
+ icon: 'icon-time-tracking-stop',
+ link: 'logTime',
+ hidden: !this.deviceService.isSmallDesktop,
+ };
} else {
- return 'start_timer';
+ return {
+ key: 'start_timer',
+ icon: 'icon-time-tracking-start',
+ link: 'logTime',
+ hidden: !this.deviceService.isSmallDesktop,
+ };
}
}
@@ -161,15 +168,12 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
}
private addTimerAction(actions:WorkPackageAction[]) {
- const key = this.getTimerAction();
- const action = {
- key,
- icon: 'icon-time-tracking-start',
- link: 'logTime',
- };
-
+ const action = this.getTimerAction();
const timeIndex = actions.findIndex((action) => action.key === 'log_time');
- actions.splice(timeIndex + 1, 0, action);
+
+ if (timeIndex !== -1) {
+ actions.splice(timeIndex + 1, 0, action);
+ }
return actions;
}
@@ -180,15 +184,17 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
}
protected buildItems(permittedActions:WorkPackageAction[]):OpContextMenuItem[] {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const configureFormLink = this.workPackage.configureForm;
this.items = permittedActions.map((action:WorkPackageAction) => {
const { key } = action;
return {
disabled: false,
+ hidden: action.hidden === true,
linkText: I18n.t(`js.button_${key}`),
href: action.link,
- icon: action.icon || `icon-${key}`,
+ icon: action.icon ?? `icon-${key}`,
onClick: ($event:JQuery.TriggeredEvent) => {
if (action.link && isClickedWithModifier($event)) {
return false;
diff --git a/spec/features/work_packages/details/context_menu_timer_spec.rb b/spec/features/work_packages/details/context_menu_timer_spec.rb
new file mode 100644
index 00000000000..ffb742f849b
--- /dev/null
+++ b/spec/features/work_packages/details/context_menu_timer_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe "Work package single context menu timer", :js do
+ shared_let(:project) { create(:project) }
+ shared_let(:work_package) { create(:work_package, project:) }
+
+ let(:wp_view) { Pages::FullWorkPackage.new(work_package, project) }
+
+ before do
+ login_as(user)
+ end
+
+ context "with a user having permission to log time" do
+ let(:user) { create(:user, member_with_permissions: { project => %i[view_work_packages log_time] }) }
+
+ context "when mobile" do
+ include_context "with mobile screen size"
+
+ it "shows the timer entries" do
+ wp_view.visit!
+ find("#action-show-more-dropdown-menu .button").click
+
+ expect(page).to have_css(".menu-item", text: "Log time")
+ expect(page).to have_css(".menu-item", text: "Start timer")
+ expect(page).to have_no_css(".menu-item", text: "Stop timer")
+
+ find(".menu-item", text: "Start timer").click
+ wait_for_network_idle
+
+ retry_block do
+ find("#action-show-more-dropdown-menu .button").click
+ expect(page).to have_css(".menu-item", text: "Log time")
+ expect(page).to have_css(".menu-item", text: "Stop timer")
+ expect(page).to have_no_css(".menu-item", text: "Start timer")
+ end
+ end
+ end
+
+ context "when not mobile" do
+ it "does not show the timer entries" do
+ wp_view.visit!
+ find("#action-show-more-dropdown-menu .button").click
+
+ expect(page).to have_css(".menu-item", text: "Log time")
+ expect(page).to have_no_css(".menu-item", text: "Start timer")
+ expect(page).to have_no_css(".menu-item", text: "Stop timer")
+ end
+ end
+ end
+
+ context "when user does not have permission to log time" do
+ let(:user) { create(:user, member_with_permissions: { project => %i[view_work_packages] }) }
+
+ it "does not show the timer entries" do
+ wp_view.visit!
+ find("#action-show-more-dropdown-menu .button").click
+
+ expect(page).to have_no_css(".menu-item", text: "Log time")
+ expect(page).to have_no_css(".menu-item", text: "Start timer")
+ expect(page).to have_no_css(".menu-item", text: "Stop timer")
+ end
+ end
+end