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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Avoid saving variables in baseline service
Oliver Günther9dfe8388956c
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex d7babd971f9..bfb164cdd53 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1351,7 +1351,7 @@ en:header_description: 'View changes made to work packages in the current view within a time period.'show_changes_since: 'Show changes since'help_description: 'Default time zone of the instance set by the administrator.'- time_description: 'In default time zone: %{time} %{days} day(s).'+ time_description: 'In your time zone: %{time} %{days} day(s).'time: 'Time'from: 'From'to: 'To'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.tsnew file mode 100644index 00000000000..161a6b230f0--- /dev/null+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts@@ -0,0 +1,22 @@+import { DEFAULT_TIMESTAMP } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';++export type BaselineOption = 'oneDayAgo'|'lastWorkingDay'|'oneWeekAgo'|'oneMonthAgo'|'aSpecificDate'|'betweenTwoSpecificDates';++const BASELINE_OPTIONS = ['oneDayAgo', 'lastWorkingDay', 'oneWeekAgo', 'oneMonthAgo', 'aSpecificDate', 'betweenTwoSpecificDates'];++export function baselineFilterFromValue(selectedDates:string[]):BaselineOption|null {+ if (selectedDates.length < 2) {+ return null;+ }++ const first = selectedDates[0].split('@')[0];+ if (BASELINE_OPTIONS.includes(first)) {+ return first as BaselineOption;+ }++ if (selectedDates[1] === DEFAULT_TIMESTAMP) {+ return 'aSpecificDate';+ }++ return 'betweenTwoSpecificDates';+}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.tsindex 05105fb51d6..d2839494d58 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@@ -41,6 +41,7 @@ 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';@Component({templateUrl: './baseline-legends.component.html',@@ -78,35 +79,42 @@ export class OpBaselineLegendsComponent {}public getFilterName() {- const timestamp = this.wpTableBaseline.current[0].split(/[@T]/);- const filter = timestamp[0];- let dateTime = '';+ const timestamps = this.wpTableBaseline.current.map((el) => el.split(/[@T]/));+ const filter = baselineFilterFromValue(this.wpTableBaseline.current);const changesSince = this.I18n.t('js.baseline.legends.changes_since');- const time = timestamp[1].split(/[+-]/)[0];+ const time = timestamps[0][1].split(/[+-]/)[0];+ let dateTime = '';+switch (filter) {case 'oneDayAgo':dateTime = this.I18n.t('js.baseline.drop_down.yesterday');+ dateTime += ` (${this.wpTableBaseline.yesterdayDate()[0]}, ${timestamps[0][1]})`;break;case 'lastWorkingDay':dateTime = this.I18n.t('js.baseline.drop_down.last_working_day');+ dateTime += ` (${this.wpTableBaseline.lastWorkingDate()[0]}, ${timestamps[0][1]})`;break;case 'oneWeekAgo':dateTime = this.I18n.t('js.baseline.drop_down.last_week');+ dateTime += ` (${this.wpTableBaseline.lastweekDate()[0]}, ${timestamps[0][1]})`;break;case 'oneMonthAgo':dateTime = this.I18n.t('js.baseline.drop_down.last_month');+ dateTime += ` (${this.wpTableBaseline.lastMonthDate()[0]}, ${timestamps[0][1]})`;break;case 'aSpecificDate':dateTime = this.I18n.t('js.baseline.drop_down.a_specific_date');+ dateTime += ` (${timestamps[0].join(', ')})`;break;case 'betweenTwoSpecificDates':dateTime = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');+ dateTime += ` (${timestamps[0].join(', ')} - ${timestamps[1].join(', ')})`;break;default:dateTime = '';break;}- dateTime = `${changesSince} ${dateTime} (${this.wpTableBaseline.selectedDate}, ${time})`;+ dateTime = `${changesSince} ${dateTime}`;this.text.time_description = dateTime;return dateTime;}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.htmlindex 65c706d8d56..72f4a735f81 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@@ -67,7 +67,7 @@</spot-tooltip>- <span slot="description" [textContent]="text.time_description()"></span>+ <span slot="description" [textContent]="text.time_description(0)"></span></spot-form-field><div@@ -123,7 +123,7 @@</spot-tooltip>- <span slot="description" [textContent]="text.time_description()"></span>+ <span slot="description" [textContent]="text.time_description(0)"></span></spot-form-field><spot-form-field@@ -148,7 +148,7 @@</spot-tooltip>- <span slot="description" [textContent]="text.time_description()"></span>+ <span slot="description" [textContent]="text.time_description(1)"></span></spot-form-field></div>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.tsindex 8cb6d1e0a48..7f4d60c19b6 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@@ -51,10 +51,7 @@ import {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';--type BaselineOption = 'oneDayAgo'|'lastWorkingDay'|'oneWeekAgo'|'oneMonthAgo'|'aSpecificDate'|'betweenTwoSpecificDates';--const BASELINE_OPTIONS = ['oneDayAgo', 'lastWorkingDay', 'oneWeekAgo', 'oneMonthAgo', 'aSpecificDate', 'betweenTwoSpecificDates'];+import { baselineFilterFromValue } from 'core-app/features/work-packages/components/wp-baseline/baseline-helpers';@Component({selector: 'op-baseline',@@ -100,8 +97,8 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {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,+ time_description: (i:number) => this.I18n.t('js.baseline.time_description', {+ time: this.selectedTimezoneFormattedTime[i],days: this.daysNumber,}),};@@ -149,7 +146,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {this.resetSelection();if (this.wpTableBaseline.isActive()) {- this.filterChange(this.filterFromSelected(this.wpTableBaseline.current));+ this.filterChange(baselineFilterFromValue(this.wpTableBaseline.current));this.wpTableBaseline.current.forEach((value, i) => {@@ -205,20 +202,16 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {this.selectedFilter = value;switch (value) {case 'oneDayAgo':- this.dropDownDescription = this.wpTableBaseline.yesterdayDate();- this.daysNumber = this.wpTableBaseline.daysNumber;+ [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.yesterdayDate();break;case 'lastWorkingDay':- this.dropDownDescription = this.wpTableBaseline.lastWorkingDate();- this.daysNumber = this.wpTableBaseline.daysNumber;+ [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastWorkingDate();break;case 'oneWeekAgo':- this.dropDownDescription = this.wpTableBaseline.lastweekDate();- this.daysNumber = this.wpTableBaseline.daysNumber;+ [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastweekDate();break;case 'oneMonthAgo':- this.dropDownDescription = this.wpTableBaseline.lastMonthDate();- this.daysNumber = this.wpTableBaseline.daysNumber;+ [this.dropDownDescription, this.daysNumber] = this.wpTableBaseline.lastMonthDate();break;default:this.dropDownDescription = '';@@ -227,22 +220,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {}}- private filterFromSelected(selectedDates:string[]):string|null {- if (selectedDates.length < 2) {- return null;- }-- const first = selectedDates[0].split('@')[0];- if (BASELINE_OPTIONS.includes(first)) {- return first;- }-- if (selectedDates[1] === DEFAULT_TIMESTAMP) {- return 'aSpecificDate';- }- return 'betweenTwoSpecificDates';- }private buildBaselineFilter():string[] {switch (this.selectedFilter) {diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.tsindex d9404ce6b38..f709b4fc695 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service.ts@@ -59,37 +59,35 @@ export class WorkPackageViewBaselineService extends WorkPackageQueryStateServicepublic nonWorkingDays:IDay[] = [];- public daysNumber = 0;-public nonWorkingDays$:Observable<IDay[]> = this.requireNonWorkingDaysOfTwoYears();- public selectedDate = '';-- public yesterdayDate():string {+ public yesterdayDate():[string, number] {const today = new Date();- this.daysNumber = -1;+ const daysNumber = -1;today.setDate(today.getDate() - 1);- this.selectedDate = this.timezoneService.formattedDate(today.toString());- return this.selectedDate;+ const selectedDate = this.timezoneService.formattedDate(today.toString());+ return [selectedDate, daysNumber];}- public lastMonthDate():string {+ public lastMonthDate():[string, number] {const today = new Date();const lastMonthDate = new Date(today);lastMonthDate.setMonth(today.getMonth() - 1);- this.selectedDate = this.timezoneService.formattedDate(lastMonthDate.toString());- this.daysNumber = moment(lastMonthDate).diff(moment(today), 'days');- return this.selectedDate;+ const selectedDate = this.timezoneService.formattedDate(lastMonthDate.toString());+ const daysNumber = moment(lastMonthDate).diff(moment(today), 'days');++ return [selectedDate, daysNumber];}- public lastweekDate():string {+ public lastweekDate():[string, number] {const today = new Date();- this.daysNumber = -7;+ const daysNumber = -7;today.setDate(today.getDate() - 7);- this.selectedDate = this.timezoneService.formattedDate(today.toString());- return this.selectedDate;+ const selectedDate = this.timezoneService.formattedDate(today.toString());++ return [selectedDate, daysNumber];}requireNonWorkingDaysOfTwoYears() {@@ -112,22 +110,24 @@ export class WorkPackageViewBaselineService extends WorkPackageQueryStateServicereturn (this.nonWorkingDays.findIndex((el) => el.date === formatted) !== -1);}- public lastWorkingDate():string {+ public lastWorkingDate():[string, number] {const today = new Date();const yesterday = new Date(today);- this.selectedDate = '';++ let selectedDate = '';+ let daysNumber = 0;yesterday.setDate(today.getDate() - 1);- while (this.selectedDate === '') {+ while (selectedDate === '') {if (this.isNonWorkingDay(yesterday) || this.weekdaysService.isNonWorkingDay(yesterday)) {yesterday.setDate(yesterday.getDate() - 1);- continue;} else {- this.selectedDate = this.timezoneService.formattedDate(yesterday.toString());- this.daysNumber = moment(yesterday).diff(moment(today), 'days');+ selectedDate = this.timezoneService.formattedDate(yesterday.toString());+ daysNumber = moment(yesterday).diff(moment(today), 'days');break;}}- return this.selectedDate;++ return [selectedDate, daysNumber];}public isActive():boolean {