Skip to content

Commit

Permalink
add new time entry modal to the context menu within a work package
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Dec 17, 2024
1 parent 897e866 commit 5d2ec6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import { PERMITTED_CONTEXT_MENU_ACTIONS } from 'core-app/shared/components/op-co
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { CopyToClipboardService } from 'core-app/shared/components/copy-to-clipboard/copy-to-clipboard.service';
import { WorkPackageAction } from 'core-app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { TimeEntryCreateService } from 'core-app/shared/components/time_entries/create/create.service';
import { WpDestroyModalComponent } from 'core-app/shared/components/modals/wp-destroy-modal/wp-destroy.modal';
import { WorkPackageAuthorization } from 'core-app/features/work-packages/services/work-package-authorization.service';
import * as moment from 'moment-timezone';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';

@Directive({
Expand All @@ -27,9 +24,8 @@ import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service
export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger {
@Input('wpSingleContextMenu-workPackage') public workPackage:WorkPackageResource;

@InjectField() public timeEntryCreateService:TimeEntryCreateService;

constructor(readonly HookService:HookService,
constructor(
readonly HookService:HookService,
readonly $state:StateService,
readonly injector:Injector,
readonly PathHelper:PathHelperService,
Expand Down Expand Up @@ -70,11 +66,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
this.opModalService.show(WpDestroyModalComponent, this.injector, { workPackages: [this.workPackage] });
break;
case 'log_time':
this.timeEntryCreateService
.create(moment(new Date()), this.workPackage, { showWorkPackageField: false })
.catch(() => {
// do nothing, the user closed without changes
});
void this.turboRequests.request(this.PathHelper.timeEntryWorkPackageDialog(this.workPackage.id as string), { method: 'GET' });
break;
case 'generate_pdf':
void this.turboRequests.requestStream(link as string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { splitViewRoute } from 'core-app/features/work-packages/routing/split-vi
import { WpDestroyModalComponent } from 'core-app/shared/components/modals/wp-destroy-modal/wp-destroy.modal';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import * as moment from 'moment-timezone';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';

export class WorkPackageViewContextMenu extends OpContextMenuHandler {
@InjectField() protected states!:States;
Expand All @@ -42,6 +42,8 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {

@InjectField() protected pathHelper:PathHelperService;

@InjectField() protected turboRequests:TurboRequestsService;

protected workPackage = this.states.workPackages.get(this.workPackageId).value!;

protected selectedWorkPackages = this.getSelectedWorkPackages();
Expand Down Expand Up @@ -160,11 +162,7 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {
}

private logTimeForSelectedWorkPackage() {
this.timeEntryCreateService
.create(moment(new Date()), this.workPackage)
.catch(() => {
// do nothing, the user closed without changes
});
void this.turboRequests.request(this.pathHelper.timeEntryWorkPackageDialog(this.workPackage.id as string), { method: 'GET' });
}

private getSelectedWorkPackages() {
Expand All @@ -183,7 +181,7 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {

protected buildItems():OpContextMenuItem[] {
const items = this.permittedActions.map((action:WorkPackageAction) => ({
class: undefined as string|undefined,
class: undefined as string | undefined,
disabled: false,
linkText: action.text,
href: action.href,
Expand Down
6 changes: 5 additions & 1 deletion modules/costs/app/controllers/time_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def dialog
nil
end
end
@work_package = WorkPackage.visible.find_by(id: params[:work_package_id]) if params[:work_package_id].present?

if params[:work_package_id].present?
@work_package = WorkPackage.visible.find_by(id: params[:work_package_id])
@project = @work_package.project
end

@time_entry = if params[:time_entry_id]
# TODO: Properly handle authorization
Expand Down

0 comments on commit 5d2ec6c

Please sign in to comment.