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
[47911] Implement show changes legend (#12532)
Behrokh Satarnejadf3d659d3c3a8
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 33fbce0cabf..f23f94e00b1 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1361,6 +1361,11 @@ en:last_month: 'last month'a_specific_date: 'a specific date'between_two_specific_dates: 'between two specific dates'+ legends:+ changes_since: 'Changes since'+ now_meets_filter_criteria: 'Now meets filter criteria'+ no_longer_meets_filter_criteria: 'No longer meets filter criteria'+ maintained_with_changes: 'Maintained with changes'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-legends/baseline-legends.component.html b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.htmlnew file mode 100644index 00000000000..71843208cc0--- /dev/null+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.html@@ -0,0 +1,9 @@+<span class="op-baseline-legends--filter">{{ text.time_description }}</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>+ <span class="spot-icon spot-icon_minus1 op-baseline-legends--details-icon-removed"></span>+ <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 filediff --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.sassnew file mode 100644index 00000000000..d215fb2e8c0--- /dev/null+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.sass@@ -0,0 +1,23 @@+@import 'helpers'++.op-baseline-legends+ display: flex+ flex-direction: row+ align-items: center+ padding: $spot-spacing-0_75 $spot-spacing-1+ border: 1px solid $spot-color-basic-gray-4+ line-height: $spot-spacing-1_5++ &--details+ display: flex+ flex-direction: row+ align-items: flex-start+ justify-content: flex-end+ gap: $spot-spacing-1+ margin-left: auto++ &-icon-added+ color: #35C53F++ &-icon-changed+ color: #54AFE0\ No newline at end of filediff --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.tsnew file mode 100644index 00000000000..e200167b90a--- /dev/null+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component.ts@@ -0,0 +1,156 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2023 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,+ ChangeDetectorRef,+ Component,+ HostBinding,+ ViewEncapsulation,+} from '@angular/core';+import { I18nService } from 'core-app/core/i18n/i18n.service';+import { WorkPackageViewBaselineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';+import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';+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';++@Component({+ templateUrl: './baseline-legends.component.html',+ styleUrls: ['./baseline-legends.component.sass'],+ changeDetection: ChangeDetectionStrategy.OnPush,+ selector: 'op-baseline-legends',+ encapsulation: ViewEncapsulation.None,+})+export class OpBaselineLegendsComponent {+ @HostBinding('class.op-baseline-legends') className = true;++ public numAdded = 0;++ public numRemoved = 0;++ public numUpdated = 0;++ 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'),+ };++ constructor(+ readonly I18n:I18nService,+ readonly wpTableBaseline:WorkPackageViewBaselineService,+ readonly querySpace:IsolatedQuerySpace,+ readonly schemaCache:SchemaCacheService,+ readonly wpTableColumns:WorkPackageViewColumnsService,+ readonly cdRef:ChangeDetectorRef,+ ) {+ this.getBaselineDetails();+ this.getFilterName();+ }++ public getFilterName() {+ const timestamp = this.wpTableBaseline.current[0].split('@');+ const filter = timestamp[0];+ let dateTime = '';+ const changesSince = this.I18n.t('js.baseline.legends.changes_since');+ const time = timestamp[1].split(/[+-]/)[0];+ switch (filter) {+ case 'oneDayAgo':+ dateTime = this.I18n.t('js.baseline.drop_down.yesterday');+ break;+ case 'lastWorkingDay':+ dateTime = this.I18n.t('js.baseline.drop_down.last_working_day');+ break;+ case 'oneWeekAgo':+ dateTime = this.I18n.t('js.baseline.drop_down.last_week');+ break;+ case 'oneMonthAgo':+ dateTime = this.I18n.t('js.baseline.drop_down.last_month');+ break;+ case 'aSpecificDate':+ dateTime = this.I18n.t('js.baseline.drop_down.a_specific_date');+ break;+ case 'betweenTwoSpecificDates':+ dateTime = this.I18n.t('js.baseline.drop_down.between_two_specific_dates');+ break;+ default:+ dateTime = '';+ break;+ }+ dateTime = `${changesSince} ${dateTime} (${this.wpTableBaseline.selectedDate}, ${time})`;+ this.text.time_description = dateTime;+ return dateTime;+ }++ public getBaselineDetails() {+ this.numAdded = 0;+ this.numRemoved = 0;+ this.numUpdated = 0;+ const results = this.querySpace.results.value;+ if (results && results.elements.length > 0) {+ results.elements.forEach((workPackage:WorkPackageResource) => {+ const schema = this.schemaCache.of(workPackage);+ const timestamps = workPackage.attributesByTimestamp || [];+ if (timestamps.length > 1) {+ const base = timestamps[0];+ const compare = timestamps[1];+ if ((!base._meta.exists && compare._meta.exists) || (!base._meta.matchesFilters && compare._meta.matchesFilters)) {+ this.numAdded+=1;+ } else if ((base._meta.exists && !compare._meta.exists) || (base._meta.matchesFilters && !compare._meta.matchesFilters)) {+ this.numRemoved+=1;+ } else if (this.visibleAttributeChanged(base, schema)) {+ this.numUpdated+=1;+ }+ }+ });+ this.text.maintained_with_changes = `${this.I18n.t('js.baseline.legends.maintained_with_changes')} (${this.numUpdated})`;+ this.text.no_longer_meets_filter_criteria = `${this.I18n.t('js.baseline.legends.no_longer_meets_filter_criteria')} (${this.numRemoved})`;+ this.text.now_meets_filter_criteria = `${this.I18n.t('js.baseline.legends.now_meets_filter_criteria')} (${this.numAdded})`;+ }+ }++ private visibleAttributeChanged(base:IWorkPackageTimestamp, schema:ISchemaProxy):boolean {+ return !!this+ .wpTableColumns+ .getColumns()+ .find((column) => {+ const name = schema.mappedName(column.id);+ 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-baseline/baseline/baseline.component.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline/baseline.component.tsindex 91fc1e3b597..bc0e5b948e6 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@@ -66,9 +66,7 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {public dropDownDescription = '';- public nonWorkingDays:IDay[] = [];-- public nonWorkingDays$:Observable<IDay[]> = this.requireNonWorkingDaysOfTwoYears();+ public nonWorkingDays$:Observable<IDay[]> = this.wpTableBaseline.nonWorkingDays$;public selectedDate = '';@@ -173,66 +171,6 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {this.submitted.emit();}- public yesterdayDate():string {- const today = new Date();- this.daysNumber = -1;-- today.setDate(today.getDate() - 1);- this.selectedDate = this.timezoneService.formattedDate(today.toString());- return this.selectedDate;- }-- public lastMonthDate():string {- 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;- }-- public lastweekDate():string {- const today = new Date();- this.daysNumber = -7;- today.setDate(today.getDate() - 7);- this.selectedDate = this.timezoneService.formattedDate(today.toString());- return this.selectedDate;- }-- requireNonWorkingDaysOfTwoYears() {- const today = new Date();- const lastYear = new Date(today);- lastYear.setFullYear(today.getFullYear() - 1);- return this- .daysService- .requireNonWorkingYears$(lastYear, today);- }-- isNonWorkingDay(date:Date|string):boolean {- const formatted = moment(date).format('YYYY-MM-DD');- return (this.nonWorkingDays.findIndex((el) => el.date === formatted) !== -1);- }-- public lastWorkingDate():string {- const today = new Date();- const yesterday = new Date(today);- this.selectedDate = '';- yesterday.setDate(today.getDate() - 1);- while (this.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');- break;- }- }-- return this.selectedDate;- }-public timeChange(value:string):void {this.selectedTime = value;const dateTime= `${this.selectedDate} ${value}`;@@ -245,21 +183,27 @@ export class OpBaselineComponent extends UntilDestroyedMixin implements OnInit {this.selectedFilter = value;switch (value) {case 'oneDayAgo':- this.dropDownDescription = this.yesterdayDate();+ this.dropDownDescription = this.wpTableBaseline.yesterdayDate();+ this.daysNumber = this.wpTableBaseline.daysNumber;break;case 'lastWorkingDay':- this.dropDownDescription=this.lastWorkingDate();+ this.dropDownDescription = this.wpTableBaseline.lastWorkingDate();+ this.daysNumber = this.wpTableBaseline.daysNumber;break;case 'oneWeekAgo':- this.dropDownDescription = this.lastweekDate();+ this.dropDownDescription = this.wpTableBaseline.lastweekDate();+ this.daysNumber =this.wpTableBaseline.daysNumber;break;case 'oneMonthAgo':- this.dropDownDescription = this.lastMonthDate();+ 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();}diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.htmlindex 8a717a72df0..8df586fe9b7 100644--- a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html+++ b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html@@ -1,5 +1,8 @@<div class="work-packages-split-view--tabletimeline-content" *ngIf="query"><div class="work-packages-tabletimeline--table-side work-package-table--container __hidden_overflow_container">+ <op-baseline-legends+ *ngIf="baselineEnabled"+ ></op-baseline-legends><tableclass="keyboard-accessible-list generic-table work-package-table"[class.op-table-baseline]="baselineEnabled"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.tsindex 250f6f6e468..d2d83ff3e8f 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@@ -37,6 +37,7 @@ import {NgZone,OnInit,Output,+ ViewChild,ViewEncapsulation,} from '@angular/core';import { QueryResource } from 'core-app/features/hal/resources/query-resource';@@ -67,6 +68,7 @@ import {import { States } from 'core-app/core/states/states.service';import { QueryGroupByResource } from 'core-app/features/hal/resources/query-group-by-resource';import { WorkPackageViewBaselineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';+import { OpBaselineLegendsComponent } from '../wp-baseline/baseline-legends/baseline-legends.component';export interface WorkPackageFocusContext {/** Work package that was focused */@@ -83,6 +85,8 @@ 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;@@ -215,6 +219,7 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O}if (this.baselineEnabled) {+ this.baselineLegends?.refresh();this.numTableColumns += 1;}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.tsindex b67cce17eb0..f46ac10142a 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@@ -184,6 +184,7 @@ import { ProjectStoragesResourceService } from 'core-app/core/state/project-storimport { OpBaselineModalComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline-modal/baseline-modal.component';import { OpBaselineComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline/baseline.component';import { OpBaselineLoadingComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline-loading/baseline-loading.component';+import { OpBaselineLegendsComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component';@NgModule({imports: [@@ -417,6 +418,7 @@ import { OpBaselineLoadingComponent } from 'core-app/features/work-packages/compOpBaselineModalComponent,OpBaselineComponent,OpBaselineLoadingComponent,+ OpBaselineLegendsComponent,],exports: [WorkPackagesTableComponent,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 ae50c4c51a1..d9404ce6b38 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@@ -33,6 +33,11 @@ import { States } from 'core-app/core/states/states.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { WorkPackageQueryStateService } from './wp-view-base.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';+import { Observable } from 'rxjs';+import { IDay } from 'core-app/core/state/days/day.model';+import { TimezoneService } from 'core-app/core/datetime/timezone.service';+import { WeekdayService } from 'core-app/core/days/weekday.service';+import { DayResourceService } from 'core-app/core/state/days/day.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';@@ -45,10 +50,86 @@ export class WorkPackageViewBaselineService extends WorkPackageQueryStateServiceprotected readonly querySpace:IsolatedQuerySpace,protected readonly pathHelper:PathHelperService,protected readonly configurationService:ConfigurationService,+ protected readonly timezoneService:TimezoneService,+ protected readonly weekdaysService:WeekdayService,+ protected readonly daysService:DayResourceService,) {super(querySpace);}+ public nonWorkingDays:IDay[] = [];++ public daysNumber = 0;++ public nonWorkingDays$:Observable<IDay[]> = this.requireNonWorkingDaysOfTwoYears();++ public selectedDate = '';++ public yesterdayDate():string {+ const today = new Date();+ this.daysNumber = -1;++ today.setDate(today.getDate() - 1);+ this.selectedDate = this.timezoneService.formattedDate(today.toString());+ return this.selectedDate;+ }++ public lastMonthDate():string {+ 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;+ }++ public lastweekDate():string {+ const today = new Date();+ this.daysNumber = -7;+ today.setDate(today.getDate() - 7);+ this.selectedDate = this.timezoneService.formattedDate(today.toString());+ return this.selectedDate;+ }++ requireNonWorkingDaysOfTwoYears() {+ const today = new Date();+ const lastYear = new Date(today);+ lastYear.setFullYear(today.getFullYear() - 1);+ const nonWorkingDays$= this+ .daysService+ .requireNonWorkingYears$(lastYear, today);++ nonWorkingDays$.subscribe((nonWorkingDays) => {+ this.nonWorkingDays =nonWorkingDays;+ });++ return nonWorkingDays$;+ }++ isNonWorkingDay(date:Date|string):boolean {+ const formatted = moment(date).format('YYYY-MM-DD');+ return (this.nonWorkingDays.findIndex((el) => el.date === formatted) !== -1);+ }++ public lastWorkingDate():string {+ const today = new Date();+ const yesterday = new Date(today);+ this.selectedDate = '';+ yesterday.setDate(today.getDate() - 1);+ while (this.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');+ break;+ }+ }+ return this.selectedDate;+ }+public isActive():boolean {if (!this.configurationService.activeFeatureFlags.includes('showChanges')) {return false;diff --git a/spec/features/work_packages/table/baseline/baseline_query_spec.rb b/spec/features/work_packages/table/baseline/baseline_query_spec.rbindex f2c82a97b78..e3aba1a051a 100644--- a/spec/features/work_packages/table/baseline/baseline_query_spec.rb+++ b/spec/features/work_packages/table/baseline/baseline_query_spec.rb@@ -46,6 +46,7 @@ describe 'baseline query saving', js: true dowp_table.visit!baseline_modal.expect_closed+ baseline.expect_no_legendsbaseline_modal.toggle_drop_modalbaseline_modal.expect_openbaseline_modal.expect_selected '-'@@ -60,6 +61,10 @@ describe 'baseline query saving', js: true dobaseline_modal.expect_selected 'yesterday'baseline_modal.toggle_drop_modalbaseline_modal.expect_closed+ baseline.expect_legends+ expect(page).to have_selector(".op-baseline-legends--details-added", text: 'Now meets filter criteria (1)')+ expect(page).to have_selector(".op-baseline-legends--details-removed", text: 'No longer meets filter criteria (0)')+ expect(page).to have_selector(".op-baseline-legends--details-changed", text: 'Maintained with changes (0)')wp_table.save_as 'Baseline query'wp_table.expect_and_dismiss_toaster(message: 'Successful creation.')@@ -75,6 +80,7 @@ describe 'baseline query saving', js: true dobaseline_modal.expect_selected 'yesterday'baseline_modal.select_filter '-'baseline_modal.apply+ baseline.expect_no_legendsloading_indicator_saveguardwp_table.savediff --git a/spec/support/components/work_packages/baseline.rb b/spec/support/components/work_packages/baseline.rbindex 43181772d74..e0b5c910c93 100644--- a/spec/support/components/work_packages/baseline.rb+++ b/spec/support/components/work_packages/baseline.rb@@ -37,6 +37,14 @@ module Componentsexpect(page).to have_selector('.wp-table--baseline-th')end+ def expect_legends+ expect(page).to have_selector('.op-baseline-legends')+ end++ def expect_no_legends+ expect(page).not_to have_selector('.op-baseline-legends')+ end+def expect_inactiveexpect(page).not_to have_selector('.wp-table--baseline-th')expect(page).not_to have_selector('.op-table-baseline--column-cell')