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

Move listener for card selection to child component which contains the actual card

Henriette Dingerc91de43d9d6d
diff --git a/frontend/src/app/components/wp-card-view/wp-card-view.component.ts b/frontend/src/app/components/wp-card-view/wp-card-view.component.ts
index 822b063dbc7..a78b95400ab 100644
--- a/frontend/src/app/components/wp-card-view/wp-card-view.component.ts
+++ b/frontend/src/app/components/wp-card-view/wp-card-view.component.ts
@@ -132,15 +132,6 @@ export class WorkPackageCardViewComponent implements OnInit, AfterViewInit {
this.isResultEmpty = this.workPackages.length === 0;
this.cdRef.detectChanges();
});
-
- // Update selection state
- this.wpTableSelection.selection$()
- .pipe(
- untilComponentDestroyed(this)
- )
- .subscribe(() => {
- this.cdRef.detectChanges();
- });
}
ngAfterViewInit() {
diff --git a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.html b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.html
index 202ffe10cbf..1d2e019fbc0 100644
--- a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.html
+++ b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.html
@@ -1,5 +1,5 @@
<div class="wp-card"
- [ngClass]="cardClasses(workPackage)">
+ [ngClass]="cardClasses()">
<div class="wp-card--highlighting"
[ngClass]="cardHighlightingClass(workPackage)">
diff --git a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts
index f98900e58aa..e6e77315d38 100644
--- a/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts
+++ b/frontend/src/app/components/wp-card-view/wp-single-card/wp-single-card.component.ts
@@ -1,4 +1,12 @@
-import {ChangeDetectionStrategy, Component, EventEmitter, Input, Output} from "@angular/core";
+import {
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ EventEmitter,
+ Input,
+ OnDestroy, OnInit,
+ Output
+} from "@angular/core";
import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";
import {checkedClassName, uiStateLinkClass} from "core-components/wp-fast-table/builders/ui-state-link-builder";
import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
@@ -9,6 +17,7 @@ import {WorkPackageCardViewService} from "core-components/wp-card-view/services/
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {CardHighlightingMode} from "core-components/wp-fast-table/builders/highlighting/highlighting-mode.const";
import {CardViewOrientation} from "core-components/wp-card-view/wp-card-view.component";
+import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
@Component({
@@ -17,7 +26,7 @@ import {CardViewOrientation} from "core-components/wp-card-view/wp-card-view.com
templateUrl: './wp-single-card.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
-export class WorkPackageSingleCardComponent {
+export class WorkPackageSingleCardComponent implements OnDestroy, OnInit {
@Input() public workPackage:WorkPackageResource;
@Input() public showInfoButton:boolean = false;
@Input() public showStatusButton:boolean = true;
@@ -40,7 +49,22 @@ export class WorkPackageSingleCardComponent {
readonly I18n:I18nService,
readonly $state:StateService,
readonly wpTableSelection:WorkPackageViewSelectionService,
- readonly cardView:WorkPackageCardViewService) {
+ readonly cardView:WorkPackageCardViewService,
+ readonly cdRef:ChangeDetectorRef) {
+ }
+
+ ngOnInit():void {
+ // Update selection state
+ this.wpTableSelection.selection$()
+ .pipe(
+ untilComponentDestroyed(this)
+ )
+ .subscribe(() => {
+ this.cdRef.detectChanges();
+ });
+ }
+
+ ngOnDestroy():void {
}
public classIdentifier(wp:WorkPackageResource) {
@@ -56,20 +80,16 @@ export class WorkPackageSingleCardComponent {
);
}
- public cardClasses(wp:WorkPackageResource) {
- let classes = this.isSelected(wp) ? checkedClassName : '';
+ public cardClasses() {
+ let classes = this.isSelected(this.workPackage) ? checkedClassName : '';
classes += this.draggable ? ' -draggable' : '';
- classes += wp.isNew ? ' -new' : '';
- classes += ' wp-card-' + wp.id;
+ classes += this.workPackage.isNew ? ' -new' : '';
+ classes += ' wp-card-' + this.workPackage.id;
classes += ' -' + this.orientation;
classes += this.shrinkOnMobile ? ' -shrink' : '';
return classes;
}
- public isSelected(wp:WorkPackageResource):boolean {
- return this.wpTableSelection.isSelected(wp.id!);
- }
-
public wpTypeAttribute(wp:WorkPackageResource) {
return wp.type.name;
}
@@ -99,6 +119,10 @@ export class WorkPackageSingleCardComponent {
}
}
+ private isSelected(wp:WorkPackageResource):boolean {
+ return this.wpTableSelection.isSelected(wp.id!);
+ }
+
private cardHighlighting(wp:WorkPackageResource) {
if (['status', 'priority', 'type'].includes(this.highlightingMode)) {
return Highlighting.backgroundClass(this.highlightingMode, wp[this.highlightingMode].id);
diff --git a/spec/features/work_packages/select/select_card_view.spec.rb b/spec/features/work_packages/select/select_card_view.spec.rb
new file mode 100644
index 00000000000..257640f98c7
--- /dev/null
+++ b/spec/features/work_packages/select/select_card_view.spec.rb
@@ -0,0 +1,107 @@
+#-- copyright
+# OpenProject is a project management system.
+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
+#
+# 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-2017 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe 'Selecting cards in the card view (regression #31962)', js: true do
+ let(:user) { FactoryBot.create(:admin) }
+ let(:project) { FactoryBot.create(:project) }
+ let(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let(:cards) { ::Pages::WorkPackageCards.new(project) }
+ let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new }
+ let(:work_package_1) { FactoryBot.create(:work_package, project: project) }
+ let(:work_package_2) { FactoryBot.create(:work_package, project: project) }
+ let(:work_package_3) { FactoryBot.create(:work_package, project: project) }
+
+ before do
+ work_package_1
+ work_package_2
+ work_package_3
+
+ login_as(user)
+ wp_table.visit!
+ display_representation.switch_to_card_layout
+ cards.expect_work_package_listed work_package_1, work_package_2, work_package_3
+ end
+
+ context 'selecting cards' do
+ it 'can select and deselect all cards' do
+ # Select all
+ cards.select_all_work_packages
+ cards.expect_work_package_selected work_package_1, true
+ cards.expect_work_package_selected work_package_2, true
+ cards.expect_work_package_selected work_package_3, true
+
+ # Deselect all
+ cards.deselect_all_work_packages
+ cards.expect_work_package_selected work_package_1, false
+ cards.expect_work_package_selected work_package_2, false
+ cards.expect_work_package_selected work_package_3, false
+ end
+
+ it 'can select and deselect single cards' do
+ # Select a card
+ cards.select_work_package work_package_1
+ cards.expect_work_package_selected work_package_1, true
+ cards.expect_work_package_selected work_package_2, false
+ cards.expect_work_package_selected work_package_3, false
+
+ # Selecting another card changes the selection
+ cards.select_work_package work_package_2
+ cards.expect_work_package_selected work_package_1, false
+ cards.expect_work_package_selected work_package_2, true
+ cards.expect_work_package_selected work_package_3, false
+
+ # Deselect a card
+ cards.deselect_work_package work_package_2
+ cards.expect_work_package_selected work_package_1, false
+ cards.expect_work_package_selected work_package_2, false
+ cards.expect_work_package_selected work_package_3, false
+ end
+
+ it 'can select and deselect range of cards' do
+ # Select the first WP
+ cards.select_work_package work_package_1
+ cards.expect_work_package_selected work_package_1, true
+ cards.expect_work_package_selected work_package_2, false
+ cards.expect_work_package_selected work_package_3, false
+
+ # Select the third with Shift results in all WPs being selected
+ cards.select_work_package_with_shift work_package_3
+ cards.expect_work_package_selected work_package_1, true
+ cards.expect_work_package_selected work_package_2, true
+ cards.expect_work_package_selected work_package_3, true
+
+ # The range can be changed
+ cards.select_work_package_with_shift work_package_2
+ cards.expect_work_package_selected work_package_1, true
+ cards.expect_work_package_selected work_package_2, true
+ cards.expect_work_package_selected work_package_3, false
+ end
+ end
+end
diff --git a/spec/support/pages/work_packages/work_package_cards.rb b/spec/support/pages/work_packages/work_package_cards.rb
index cdb5e959789..d7092713e0b 100644
--- a/spec/support/pages/work_packages/work_package_cards.rb
+++ b/spec/support/pages/work_packages/work_package_cards.rb
@@ -64,6 +64,34 @@ module Pages
card(work_package).click
end
+ def deselect_work_package(work_package)
+ element = find("wp-single-card[data-work-package-id='#{work_package.id}']")
+
+ page.driver.browser.action.key_down(:command)
+ .click(element.native)
+ .key_up(:command)
+ .perform
+ end
+
+ def select_work_package_with_shift(work_package)
+ element = find("wp-single-card[data-work-package-id='#{work_package.id}']")
+
+ page.driver.browser.action.key_down(:shift)
+ .click(element.native)
+ .key_up(:shift)
+ .perform
+ end
+
+ def select_all_work_packages
+ find('body').send_keys [:control, 'a']
+ expect(page).to have_no_selector '#work-package-context-menu'
+ end
+
+ def deselect_all_work_packages
+ find('body').send_keys [:control, 'd']
+ expect(page).to have_no_selector '#work-package-context-menu'
+ end
+
def card(work_package)
page.find(".wp-card-#{work_package.id}")
end
@@ -71,5 +99,13 @@ module Pages
def status_button(work_package)
WorkPackageStatusField.new card(work_package)
end
+
+ def expect_work_package_selected(work_package, selected)
+ selector = "wp-single-card[data-work-package-id='#{work_package.id}']"
+ checked_selector = "wp-single-card[data-work-package-id='#{work_package.id}'] .-checked"
+
+ expect(page).to have_selector(selector)
+ expect(page).to (selected ? have_selector(checked_selector) : have_no_selector(checked_selector))
+ end
end
end