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

edit time entry via modal

ulferts799fa8298391
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 147fc1bcf56..1a8b006525f 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -508,7 +508,9 @@ en:
activity: 'Activity'
comment: 'Comment'
duration: 'Duration'
+ spent_on: 'Date'
hours: 'Hours'
+ edit: 'Edit time entry'
two_factor_authentication:
label_two_factor_authentication: 'Two-factor authentication'
diff --git a/frontend/src/app/angular4-modules.ts b/frontend/src/app/angular4-modules.ts
index bf63cebaebf..593ee7e2f8c 100644
--- a/frontend/src/app/angular4-modules.ts
+++ b/frontend/src/app/angular4-modules.ts
@@ -94,6 +94,7 @@ import {OpenprojectOverviewModule} from "core-app/modules/overview/openproject-o
import {OpenprojectMyPageModule} from "core-app/modules/my-page/openproject-my-page.module";
import {OpenprojectProjectsModule} from "core-app/modules/projects/openproject-projects.module";
import {OpenprojectIFCModelsModule} from "core-app/modules/ifc_models/openproject-ifc-models.module";
+import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cache.service";
@NgModule({
imports: [
@@ -164,6 +165,7 @@ import {OpenprojectIFCModelsModule} from "core-app/modules/ifc_models/openprojec
OpTitleService,
UrlParamsHelperService,
ProjectCacheService,
+ TimeEntryCacheService,
FormsCacheService,
UserCacheService,
StatusCacheService,
diff --git a/frontend/src/app/components/states.service.ts b/frontend/src/app/components/states.service.ts
index 2d745e37682..9f6aeaa5043 100644
--- a/frontend/src/app/components/states.service.ts
+++ b/frontend/src/app/components/states.service.ts
@@ -14,6 +14,7 @@ import {QuerySortByResource} from "core-app/modules/hal/resources/query-sort-by-
import {QueryGroupByResource} from "core-app/modules/hal/resources/query-group-by-resource";
import {VersionResource} from "core-app/modules/hal/resources/version-resource";
import {wpDisplayRepresentation} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-display-representation.service";
+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
export class States extends StatesGroup {
name = 'MainStore';
@@ -36,6 +37,9 @@ export class States extends StatesGroup {
/* /api/v3/statuses */
statuses = multiInput<StatusResource>();
+ /* /api/v3/projects */
+ timeEntries:MultiInputState<TimeEntryResource> = multiInput<TimeEntryResource>();
+
/* /api/v3/versions */
versions = multiInput<VersionResource>();
diff --git a/frontend/src/app/components/time-entries/time-entry-cache.service.ts b/frontend/src/app/components/time-entries/time-entry-cache.service.ts
new file mode 100644
index 00000000000..adf75dc7d6d
--- /dev/null
+++ b/frontend/src/app/components/time-entries/time-entry-cache.service.ts
@@ -0,0 +1,71 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {MultiInputState} from 'reactivestates';
+import {States} from '../states.service';
+import {StateCacheService} from '../states/state-cache.service';
+import {Injectable} from '@angular/core';
+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";
+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
+import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";
+
+@Injectable()
+export class TimeEntryCacheService extends StateCacheService<TimeEntryResource> {
+
+ constructor(readonly states:States,
+ readonly schemaCacheService:SchemaCacheService,
+ readonly timeEntryDm:TimeEntryDmService) {
+ super();
+ }
+
+ protected loadAll(ids:string[]):Promise<undefined> {
+ return Promise
+ .all(ids.map(id => this.load(id)))
+ .then(_ => undefined);
+ }
+
+ updateValue(id:string, val:TimeEntryResource) {
+ this.schemaCacheService.ensureLoaded(val).then(() => {
+ super.updateValue(id, val);
+ });
+ }
+
+ protected load(id:string):Promise<TimeEntryResource> {
+ return this
+ .timeEntryDm
+ .one(parseInt(id))
+ .then((timeEntry) => {
+ return this.schemaCacheService.ensureLoaded(timeEntry).then(() => timeEntry);
+ });
+ }
+
+ protected get multiState():MultiInputState<TimeEntryResource> {
+ return this.states.timeEntries;
+ }
+
+}
diff --git a/frontend/src/app/modules/calendar/openproject-calendar.module.ts b/frontend/src/app/modules/calendar/openproject-calendar.module.ts
index e909ff09107..a8a3d3f0a59 100644
--- a/frontend/src/app/modules/calendar/openproject-calendar.module.ts
+++ b/frontend/src/app/modules/calendar/openproject-calendar.module.ts
@@ -34,6 +34,9 @@ import {WorkPackagesCalendarController} from "core-app/modules/calendar/wp-calen
import {OpenprojectWorkPackagesModule} from "core-app/modules/work_packages/openproject-work-packages.module";
import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular";
import {TimeEntryCalendarComponent} from "core-app/modules/calendar/te-calendar/te-calendar.component";
+import {TimeEntryEditModal} from "core-app/modules/calendar/te-calendar/edit/edit.modal";
+import {TimeEntryEditService} from "core-app/modules/calendar/te-calendar/edit/edit.service";
+import {OpenprojectFieldsModule} from "core-app/modules/fields/openproject-fields.module";
const menuItemClass = 'calendar-menu-item';
@@ -62,19 +65,27 @@ export const CALENDAR_ROUTES:Ng2StateDeclaration[] = [
// Work Package module
OpenprojectWorkPackagesModule,
+ // Editable fields e.g. for modals
+ OpenprojectFieldsModule,
+
// Calendar component
FullCalendarModule,
],
+ providers: [
+ TimeEntryEditService,
+ ],
declarations: [
// Work package calendars
WorkPackagesCalendarEntryComponent,
WorkPackagesCalendarController,
- TimeEntryCalendarComponent
+ TimeEntryCalendarComponent,
+ TimeEntryEditModal,
],
entryComponents: [
WorkPackagesCalendarController,
WorkPackagesCalendarEntryComponent,
TimeEntryCalendarComponent,
+ TimeEntryEditModal,
],
exports: [
WorkPackagesCalendarController,
diff --git a/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.html b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.html
new file mode 100644
index 00000000000..c2cce63a3e1
--- /dev/null
+++ b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.html
@@ -0,0 +1,87 @@
+<div class="op-modal--portal ngdialog-theme-openproject">
+ <div class="op-modal--modal-container confirm-dialog--modal loading-indicator--location"
+ data-indicator-name="modal"
+ tabindex="0">
+ <div class="op-modal--modal-header">
+ <a class="op-modal--modal-close-button">
+ <i
+ class="icon-close"
+ (click)="closeMe($event)"
+ [attr.title]="text.close">
+ </i>
+ </a>
+ <h3 class="icon-context icon-attention" [textContent]="text.title"></h3>
+ </div>
+
+ <div class="ngdialog-body op-modal--modal-body">
+ <edit-form
+ [resource]="entry"
+ (onSaved)="setModifiedEntry($event)">
+ <div class="attributes-map">
+
+ <div class="attributes-map--key" [textContent]="text.attributes.spentOn"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'spentOn'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.hours"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'hours'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.workPackage"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'workPackage'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.activity"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'activity'">
+ </editable-attribute-field>
+ </div>
+
+ <div class="attributes-map--key" [textContent]="text.attributes.comment"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="'comment'">
+ </editable-attribute-field>
+ </div>
+
+ <ng-container *ngFor="let cf of customFields">
+ <div class="attributes-map--key" [textContent]="cf.label"></div>
+ <div class="attributes-map--value">
+ <editable-attribute-field [resource]="entry"
+ [fieldName]="cf.key">
+ </editable-attribute-field>
+ </div>
+ </ng-container>
+ </div>
+ </edit-form>
+ </div>
+
+ <div class="op-modal--modal-footer">
+ <button class="button -highlight"
+ (click)="closeMe($event)"
+ [textContent]="text.close"
+ [attr.title]="text.close">
+ </button>
+
+ <button class="button"
+ *ngIf="deleteAllowed"
+ (click)="destroy()"
+ [attr.title]="text.delete">
+ <op-icon icon-classes="button--icon icon-delete"></op-icon>
+ <span class="button--text"
+ [textContent]="text.delete"
+ aria-hidden="true"></span>
+ </button>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.sass b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.sass
new file mode 100644
index 00000000000..1a821013f3c
--- /dev/null
+++ b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.sass
@@ -0,0 +1,9 @@
+.op-modal--modal-container
+ min-width: 800px
+ max-width: 800px
+
+.op-modal--modal-footer
+ margin-top: 2em
+
+ .button
+ margin-bottom: 0
\ No newline at end of file
diff --git a/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.ts b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.ts
new file mode 100644
index 00000000000..725d0af455a
--- /dev/null
+++ b/frontend/src/app/modules/calendar/te-calendar/edit/edit.modal.ts
@@ -0,0 +1,76 @@
+import {Component, ElementRef, Inject, ChangeDetectorRef} from "@angular/core";
+import {OpModalComponent} from "app/components/op-modals/op-modal.component";
+import {OpModalLocalsToken} from "app/components/op-modals/op-modal.service";
+import {OpModalLocalsMap} from "app/components/op-modals/op-modal.types";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";
+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
+import {HalResource} from "core-app/modules/hal/resources/hal-resource";
+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
+
+@Component({
+ templateUrl: './edit.modal.html',
+ styleUrls: ['./edit.modal.sass'],
+ providers: [
+ HalResourceEditingService
+ ]
+})
+export class TimeEntryEditModal extends OpModalComponent {
+
+ text = {
+ title: this.i18n.t('js.time_entry.edit'),
+ attributes: {
+ comment: this.i18n.t('js.time_entry.comment'),
+ hours: this.i18n.t('js.time_entry.hours'),
+ activity: this.i18n.t('js.time_entry.activity'),
+ workPackage: this.i18n.t('js.time_entry.work_package'),
+ spentOn: this.i18n.t('js.time_entry.spent_on'),
+ },
+ close: this.i18n.t('js.button_close'),
+ delete: this.i18n.t('js.button_delete')
+ };
+
+ public closeOnEscape = false;
+ public closeOnOutsideClick = false;
+ public customFields:{key:string, label:string}[] = [];
+
+ public modifiedEntry:TimeEntryResource;
+ public destroyedEntry:TimeEntryResource;
+
+ constructor(readonly elementRef:ElementRef,
+ @Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,
+ readonly cdRef:ChangeDetectorRef,
+ readonly i18n:I18nService) {
+ super(locals, cdRef, elementRef);
+ }
+
+ public get entry() {
+ return this.locals.entry;
+ }
+
+ public setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}) {
+ this.modifiedEntry = $event.savedResource as TimeEntryResource;
+ }
+
+ public get deleteAllowed() {
+ return !!this.entry.delete;
+ }
+
+ public destroy() {
+ this.destroyedEntry = this.entry;
+ this.service.close();
+ }
+
+ ngOnInit() {
+ super.ngOnInit();
+ this.setCustomFields(this.entry.schema);
+ }
+
+ private setCustomFields(schema:SchemaResource) {
+ Object.entries(schema).forEach(([key, keySchema]) => {
+ if (key.match(/customField\d+/)) {
+ this.customFields.push({key: key, label: keySchema.name });
+ }
+ });
+ }
+}
diff --git a/frontend/src/app/modules/calendar/te-calendar/edit/edit.service.ts b/frontend/src/app/modules/calendar/te-calendar/edit/edit.service.ts
new file mode 100644
index 00000000000..8d6fc8bc02d
--- /dev/null
+++ b/frontend/src/app/modules/calendar/te-calendar/edit/edit.service.ts
@@ -0,0 +1,38 @@
+import {Injectable, Injector} from "@angular/core";
+import {OpModalService} from "app/components/op-modals/op-modal.service";
+import {HalResourceService} from "app/modules/hal/services/hal-resource.service";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import { TimeEntryResource } from 'core-app/modules/hal/resources/time-entry-resource';
+import { TimeEntryEditModal } from './edit.modal';
+import { take } from 'rxjs/operators';
+
+@Injectable()
+export class TimeEntryEditService {
+
+ constructor(readonly opModalService:OpModalService,
+ readonly injector:Injector,
+ readonly halResource:HalResourceService,
+ readonly i18n:I18nService) {
+ }
+
+ public edit(entry:TimeEntryResource) {
+ return new Promise<{entry:TimeEntryResource, action:'update'|'destroy'}>((resolve, reject) => {
+ const modal = this.opModalService.show(TimeEntryEditModal, this.injector, { entry: entry });
+
+ modal
+ .closingEvent
+ .pipe(take(1))
+ .subscribe(() => {
+ if (modal.destroyedEntry) {
+ modal.destroyedEntry.delete().then(() => {
+ resolve({entry: modal.destroyedEntry, action: 'destroy'});
+ });
+ } else if (modal.modifiedEntry) {
+ resolve({ entry: modal.modifiedEntry, action: 'update' });
+ } else {
+ reject();
+ }
+ });
+ });
+ }
+}
diff --git a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
index c00950159f9..acb3a796558 100644
--- a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
+++ b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts
@@ -1,4 +1,4 @@
-import {Component, ElementRef, Input, OnDestroy, OnInit, SecurityContext, ViewChild, AfterViewInit, Output, EventEmitter} from "@angular/core";
+import {Component, ElementRef, Input, OnDestroy, OnInit, SecurityContext, ViewChild, AfterViewInit, Output, EventEmitter, Injector} from "@angular/core";
import {FullCalendarComponent} from '@fullcalendar/angular';
import {States} from "core-components/states.service";
import * as moment from "moment";
@@ -17,6 +17,8 @@ import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";
import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
import {TimezoneService} from "core-components/datetime/timezone.service";
import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";
+import { TimeEntryEditService } from './edit/edit.service';
+import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cache.service";
interface CalendarViewEvent {
el:HTMLElement;
@@ -47,16 +49,22 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
public calendarAllDaySlot = false;
public calendarDisplayEventTime = false;
public calendarSlotEventOverlap = false;
+ public calendarEditable = false;
+
+ protected memoizedTimeEntries:{start:Date, end:Date, entries:Promise<CollectionResource<TimeEntryResource>>};
constructor(readonly states:States,
readonly timeEntryDm:TimeEntryDmService,
readonly $state:StateService,
private element:ElementRef,
readonly i18n:I18nService,
+ readonly injector:Injector,
readonly notificationsService:NotificationsService,
private sanitizer:DomSanitizer,
private configuration:ConfigurationService,
- private timezone:TimezoneService) { }
+ private timezone:TimezoneService,
+ private timeEntryEdit:TimeEntryEditService,
+ private timeEntryCache:TimeEntryCacheService) { }
ngOnInit() {
this.initializeCalendar();
@@ -71,20 +79,41 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
// see: https://github.com/fullcalendar/fullcalendar-angular/issues/228#issuecomment-523505044
// Therefore, setting the outputs via the underlying API
this.ucCalendar.getApi().setOption('eventRender', (event:CalendarViewEvent) => { this.addTooltip(event); });
+ this.ucCalendar.getApi().setOption('eventClick', (event:CalendarViewEvent) => { this.editEvent(event); });
}
- public calendarEventsFunction(fetchInfo:{ start:Date, end:Date, timeZone:string },
+ public calendarEventsFunction(fetchInfo:{ start:Date, end:Date },
successCallback:(events:EventInput[]) => void,
failureCallback:(error:EventSourceError) => void ):void | PromiseLike<EventInput[]> {
- this.timeEntryDm.list({ filters: this.dmFilters(fetchInfo) })
+ this.fetchTimeEntries(fetchInfo.start, fetchInfo.end)
.then((collection) => {
this.entries.emit(collection);
+
successCallback(this.buildEntries(collection.elements));
});
}
- private buildEntries(entries:TimeEntryResource[]) {
+ protected fetchTimeEntries(start:Date, end:Date) {
+ if (!this.memoizedTimeEntries ||
+ this.memoizedTimeEntries.start.getTime() !== start.getTime() ||
+ this.memoizedTimeEntries.end.getTime() !== end.getTime()) {
+ let promise = this
+ .timeEntryDm
+ .list({ filters: this.dmFilters(start, end) })
+ .then(collection => {
+ collection.elements.forEach(timeEntry => this.timeEntryCache.updateValue(timeEntry.id!, timeEntry));
+
+ return collection;
+ });
+
+ this.memoizedTimeEntries = { start: start, end: end, entries: promise };
+ }
+
+ return this.memoizedTimeEntries.entries;
+ }
+
+private buildEntries(entries:TimeEntryResource[]) {
let calendarEntries = [];
let hoursDistribution:{ [key:string]:Moment } = {};
@@ -113,9 +142,9 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
});
}
- protected dmFilters(fetchInfo:{ start:Date, end:Date, timeZone:string }):Array<[string, FilterOperator, string[]]> {
- let startDate = moment(fetchInfo.start).format('YYYY-MM-DD');
- let endDate = moment(fetchInfo.end).subtract(1, 'd').format('YYYY-MM-DD');
+ protected dmFilters(start:Date, end:Date):Array<[string, FilterOperator, string[]]> {
+ let startDate = moment(start).format('YYYY-MM-DD');
+ let endDate = moment(end).subtract(1, 'd').format('YYYY-MM-DD');
return [['spentOn', '<>d', [startDate, endDate]] as [string, FilterOperator, string[]],
['user_id', '=', ['me']] as [string, FilterOperator, [string]]];
}
@@ -124,10 +153,6 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
this.calendarEvents = this.calendarEventsFunction.bind(this);
}
- public get calendarEditable() {
- return false;
- }
-
public get calendarEventLimit() {
return false;
}
@@ -152,6 +177,33 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
return jQuery(this.element.nativeElement).find('.fc-view-container');
}
+ private editEvent(event:CalendarViewEvent) {
+ let originalEntry = event.event.extendedProps.entry;
+
+ this
+ .timeEntryEdit
+ .edit(originalEntry)
+ .then(modificationAction => {
+ this.memoizedTimeEntries.entries.then(collection => {
+ let foundIndex = collection.elements.findIndex(x => x.id === originalEntry.id);
+
+ switch (modificationAction.action) {
+ case 'update':
+ collection.elements[foundIndex] = modificationAction.entry;
+ break;
+ case 'destroy':
+ collection.elements.splice(foundIndex, 1);
+ break;
+ }
+
+ this.ucCalendar.getApi().refetchEvents();
+ });
+ })
+ .catch(() => {
+ // do nothing, the user closed without changes
+ });
+ }
+
private addTooltip(event:CalendarViewEvent) {
jQuery(event.el).tooltip({
content: this.tooltipContentString(event.event.extendedProps.entry),
@@ -195,7 +247,7 @@ export class TimeEntryCalendarComponent implements OnInit, OnDestroy, AfterViewI
</li>
<li class="tooltip--map--item">
<span class="tooltip--map--key">${this.i18n.t('js.time_entry.comment')}:</span>
- <span class="tooltip--map--value">${entry.comment.html || this.i18n.t('js.placeholders.default')}</span>
+ <span class="tooltip--map--value">${entry.comment.raw || this.i18n.t('js.placeholders.default')}</span>
</li>
`;
}
diff --git a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html
index 5e1602f25e4..e62f2e18c77 100644
--- a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html
+++ b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.html
@@ -7,6 +7,7 @@
[required]="required"
[clearable]="!required"
[disabled]="disabled"
+ [typeahead]="typeahead"
[clearOnBackspace]="false"
[appendTo]="appendTo"
[id]="id"
@@ -18,4 +19,7 @@
<ng-template ng-tag-tmp let-search="searchTerm">
<b [textContent]="text.add_new_action"></b>: {{search}}
</ng-template>
+ <ng-template ng-option-tmp let-item="item" let-search="searchTerm">
+ <div [ngOptionHighlight]="search" class="ng-option-label ellipsis">{{ item.name }}</div>
+ </ng-template>
</ng-select>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.ts b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.ts
index b5e06d59e74..18f309c9128 100644
--- a/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.ts
+++ b/frontend/src/app/modules/common/autocomplete/create-autocompleter.component.ts
@@ -27,6 +27,11 @@
// ++
import {AfterViewInit, ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
+
+export interface CreateAutocompleterValueOption {
+ name:string;
+ $href:string|null;
+}
import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper";
import {NgSelectComponent} from "@ng-select/ng-select";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
@@ -34,13 +39,14 @@ import {CurrentProjectService} from "core-components/projects/current-project.se
import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {AddTagFn} from "@ng-select/ng-select/lib/ng-select.component";
+import { Subject } from 'rxjs';
@Component({
templateUrl: './create-autocompleter.component.html',
selector: 'create-autocompleter'
})
export class CreateAutocompleterComponent implements AfterViewInit {
- @Input() public availableValues:any[];
+ @Input() public availableValues:CreateAutocompleterValueOption[];
@Input() public appendTo:string;
@Input() public model:any;
@Input() public required:boolean = false;
@@ -48,6 +54,7 @@ export class CreateAutocompleterComponent implements AfterViewInit {
@Input() public finishedLoading:boolean = false;
@Input() public id:string = '';
@Input() public classes:string = '';
+ @Input() public typeahead?:Subject<string>;
@Output() public onChange = new EventEmitter<HalResource>();
@Output() public onKeydown = new EventEmitter<JQuery.TriggeredEvent>();
diff --git a/frontend/src/app/modules/common/autocomplete/wp-autocompleter.component.ts b/frontend/src/app/modules/common/autocomplete/wp-autocompleter.component.ts
new file mode 100644
index 00000000000..fd146c7f50e
--- /dev/null
+++ b/frontend/src/app/modules/common/autocomplete/wp-autocompleter.component.ts
@@ -0,0 +1,54 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {
+ AfterViewInit,
+ ChangeDetectorRef,
+ Component,
+ EventEmitter,
+ Input,
+ OnInit,
+ Output,
+ ViewChild
+} from '@angular/core';
+import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper";
+import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";
+import {CurrentProjectService} from "core-components/projects/current-project.service";
+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
+import {VersionResource} from "core-app/modules/hal/resources/version-resource";
+import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";
+import { Subject } from 'rxjs';
+
+@Component({
+ templateUrl: './create-autocompleter.component.html',
+ selector: 'wp-autocompleter'
+})
+export class WorkPackageAutocompleterComponent extends CreateAutocompleterComponent implements AfterViewInit {
+}
diff --git a/frontend/src/app/modules/common/openproject-common.module.ts b/frontend/src/app/modules/common/openproject-common.module.ts
index 17f402abec8..34d2f1559b3 100644
--- a/frontend/src/app/modules/common/openproject-common.module.ts
+++ b/frontend/src/app/modules/common/openproject-common.module.ts
@@ -97,6 +97,7 @@ import {NgSelectModule} from "@ng-select/ng-select";
import {NgOptionHighlightModule} from "@ng-select/ng-option-highlight";
import {CurrentProjectService} from "core-components/projects/current-project.service";
import {CurrentUserService} from "core-components/user/current-user.service";
+import {WorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/wp-autocompleter.component";
export function bootstrapModule(injector:Injector) {
return () => {
@@ -142,7 +143,9 @@ export function bootstrapModule(injector:Injector) {
NgSelectModule,
NgOptionHighlightModule,
- DynamicModule.withComponents([VersionAutocompleterComponent,
+ DynamicModule.withComponents([
+ VersionAutocompleterComponent,
+ WorkPackageAutocompleterComponent,
CreateAutocompleterComponent]),
],
exports: [
@@ -205,6 +208,8 @@ export function bootstrapModule(injector:Injector) {
EnterpriseBannerComponent,
DynamicModule,
+
+ WorkPackageAutocompleterComponent,
],
declarations: [
OpDatePickerComponent,
@@ -274,6 +279,7 @@ export function bootstrapModule(injector:Injector) {
// Autocompleter
CreateAutocompleterComponent,
VersionAutocompleterComponent,
+ WorkPackageAutocompleterComponent,
HomescreenNewFeaturesBlockComponent,
BoardVideoTeaserModalComponent
diff --git a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts
index 3c85d859bb0..c7e9dc5800d 100644
--- a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts
+++ b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts
@@ -27,16 +27,21 @@
// ++
import {
+ SimpleResource,
SimpleResourceCollection
} from 'core-app/modules/common/path-helper/apiv3/path-resources';
-import {Apiv3NewsPaths} from "core-app/modules/common/path-helper/apiv3/news/apiv3-news-paths";
+import {Apiv3TimeEntryPaths} from "core-app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths";
export class Apiv3TimeEntriesPaths extends SimpleResourceCollection {
constructor(basePath:string) {
super(basePath, 'time_entries');
}
- public id(gridId:string|number) {
- return new Apiv3NewsPaths(this.path, gridId);
+ public id(timeEntryId:string|number) {
+ return new Apiv3TimeEntryPaths(this.path, timeEntryId);
+ }
+
+ public form() {
+ return new SimpleResource(this.path, 'form');
}
}
diff --git a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts
index 2044f4c5e4a..b1b0104dc35 100644
--- a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts
+++ b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts
@@ -34,4 +34,7 @@ export class Apiv3TimeEntryPaths extends SimpleResource {
constructor(basePath:string, newsId:string|number) {
super(basePath, newsId);
}
+
+ // Static paths
+ readonly form = new SimpleResource(this.path, 'form');
}
diff --git a/frontend/src/app/modules/fields/display/display-field.initializer.ts b/frontend/src/app/modules/fields/display/display-field.initializer.ts
index b5ce765d299..150d981d32d 100644
--- a/frontend/src/app/modules/fields/display/display-field.initializer.ts
+++ b/frontend/src/app/modules/fields/display/display-field.initializer.ts
@@ -47,6 +47,8 @@ import {UserDisplayField} from "core-app/modules/fields/display/field-types/user
import {MultipleUserFieldModule} from "core-app/modules/fields/display/field-types/multiple-user-display-field.module";
import {WorkPackageIdDisplayField} from "core-app/modules/fields/display/field-types/wp-id-display-field.module";
import {ProjectStatusDisplayField} from "core-app/modules/fields/display/field-types/project-status-display-field.module";
+import {PlainFormattableDisplayField} from "core-app/modules/fields/display/field-types/plain-formattable-display-field.module";
+import {LinkedWorkPackageDisplayField} from "core-app/modules/fields/display/field-types/linked-work-package-display-field.module";
export function initializeCoreDisplayFields(displayFieldService:DisplayFieldService) {
return () => {
@@ -62,6 +64,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ
.addFieldType(TypeDisplayField, 'type', ['Type'])
.addFieldType(ResourceDisplayField, 'resource', [
'Project',
+ 'TimeEntriesActivity',
'Version',
'Category',
'CustomOption'])
@@ -73,13 +76,15 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ
.addFieldType(DateTimeDisplayField, 'datetime', ['DateTime'])
.addFieldType(BooleanDisplayField, 'boolean', ['Boolean'])
.addFieldType(ProgressDisplayField, 'progress', ['percentageDone'])
- .addFieldType(WorkPackageDisplayField, 'work_package', ['WorkPackage'])
+ .addFieldType(LinkedWorkPackageDisplayField, 'work_package', ['WorkPackage'])
.addFieldType(IdDisplayField, 'id', ['id'])
.addFieldType(ProjectStatusDisplayField, 'project_status', ['ProjectStatus'])
.addFieldType(UserDisplayField, 'user', ['User']);
displayFieldService
.addSpecificFieldType('WorkPackage', WorkPackageIdDisplayField, 'id', ['id'])
- .addSpecificFieldType('WorkPackage', WorkPackageSpentTimeDisplayField, 'spentTime', ['spentTime']);
+ .addSpecificFieldType('WorkPackage', WorkPackageSpentTimeDisplayField, 'spentTime', ['spentTime'])
+ .addSpecificFieldType('TimeEntry', PlainFormattableDisplayField, 'comment', ['comment'])
+ .addSpecificFieldType('TimeEntry', WorkPackageDisplayField, 'work_package', ['workPackage']);
};
}
diff --git a/frontend/src/app/modules/fields/display/field-types/linked-work-package-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/linked-work-package-display-field.module.ts
new file mode 100644
index 00000000000..625887bbd38
--- /dev/null
+++ b/frontend/src/app/modules/fields/display/field-types/linked-work-package-display-field.module.ts
@@ -0,0 +1,69 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {StateService} from '@uirouter/core';
+import {KeepTabService} from 'core-components/wp-single-view-tabs/keep-tab/keep-tab.service';
+import {UiStateLinkBuilder} from "core-components/wp-fast-table/builders/ui-state-link-builder";
+import {WorkPackageDisplayField} from "core-app/modules/fields/display/field-types/work-package-display-field.module";
+
+export class LinkedWorkPackageDisplayField extends WorkPackageDisplayField {
+
+ public text = {
+ linkTitle: this.I18n.t('js.work_packages.message_successful_show_in_fullscreen'),
+ none: this.I18n.t('js.filter.noneElement')
+ };
+
+ private $state:StateService = this.$injector.get(StateService);
+ private keepTab:KeepTabService = this.$injector.get(KeepTabService);
+
+ private uiStateBuilder:UiStateLinkBuilder = new UiStateLinkBuilder(this.$state, this.keepTab);
+
+ public render(element:HTMLElement, displayText:string):void {
+ if (this.isEmpty()) {
+ element.innerText = this.placeholder;
+ return;
+ }
+
+ let link = this.uiStateBuilder.linkToShow(
+ this.wpId,
+ this.text.linkTitle,
+ this.valueString
+ );
+
+ element.innerHTML = '';
+ element.appendChild(link);
+ }
+
+ public get writable():boolean {
+ return false;
+ }
+
+ public get valueString() {
+ return '#' + this.wpId;
+ }
+}
diff --git a/frontend/src/app/modules/fields/display/field-types/plain-formattable-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/plain-formattable-display-field.module.ts
new file mode 100644
index 00000000000..8684745b4ee
--- /dev/null
+++ b/frontend/src/app/modules/fields/display/field-types/plain-formattable-display-field.module.ts
@@ -0,0 +1,40 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {DisplayField} from "core-app/modules/fields/display/display-field.module";
+
+export class PlainFormattableDisplayField extends DisplayField {
+ public get value() {
+ if (!this.schema) {
+ return null;
+ }
+ const element = this.resource[this.name];
+
+ return element && element.raw || '';
+ }
+}
diff --git a/frontend/src/app/modules/fields/display/field-types/work-package-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/work-package-display-field.module.ts
index 252cb9cf5c0..e1e4caf8caa 100644
--- a/frontend/src/app/modules/fields/display/field-types/work-package-display-field.module.ts
+++ b/frontend/src/app/modules/fields/display/field-types/work-package-display-field.module.ts
@@ -27,38 +27,13 @@
// ++
import {DisplayField} from "core-app/modules/fields/display/display-field.module";
-import {StateService} from '@uirouter/core';
-import {KeepTabService} from 'core-components/wp-single-view-tabs/keep-tab/keep-tab.service';
-import {UiStateLinkBuilder} from "core-components/wp-fast-table/builders/ui-state-link-builder";
export class WorkPackageDisplayField extends DisplayField {
public text = {
- linkTitle: this.I18n.t('js.work_packages.message_successful_show_in_fullscreen'),
none: this.I18n.t('js.filter.noneElement')
};
- private $state:StateService = this.$injector.get(StateService);
- private keepTab:KeepTabService = this.$injector.get(KeepTabService);
-
- private uiStateBuilder:UiStateLinkBuilder = new UiStateLinkBuilder(this.$state, this.keepTab);
-
- public render(element:HTMLElement, displayText:string):void {
- if (this.isEmpty()) {
- element.innerText = this.placeholder;
- return;
- }
-
- let link = this.uiStateBuilder.linkToShow(
- this.wpId,
- this.text.linkTitle,
- this.valueString
- );
-
- element.innerHTML = '';
- element.appendChild(link);
- }
-
public get value() {
return this.resource[this.name];
}
@@ -84,12 +59,9 @@ export class WorkPackageDisplayField extends DisplayField {
return this.value.href.match(/(\d+)$/)[0];
}
- public get writable():boolean {
- return false;
- }
-
public get valueString() {
- return '#' + this.wpId;
+ // cannot display the type name easily here as it may not be loaded
+ return `#${ this.wpId } ${ this.title }`;
}
public isEmpty():boolean {
@@ -99,5 +71,4 @@ export class WorkPackageDisplayField extends DisplayField {
public get unknownAttribute():boolean {
return false;
}
-
}
diff --git a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts b/frontend/src/app/modules/fields/edit/edit-field.initializer.ts
index c733468d79e..96a81eb0915 100644
--- a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts
+++ b/frontend/src/app/modules/fields/edit/edit-field.initializer.ts
@@ -40,8 +40,10 @@ import {FormattableEditFieldComponent} from "core-app/modules/fields/edit/field-
import {WorkPackageCommentFieldComponent} from "core-components/work-packages/work-package-comment/wp-comment-field.component";
import {SelectAutocompleterRegisterService} from "core-app/modules/fields/edit/field-types/select-autocompleter-register.service";
import {VersionAutocompleterComponent} from "core-app/modules/common/autocomplete/version-autocompleter.component";
-import {ProjectStatusDisplayField} from "core-app/modules/fields/display/field-types/project-status-display-field.module";
import {ProjectStatusEditFieldComponent} from "core-app/modules/fields/edit/field-types/project-status-edit-field.component";
+import {PlainFormattableEditFieldComponent} from "core-app/modules/fields/edit/field-types/plain-formattable-edit-field.component";
+import {WorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/wp-autocompleter.component";
+import {TimeEntryWorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/te-work-package-edit-field.component";
export function initializeCoreEditFields(editFieldService:EditFieldService, selectAutocompleterRegisterService:SelectAutocompleterRegisterService) {
@@ -56,6 +58,7 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele
'Type',
'User',
'Version',
+ 'TimeEntriesActivity',
'Category',
'CustomOption',
'Project'])
@@ -71,6 +74,11 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele
.addFieldType(ProjectStatusEditFieldComponent, 'project_status', ['ProjectStatus'])
.addFieldType(WorkPackageCommentFieldComponent, '_comment', ['comment']);
+ editFieldService
+ .addSpecificFieldType('TimeEntry', PlainFormattableEditFieldComponent, 'comment', ['comment'])
+ .addSpecificFieldType('TimeEntry', TimeEntryWorkPackageEditFieldComponent, 'workPackage', ['WorkPackage']);
+
selectAutocompleterRegisterService.register(VersionAutocompleterComponent, 'Version');
+ selectAutocompleterRegisterService.register(WorkPackageAutocompleterComponent, 'WorkPackage');
};
}
diff --git a/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts b/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts
index d67be2a80d5..66d93fe1dce 100644
--- a/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts
+++ b/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts
@@ -82,7 +82,7 @@ export class EditFormComponent extends EditForm<HalResource> implements OnInit,
}
// Show confirmation message when transitioning to a new state
- // that's not withing the edit mode.
+ // that's not within the edit mode.
if (!this.editFormRouting || this.editFormRouting.blockedTransition(transition)) {
if (requiresConfirmation && !window.confirm(confirmText)) {
return false;
diff --git a/frontend/src/app/modules/fields/edit/editing-portal/edit-form-portal.component.ts b/frontend/src/app/modules/fields/edit/editing-portal/edit-form-portal.component.ts
index a3fca03a6e6..4d8065f1e41 100644
--- a/frontend/src/app/modules/fields/edit/editing-portal/edit-form-portal.component.ts
+++ b/frontend/src/app/modules/fields/edit/editing-portal/edit-form-portal.component.ts
@@ -57,7 +57,7 @@ export class EditFormPortalComponent implements OnInit, OnDestroy, AfterViewInit
this.change = this.injector.get<ResourceChangeset>(OpEditingPortalChangesetToken);
}
- this.componentClass = this.editField.getClassFor(this.handler.fieldName, this.schema.type);
+ this.componentClass = this.editField.getSpecificClassFor(this.change.pristineResource._type, this.handler.fieldName, this.schema.type);
this.fieldInjector = createLocalInjector(this.injector, this.change, this.handler, this.schema);
}
diff --git a/frontend/src/app/modules/fields/edit/field-types/plain-formattable-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/plain-formattable-edit-field.component.ts
new file mode 100644
index 00000000000..01423396189
--- /dev/null
+++ b/frontend/src/app/modules/fields/edit/field-types/plain-formattable-edit-field.component.ts
@@ -0,0 +1,51 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {Component} from "@angular/core";
+import {EditFieldComponent} from "core-app/modules/fields/edit/edit-field.component";
+
+@Component({
+ templateUrl: './text-edit-field.component.html'
+})
+export class PlainFormattableEditFieldComponent extends EditFieldComponent {
+ // only exists because the template is reused and the property is required there.
+ public shouldFocus = false;
+
+ public get value() {
+ if (!this.schema) {
+ return '';
+ }
+ const element = this.resource[this.name];
+
+ return element && element.raw || '';
+ }
+
+ public set value(newValue:string) {
+ this.resource[this.name] = { raw: newValue };
+ }
+}
diff --git a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
index d03629d1077..c8a4371b107 100644
--- a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts
@@ -26,16 +26,17 @@
// See docs/COPYRIGHT.rdoc for more details.
// ++
-import {Component, OnInit, ViewChild} from "@angular/core";
+import {Component, OnInit} from "@angular/core";
import {HalResourceSortingService} from "core-app/modules/hal/services/hal-resource-sorting.service";
import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {EditFieldComponent} from "../edit-field.component";
-import {AngularTrackingHelpers} from "core-components/angular/tracking-functions";
import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
-import {NgSelectComponent} from "@ng-select/ng-select";
import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";
import {SelectAutocompleterRegisterService} from "app/modules/fields/edit/field-types/select-autocompleter-register.service";
+import { from } from 'rxjs';
+import { tap, map, skip } from 'rxjs/operators';
+import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";
export interface ValueOption {
name:string;
@@ -47,9 +48,12 @@ export interface ValueOption {
})
export class SelectEditFieldComponent extends EditFieldComponent implements OnInit {
public selectAutocompleterRegister = this.injector.get(SelectAutocompleterRegisterService);
+ public halNotification = this.injector.get(HalResourceNotificationService);
public availableOptions:any[];
public valueOptions:ValueOption[];
+ private valuesLoaded = false;
+
public text:{ requiredPlaceholder:string, placeholder:string };
public appendTo:any = null;
@@ -74,18 +78,10 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
requiredPlaceholder: this.I18n.t('js.placeholders.selection'),
placeholder: this.I18n.t('js.placeholders.default')
};
+ }
- const loadingPromise = this.loadValues();
- this.handler
- .$onUserActivate
- .pipe(
- untilComponentDestroyed(this)
- )
- .subscribe(() => {
- loadingPromise.then(() => {
- this._autocompleterComponent.openDirectly = true;
- });
- });
+ protected initialValueLoading() {
+ return this.loadValues().toPromise();
}
public autocompleterComponent() {
@@ -96,6 +92,21 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
public ngOnInit() {
super.ngOnInit();
this.appendTo = this.overflowingSelector;
+
+ let loadingPromise = this.change.getForm().then(() => {
+ return this.initialValueLoading();
+ });
+
+ this.handler
+ .$onUserActivate
+ .pipe(
+ untilComponentDestroyed(this),
+ )
+ .subscribe(() => {
+ loadingPromise.then(() => {
+ this._autocompleterComponent.openDirectly = true;
+ });
+ });
}
public get selectedOption() {
@@ -118,23 +129,39 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
private setValues(availableValues:HalResource[]) {
this.availableOptions = this.halSorting.sort(availableValues);
this.addEmptyOption();
- this.valueOptions = this.availableOptions.map(el => {
- return {name: el.name, $href: el.$href};
- });
+ this.valueOptions = this.availableOptions.map(el => this.mapAllowedValue(el));
}
- private loadValues() {
+ protected loadValues(query?:string) {
let allowedValues = this.schema.allowedValues;
+
if (Array.isArray(allowedValues)) {
this.setValues(allowedValues);
- } else if (allowedValues) {
- return allowedValues.$load(false).then((values:CollectionResource) => {
- this.setValues(values.elements);
- });
+ this.valuesLoaded = true;
+ } else if (allowedValues && !this.valuesLoaded) {
+ return this.loadValuesFromBackend(query);
} else {
this.setValues([]);
}
- return Promise.resolve();
+
+ return from(Promise.resolve(this.valueOptions));
+ }
+
+ protected loadValuesFromBackend(query?:string) {
+ return from(
+ this.schema.allowedValues.$link.$fetch(this.allowedValuesFilter(query)) as Promise<CollectionResource>
+ ).pipe(
+ tap(collection => {
+ // if it is an unpaginated collection or if we get all possible entries when fetching with a blank
+ // query, we do not need to load the values again;
+ if (collection.count === undefined || collection.total === undefined || (!query && collection.total === collection.count)) {
+ this.valuesLoaded = true;
+ }
+ }),
+ map(collection => collection.elements),
+ tap(elements => this.setValues(elements)),
+ map(() => this.valueOptions)
+ );
}
private addValue(val:HalResource) {
@@ -183,7 +210,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
private addEmptyOption() {
// Empty options are not available for required fields
- if (this.schema.required) {
+ if (this.isRequired()) {
return;
}
@@ -198,6 +225,20 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
}
}
+ protected isRequired() {
+ return this.schema.required;
+ }
+
+ protected mapAllowedValue(value:HalResource):ValueOption {
+ return {name: value.name, $href: value.$href};
+ }
+
+ // Subclasses shall be able to override the filters with which the
+ // allowed values are reduced in the backend.
+ protected allowedValuesFilter(query?:string) {
+ return {};
+ }
+
private getEmptyOption():ValueOption|undefined {
return _.find(this.availableOptions, el => el.name === this.text.placeholder);
}
diff --git a/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts
new file mode 100644
index 00000000000..2dad6e66317
--- /dev/null
+++ b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts
@@ -0,0 +1,44 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {Component} from "@angular/core";
+import {WorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/work-package-edit-field.component";
+
+@Component({
+ templateUrl: './work-package-edit-field.component.html'
+})
+export class TimeEntryWorkPackageEditFieldComponent extends WorkPackageEditFieldComponent {
+ // Although the schema states the work packages to not be required,
+ // as time entries can also be assigned to a project, we want to only assign
+ // time entries to work packages and thus require a value.
+ // The back end will have to be changed in due time but not as long as there is still a rails based
+ // time entry view in the application.
+ protected isRequired() {
+ return true;
+ }
+}
diff --git a/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.html b/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.html
new file mode 100644
index 00000000000..e18068f6865
--- /dev/null
+++ b/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.html
@@ -0,0 +1,10 @@
+<input type="text"
+ class="inline-edit--field"
+ [focus]="shouldFocus"
+ [attr.aria-required]="required"
+ [attr.required]="required"
+ [disabled]="inFlight"
+ [(ngModel)]="value"
+ (keydown)="handler.handleUserKeydown($event)"
+ (focusout)="handler.onFocusOut()"
+ [id]="handler.htmlId" />
diff --git a/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.ts
index 50784309f98..c995bd7885c 100644
--- a/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/text-edit-field.component.ts
@@ -30,18 +30,7 @@ import {Component} from "@angular/core";
import {EditFieldComponent} from "core-app/modules/fields/edit/edit-field.component";
@Component({
- template: `
- <input type="text"
- class="inline-edit--field"
- [focus]="shouldFocus"
- [attr.aria-required]="required"
- [attr.required]="required"
- [disabled]="inFlight"
- [(ngModel)]="value"
- (keydown)="handler.handleUserKeydown($event)"
- (focusout)="handler.onFocusOut()"
- [id]="handler.htmlId" />
- `
+ templateUrl: './text-edit-field.component.html'
})
export class TextEditFieldComponent extends EditFieldComponent {
// ToDo: Work package specific
diff --git a/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.html b/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.html
new file mode 100644
index 00000000000..a49ff6c1ac4
--- /dev/null
+++ b/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.html
@@ -0,0 +1,12 @@
+<ndc-dynamic [ndcDynamicComponent]="autocompleterComponent()"
+ [ndcDynamicInputs]="{ availableValues: requests.output$ | async,
+ appendTo: appendTo,
+ model: selectedOption ? selectedOption : '',
+ required: required,
+ disabled: inFlight,
+ typeahead: requests.input$,
+ id: handler.htmlId,
+ finishedLoading: true,
+ classes: 'inline-edit--field ' + handler.fieldName }"
+ [ndcDynamicOutputs]="referenceOutputs">
+</ndc-dynamic>
diff --git a/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.ts
index 4f88485e354..82148d1e283 100644
--- a/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/work-package-edit-field.component.ts
@@ -27,16 +27,56 @@
// ++
import {Component} from "@angular/core";
-import {EditFieldComponent} from "core-app/modules/fields/edit/edit-field.component";
+import {SelectEditFieldComponent, ValueOption} from './select-edit-field.component';
+import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";
+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";
+import {DebouncedRequestSwitchmap, errorNotificationHandler} from "core-app/helpers/rxjs/debounced-input-switchmap";
+import { take } from 'rxjs/operators';
@Component({
- template: `
- <input type="text"
- class="inline-edit--field"
- disabled
- [ngModel]="value"
- [id]="handler.htmlId" />
- `
+ templateUrl: './work-package-edit-field.component.html'
})
-export class WorkPackageEditFieldComponent extends EditFieldComponent {
+export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {
+ /** Keep a switchmap for search term and loading state */
+ public requests = new DebouncedRequestSwitchmap<string, ValueOption>(
+ (searchTerm:string) => this.loadValues(searchTerm),
+ errorNotificationHandler(this.halNotification)
+ );
+
+ protected initialValueLoading() {
+ // Using this hack with the empty value to have the values loaded initially
+ // while avoiding loading it multiple times.
+ return new Promise<ValueOption[]>((resolve) => {
+ this.requests.output$.pipe(take(1)).subscribe(options => {
+ resolve(options);
+ });
+
+ this.requests.input$.next('');
+ });
+ }
+
+ protected allowedValuesFilter(query?:string):{} {
+ let filterParams = super.allowedValuesFilter(query);
+
+ if (query) {
+ let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();
+
+ filters.add('subjectOrId', '**', [query]);
+
+ filterParams = { filters: filters.toJson() };
+ }
+
+ return filterParams;
+ }
+
+ protected mapAllowedValue(value:WorkPackageResource|ValueOption):ValueOption {
+ if ((value as WorkPackageResource).id) {
+ return {
+ name: `${(value as WorkPackageResource).type.name } #${ (value as WorkPackageResource).id } ${ (value as WorkPackageResource).subject }`,
+ $href: value.$href
+ };
+ } else {
+ return value;
+ }
+ }
}
diff --git a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts
index 8fcf912a851..1cb917fb67e 100644
--- a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts
@@ -116,8 +116,8 @@ export class EditableAttributeFieldComponent implements OnInit, OnDestroy {
.pipe(
untilComponentDestroyed(this)
)
- .subscribe(workPackage => {
- this.resource = workPackage;
+ .subscribe(resource => {
+ this.resource = resource;
this.render();
});
}
diff --git a/frontend/src/app/modules/fields/openproject-fields.module.ts b/frontend/src/app/modules/fields/openproject-fields.module.ts
index db96edfd921..37bf6359a95 100644
--- a/frontend/src/app/modules/fields/openproject-fields.module.ts
+++ b/frontend/src/app/modules/fields/openproject-fields.module.ts
@@ -54,6 +54,8 @@ import {WorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-
import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/field/editable-attribute-field.component";
import {ProjectStatusEditFieldComponent} from "core-app/modules/fields/edit/field-types/project-status-edit-field.component";
import {PortalCleanupService} from "core-app/modules/fields/display/display-portal/portal-cleanup.service";
+import {PlainFormattableEditFieldComponent} from "core-app/modules/fields/edit/field-types/plain-formattable-edit-field.component";
+import {TimeEntryWorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/te-work-package-edit-field.component";
@NgModule({
imports: [
@@ -87,11 +89,13 @@ import {PortalCleanupService} from "core-app/modules/fields/display/display-port
FloatEditFieldComponent,
IntegerEditFieldComponent,
FormattableEditFieldComponent,
+ PlainFormattableEditFieldComponent,
MultiSelectEditFieldComponent,
SelectEditFieldComponent,
TextEditFieldComponent,
EditFieldControlsComponent,
WorkPackageEditFieldComponent,
+ TimeEntryWorkPackageEditFieldComponent,
EditFormComponent,
EditableAttributeFieldComponent,
ProjectStatusEditFieldComponent,
@@ -105,10 +109,12 @@ import {PortalCleanupService} from "core-app/modules/fields/display/display-port
FloatEditFieldComponent,
IntegerEditFieldComponent,
FormattableEditFieldComponent,
+ PlainFormattableEditFieldComponent,
MultiSelectEditFieldComponent,
SelectEditFieldComponent,
TextEditFieldComponent,
WorkPackageEditFieldComponent,
+ TimeEntryWorkPackageEditFieldComponent,
EditableAttributeFieldComponent,
ProjectStatusEditFieldComponent,
]
diff --git a/frontend/src/app/modules/global_search/input/global-search-input.component.ts b/frontend/src/app/modules/global_search/input/global-search-input.component.ts
index f2d7061fe4c..150630ce26b 100644
--- a/frontend/src/app/modules/global_search/input/global-search-input.component.ts
+++ b/frontend/src/app/modules/global_search/input/global-search-input.component.ts
@@ -116,8 +116,6 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {
this.ngSelectComponent.searchTerm = this.currentValue = this.globalSearchService.searchTerm;
this.expanded = (this.ngSelectComponent.searchTerm.length > 0);
jQuery('#top-menu').toggleClass('-global-search-expanded', this.expanded);
-
-
}
ngOnDestroy() {
diff --git a/frontend/src/app/modules/grids/widgets/add/add.modal.ts b/frontend/src/app/modules/grids/widgets/add/add.modal.ts
index a8be66d1ab8..2f102934284 100644
--- a/frontend/src/app/modules/grids/widgets/add/add.modal.ts
+++ b/frontend/src/app/modules/grids/widgets/add/add.modal.ts
@@ -5,7 +5,6 @@ import {OpModalLocalsToken} from "app/components/op-modals/op-modal.service";
import {OpModalLocalsMap} from "app/components/op-modals/op-modal.types";
import {GridWidgetsService} from "app/modules/grids/widgets/widgets.service";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
-import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component";
import {BannersService} from "core-app/modules/common/enterprise/banners.service";
@Component({
diff --git a/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts b/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts
index 3396dbe54d5..dc039eb8902 100644
--- a/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts
+++ b/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts
@@ -29,9 +29,21 @@
import {Injectable} from '@angular/core';
import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";
import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";
+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
+import {FormResource} from "core-app/modules/hal/resources/form-resource";
+import {HalResource} from "core-app/modules/hal/resources/hal-resource";
+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";
+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
+import {PayloadDmService} from "core-app/modules/hal/dm-services/payload-dm.service";
@Injectable()
export class TimeEntryDmService extends AbstractDmService<TimeEntryResource> {
+ constructor(protected halResourceService:HalResourceService,
+ protected pathHelper:PathHelperService,
+ protected payloadDm:PayloadDmService) {
+ super(halResourceService, pathHelper);
+ }
+
protected listUrl() {
return this.pathHelper.api.v3.time_entries.toString();
}
@@ -39,4 +51,21 @@ export class TimeEntryDmService extends AbstractDmService<TimeEntryResource> {
protected oneUrl(id:number|string) {
return this.pathHelper.api.v3.time_entries.id(id).toString();
}
+
+ public updateForm(resource:TimeEntryResource, schema:SchemaResource|null = null) {
+ let payload = this.extractPayload(resource, schema);
+
+ return this.halResourceService.post<FormResource>(this.pathHelper.api.v3.time_entries.id(resource.idFromLink).form.toString(),
+ payload).toPromise();
+ }
+
+ public extractPayload(resource:TimeEntryResource|null = null, schema:SchemaResource|null = null) {
+ if (resource && schema) {
+ return this.payloadDm.extract(resource, schema);
+ } else if (!(resource instanceof HalResource)) {
+ return resource;
+ } else {
+ return {};
+ }
+ }
}
diff --git a/frontend/src/app/modules/hal/resources/hal-resource.ts b/frontend/src/app/modules/hal/resources/hal-resource.ts
index d4aa4e3d38e..82847b85e97 100644
--- a/frontend/src/app/modules/hal/resources/hal-resource.ts
+++ b/frontend/src/app/modules/hal/resources/hal-resource.ts
@@ -31,8 +31,6 @@ import {HalLinkInterface} from 'core-app/modules/hal/hal-link/hal-link';
import {Injector} from '@angular/core';
import {States} from 'core-components/states.service';
import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
-import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";
-
export interface HalResourceClass<T extends HalResource = HalResource> {
new(injector:Injector,
diff --git a/frontend/src/app/modules/hal/resources/time-entry-resource.ts b/frontend/src/app/modules/hal/resources/time-entry-resource.ts
index ed934b2b61c..d0bc1a6cd28 100644
--- a/frontend/src/app/modules/hal/resources/time-entry-resource.ts
+++ b/frontend/src/app/modules/hal/resources/time-entry-resource.ts
@@ -27,6 +27,35 @@
//++
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";
export class TimeEntryResource extends HalResource {
+
+ private schemaCacheService = this.injector.get(SchemaCacheService);
+
+ /**
+ * Get the schema of the time entry
+ * ensure that it's loaded
+ */
+ public get schema():SchemaResource {
+ const state = this.schemaCacheService.state(this as any);
+
+ if (!state.hasValue()) {
+ throw `Accessing schema of time entry ${this.id} without it being loaded.`;
+ }
+
+ return state.value!;
+ }
+
+ public get state() {
+ return this.states.timeEntries.get(this.id!) as any;
+ }
+
+ /**
+ * Exclude the schema _link from the linkable Resources.
+ */
+ public $linkableKeys():string[] {
+ return _.without(super.$linkableKeys(), 'schema');
+ }
}
diff --git a/lib/api/v3/time_entries/available_work_packages_helper.rb b/lib/api/v3/time_entries/available_work_packages_helper.rb
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/lib/api/v3/time_entries/available_work_packages_on_create_api.rb b/lib/api/v3/time_entries/available_work_packages_on_create_api.rb
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/lib/api/v3/time_entries/available_work_packages_on_edit_api.rb b/lib/api/v3/time_entries/available_work_packages_on_edit_api.rb
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/modules/dashboards/spec/features/time_entries_spec.rb b/modules/dashboards/spec/features/time_entries_spec.rb
index dc4c9621eb5..12fc9ca2f92 100644
--- a/modules/dashboards/spec/features/time_entries_spec.rb
+++ b/modules/dashboards/spec/features/time_entries_spec.rb
@@ -93,7 +93,7 @@ describe 'Time entries widget on dashboard', type: :feature, js: true, with_mail
it 'adds the widget and checks the displayed entries' do
# within top-right area, add an additional widget
- dashboard.add_widget(1, 1, :within, 'Spent time \(last 7 days\)')
+ dashboard.add_widget(1, 1, :within, 'Spent time')
spent_time_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
diff --git a/modules/grids/config/locales/js-en.yml b/modules/grids/config/locales/js-en.yml
index f162bb56239..34e9e64cef9 100644
--- a/modules/grids/config/locales/js-en.yml
+++ b/modules/grids/config/locales/js-en.yml
@@ -39,6 +39,7 @@ en:
no_results: 'No subprojects.'
time_entries_list:
title: 'Spent time'
+ no_results: 'No time entries for the last 7 days.'
work_packages_accountable:
title: "Work packages I am accountable for"
work_packages_assigned:
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 1170419751d..483f45c8b36 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
@@ -33,16 +33,25 @@ require_relative '../../support/pages/my/page'
describe 'My page time entries current user widget spec', type: :feature, js: true, with_mail: false do
let!(:type) { FactoryBot.create :type }
let!(:project) { FactoryBot.create :project, types: [type] }
+ let!(:activity) { FactoryBot.create :time_entry_activity }
+ let!(:other_activity) { FactoryBot.create :time_entry_activity }
let!(:work_package) do
FactoryBot.create :work_package,
project: project,
type: type,
author: user
end
+ let!(:other_work_package) do
+ FactoryBot.create :work_package,
+ project: project,
+ type: type,
+ author: user
+ end
let!(:visible_time_entry) do
FactoryBot.create :time_entry,
work_package: work_package,
project: project,
+ activity: activity,
user: user,
spent_on: Date.today,
hours: 3,
@@ -52,6 +61,7 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
FactoryBot.create :time_entry,
work_package: work_package,
project: project,
+ activity: activity,
user: user,
# limit the date to ensure that it is on the current calendar sheet
spent_on: Date.today - [1, Date.today.wday].min.days,
@@ -62,6 +72,7 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
FactoryBot.create :time_entry,
work_package: work_package,
project: project,
+ activity: activity,
user: user,
spent_on: Date.today - (Date.today.wday + 3).days,
hours: 8,
@@ -71,20 +82,29 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
FactoryBot.create :time_entry,
work_package: work_package,
project: project,
+ activity: activity,
user: other_user,
hours: 4
end
+ let!(:custom_field) do
+ FactoryBot.create :time_entry_custom_field, field_format: 'string'
+ end
let(:other_user) do
FactoryBot.create(:user)
end
let(:user) do
FactoryBot.create(:user,
member_in_project: project,
- member_with_permissions: %i[view_time_entries])
+ member_with_permissions: %i[view_time_entries edit_time_entries view_work_packages])
end
let(:my_page) do
Pages::My::Page.new
end
+ let(:comments_field) { ::EditField.new(page, 'comment') }
+ let(:activity_field) { ::EditField.new(page, 'activity') }
+ let(:hours_field) { ::EditField.new(page, 'hours') }
+ let(:wp_field) { ::EditField.new(page, 'workPackage') }
+ let(:cf_field) { ::EditField.new(page, "customField#{custom_field.id}") }
before do
login_as user
@@ -97,18 +117,21 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
my_page.add_widget(1, 1, :within, 'Spent time')
entries_area = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+
+ my_page.expect_and_dismiss_notification message: I18n.t(:notice_successful_update)
+
entries_area.expect_to_span(1, 1, 2, 2)
expect(page)
.to have_content "Total: 5.00"
expect(page)
- .to have_content visible_time_entry.spent_on.strftime('%m/%d')
+ .to have_content visible_time_entry.spent_on.strftime('%-m/%-d')
expect(page)
.to have_selector('.fc-event .fc-title', text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
expect(page)
- .to have_content(other_visible_time_entry.spent_on.strftime('%m/%d'))
+ .to have_content(other_visible_time_entry.spent_on.strftime('%-m/%-d'))
expect(page)
.to have_selector('.fc-event .fc-title', text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
@@ -121,7 +144,7 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
.to have_content "Total: 8.00"
expect(page)
- .to have_content(last_week_visible_time_entry.spent_on.strftime('%m/%d'))
+ .to have_content(last_week_visible_time_entry.spent_on.strftime('%-m/%-d'))
expect(page)
.to have_selector('.fc-event .fc-title', text: "#{project.name} - ##{work_package.id}: #{work_package.subject}")
@@ -140,6 +163,82 @@ describe 'My page time entries current user widget spec', type: :feature, js: tr
expect(page)
.to have_selector('.ui-tooltip', text: "Project: #{project.name}")
+ # Editing an entry
+
+ within entries_area.area do
+ find(".fc-content-skeleton td:nth-of-type(#{Date.today.wday + 1}) .fc-event-container .fc-event").click
+ end
+
+ expect(page)
+ .to have_content(I18n.t('js.time_entry.edit'))
+
+ activity_field.activate!
+ activity_field.set_value(other_activity.name)
+ activity_field.expect_display_value(other_activity.name)
+
+ wp_field.activate!
+ wp_field.set_value(other_work_package.subject)
+ wp_field.expect_display_value(other_work_package.name)
+
+ hours_field.activate!
+ hours_field.set_value('6')
+ hours_field.save!
+
+ hours_field.expect_display_value('6 h')
+
+ comments_field.activate!
+ comments_field.set_value('Some comment')
+ comments_field.save!
+
+ comments_field.expect_display_value('Some comment')
+
+ cf_field.activate!
+ cf_field.set_value('Cf text value')
+ cf_field.save!
+
+ cf_field.expect_display_value('Cf text value')
+
+ sleep(1)
+
+ find(".op-modal--portal .op-modal--modal-close-button").click
+
+ sleep(0.1)
+ my_page.expect_and_dismiss_notification message: I18n.t(:notice_successful_update)
+
+ within entries_area.area do
+ find(".fc-content-skeleton td:nth-of-type(#{Date.today.wday + 1}) .fc-event-container .fc-event").hover
+ end
+
+ expect(page)
+ .to have_selector('.ui-tooltip', text: "Comment: Some comment")
+
+ expect(page)
+ .to have_selector('.ui-tooltip', text: "Activity: #{other_activity.name}")
+
+ expect(page)
+ .to have_content "Total: 9.00"
+
+ # Removing the time entry
+
+ within entries_area.area do
+ find(".fc-content-skeleton td:nth-of-type(#{Date.today.wday + 1}) .fc-event-container .fc-event").click
+ end
+
+ click_button 'Delete'
+
+ within entries_area.area do
+ expect(page)
+ .not_to have_selector(".fc-content-skeleton td:nth-of-type(#{Date.today.wday + 1}) .fc-event-container .fc-event")
+ end
+
+ expect(page)
+ .to have_content "Total: 3.00"
+
+ expect(TimeEntry.where(id: other_visible_time_entry.id))
+ .not_to be_exist
+
+ # Removing the widget
+
entries_area.remove
# as the last widget has been removed, the add button is always displayed
diff --git a/spec/support/edit_fields/edit_field.rb b/spec/support/edit_fields/edit_field.rb
index 89be93e1620..7a6c15d0cc1 100644
--- a/spec/support/edit_fields/edit_field.rb
+++ b/spec/support/edit_fields/edit_field.rb
@@ -51,6 +51,11 @@ class EditField
expect(input_element.value).to eq(value)
end
+ def expect_display_value(value)
+ expect(display_element)
+ .to have_content(value)
+ end
+
##
# Activate the field and check it opened correctly
def activate!(expect_open: true)
@@ -222,8 +227,11 @@ class EditField
'status',
'project',
'type',
- 'category'
+ 'category',
+ 'workPackage'
'create-autocompleter'
+ when 'activity'
+ 'activity-autocompleter'
else
:input
end.to_s