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

Extend baseline to deal with two dates

Oliver Günther052528cd5133
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index f23f94e00b1..d7babd971f9 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -1353,6 +1353,8 @@ en:
help_description: 'Default time zone of the instance set by the administrator.'
time_description: 'In default time zone: %{time} %{days} day(s).'
time: 'Time'
+ from: 'From'
+ to: 'To'
drop_down:
none: '-'
yesterday: 'yesterday'
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
index e1ce843521a..1c202cf5007 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.html
@@ -2,6 +2,7 @@
*ngIf="(nonWorkingDays$ | async); else loadingTemplate"
(submit)="onSubmit($event)"
class="spot-container op-baseline--body"
+ [class.op-baseline--body_ranged]="selectedFilter === 'betweenTwoSpecificDates'"
>
<spot-form-field
[label]="text.show_changes_since">
@@ -29,15 +30,29 @@
</spot-form-field>
<spot-form-field
+ [label]="text.date"
+ *ngIf="selectedFilter === 'aSpecificDate'"
+ class="op-baseline--date">
+
+ <input
+ slot="input"
+ name="op-baseline-date"
+ [value]="selectedDates[0] || ''"
+ (input)="dateChange([$event.target.value, ''])"
+ type="text"
+ class="op-baseline--date-input"/>
+ </spot-form-field>
+
+ <spot-form-field
+ *ngIf="selectedFilter && selectedFilter !== 'betweenTwoSpecificDates'"
[label]="text.time"
- *ngIf="filterSelected"
class="op-baseline--time">
<input
slot="input"
name="op-baseline-time"
[value]="selectedTime"
- (change)="timeChange($event.target.value)"
+ (change)="timesChange([$event.target.value])"
type="time"
class="op-baseline--time-input"/>
@@ -55,15 +70,105 @@
<span slot="description" [textContent]="text.time_description()"></span>
</spot-form-field>
+ <div
+ *ngIf="selectedFilter === 'betweenTwoSpecificDates'"
+ class="op-baseline--range-container"
+ >
+
+ <spot-form-field
+ [label]="text.from"
+ class="op-baseline--from-date">
+
+ <input
+ slot="input"
+ name="op-baseline-from-date"
+ [value]="selectedDates[0] || ''"
+ (input)="dateChange([$event.target.value, selectedDates[1] || ''])"
+ type="text"
+ class="op-baseline--date-input"/>
+ </spot-form-field>
+
+ <spot-form-field
+ [label]="text.to"
+ class="op-baseline--date">
+
+ <input
+ slot="input"
+ name="op-baseline-to-date"
+ [value]="selectedDates[1] || ''"
+ (input)="dateChange([selectedDates[1] || '', $event.target.value])"
+ type="text"
+ class="op-baseline--date-input"/>
+ </spot-form-field>
+
+ <spot-form-field
+ class="op-baseline--time">
+
+ <input
+ slot="input"
+ name="op-baseline-time"
+ [value]="selectedTimes[0] || ''"
+ (change)="timeChange($event.target.value)"
+ type="time"
+ class="op-baseline--time-input"/>
+
+ <spot-tooltip
+ slot="input"
+ class="op-baseline--time-tooltip op-baseline--time-help spot-body-small"
+ [alignment]="tooltipPosition"
+ [disabled]="false"
+ [light]="true">
+ <span slot="trigger">{{text.timeZone}}</span>
+ <span slot="body" class="spot-body-small op-baseline--time-tooltip-body">{{ text.help_description }}</span>
+ </spot-tooltip>
+
+
+ <span slot="description" [textContent]="text.time_description()"></span>
+ </spot-form-field>
+
+ <spot-form-field
+ class="op-baseline--time">
+
+ <input
+ slot="input"
+ name="op-baseline-time"
+ [value]="selectedTimes[1] || ''"
+ (change)="timeChange($event.target.value)"
+ type="time"
+ class="op-baseline--time-input"/>
+
+ <spot-tooltip
+ slot="input"
+ class="op-baseline--time-tooltip op-baseline--time-help spot-body-small"
+ [alignment]="tooltipPosition"
+ [disabled]="false"
+ [light]="true">
+ <span slot="trigger">{{text.timeZone}}</span>
+ <span slot="body" class="spot-body-small op-baseline--time-tooltip-body">{{ text.help_description }}</span>
+ </spot-tooltip>
+
+
+ <span slot="description" [textContent]="text.time_description()"></span>
+ </spot-form-field>
+ </div>
+
+ <op-datepicker-sheet
+ *ngIf="selectedFilter === 'aSpecificDate' || selectedFilter === 'betweenTwoSpecificDates'"
+ [dates]="selectedDates"
+ [mode]="selectedFilter === 'betweenTwoSpecificDates' ? 'range' : 'single'"
+ (datesSelected)="selectedDates = $event"
+ >
+ </op-datepicker-sheet>
+
<div class="spot-action-bar"
*ngIf="showActionBar">
<div class="spot-action-bar--right">
<button
class="button spot-action-bar--action"
- [disabled]="!filterSelected"
+ [disabled]="!selectedFilter"
type="button"
- (click)="clearSelection()"
+ (click)="resetSelection()"
>
{{ text.clear }}
</button>
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
index 9c6a484fb9f..c0a71404424 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.sass
@@ -11,6 +11,10 @@
@media screen and #{$spot-mq-drop-modal-in-context}
width: 300px
max-height: 70vh
+
+ &_ranged
+ width: 600px
+
&--time
&-input
@@ -37,3 +41,9 @@
font-style: italic
line-height: $spot-spacing-1
color: $spot-color-basic-gray-2
+
+ &--range-container
+ margin: 1rem
+ display: grid
+ grid-template-columns: 1fr 1fr
+ grid-gap: 1rem
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
index bc0e5b948e6..045ff59d53e 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.ts
@@ -50,6 +50,7 @@ import {
DEFAULT_TIMESTAMP,
WorkPackageViewBaselineService,
} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
+import { validDate } from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';
@Component({
selector: 'op-baseline',
@@ -68,15 +69,13 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
public nonWorkingDays$:Observable<IDay[]> = this.wpTableBaseline.nonWorkingDays$;
- public selectedDate = '';
+ public selectedDates:string[];
- public selectedTime = '00:00';
+ public selectedTimes:string[];
- public selectedFilter = '-';
+ public selectedFilter:string|null;
- public selectedTimezoneFormattedTime = `${this.selectedTime}+00:00`;
-
- public filterSelected = false;
+ public selectedTimezoneFormattedTime:string[];
public daysNumber = 0;
@@ -89,10 +88,16 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
clear: this.I18n.t('js.baseline.clear'),
apply: this.I18n.t('js.baseline.apply'),
show_changes_since: this.I18n.t('js.baseline.show_changes_since'),
+ from: this.I18n.t('js.baseline.from'),
+ to: this.I18n.t('js.baseline.to'),
+ date: this.I18n.t('js.label_date'),
time: this.I18n.t('js.baseline.time'),
help_description: this.I18n.t('js.baseline.help_description'),
timeZone: this.configuration.isTimezoneSet() ? moment().tz(this.configuration.timezone()).zoneAbbr() : 'local',
- time_description: () => this.I18n.t('js.baseline.time_description', { time: this.selectedTimezoneFormattedTime, days: this.daysNumber }),
+ time_description: () => this.I18n.t('js.baseline.time_description', {
+ time: this.selectedTimezoneFormattedTime,
+ days: this.daysNumber,
+ }),
};
public baselineAvailableValues = [
@@ -135,23 +140,27 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
}
public ngOnInit():void {
+ this.resetSelection();
+
if (this.wpTableBaseline.isActive()) {
- const value = this.wpTableBaseline.current[0];
- const [date, timeWithZone] = value.split('@');
- const time = timeWithZone.split(/[+-]/)[0];
-
- this.filterChange(date);
- this.selectedTime = time || '00:00';
- this.selectedTimezoneFormattedTime = timeWithZone || '00:00+00:00';
- this.filterSelected = true;
+ this.wpTableBaseline.current.forEach((value, i) => {
+ const [date, timeWithZone] = value.split('@');
+ const time = timeWithZone.split(/[+-]/)[0];
+
+ this.selectedDates[i] = date;
+ this.selectedTimes[i] = time || '00:00';
+ this.selectedTimezoneFormattedTime[i] = timeWithZone || '00:00+00:00';
+ });
+
+ this.filterChange(this.filterFromSelected(this.selectedDates));
}
}
- public clearSelection():void {
- this.filterSelected = false;
- this.selectedTime = '0:00';
- this.selectedDate = '';
- this.selectedFilter = '-';
+ public resetSelection():void {
+ this.selectedTimes = ['00:00', '00:00'];
+ this.selectedTimezoneFormattedTime = this.selectedTimes.map((time) => `${time}+00:00`);
+ this.selectedDates = ['', ''];
+ this.selectedFilter = null;
this.dropDownDescription = '';
}
@@ -161,7 +170,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
}
public onSave() {
- if (this.selectedFilter === '-') {
+ if (!this.selectedFilter) {
this.wpTableBaseline.disable();
} else {
const filterString = `${this.selectedFilter}@${this.selectedTimezoneFormattedTime}`;
@@ -171,41 +180,56 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {
this.submitted.emit();
}
- public timeChange(value:string):void {
- this.selectedTime = value;
- const dateTime= `${this.selectedDate} ${value}`;
- this.selectedTimezoneFormattedTime = this.timezoneService.formattedTime(dateTime, 'HH:mmZ');
+ public timesChange(value:string[]):void {
+ this.selectedTimes = value;
+ this.selectedTimezoneFormattedTime = this.selectedDates
+ .map((el:string, i:number) => {
+ const dateTime = `${el} ${value[i]}`;
+ return this.timezoneService.formattedTime(dateTime, 'HH:mmZ');
+ });
}
- public filterChange(value:string):void {
- if (value !== '-') {
- this.filterSelected = true;
- this.selectedFilter = value;
- switch (value) {
- case 'oneDayAgo':
- this.dropDownDescription = this.wpTableBaseline.yesterdayDate();
- this.daysNumber = this.wpTableBaseline.daysNumber;
- break;
- case 'lastWorkingDay':
- this.dropDownDescription = this.wpTableBaseline.lastWorkingDate();
- this.daysNumber = this.wpTableBaseline.daysNumber;
- break;
- case 'oneWeekAgo':
- this.dropDownDescription = this.wpTableBaseline.lastweekDate();
- this.daysNumber =this.wpTableBaseline.daysNumber;
- break;
- case 'oneMonthAgo':
- this.dropDownDescription = this.wpTableBaseline.lastMonthDate();
- this.daysNumber = this.wpTableBaseline.daysNumber;
- break;
- default:
- this.dropDownDescription = '';
- this.daysNumber = 0;
- break;
- }
- this.selectedDate = this.dropDownDescription;
- } else {
- this.clearSelection();
+ public dateChange(values:string[]):void {
+ if (_.every(values, validDate)) {
+ this.selectedDates = values;
+ }
+ }
+
+ public filterChange(value:string|null):void {
+ this.selectedFilter = value;
+ switch (value) {
+ case 'oneDayAgo':
+ this.dropDownDescription = this.wpTableBaseline.yesterdayDate();
+ this.daysNumber = this.wpTableBaseline.daysNumber;
+ break;
+ case 'lastWorkingDay':
+ this.dropDownDescription = this.wpTableBaseline.lastWorkingDate();
+ this.daysNumber = this.wpTableBaseline.daysNumber;
+ break;
+ case 'oneWeekAgo':
+ this.dropDownDescription = this.wpTableBaseline.lastweekDate();
+ this.daysNumber = this.wpTableBaseline.daysNumber;
+ break;
+ case 'oneMonthAgo':
+ this.dropDownDescription = this.wpTableBaseline.lastMonthDate();
+ this.daysNumber = this.wpTableBaseline.daysNumber;
+ break;
+ default:
+ this.dropDownDescription = '';
+ this.daysNumber = 0;
+ break;
+ }
+ }
+
+ private filterFromSelected(selectedDates:string[]):string {
+ if (selectedDates.length === 2) {
+ return 'betweenTwoSpecificDates';
}
+
+ if (['oneDayAgo', 'lastWorkingDay', 'oneWeekAgo', 'oneMonthAgo'].includes(selectedDates[0])) {
+ return selectedDates[0];
+ }
+
+ return 'aSpecificDate';
}
}