From f29950805071f4963e7f5dc777397defb9fbb64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 21 Jul 2022 05:49:46 +0200 Subject: [PATCH] Hide user field in my page spent time --- .../te-calendar/te-calendar.component.ts | 4 +- .../hal/resources/time-entry-resource.ts | 5 +- .../wp-spent-time-display-field.module.ts | 2 +- .../wp-context-menu/wp-single-context-menu.ts | 2 +- .../time_entries/create/create.service.ts | 36 ++++++++++---- .../time_entries/edit/edit.service.ts | 21 ++++++-- .../time_entries/form/form.component.html | 48 ++++++++++--------- .../time_entries/form/form.component.ts | 2 + .../time_entries/shared/modal/base.modal.html | 1 + .../time_entries/shared/modal/base.modal.ts | 33 ++++++++----- .../my/time_entries_current_user_spec.rb | 2 + .../support/components/time_logging_modal.rb | 2 + 12 files changed, 106 insertions(+), 52 deletions(-) diff --git a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts index c829109ed2..3ea6e3b823 100644 --- a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts +++ b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts @@ -372,7 +372,7 @@ export class TimeEntryCalendarComponent { private editEvent(entry:TimeEntryResource):void { this .timeEntryEdit - .edit(entry) + .edit(entry, { showUserField: false }) .then((modificationAction) => { this.updateEventSet(modificationAction.entry, modificationAction.action); }) @@ -418,7 +418,7 @@ export class TimeEntryCalendarComponent { this .timeEntryCreate - .create(date) + .create(date, undefined, { showUserField: false }) .then((modificationAction) => { this.updateEventSet(modificationAction.entry, modificationAction.action); }) diff --git a/frontend/src/app/features/hal/resources/time-entry-resource.ts b/frontend/src/app/features/hal/resources/time-entry-resource.ts index 9db075ba87..e0086d71b2 100644 --- a/frontend/src/app/features/hal/resources/time-entry-resource.ts +++ b/frontend/src/app/features/hal/resources/time-entry-resource.ts @@ -28,6 +28,7 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource'; import { ProjectResource } from 'core-app/features/hal/resources/project-resource'; +import { InputState } from 'reactivestates'; import Formattable = api.v3.Formattable; export class TimeEntryResource extends HalResource { @@ -37,8 +38,8 @@ export class TimeEntryResource extends HalResource { comment:Formattable; - public get state() { - return this.states.timeEntries.get(this.id!) as any; + public get state():InputState { + return this.states.timeEntries.get(this.id as string) as unknown as InputState; } /** diff --git a/frontend/src/app/shared/components/fields/display/field-types/wp-spent-time-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/wp-spent-time-display-field.module.ts index 971e1f529c..b7e1a16890 100644 --- a/frontend/src/app/shared/components/fields/display/field-types/wp-spent-time-display-field.module.ts +++ b/frontend/src/app/shared/components/fields/display/field-types/wp-spent-time-display-field.module.ts @@ -100,7 +100,7 @@ export class WorkPackageSpentTimeDisplayField extends EstimatedTimeDisplayField private showTimelogWidget(wp:WorkPackageResource) { this.timeEntryCreateService - .create(moment(new Date()), wp, false) + .create(moment(new Date()), wp, { showWorkPackageField: false }) .catch(() => { // do nothing, the user closed without changes }); 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 b891a608bc..c001916518 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 @@ -65,7 +65,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger break; case 'log_time': this.timeEntryCreateService - .create(moment(new Date()), this.workPackage, false) + .create(moment(new Date()), this.workPackage, { showWorkPackageField: false }) .catch(() => { // do nothing, the user closed without changes }); diff --git a/frontend/src/app/shared/components/time_entries/create/create.service.ts b/frontend/src/app/shared/components/time_entries/create/create.service.ts index e4968d1f95..26aa1774bf 100644 --- a/frontend/src/app/shared/components/time_entries/create/create.service.ts +++ b/frontend/src/app/shared/components/time_entries/create/create.service.ts @@ -1,4 +1,7 @@ -import { Injectable, Injector } from '@angular/core'; +import { + Injectable, + Injector, +} from '@angular/core'; import { OpModalService } from 'core-app/shared/components/modal/modal.service'; import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service'; import { I18nService } from 'core-app/core/i18n/i18n.service'; @@ -12,6 +15,8 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packag import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service'; import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource'; +import { TimeEntryModalOptions } from 'core-app/shared/components/time_entries/edit/edit.service'; +import { HalResource } from 'core-app/features/hal/resources/hal-resource'; @Injectable() export class TimeEntryCreateService { @@ -24,12 +29,20 @@ export class TimeEntryCreateService { readonly i18n:I18nService) { } - public create(date:Moment, wp?:WorkPackageResource, showWorkPackageField = true) { + public create( + date:Moment, + wp?:WorkPackageResource, + options:TimeEntryModalOptions = {}, + ):Promise<{ entry:TimeEntryResource, action:'create' }> { return new Promise<{ entry:TimeEntryResource, action:'create' }>((resolve, reject) => { - this + void this .createNewTimeEntry(date, wp) .then((changeset) => { - const modal = this.opModalService.show(TimeEntryCreateModalComponent, this.injector, { changeset, showWorkPackageField }); + const modal = this.opModalService.show( + TimeEntryCreateModalComponent, + this.injector, + { ...options, changeset }, + ); modal .closingEvent @@ -45,12 +58,13 @@ export class TimeEntryCreateService { }); } - public createNewTimeEntry(date:Moment, wp?:WorkPackageResource) { + public createNewTimeEntry(date:Moment, wp?:WorkPackageResource):Promise { const payload:any = { spentOn: date.format('YYYY-MM-DD'), }; if (wp) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access payload._links = { workPackage: { href: wp.href, @@ -73,9 +87,13 @@ export class TimeEntryCreateService { return this.halEditing.edit>(entry, form); } - private initializeNewResource(form:FormResource) { - const entry = this.halResource.createHalResourceOfType('TimeEntry', form.payload.$plain()); + private initializeNewResource(form:FormResource):TimeEntryResource { + const entry = this.halResource.createHalResourceOfType( + 'TimeEntry', + (form.payload as HalResource).$plain(), + ); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access entry.$links.schema = { href: 'new' }; entry._type = 'TimeEntry'; @@ -83,9 +101,11 @@ export class TimeEntryCreateService { entry.hours = 'PT1H'; // Set update link to form + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,no-multi-assign entry.update = entry.$links.update = form.$links.self; // Use POST /work_packages for saving link - entry.updateImmediately = entry.$links.updateImmediately = (payload:{}) => this + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,no-multi-assign + entry.updateImmediately = entry.$links.updateImmediately = (payload:Record) => this .apiV3Service .time_entries .post(payload) diff --git a/frontend/src/app/shared/components/time_entries/edit/edit.service.ts b/frontend/src/app/shared/components/time_entries/edit/edit.service.ts index 50b9b19aa3..90b7f8c0f6 100644 --- a/frontend/src/app/shared/components/time_entries/edit/edit.service.ts +++ b/frontend/src/app/shared/components/time_entries/edit/edit.service.ts @@ -9,6 +9,11 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource'; import { TimeEntryEditModalComponent } from './edit.modal'; +export interface TimeEntryModalOptions { + showWorkPackageField?:boolean; + showUserField?:boolean; +} + @Injectable() export class TimeEntryEditService { constructor(readonly opModalService:OpModalService, @@ -19,18 +24,26 @@ export class TimeEntryEditService { readonly i18n:I18nService) { } - public edit(entry:TimeEntryResource) { + public edit( + entry:TimeEntryResource, + options:TimeEntryModalOptions = {}, + ):Promise<{ entry:TimeEntryResource, action:'update'|'destroy' }> { return new Promise<{ entry:TimeEntryResource, action:'update'|'destroy' }>((resolve, reject) => { - this + void this .createChangeset(entry) .then((changeset) => { - const modal = this.opModalService.show(TimeEntryEditModalComponent, this.injector, { changeset }); + const modal = this.opModalService.show( + TimeEntryEditModalComponent, + this.injector, + { ...options, changeset }, + ); modal .closingEvent .pipe(take(1)) .subscribe(() => { if (modal.destroyedEntry) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access modal.destroyedEntry.delete().then(() => { resolve({ entry: modal.destroyedEntry, action: 'destroy' }); }); @@ -44,7 +57,7 @@ export class TimeEntryEditService { }); } - public createChangeset(entry:TimeEntryResource) { + public createChangeset(entry:TimeEntryResource):Promise> { return this .apiV3Service .time_entries diff --git a/frontend/src/app/shared/components/time_entries/form/form.component.html b/frontend/src/app/shared/components/time_entries/form/form.component.html index bed034f1ad..44c240da24 100644 --- a/frontend/src/app/shared/components/time_entries/form/form.component.html +++ b/frontend/src/app/shared/components/time_entries/form/form.component.html @@ -4,20 +4,22 @@ [inEditMode]="inEditMode" (onSaved)="signalModifiedEntry($event)">
-
-
-
- - -
+ +
+
+
+ + +
+
+ [ngClass]="{'-required': isRequired('spentOn')}" + [textContent]="schema.spentOn.name">
-
-
-
- - -
+ +
+
+
+ + +
+
(); @ViewChild('editForm', { static: true }) editForm:EditFormComponent; diff --git a/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.html b/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.html index 215fbb5f71..9fc662f48e 100644 --- a/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.html +++ b/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.html @@ -12,6 +12,7 @@
diff --git a/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.ts b/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.ts index 95b185530d..a6ab11e4bf 100644 --- a/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.ts +++ b/frontend/src/app/shared/components/time_entries/shared/modal/base.modal.ts @@ -1,5 +1,10 @@ import { - ChangeDetectorRef, Directive, ElementRef, Inject, Injector, ViewChild, + ChangeDetectorRef, + Directive, + ElementRef, + Inject, + Injector, + ViewChild, } from '@angular/core'; import { OpModalComponent } from 'core-app/shared/components/modal/modal.component'; import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service'; @@ -9,6 +14,8 @@ import { TimeEntryFormComponent } from 'core-app/shared/components/time_entries/ import { HalResource } from 'core-app/features/hal/resources/hal-resource'; import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator'; import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; +import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource'; +import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset'; @Directive() export abstract class TimeEntryBaseModal extends OpModalComponent { @@ -40,19 +47,23 @@ export abstract class TimeEntryBaseModal extends OpModalComponent { public abstract setModifiedEntry($event:{ savedResource:HalResource, isInital:boolean }):void; - public get changeset() { + public get changeset():ResourceChangeset { return this.locals.changeset; } - public get entry() { + public get entry():TimeEntryResource { return this.changeset.projectedResource; } - public get showWorkPackageField() { - return this.locals.showWorkPackageField !== undefined ? this.locals.showWorkPackageField : true; + public get showWorkPackageField():boolean { + return this.locals.showWorkPackageField !== false; } - public saveEntry() { + public get showUserField():boolean { + return this.locals.showUserField !== false; + } + + public saveEntry():void { this.formInFlight = true; this.editForm.save() @@ -63,22 +74,22 @@ export abstract class TimeEntryBaseModal extends OpModalComponent { }); } - public get saveText() { + public get saveText():string { return this.i18n.t('js.button_save'); } - public get saveAllowed() { + public get saveAllowed():boolean { return true; } - public get deleteAllowed() { + public get deleteAllowed():boolean { return true; } - protected reloadWorkPackageAndClose() { + protected reloadWorkPackageAndClose():void { // reload workPackage if (this.entry.workPackage) { - this + void this .apiV3Service .work_packages .id(this.entry.workPackage) 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 641a156b04..1e47bcc8ec 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 @@ -184,6 +184,8 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr time_logging_modal.has_field_with_value 'spentOn', (Date.today.beginning_of_week(:sunday) + 3.days).strftime + time_logging_modal.shows_field 'user', false + expect(page) .not_to have_selector('.ng-spinner-loader') diff --git a/spec/features/support/components/time_logging_modal.rb b/spec/features/support/components/time_logging_modal.rb index ec947ea578..7dad205555 100644 --- a/spec/features/support/components/time_logging_modal.rb +++ b/spec/features/support/components/time_logging_modal.rb @@ -114,6 +114,8 @@ module Components 'wp-new-inline-edit--field-spentOn' when 'work_package' 'wp-new-inline-edit--field-workPackage' + when 'user' + 'wp-new-inline-edit--field-user' end end