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

Add "in your timezone" for legends

Oliver Günther0f1e8e5f40f6
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index bb2f2ae9425..ae231709381 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -1368,6 +1368,7 @@ en:
now_meets_filter_criteria: 'Now meets filter criteria'
no_longer_meets_filter_criteria: 'No longer meets filter criteria'
maintained_with_changes: 'Maintained with changes'
+ in_your_timezone: 'In your local timezone:'
forms:
submit_success_message: 'The form was successfully submitted'
load_error_message: 'There was an error loading the form'
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
index 161a6b230f0..8a56003278e 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
@@ -1,4 +1,5 @@
import { DEFAULT_TIMESTAMP } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
+import * as moment from 'moment-timezone';
export type BaselineOption = 'oneDayAgo'|'lastWorkingDay'|'oneWeekAgo'|'oneMonthAgo'|'aSpecificDate'|'betweenTwoSpecificDates';
@@ -20,3 +21,18 @@ export function baselineFilterFromValue(selectedDates:string[]):BaselineOption|n
return 'betweenTwoSpecificDates';
}
+
+export function getOffsetFromBaseline(value:string):string|null {
+ if (value.includes('@')) {
+ const [, timeWithZone] = value.split(/[@]/);
+ const [, offset] = timeWithZone.split(/\s+/)[0];
+ return offset;
+ }
+
+ if (value !== 'PT0S') {
+ const date = moment(value);
+ return date.format('Z');
+ }
+
+ return null;
+}
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.html b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.html
index 71843208cc0..65ab41f1ebf 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.html
@@ -1,4 +1,22 @@
-<span class="op-baseline-legends--filter">{{ text.time_description }}</span>
+<span class="op-baseline-legends--filter">
+ <span [textContent]="legendDescription"></span>
+ &ngsp;
+ <spot-tooltip
+ *ngIf="userOffset !== offset"
+ >
+ <span
+ slot="trigger"
+ class="spot-icon spot-icon_info2"
+ ></span>
+ <p
+ slot="body"
+ class="spot-body-small"
+ >
+ {{ text.in_your_timezone }}
+ {{ localDate }}
+ </p>
+ </spot-tooltip>
+</span>
<div class="op-baseline-legends--details hidden-for-mobile">
<span class="spot-icon spot-icon_add op-baseline-legends--details-icon-added"></span>
<span class="op-baseline-legends--details-added">{{text.now_meets_filter_criteria}}</span>
@@ -6,4 +24,4 @@
<span class="op-baseline-legends--details-removed">{{text.no_longer_meets_filter_criteria}}</span>
<span class="spot-icon spot-icon_arrow-left-right op-baseline-legends--details-icon-changed"></span>
<span class="op-baseline-legends--details-changed">{{text.maintained_with_changes}}</span>
-</div>
\ No newline at end of file
+</div>
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.sass b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.sass
index d215fb2e8c0..226b57a122c 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.sass
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.sass
@@ -8,6 +8,11 @@
border: 1px solid $spot-color-basic-gray-4
line-height: $spot-spacing-1_5
+ &--filter
+ display: flex
+ align-items: center
+ column-gap: $spot-spacing-0_5
+
&--details
display: flex
flex-direction: row
@@ -20,4 +25,4 @@
color: #35C53F
&-icon-changed
- color: #54AFE0
\ No newline at end of file
+ color: #54AFE0
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
index 6cae3daae1d..a52048acba3 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts
@@ -31,6 +31,7 @@ import {
ChangeDetectorRef,
Component,
HostBinding,
+ OnInit,
ViewEncapsulation,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -41,10 +42,16 @@ import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
-import { baselineFilterFromValue } from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';
+import {
+ baselineFilterFromValue,
+ getOffsetFromBaseline,
+} from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import * as moment from 'moment-timezone';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import { Moment } from 'moment';
+import { filter } from 'rxjs/operators';
@Component({
templateUrl: './baseline-legends.component.html',
@@ -53,7 +60,7 @@ import { ConfigurationService } from 'core-app/core/config/configuration.service
selector: 'op-baseline-legends',
encapsulation: ViewEncapsulation.None,
})
-export class OpBaselineLegendsComponent {
+export class OpBaselineLegendsComponent extends UntilDestroyedMixin implements OnInit {
@HostBinding('class.op-baseline-legends') className = true;
public numAdded = 0;
@@ -62,11 +69,21 @@ export class OpBaselineLegendsComponent {
public numUpdated = 0;
+ public offset:string|null;
+
+ public userOffset:string;
+
+ public userTimezone:string;
+
+ public localDate:string;
+
+ public legendDescription:string;
+
public text = {
- time_description: '',
now_meets_filter_criteria: this.I18n.t('js.baseline.legends.now_meets_filter_criteria'),
no_longer_meets_filter_criteria: this.I18n.t('js.baseline.legends.no_longer_meets_filter_criteria'),
maintained_with_changes: this.I18n.t('js.baseline.legends.maintained_with_changes'),
+ in_your_timezone: this.I18n.t('js.baseline.legends.in_your_timezone'),
};
constructor(
@@ -79,49 +96,96 @@ export class OpBaselineLegendsComponent {
readonly configuration:ConfigurationService,
readonly cdRef:ChangeDetectorRef,
) {
- this.getBaselineDetails();
- this.getFilterName();
+ super();
+ }
+
+ ngOnInit() {
+ this
+ .wpTableBaseline
+ .live$()
+ .pipe(
+ this.untilDestroyed(),
+ filter(() => this.wpTableBaseline.isActive())
+ )
+ .subscribe((timestamps) => {
+ this.offset = getOffsetFromBaseline(timestamps[0]);
+ this.userTimezone = this.timezoneService.userTimezone();
+ this.userOffset = moment().tz(this.userTimezone).format('Z') as string;
+
+ this.getBaselineDetails();
+ this.getFilterName(timestamps);
+ this.cdRef.detectChanges();
+ });
}
- public getFilterName() {
- const timestamps = this.wpTableBaseline.current;
- const datesAndTimes = this.wpTableBaseline.current.map((el) => el.split(/[@T]/));
+ public getFilterName(timestamps:string[]) {
+ const datesAndTimes = timestamps.map((el) => el.split(/[@T]/));
const filter = baselineFilterFromValue(this.wpTableBaseline.current);
const changesSince = this.I18n.t('js.baseline.legends.changes_since');
- let dateTime = '';
+ let description = '';
+ let upstreamDate = '';
+ let localDate = '';
switch (filter) {
case 'oneDayAgo':
- dateTime = this.I18n.t('js.baseline.drop_down.yesterday');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.yesterdayDate(), datesAndTimes[0][1])})`;
+ [upstreamDate, localDate] = this.deriveSingleDate(this.wpTableBaseline.yesterdayDate(), datesAndTimes[0][1]);
+ description = this.I18n.t('js.baseline.drop_down.yesterday');
+ description += ` (${upstreamDate})`;
break;
case 'lastWorkingDay':
- dateTime = this.I18n.t('js.baseline.drop_down.last_working_day');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastWorkingDate(), datesAndTimes[0][1])})`;
+ [upstreamDate, localDate] = this.deriveSingleDate(this.wpTableBaseline.lastWorkingDate(), datesAndTimes[0][1]);
+ description = this.I18n.t('js.baseline.drop_down.last_working_day');
+ description += ` (${upstreamDate})`;
break;
case 'oneWeekAgo':
- dateTime = this.I18n.t('js.baseline.drop_down.last_week');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastweekDate(), datesAndTimes[0][1])})`;
+ [upstreamDate, localDate] = this.deriveSingleDate(this.wpTableBaseline.lastweekDate(), datesAndTimes[0][1]);
+ description = this.I18n.t('js.baseline.drop_down.last_week');
+ description += ` (${upstreamDate})`;
break;
case 'oneMonthAgo':
- dateTime = this.I18n.t('js.baseline.drop_down.last_month');
- dateTime += ` (${this.getFormattedDate(this.wpTableBaseline.lastMonthDate(), datesAndTimes[0][1])})`;
+ [upstreamDate, localDate] = this.deriveSingleDate(this.wpTableBaseline.lastMonthDate(), datesAndTimes[0][1]);
+ description = this.I18n.t('js.baseline.drop_down.last_month');
+ description += ` (${upstreamDate})`;
break;
case 'aSpecificDate':
- dateTime = this.I18n.t('js.baseline.drop_down.a_specific_date');
- dateTime += ` (${this.timezoneService.formattedDatetime(timestamps[0])})`;
+ [upstreamDate, localDate] = this.formatUpstreamAndLocal(moment(timestamps[0]));
+ description = this.I18n.t('js.baseline.drop_down.a_specific_date');
+ description += ` (${upstreamDate})`;
break;
case 'betweenTwoSpecificDates':
- dateTime = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');
- dateTime += ` (${this.timezoneService.formattedDatetime(timestamps[0])} - ${this.timezoneService.formattedDatetime(timestamps[1])})`;
+ [upstreamDate, localDate] = this.deriveDateRange(moment(timestamps[0]), moment(timestamps[1]));
+ description = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');
+ description += ` (${upstreamDate})`;
break;
default:
- dateTime = '';
break;
}
- dateTime = `${changesSince} ${dateTime}`;
- this.text.time_description = dateTime;
- return dateTime;
+ description = `${changesSince} ${description}`;
+ this.legendDescription = description;
+ this.localDate = localDate;
+ return description;
+ }
+
+ private deriveSingleDate(date:string, timestamp:string):[string, string] {
+ const parsedDate:Moment = moment(`${date}T${timestamp}`);
+ return this.formatUpstreamAndLocal(parsedDate);
+ }
+
+ private deriveDateRange(start:Moment, end:Moment):[string, string] {
+ const startRange = this.formatUpstreamAndLocal(start);
+ const endRange = this.formatUpstreamAndLocal(end);
+
+ return [
+ `${startRange[0]} - ${endRange[0]}`,
+ `${startRange[1]} - ${endRange[1]}`,
+ ];
+ }
+
+ private formatUpstreamAndLocal(date:Moment):[string, string] {
+ return [
+ this.formatDate(date),
+ this.formatDate(date.tz(this.userTimezone)),
+ ];
}
public getBaselineDetails() {
@@ -151,12 +215,10 @@ export class OpBaselineLegendsComponent {
}
}
- private getFormattedDate(date:string, time:string):string {
- const combined = moment(`${date}T${time}`);
-
- const formattedDate = combined.format(this.timezoneService.getDateFormat());
- const formattedTime = combined.format(this.timezoneService.getTimeFormat());
- const offset = combined.format('Z');
+ private formatDate(date:Moment):string {
+ const formattedDate = date.format(this.timezoneService.getDateFormat());
+ const formattedTime = date.format(this.timezoneService.getTimeFormat());
+ const offset = date.format('Z');
return `${formattedDate} ${formattedTime} ${offset}`;
}
@@ -170,10 +232,4 @@ export class OpBaselineLegendsComponent {
return Object.prototype.hasOwnProperty.call(base, name) || Object.prototype.hasOwnProperty.call(base.$links, name);
});
}
-
- public refresh() {
- this.getBaselineDetails();
- this.getFilterName();
- this.cdRef.detectChanges();
- }
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
index d2d83ff3e8f..77c88181a63 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
@@ -85,8 +85,6 @@ export interface WorkPackageFocusContext {
selector: 'wp-table',
})
export class WorkPackagesTableComponent extends UntilDestroyedMixin implements OnInit, TableEventComponent {
- @ViewChild(OpBaselineLegendsComponent) baselineLegends:OpBaselineLegendsComponent;
-
@Input() projectIdentifier:string;
@Input('configuration') configurationObject:WorkPackageTableConfigurationObject;
@@ -219,7 +217,6 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O
}
if (this.baselineEnabled) {
- this.baselineLegends?.refresh();
this.numTableColumns += 1;
}