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

Implement date picker banner

Oliver Güntherbbc9a351406a
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 9aeb873b963..1fe42d39bcf 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -924,6 +924,13 @@ en:
comment_send_failed: "An error has occurred. Could not submit the comment."
comment_updated: "The comment was successfully updated."
confirm_edit_cancel: "Are you sure you want to cancel editing the work package?"
+ datepicker_modal:
+ automatically_scheduled_parent: "Automatically scheduled. Dates are derived from relations."
+ manually_scheduled: "Manual scheduling enabled, all relations ignored."
+ start_date_limited_by_relations: "Available start date is limited by relations."
+ changing_dates_affects_follow_relations: "Changing these dates will affect dates of related work packages."
+ click_on_show_relations_to_open_gantt: 'Click on "%{button_name}" for GANTT overview.'
+ show_relations: 'Show relations'
description_filter: "Filter"
description_enter_text: "Enter text"
description_options_hide: "Hide options"
diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
index 7726526da00..5876c445201 100644
--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
@@ -396,6 +396,7 @@ import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { OpenprojectFileLinksModule } from 'core-app/shared/components/file-links/openproject-file-links.module';
import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
+import { DatepickerBannerComponent } from 'core-app/shared/components/datepicker/banner/datepicker-banner.component';
@NgModule({
imports: [
@@ -604,6 +605,7 @@ import { StoragesResourceService } from 'core-app/core/state/storages/storages.s
SaveQueryModalComponent,
WpDestroyModalComponent,
DatePickerModalComponent,
+ DatepickerBannerComponent,
// CustomActions
WpCustomActionComponent,
diff --git a/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.html b/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.html
new file mode 100644
index 00000000000..4c2298ed960
--- /dev/null
+++ b/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.html
@@ -0,0 +1,43 @@
+<op-modal-banner
+ *ngIf="scheduleManually && (hasRelations$ | async)"
+ type="warning"
+ [title]="text.manually_scheduled"
+ [subtitle]="text.click_on_show_relations_to_open_gantt"
+ [actionButton]="text.show_relations_button"
+ actionButtonClasses="icon-view-timeline"
+ (buttonClicked)="openGantt($event)"
+>
+</op-modal-banner>
+<op-modal-banner
+ *ngIf="!scheduleManually && isParent"
+ type="info"
+ [title]="text.automatically_scheduled_parent"
+ [subtitle]="text.click_on_show_relations_to_open_gantt"
+ [actionButton]="text.show_relations_button"
+ actionButtonClasses="icon-view-timeline"
+ (buttonClicked)="openGantt($event)"
+>
+</op-modal-banner>
+<ng-container *ngIf="!scheduleManually && !isParent">
+ <op-modal-banner
+ *ngIf="(hasPrecedingRelations$ | async) === true"
+ type="info"
+ [title]="text.start_date_limited_by_relations"
+ [subtitle]="text.click_on_show_relations_to_open_gantt"
+ [actionButton]="text.show_relations_button"
+ actionButtonClasses="icon-view-timeline"
+ (buttonClicked)="openGantt($event)"
+ >
+ </op-modal-banner>
+
+ <op-modal-banner
+ *ngIf="(hasPrecedingRelations$ | async) === false && (hasFollowingRelations$ | async) === true"
+ type="info"
+ [title]="text.changing_dates_affects_follow_relations"
+ [subtitle]="text.click_on_show_relations_to_open_gantt"
+ [actionButton]="text.show_relations_button"
+ actionButtonClasses="icon-view-timeline"
+ (buttonClicked)="openGantt($event)"
+ >
+ </op-modal-banner>
+</ng-container>
diff --git a/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.ts b/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.ts
new file mode 100644
index 00000000000..ed0ffda60c1
--- /dev/null
+++ b/frontend/src/app/shared/components/datepicker/banner/datepicker-banner.component.ts
@@ -0,0 +1,117 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2022 the OpenProject GmbH
+//
+// 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 COPYRIGHT and LICENSE files for more details.
+//++
+
+import {
+ ChangeDetectionStrategy,
+ Component,
+ Injector,
+ Input,
+} from '@angular/core';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { DatepickerModalService } from 'core-app/shared/components/datepicker/datepicker.modal.service';
+import {
+ map,
+ take,
+} from 'rxjs/operators';
+import { StateService } from '@uirouter/core';
+
+@Component({
+ selector: 'op-datepicker-banner',
+ templateUrl: './datepicker-banner.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class DatepickerBannerComponent {
+ @Input() scheduleManually = false;
+
+ hasRelations$ = this.datepickerService.hasRelations$;
+
+ hasPrecedingRelations$ = this
+ .datepickerService
+ .precedingWorkPackages$
+ .pipe(
+ map((relations) => relations?.length > 0),
+ );
+
+ hasFollowingRelations$ = this
+ .datepickerService
+ .followingWorkPackages$
+ .pipe(
+ map((relations) => relations?.length > 0),
+ );
+
+ isParent = this.datepickerService.isParent;
+
+ text = {
+ automatically_scheduled_parent: this.I18n.t('js.work_packages.datepicker_modal.automatically_scheduled_parent'),
+ manually_scheduled: this.I18n.t('js.work_packages.datepicker_modal.manually_scheduled'),
+ start_date_limited_by_relations: this.I18n.t('js.work_packages.datepicker_modal.start_date_limited_by_relations'),
+ changing_dates_affects_follow_relations: this.I18n.t('js.work_packages.datepicker_modal.changing_dates_affects_follow_relations'),
+ click_on_show_relations_to_open_gantt: this.I18n.t(
+ 'js.work_packages.datepicker_modal.click_on_show_relations_to_open_gantt',
+ { button_name: this.I18n.t('js.work_packages.datepicker_modal.show_relations') },
+ ),
+ show_relations_button: this.I18n.t('js.work_packages.datepicker_modal.show_relations'),
+ };
+
+ constructor(
+ readonly datepickerService:DatepickerModalService,
+ readonly injector:Injector,
+ readonly I18n:I18nService,
+ readonly state:StateService,
+ ) {}
+
+ openGantt(evt:MouseEvent):void {
+ evt.preventDefault();
+
+ this
+ .datepickerService
+ .getInvolvedWorkPackageIds()
+ .pipe(
+ take(1),
+ )
+ .subscribe((ids) => {
+ const props = {
+ c: ['id', 'subject', 'type', 'status', 'assignee', 'createdAt'],
+ t: 'createdAt:desc',
+ tv: true,
+ f: [{ n: 'id', o: '=', v: ids }],
+ };
+
+ const href = this.state.href(
+ 'work-packages.partitioned.list',
+ {
+ query_id: null,
+ projects: null,
+ projectPath: null,
+ query_props: JSON.stringify(props),
+ },
+ );
+ window.open(href, '_blank');
+ });
+ }
+}
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.html b/frontend/src/app/shared/components/datepicker/datepicker.modal.html
index 3cb25f9d4fd..d29f6a3d375 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.html
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.html
@@ -6,6 +6,7 @@
data-indicator-name="modal"
(submit)="save($event)"
>
+ <op-datepicker-banner [scheduleManually]="scheduleManually"></op-datepicker-banner>
<div class="op-modal--body form -vertical">
<div class="form--field op-datepicker-modal--scheduling-action-container">
<div class="form--field-container">
@@ -34,11 +35,11 @@
<spot-text-field
name="date"
class="op-datepicker-modal--date-field"
- [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerHelper.isStateOfCurrentActivatedField('date')}"
+ [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerService.isStateOfCurrentActivatedField('date')}"
[ngModel]="dates.date"
(ngModelChange)="updateDate('date', $event)"
- [showClearButton]="datepickerHelper.isStateOfCurrentActivatedField('date')"
- (click)="datepickerHelper.setCurrentActivatedField('date')"
+ [showClearButton]="datepickerService.isStateOfCurrentActivatedField('date')"
+ (click)="datepickerService.setCurrentActivatedField('date')"
></spot-text-field>
</div>
</div>
@@ -63,12 +64,12 @@
name="startDate"
data-qa-selector="op-datepicker-modal--start-date-field"
class="op-datepicker-modal--date-field"
- [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerHelper.isStateOfCurrentActivatedField('start')}"
+ [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerService.isStateOfCurrentActivatedField('start')}"
[ngModel]="dates.start"
(ngModelChange)="updateDate('start', $event)"
[disabled]="!isSchedulable"
- [showClearButton]="datepickerHelper.isStateOfCurrentActivatedField('start')"
- (focusin)="datepickerHelper.setCurrentActivatedField('start')"
+ [showClearButton]="datepickerService.isStateOfCurrentActivatedField('start')"
+ (focusin)="datepickerService.setCurrentActivatedField('start')"
></spot-text-field>
</div>
</div>
@@ -91,12 +92,12 @@
name="endDate"
data-qa-selector="op-datepicker-modal--end-date-field"
class="op-datepicker-modal--date-field"
- [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerHelper.isStateOfCurrentActivatedField('end')}"
+ [ngClass]="{'op-datepicker-modal--date-field_current' : datepickerService.isStateOfCurrentActivatedField('end')}"
[ngModel]="dates.end"
(ngModelChange)="updateDate('end', $event)"
[disabled]="!isSchedulable"
- [showClearButton]="datepickerHelper.isStateOfCurrentActivatedField('end')"
- (focusin)="datepickerHelper.setCurrentActivatedField('end')"
+ [showClearButton]="datepickerService.isStateOfCurrentActivatedField('end')"
+ (focusin)="datepickerService.setCurrentActivatedField('end')"
></spot-text-field>
</div>
</div>
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.sass b/frontend/src/app/shared/components/datepicker/datepicker.modal.sass
index 7560589e945..a7f9cf67a9c 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.sass
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.sass
@@ -8,6 +8,9 @@
max-width: 730px
min-height: 200px
box-shadow: $spot-shadow-light-mid
+ // Apply a bottom margin before the banners are loaded
+ // to avoid overlapping
+ margin-bottom: 60px
&--dates-container
display: grid
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.helper.ts b/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
similarity index 58%
rename from frontend/src/app/shared/components/datepicker/datepicker.modal.helper.ts
rename to frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
index 47359c06450..c6469942a6c 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.helper.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
@@ -26,15 +26,97 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { Injectable } from '@angular/core';
+import {
+ Inject,
+ Injectable,
+} from '@angular/core';
import { DateKeys } from 'core-app/shared/components/datepicker/datepicker.modal';
import { DatePicker } from 'core-app/shared/components/op-date-picker/datepicker';
import { DateOption } from 'flatpickr/dist/types/options';
+import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { ApiV3Filter } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
+import {
+ map,
+ shareReplay,
+} from 'rxjs/operators';
+import {
+ combineLatest,
+ Observable,
+} from 'rxjs';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-@Injectable({ providedIn: 'root' })
-export class DatePickerModalHelper {
+@Injectable()
+export class DatepickerModalService {
currentlyActivatedDateField:DateKeys;
+ private changeset:WorkPackageChangeset = this.locals.changeset as WorkPackageChangeset;
+
+ precedingWorkPackages$:Observable<WorkPackageResource[]> = this
+ .apiV3Service
+ .work_packages
+ .filtered(ApiV3Filter('precedes', '=', [this.changeset.id]))
+ .get()
+ .pipe(
+ map((collection) => collection.elements),
+ shareReplay(1),
+ );
+
+ followingWorkPackages$:Observable<WorkPackageResource[]> = this
+ .apiV3Service
+ .work_packages
+ .filtered(ApiV3Filter('follows', '=', [this.changeset.id]))
+ .get()
+ .pipe(
+ map((collection) => collection.elements),
+ shareReplay(1),
+ );
+
+ hasRelations$ = combineLatest([
+ this.precedingWorkPackages$,
+ this.followingWorkPackages$,
+ ])
+ .pipe(
+ map(([precedes, follows]) => precedes.length > 0 || follows.length > 0 || this.isParent),
+ );
+
+ constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ private apiV3Service:ApiV3Service,
+ ) {}
+
+ /**
+ * Determines whether the work package is a parent. It does so
+ * by checking the children links.
+ */
+ get isParent():boolean {
+ return this.children.length > 0;
+ }
+
+ get children():HalResource[] {
+ const wp = this.changeset.projectedResource;
+ return wp.children || [];
+ }
+
+ getInvolvedWorkPackageIds():Observable<string[]> {
+ return combineLatest([
+ this.precedingWorkPackages$,
+ this.followingWorkPackages$,
+ ])
+ .pipe(
+ map(
+ ([preceding, following]) => [
+ ...preceding,
+ ...following,
+ ...this.children,
+ ].map((el) => el.id as string),
+ ),
+ );
+ }
+
/**
* Map the date to the internal format,
* setting to null if it's empty.
@@ -49,7 +131,8 @@ export class DatePickerModalHelper {
parseDate(date:Date|string):Date|'' {
if (date instanceof Date) {
return new Date(date.setHours(0, 0, 0, 0));
- } if (date === '') {
+ }
+ if (date === '') {
return '';
}
return new Date(new Date(date).setHours(0, 0, 0, 0));
@@ -90,6 +173,7 @@ export class DatePickerModalHelper {
const { currentYear } = datePicker.datepickerInstance;
datePicker.setDates(dates);
+ /* eslint-disable no-param-reassign */
if (enforceDate) {
datePicker.datepickerInstance.currentMonth = enforceDate.getMonth();
datePicker.datepickerInstance.currentYear = enforceDate.getFullYear();
@@ -100,5 +184,6 @@ export class DatePickerModalHelper {
}
datePicker.datepickerInstance.redraw();
+ /* eslint-enable no-param-reassign */
}
}
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts b/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
index 33db3cfd7e3..f6b553ad0eb 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
@@ -46,13 +46,12 @@ import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.servi
import { DatePicker } from 'core-app/shared/components/op-date-picker/datepicker';
import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
-import { DatePickerModalHelper } from 'core-app/shared/components/datepicker/datepicker.modal.helper';
import { BrowserDetector } from 'core-app/core/browser/browser-detector.service';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { DayElement } from 'flatpickr/dist/types/instance';
import flatpickr from 'flatpickr';
+import { DatepickerModalService } from 'core-app/shared/components/datepicker/datepicker.modal.service';
export type DateKeys = 'date'|'start'|'end';
@@ -61,6 +60,9 @@ export type DateKeys = 'date'|'start'|'end';
styleUrls: ['./datepicker.modal.sass', './datepicker_mobile.modal.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
+ providers: [
+ DatepickerModalService,
+ ],
})
export class DatePickerModalComponent extends OpModalComponent implements AfterViewInit {
@InjectField() I18n!:I18nService;
@@ -69,7 +71,7 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
@InjectField() halEditing:HalResourceEditingService;
- @InjectField() datepickerHelper:DatePickerModalHelper;
+ @InjectField() datepickerService:DatepickerModalService;
@InjectField() browserDetector:BrowserDetector;
@@ -120,11 +122,11 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
if (this.singleDate) {
this.dates.date = this.changeset.value('date') as string;
- this.datepickerHelper.setCurrentActivatedField('date');
+ this.datepickerService.setCurrentActivatedField('date');
} else {
this.dates.start = this.changeset.value('startDate') as string;
this.dates.end = this.changeset.value('dueDate') as string;
- this.datepickerHelper.setCurrentActivatedField(this.initialActivatedField());
+ this.datepickerService.setCurrentActivatedField(this.initialActivatedField());
}
}
@@ -142,7 +144,7 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
if (this.scheduleManually) {
this.initializeDatepicker();
- } else if (this.isParent) {
+ } else if (this.datepickerService.isParent) {
this.removeDateSelection();
}
}
@@ -159,10 +161,10 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
// Apply the dates if they could be changed
if (this.isSchedulable) {
if (this.singleDate) {
- this.changeset.setValue('date', this.datepickerHelper.mappedDate(this.dates.date));
+ this.changeset.setValue('date', this.datepickerService.mappedDate(this.dates.date));
} else {
- this.changeset.setValue('startDate', this.datepickerHelper.mappedDate(this.dates.start));
- this.changeset.setValue('dueDate', this.datepickerHelper.mappedDate(this.dates.end));
+ this.changeset.setValue('startDate', this.datepickerService.mappedDate(this.dates.start));
+ this.changeset.setValue('dueDate', this.datepickerService.mappedDate(this.dates.end));
}
}
@@ -177,14 +179,14 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
// Expected minimal format YYYY-M-D => 8 characters OR empty
if (val.length >= 8 || val.length === 0) {
this.dates[key] = val;
- if (this.datepickerHelper.validDate(val) && this.datePickerInstance) {
+ if (this.datepickerService.validDate(val) && this.datePickerInstance) {
this.enforceManualChangesToDatepicker(false);
}
}
}
setToday(key:DateKeys):void {
- const today = this.datepickerHelper.parseDate(new Date());
+ const today = this.datepickerService.parseDate(new Date());
this.dates[key] = this.timezoneService.formattedISODate(today);
if (today instanceof Date) {
@@ -216,22 +218,13 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
* The later is necessary as we cannot correctly calculate the resulting dates in the frontend.
*/
get isSchedulable():boolean {
- return this.scheduleManually || (!this.isParent && !this.isSwitchedFromManualToAutomatic);
+ return this.scheduleManually || (!this.datepickerService.isParent && !this.isSwitchedFromManualToAutomatic);
}
get isSavable():boolean {
return this.isSchedulable || this.isSwitchedFromManualToAutomatic;
}
- /**
- * Determines whether the work package is a parent. It does so
- * by checking the children links.
- */
- get isParent():boolean {
- const wp = this.changeset.projectedResource as WorkPackageResource;
- return wp.$links.children && wp.$links.children.length > 0;
- }
-
get isSwitchedFromManualToAutomatic():boolean {
return !this.scheduleManually && !!this.changeset.value('scheduleManually');
}
@@ -270,14 +263,14 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
private enforceManualChangesToDatepicker(toggleField = true, enforceDate?:Date) {
if (this.singleDate) {
- const date = this.datepickerHelper.parseDate(this.dates.date);
- this.datepickerHelper.setDates(date, this.datePickerInstance, enforceDate);
+ const date = this.datepickerService.parseDate(this.dates.date);
+ this.datepickerService.setDates(date, this.datePickerInstance, enforceDate);
} else {
- const dates = [this.datepickerHelper.parseDate(this.dates.start), this.datepickerHelper.parseDate(this.dates.end)];
- this.datepickerHelper.setDates(dates, this.datePickerInstance, enforceDate);
+ const dates = [this.datepickerService.parseDate(this.dates.start), this.datepickerService.parseDate(this.dates.end)];
+ this.datepickerService.setDates(dates, this.datePickerInstance, enforceDate);
if (toggleField) {
- this.datepickerHelper.toggleCurrentActivatedField();
+ this.datepickerService.toggleCurrentActivatedField();
}
}
}
@@ -296,28 +289,28 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
3. Everything in between the current start and end date is dependent on the currently activated field.
* */
- const parsedStartDate = this.datepickerHelper.parseDate(this.dates.start) as Date;
- const parsedEndDate = this.datepickerHelper.parseDate(this.dates.end) as Date;
+ const parsedStartDate = this.datepickerService.parseDate(this.dates.start) as Date;
+ const parsedEndDate = this.datepickerService.parseDate(this.dates.end) as Date;
if (selectedDate < parsedStartDate) {
this.overwriteDatePickerWithNewDates([selectedDate, parsedEndDate]);
- this.datepickerHelper.setCurrentActivatedField('end');
+ this.datepickerService.setCurrentActivatedField('end');
} else if (selectedDate > parsedEndDate) {
- if (this.datepickerHelper.isStateOfCurrentActivatedField('end')) {
+ if (this.datepickerService.isStateOfCurrentActivatedField('end')) {
this.overwriteDatePickerWithNewDates([parsedStartDate, selectedDate]);
} else {
this.dates.start = this.timezoneService.formattedISODate(selectedDate);
this.dates.end = '';
- this.datepickerHelper.toggleCurrentActivatedField();
+ this.datepickerService.toggleCurrentActivatedField();
}
- } else if (this.datepickerHelper.areDatesEqual(selectedDate, parsedStartDate) || this.datepickerHelper.areDatesEqual(selectedDate, parsedEndDate)) {
+ } else if (this.datepickerService.areDatesEqual(selectedDate, parsedStartDate) || this.datepickerService.areDatesEqual(selectedDate, parsedEndDate)) {
this.overwriteDatePickerWithNewDates([selectedDate, selectedDate]);
} else {
- const newDates = this.datepickerHelper.isStateOfCurrentActivatedField('start') ? [selectedDate, parsedEndDate] : [parsedStartDate, selectedDate];
+ const newDates = this.datepickerService.isStateOfCurrentActivatedField('start') ? [selectedDate, parsedEndDate] : [parsedStartDate, selectedDate];
this.overwriteDatePickerWithNewDates(newDates);
}
} else {
- this.dates[this.datepickerHelper.currentlyActivatedDateField] = this.timezoneService.formattedISODate(selectedDate);
+ this.dates[this.datepickerService.currentlyActivatedDateField] = this.timezoneService.formattedISODate(selectedDate);
}
break;
@@ -326,7 +319,7 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
// Write the dates to the input fields
this.dates.start = this.timezoneService.formattedISODate(dates[0]);
this.dates.end = this.timezoneService.formattedISODate(dates[1]);
- this.datepickerHelper.toggleCurrentActivatedField();
+ this.datepickerService.toggleCurrentActivatedField();
break;
}
default: {
@@ -338,7 +331,7 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
}
private overwriteDatePickerWithNewDates(dates:Date[]) {
- this.datepickerHelper.setDates(dates, this.datePickerInstance);
+ this.datepickerService.setDates(dates, this.datePickerInstance);
this.handleDatePickerChange(dates);
}
diff --git a/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.html b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.html
new file mode 100644
index 00000000000..7c024dd92ed
--- /dev/null
+++ b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.html
@@ -0,0 +1,37 @@
+<div
+ class="op-modal-banner"
+ ngClass="op-modal-banner_{{ type }}"
+ attr.data-qa-selector="op-modal-banner-{{ type }}"
+>
+ <span
+ *ngIf="type === 'info'"
+ class="op-modal-banner--icon spot-icon spot-icon_info1"
+ ></span>
+ <span
+ *ngIf="type === 'warning'"
+ class="op-modal-banner--icon spot-icon spot-icon_warning hidden-for-mobile"
+ ></span>
+ <p
+ class="op-modal-banner--text"
+ >
+ <span
+ class="op-modal-banner--title"
+ [textContent]="title"
+ ></span>
+ <br/>
+ <span
+ class="op-modal-banner--subtitle hidden-for-mobile"
+ [textContent]="subtitle"
+ ></span>
+ </p>
+
+ <button
+ *ngIf="!!actionButton"
+ class="op-modal-banner--button button"
+ type="button"
+ (click)="buttonClicked.emit($event)"
+ >
+ <op-icon icon-classes="button--icon {{ actionButtonClasses }}"></op-icon>
+ <span class="button--text" [textContent]="actionButton"></span>
+ </button>
+</div>
diff --git a/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.sass b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.sass
new file mode 100644
index 00000000000..ccc4c9aa5cf
--- /dev/null
+++ b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.sass
@@ -0,0 +1,30 @@
+@import '~app/spot/styles/sass/variables'
+
+.op-modal-banner
+ display: grid
+ grid-template-columns: 20px auto max-content
+ grid-gap: 20px
+ align-items: center
+ padding: 10px 20px
+
+ @media only screen and (max-width: 679px)
+ grid-template-columns: auto max-content
+
+ &_warning
+ background: $spot-color-feedback-warning-light
+
+ &_info
+ background: $spot-color-feedback-info-light
+
+ &--text
+ margin: 0
+ line-height: 1
+
+ &--icon
+ font-size: 20px
+
+ &--title
+ font-weight: bold
+
+ &--button
+ margin: 0
diff --git a/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.ts b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.ts
new file mode 100644
index 00000000000..bbee9269078
--- /dev/null
+++ b/frontend/src/app/shared/components/modal/modal-banner/modal-banner.component.ts
@@ -0,0 +1,55 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2022 the OpenProject GmbH
+//
+// 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 COPYRIGHT and LICENSE files for more details.
+//++
+
+import {
+ ChangeDetectionStrategy,
+ Component,
+ EventEmitter,
+ Input,
+ Output,
+} from '@angular/core';
+
+@Component({
+ selector: 'op-modal-banner',
+ templateUrl: './modal-banner.component.html',
+ styleUrls: ['./modal-banner.component.sass'],
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class OpModalBannerComponent {
+ @Input() type:'info'|'warning' = 'info';
+
+ @Input() title:string;
+
+ @Input() subtitle:string;
+
+ @Input() actionButton?:string;
+
+ @Input() actionButtonClasses?:string;
+
+ @Output() buttonClicked = new EventEmitter<MouseEvent>();
+}
diff --git a/frontend/src/app/shared/components/modal/modal.module.ts b/frontend/src/app/shared/components/modal/modal.module.ts
index 107d524f611..2f3d7392bd1 100644
--- a/frontend/src/app/shared/components/modal/modal.module.ts
+++ b/frontend/src/app/shared/components/modal/modal.module.ts
@@ -5,6 +5,7 @@ import { IconModule } from 'core-app/shared/components/icon/icon.module';
import { OpModalService } from './modal.service';
import { OpModalWrapperAugmentService } from './modal-wrapper-augment.service';
import { OpModalHeaderComponent } from './modal-header.component';
+import { OpModalBannerComponent } from 'core-app/shared/components/modal/modal-banner/modal-banner.component';
@NgModule({
imports: [
@@ -12,11 +13,18 @@ import { OpModalHeaderComponent } from './modal-header.component';
FocusModule,
IconModule,
],
- exports: [OpModalHeaderComponent],
+ exports: [
+ OpModalHeaderComponent,
+ OpModalBannerComponent,
+ ],
providers: [
OpModalService,
OpModalWrapperAugmentService,
],
- declarations: [OpModalHeaderComponent],
+ declarations: [
+ OpModalHeaderComponent,
+ OpModalBannerComponent,
+
+ ],
})
export class OpenprojectModalModule { }
diff --git a/spec/features/work_packages/details/date_editor_spec.rb b/spec/features/work_packages/details/date_editor_spec.rb
index f88dad0b8ac..e20c836b367 100644
--- a/spec/features/work_packages/details/date_editor_spec.rb
+++ b/spec/features/work_packages/details/date_editor_spec.rb
@@ -41,6 +41,7 @@ describe 'date inplace editor',
let(:user) { create :admin }
let(:work_packages_page) { Pages::FullWorkPackage.new(work_package, project) }
let(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let(:wp_timeline) { Pages::WorkPackagesTimeline.new }
let(:start_date) { work_packages_page.edit_field(:combinedDate) }
@@ -275,4 +276,202 @@ describe 'date inplace editor',
expect(wp.custom_value_for(date_cf.id).value).to eq Time.zone.today.iso8601
end
end
+
+ context 'with the work package having no relations whatsoever' do
+ let!(:work_package) { create :work_package, project: }
+
+ before do
+ start_date.activate!
+ start_date.expect_active!
+ end
+
+ it 'does not show a banner with or without manual scheduling' do
+ expect(page).to have_no_selector('[data-qa-selector="op-modal-banner-warning"]')
+ expect(page).to have_no_selector('[data-qa-selector="op-modal-banner-info"]')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: false
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: true
+
+ expect(page).to have_no_selector('[data-qa-selector="op-modal-banner-warning"]')
+ expect(page).to have_no_selector('[data-qa-selector="op-modal-banner-info"]')
+ end
+ end
+
+ context 'with the work package being a parent' do
+ let!(:child) { create :work_package, project:, start_date: 1.day.ago, due_date: 5.days.from_now }
+ let!(:work_package) do
+ wp = create :work_package, project: project, schedule_manually: schedule_manually
+ child.update! parent: wp
+ wp
+ end
+
+ before do
+ start_date.activate!
+ start_date.expect_active!
+ end
+
+ context 'when parent is manually scheduled' do
+ let(:schedule_manually) { true }
+
+ it 'shows a banner that the relations are ignored' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: true
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: false
+
+ # Expect banner to switch
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Automatically scheduled. Dates are derived from relations.')
+
+ new_window = window_opened_by { click_on 'Show relations' }
+ switch_to_window new_window
+
+ wp_table.expect_work_package_listed child
+ wp_timeline.expect_timeline!
+ end
+ end
+
+ context 'when parent is not manually scheduled' do
+ let(:schedule_manually) { false }
+
+ it 'shows a banner that the dates are not editable' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Automatically scheduled. Dates are derived from relations.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: false
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: true
+
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+
+ new_window = window_opened_by { click_on 'Show relations' }
+ switch_to_window new_window
+
+ wp_table.expect_work_package_listed child
+ wp_timeline.expect_timeline!
+ end
+ end
+ end
+
+ context 'with the work package having a precedes relation' do
+ let!(:work_package) { create :work_package, project:, schedule_manually: }
+ let!(:preceding) { create :work_package, project:, start_date: 10.days.ago, due_date: 5.days.ago }
+
+ let!(:relationship) do
+ create :relation,
+ from: preceding,
+ to: work_package,
+ relation_type: Relation::TYPE_PRECEDES
+ end
+
+ before do
+ start_date.activate!
+ start_date.expect_active!
+ end
+
+ context 'when work package is manually scheduled' do
+ let(:schedule_manually) { true }
+
+ it 'shows a banner that the relations are ignored' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: true
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: false
+
+ # Expect new banner info
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Available start date is limited by relations.')
+
+ new_window = window_opened_by { click_on 'Show relations' }
+ switch_to_window new_window
+
+ wp_table.expect_work_package_listed preceding
+ wp_timeline.expect_timeline!
+ end
+ end
+
+ context 'when work package is not manually scheduled' do
+ let(:schedule_manually) { false }
+
+ it 'shows a banner that the start date is limited' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Available start date is limited by relations.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: false
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: true
+
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+ end
+ end
+ end
+
+ context 'with the work package having a follows relation' do
+ let!(:work_package) { create :work_package, project:, schedule_manually: }
+ let!(:following) { create :work_package, project:, start_date: 5.days.from_now, due_date: 10.days.from_now }
+
+ let!(:relationship) do
+ create :relation,
+ from: following,
+ to: work_package,
+ relation_type: Relation::TYPE_FOLLOWS
+ end
+
+ before do
+ start_date.activate!
+ start_date.expect_active!
+ end
+
+ context 'when work package is manually scheduled' do
+ let(:schedule_manually) { true }
+
+ it 'shows a banner that the relations are ignored' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: true
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: false
+
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Changing these dates will affect dates of related work packages.')
+
+ new_window = window_opened_by { click_on 'Show relations' }
+ switch_to_window new_window
+
+ wp_table.expect_work_package_listed following
+ wp_timeline.expect_timeline!
+ end
+ end
+
+ context 'when work package is not manually scheduled' do
+ let(:schedule_manually) { false }
+
+ it 'shows a banner that the start date is limited' do
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-info"] span',
+ text: 'Changing these dates will affect dates of related work packages.')
+
+ # When toggling manuallly scheduled
+ start_date.expect_scheduling_mode manually: false
+ start_date.toggle_scheduling_mode
+ start_date.expect_scheduling_mode manually: true
+
+ expect(page).to have_selector('[data-qa-selector="op-modal-banner-warning"] span',
+ text: 'Manual scheduling enabled, all relations ignored.')
+ end
+ end
+ end
end