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

Feature/40330 projects include filter (#10199)

Oliver Günther67eb51769a06
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 1be55787ad4..9e6a3bb6308 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -1252,6 +1252,16 @@ en:
group: 'The group is now a part of %{project}. Meanwhile you can already plan with that group and assign work packages for instance.'
next_button: 'Continue'
+ include_projects:
+ toggle_title: 'Include Projects'
+ title: 'Projects'
+ clear_selection: 'Clear selection'
+ apply: 'Apply'
+ selected_filter:
+ all: 'All projects'
+ selected: 'Only selected'
+ search_placeholder: 'Search project...'
+
forms:
submit_success_message: 'The form was successfully submitted'
load_error_message: 'There was an error loading the form'
diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js
index 377a015cd13..72f41374c4c 100644
--- a/frontend/.eslintrc.js
+++ b/frontend/.eslintrc.js
@@ -116,12 +116,13 @@ module.exports = {
"_links",
"_embedded",
"_meta",
+ "_type",
],
- allowAfterThis: false,
+ allowAfterThis: true,
allowAfterSuper: false,
allowAfterThisConstructor: false,
enforceInMethodNames: true,
- allowFunctionParams: false,
+ allowFunctionParams: true,
}
],
diff --git a/frontend/src/app/core/state/projects/project.model.ts b/frontend/src/app/core/state/projects/project.model.ts
index 0ce383139d7..5af6b823b8b 100644
--- a/frontend/src/app/core/state/projects/project.model.ts
+++ b/frontend/src/app/core/state/projects/project.model.ts
@@ -8,6 +8,7 @@ import {
export const PROJECTS_MAX_SIZE = 100;
export interface IProjectHalResourceLinks extends IHalResourceLinks {
+ ancestors:IHalResourceLink[];
categories:IHalResourceLink;
delete:IHalResourceLink;
parent:IHalResourceLink;
diff --git a/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts b/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
index 1df73d3a2c3..3a81c544f2a 100644
--- a/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
+++ b/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
@@ -44,6 +44,7 @@ import { ZenModeButtonComponent } from 'core-app/features/work-packages/componen
import { WorkPackageSettingsButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-settings-button/wp-settings-button.component';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { QueryParamListenerService } from 'core-app/features/work-packages/components/wp-query/query-param-listener.service';
+import { OpProjectIncludeComponent } from 'core-app/shared/components/project-include/project-include.component';
@Component({
templateUrl: '../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',
@@ -90,6 +91,9 @@ export class WorkPackagesCalendarPageComponent extends PartitionedQuerySpacePage
/** Define the buttons shown in the toolbar */
toolbarButtonComponents:ToolbarButtonComponentDefinition[] = [
+ {
+ component: OpProjectIncludeComponent,
+ },
{
component: WorkPackageFilterButtonComponent,
},
diff --git a/frontend/src/app/features/team-planner/team-planner/assignee/add-assignee.component.ts b/frontend/src/app/features/team-planner/team-planner/assignee/add-assignee.component.ts
index 9cc7ef6d340..7d8197c2f7a 100644
--- a/frontend/src/app/features/team-planner/team-planner/assignee/add-assignee.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/assignee/add-assignee.component.ts
@@ -39,12 +39,17 @@ import { HalResourceService } from 'core-app/features/hal/services/hal-resource.
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { Observable } from 'rxjs';
-import { map } from 'rxjs/operators';
+import {
+ map,
+ mergeMap,
+ take,
+} from 'rxjs/operators';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
@Component({
templateUrl: './add-assignee.component.html',
@@ -67,26 +72,52 @@ export class AddAssigneeComponent {
readonly apiV3Service:ApiV3Service,
readonly injector:Injector,
readonly currentProjectService:CurrentProjectService,
+ readonly wpTableFilters:WorkPackageViewFiltersService,
) { }
public autocomplete(term:string|null):Observable<HalResource[]> {
- const filters = new ApiV3FilterBuilder();
+ return this.wpTableFilters
+ .live$()
+ .pipe(
+ take(1),
+ map((queryFilters) => {
+ const projectFilter = queryFilters.find((queryFilter) => queryFilter._type === 'ProjectQueryFilter');
- filters.add('member', '=', [this.currentProjectService.id || '']);
+ const selectedProjectIds = (() => {
+ const baseList = ((projectFilter?.values || []) as HalResource[]).map((p) => p.id);
+ const currentProjectId = this.currentProjectService.id;
+ if (baseList.includes(currentProjectId)) {
+ return [...baseList];
+ }
- if (term) {
- filters.add('typeahead', '**', [term]);
- }
+ return [
+ ...baseList,
+ currentProjectId,
+ ];
+ })();
- return this
- .apiV3Service
- .principals
- .filtered(filters)
- .get()
- .pipe(
- map((collection) => collection.elements.filter(
- (user) => !this.alreadySelected.find((selected) => selected === user.id),
- )),
+ const filters = new ApiV3FilterBuilder();
+
+ filters.add('member', '=', selectedProjectIds as string[]);
+
+ if (term) {
+ filters.add('typeahead', '**', [term]);
+ }
+
+ return filters;
+ }),
+ mergeMap(
+ (filters) => this
+ .apiV3Service
+ .principals
+ .filtered(filters)
+ .get()
+ .pipe(
+ map((collection) => collection.elements.filter(
+ (user) => !this.alreadySelected.find((selected) => selected === user.id),
+ )),
+ ),
+ ),
);
}
diff --git a/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts b/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts
index 4d90b256747..b97b7e79f68 100644
--- a/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/page/team-planner-page.component.ts
@@ -16,6 +16,7 @@ import { QueryParamListenerService } from 'core-app/features/work-packages/compo
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { WorkPackageSettingsButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-settings-button/wp-settings-button.component';
import { CalendarDragDropService } from 'core-app/features/team-planner/team-planner/calendar-drag-drop.service';
+import { OpProjectIncludeComponent } from 'core-app/shared/components/project-include/project-include.component';
@Component({
templateUrl: '../../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',
@@ -61,6 +62,9 @@ export class TeamPlannerPageComponent extends PartitionedQuerySpacePageComponent
/** Define the buttons shown in the toolbar */
toolbarButtonComponents:ToolbarButtonComponentDefinition[] = [
+ {
+ component: OpProjectIncludeComponent,
+ },
{
component: WorkPackageFilterButtonComponent,
},
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-page/wp-view-page.component.ts b/frontend/src/app/features/work-packages/routing/wp-view-page/wp-view-page.component.ts
index 811886b1b83..9c6063033a6 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-page/wp-view-page.component.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-page/wp-view-page.component.ts
@@ -44,6 +44,7 @@ import { ZenModeButtonComponent } from 'core-app/features/work-packages/componen
import { WorkPackageSettingsButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-settings-button/wp-settings-button.component';
import { of } from 'rxjs';
import { WorkPackageFoldToggleButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-fold-toggle-button/wp-fold-toggle-button.component';
+import { OpProjectIncludeComponent } from 'core-app/shared/components/project-include/project-include.component';
@Component({
selector: 'wp-view-page',
@@ -68,6 +69,9 @@ export class WorkPackageViewPageComponent extends PartitionedQuerySpacePageCompo
allowed: ['work_packages.createWorkPackage'],
},
},
+ {
+ component: OpProjectIncludeComponent,
+ },
{
component: WorkPackageFilterButtonComponent,
},
diff --git a/frontend/src/app/shared/components/project-include/insert-in-list.ts b/frontend/src/app/shared/components/project-include/insert-in-list.ts
new file mode 100644
index 00000000000..cc931bf2d7b
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/insert-in-list.ts
@@ -0,0 +1,48 @@
+import { IProject } from 'core-app/core/state/projects/project.model';
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { IProjectData } from './project-data';
+
+// Helper function that recursively inserts a project into the hierarchy at the right place
+export const insertInList = (
+ projects:IProject[],
+ project:IProject,
+ list:IProjectData[],
+ ancestors:IHalResourceLink[],
+):IProjectData[] => {
+ if (!ancestors.length) {
+ return [
+ ...list,
+ {
+ id: project.id,
+ name: project.name,
+ href: project._links.self.href,
+ found: true,
+ children: [],
+ },
+ ];
+ }
+
+ const ancestorHref = ancestors[0].href;
+ const ancestor:IProjectData|undefined = list.find((projectInList) => projectInList.href === ancestorHref);
+
+ if (ancestor) {
+ ancestor.children = insertInList(projects, project, ancestor.children, ancestors.slice(1));
+ return [...list];
+ }
+
+ const ancestorProject = projects.find((projectInList) => projectInList._links.self.href === ancestorHref);
+ if (!ancestorProject) {
+ return [...list];
+ }
+
+ return [
+ ...list,
+ {
+ id: ancestorProject.id,
+ name: ancestorProject.name,
+ href: ancestorProject._links.self.href,
+ found: false,
+ children: insertInList(projects, project, [], ancestors.slice(1)),
+ },
+ ];
+};
diff --git a/frontend/src/app/shared/components/project-include/project-data.ts b/frontend/src/app/shared/components/project-include/project-data.ts
new file mode 100644
index 00000000000..30b7ccfdedb
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-data.ts
@@ -0,0 +1,9 @@
+import { ID } from '@datorama/akita';
+
+export interface IProjectData {
+ id:ID;
+ href:string;
+ name:string;
+ found:boolean;
+ children:IProjectData[];
+}
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.html b/frontend/src/app/shared/components/project-include/project-include.component.html
new file mode 100644
index 00000000000..6ea532409db
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-include.component.html
@@ -0,0 +1,72 @@
+<spot-drop-modal
+ [open]="opened"
+ alignment="bottom-right"
+ (closed)="opened = false"
+>
+ <button
+ slot="trigger"
+ type="button"
+ class="button"
+ (click)="toggleOpen()"
+ data-qa-selector="project-include-button"
+ >
+ {{ text.toggle_title }}
+ <span
+ *ngIf="(numberOfProjectsInFilter$ | async) as count"
+ class="badge -secondary"
+ [textContent]="count"
+ >
+ </span>
+ </button>
+
+ <ng-container slot="body">
+ <div class="op-project-include--header">
+ <h1 class="op-project-include--title">{{ text.title }}</h1>
+ <spot-toggle
+ [options]="displayModeOptions"
+ [(ngModel)]="displayMode"
+ ></spot-toggle>
+ </div>
+ <form
+ (submit)="onSubmit($event)"
+ class="spot-body"
+ >
+ <spot-text-field
+ [placeholder]="text.search_placeholder"
+ name="project-include-search"
+ [(ngModel)]="query"
+ [ngModelOptions]="{standalone: true}"
+ data-qa-selector="project-include-search"
+ >
+ <span
+ slot="before"
+ class="op-icon icon-search"
+ ></span>
+ </spot-text-field>
+
+ <ul
+ op-project-list
+ [projects]="projects$ | async"
+ [selected]="selectedProjects"
+ (update)="selectedProjects = $event"
+ data-qa-selector="project-include-list"
+ ></ul>
+
+ <div class="spot-action-bar">
+ <div class="spot-action-bar--left"></div>
+ <div class="spot-action-bar--right">
+ <button
+ class="spot-button spot-button_outlined spot-button_main"
+ type="button"
+ (click)="clearSelection()"
+ >
+ {{ text.clear_selection }}
+ </button>
+ <button class="spot-button spot-button_main">
+ {{ text.apply }}
+ </button>
+ </div>
+ </div>
+ </form>
+ </ng-container>
+</spot-drop-modal>
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.sass b/frontend/src/app/shared/components/project-include/project-include.component.sass
new file mode 100644
index 00000000000..ec6218123b9
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-include.component.sass
@@ -0,0 +1,18 @@
+@import '../../../spot/styles/sass/variables'
+@import '../../../spot/styles/sass/typography'
+
+\::ng-deep .spot-drop-modal--body
+ width: 460px
+ max-width: 100vw
+
+.op-project-include
+ &--header
+ display: flex
+ justify-content: space-between
+ align-items: center
+ margin: $spot-spacing-0_5
+
+ &--title
+ margin: 0
+ padding: 0
+ @include spot-subheader-big
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.ts b/frontend/src/app/shared/components/project-include/project-include.component.ts
new file mode 100644
index 00000000000..0d326bfab5b
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-include.component.ts
@@ -0,0 +1,225 @@
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ HostBinding,
+} from '@angular/core';
+import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';
+import {
+ ApiV3ListFilter,
+ ApiV3ListParameters,
+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
+import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import {
+ BehaviorSubject,
+ combineLatest,
+} from 'rxjs';
+import {
+ debounceTime,
+ distinctUntilChanged,
+ map,
+ mergeMap,
+ take,
+} from 'rxjs/operators';
+import { IProjectData } from './project-data';
+import { insertInList } from './insert-in-list';
+import { recursiveSort } from './recursive-sort';
+import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { IProject } from 'core-app/core/state/projects/project.model';
+
+@Component({
+ selector: 'op-project-include',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ templateUrl: './project-include.component.html',
+ styleUrls: ['./project-include.component.sass'],
+})
+export class OpProjectIncludeComponent extends UntilDestroyedMixin {
+ @HostBinding('class.op-project-include') className = true;
+
+ public text = {
+ toggle_title: this.I18n.t('js.include_projects.toggle_title'),
+ title: this.I18n.t('js.include_projects.title'),
+ filter_all: this.I18n.t('js.include_projects.selected_filter.all'),
+ filter_selected: this.I18n.t('js.include_projects.selected_filter.selected'),
+ search_placeholder: this.I18n.t('js.include_projects.search_placeholder'),
+ clear_selection: this.I18n.t('js.include_projects.clear_selection'),
+ apply: this.I18n.t('js.include_projects.apply'),
+ };
+
+ public opened = false;
+
+ public displayModeOptions = [
+ { value: 'all', title: this.text.filter_all },
+ { value: 'selected', title: this.text.filter_selected },
+ ];
+
+ private _displayMode = 'all';
+
+ public get displayMode():string {
+ return this._displayMode;
+ }
+
+ public set displayMode(val:string) {
+ this._displayMode = val;
+ this.displayMode$.next(val);
+ }
+
+ public displayMode$ = new BehaviorSubject('all');
+
+ private _query = '';
+
+ public get query():string {
+ return this._query;
+ }
+
+ public set query(val:string) {
+ this._query = val;
+ this.query$.next(val);
+ }
+
+ public query$ = new BehaviorSubject('');
+
+ private _selectedProjects:string[] = [];
+
+ public get selectedProjects():string[] {
+ return this._selectedProjects;
+ }
+
+ public set selectedProjects(val:string[]) {
+ this._selectedProjects = val;
+ this.selectedProjects$.next(val);
+ }
+
+ public selectedProjects$ = new BehaviorSubject<string[]>([]);
+
+ private projectsInFilter$ = this.wpTableFilters
+ .live$()
+ .pipe(
+ this.untilDestroyed(),
+ map((queryFilters) => {
+ const projectFilter = queryFilters.find((queryFilter) => queryFilter._type === 'ProjectQueryFilter');
+ const selectedProjectHrefs = ((projectFilter?.values || []) as HalResource[]).map((p) => p.href);
+ const currentProjectHref = this.currentProjectService.apiv3Path;
+ if (selectedProjectHrefs.includes(currentProjectHref)) {
+ return selectedProjectHrefs;
+ }
+
+ return [
+ ...selectedProjectHrefs,
+ currentProjectHref,
+ ];
+ }),
+ );
+
+ public numberOfProjectsInFilter$ = this.projectsInFilter$.pipe(map((selected) => selected.length));
+
+ public allProjects$ = this.projectsResourceService.query.selectAll();
+
+ public projects$ = combineLatest([
+ this.allProjects$,
+ this.query$.pipe(distinctUntilChanged()),
+ this.displayMode$.pipe(distinctUntilChanged()),
+ ])
+ .pipe(
+ debounceTime(20),
+ mergeMap(([projects, query, displayMode]) => this.selectedProjects$.pipe(
+ take(1),
+ map((selected) => [projects, query, displayMode, selected]),
+ )),
+ map(
+ ([projects, query, displayMode, selected]:[IProject[], string, string, string[]]) => projects
+ .filter(
+ (project) => {
+ if (displayMode === 'selected' && !selected.includes(project._links.self.href)) {
+ return false;
+ }
+
+ if (query.length) {
+ return project.name.toLowerCase().includes(query.toLowerCase()) || project.identifier.toLowerCase().includes(query.toLowerCase());
+ }
+
+ return true;
+ },
+ )
+ .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)
+ .reduce(
+ (list, project) => {
+ const { ancestors } = project._links;
+
+ return insertInList(projects, project, list, ancestors);
+ },
+ [] as IProjectData[],
+ ),
+ ),
+ map((projects) => recursiveSort(projects)),
+ );
+
+ public get params():ApiV3ListParameters {
+ const filters:ApiV3ListFilter[] = [
+ ['active', '=', ['t']],
+ ];
+
+ if (this.query) {
+ filters.push([
+ 'name_and_identifier',
+ '~',
+ [this.query],
+ ]);
+ }
+
+ return { filters, pageSize: -1 };
+ }
+
+ constructor(
+ readonly I18n:I18nService,
+ readonly projectsResourceService:ProjectsResourceService,
+ readonly wpTableFilters:WorkPackageViewFiltersService,
+ readonly halResourceService:HalResourceService,
+ readonly currentProjectService:CurrentProjectService,
+ ) {
+ super();
+ }
+
+ public toggleOpen():void {
+ this.opened = !this.opened;
+ this.searchProjects();
+ this.projectsInFilter$
+ .pipe(take(1))
+ .subscribe((selectedProjects) => {
+ this.displayMode = 'all';
+ this.query = '';
+ this.selectedProjects = selectedProjects as string[];
+ });
+ }
+
+ public searchProjects():void {
+ this.projectsResourceService
+ .fetchProjects(this.params)
+ .subscribe();
+ }
+
+ public clearSelection():void {
+ this.selectedProjects = [this.currentProjectService.apiv3Path || ''];
+ }
+
+ public onSubmit(e:Event):void {
+ e.preventDefault();
+
+ // Replace actually also instantiates if it does not exist, which is handy here
+ this.wpTableFilters.replace('project', (projectFilter:QueryFilterInstanceResource) => {
+ const projectHrefs = this.selectedProjects;
+ // eslint-disable-next-line no-param-reassign
+ projectFilter.values = projectHrefs.map((href:string) => this.halResourceService.createHalResource({ href }, true));
+ });
+
+ this.close();
+ }
+
+ public close():void {
+ this.opened = false;
+ }
+}
diff --git a/frontend/src/app/shared/components/project-include/project-list.component.html b/frontend/src/app/shared/components/project-include/project-list.component.html
new file mode 100644
index 00000000000..a1e697ccd83
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-list.component.html
@@ -0,0 +1,24 @@
+<li
+ class="spot-list--item"
+ *ngFor="let project of projects"
+>
+ <label class="spot-list--item-action op-project-list--item-action">
+ <spot-checkbox
+ *ngFor="let checked of [isChecked(project.href)]"
+ [checked]="checked"
+ (change)="changeSelected(project.href)"
+ [disabled]="project.href === currentProjectHref"
+ [attr.data-qa-project-include-id]="project.id"
+ [attr.data-qa-project-include-checked]="checked ? 1 : 0"
+ ></spot-checkbox>
+ <div class="spot-list--item-title">{{ project.name }}</div>
+ </label>
+
+ <ul
+ *ngIf="project.children.length"
+ op-project-list
+ [projects]="project.children"
+ [selected]="selected"
+ (update)="updateSelected($event)"
+ ></ul>
+</li>
diff --git a/frontend/src/app/shared/components/project-include/project-list.component.sass b/frontend/src/app/shared/components/project-include/project-list.component.sass
new file mode 100644
index 00000000000..ea54f81d9d4
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-list.component.sass
@@ -0,0 +1,16 @@
+.op-project-list
+ &--item-action
+ display: flex
+
+ &--child-toggle
+ opacity: 0
+ width: 0
+ height: 0
+ margin-left: auto
+
+ &--item-action:hover &--child-toggle,
+ &--child-toggle:focus
+ opacity: 1
+ width: auto
+ height: auto
+
diff --git a/frontend/src/app/shared/components/project-include/project-list.component.ts b/frontend/src/app/shared/components/project-include/project-list.component.ts
new file mode 100644
index 00000000000..8c9d281ac84
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/project-list.component.ts
@@ -0,0 +1,58 @@
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ EventEmitter,
+ HostBinding,
+ Input,
+ Output,
+} from '@angular/core';
+import { IProjectData } from './project-data';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+
+@Component({
+ selector: '[op-project-list]',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ templateUrl: './project-list.component.html',
+ styleUrls: ['./project-list.component.sass'],
+})
+export class OpProjectListComponent {
+ @HostBinding('class.spot-list') classNameList = true;
+
+ @HostBinding('class.op-project-list') className = true;
+
+ @Output() update = new EventEmitter<string[]>();
+
+ @Input() projects:IProjectData[] = [];
+
+ @Input() selected:string[] = [];
+
+ public get currentProjectHref():string|null {
+ return this.currentProjectService.apiv3Path;
+ }
+
+ constructor(
+ readonly I18n:I18nService,
+ readonly currentProjectService:CurrentProjectService,
+ ) { }
+
+ public updateSelected(selected:string[]):void {
+ this.update.emit(selected);
+ }
+
+ public isChecked(href:string):boolean {
+ return this.selected.includes(href);
+ }
+
+ public changeSelected(href:string):void {
+ const checked = this.isChecked(href);
+ if (checked) {
+ this.updateSelected(this.selected.filter((selectedHref) => selectedHref !== href));
+ } else {
+ this.updateSelected([
+ ...this.selected,
+ href,
+ ]);
+ }
+ }
+}
diff --git a/frontend/src/app/shared/components/project-include/recursive-sort.ts b/frontend/src/app/shared/components/project-include/recursive-sort.ts
new file mode 100644
index 00000000000..19afa6e0690
--- /dev/null
+++ b/frontend/src/app/shared/components/project-include/recursive-sort.ts
@@ -0,0 +1,9 @@
+import { IProjectData } from './project-data';
+
+// Recursively sort project children and their children by name
+export const recursiveSort = (projects:IProjectData[]):IProjectData[] => projects
+ .map((project) => ({
+ ...project,
+ children: recursiveSort(project.children),
+ }))
+ .sort((a, b) => a.name.localeCompare(b.name));
diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.ts
index 04a62e7d559..6b52d521748 100644
--- a/frontend/src/app/shared/shared.module.ts
+++ b/frontend/src/app/shared/shared.module.ts
@@ -41,6 +41,7 @@ import {
StateService,
UIRouterModule,
} from '@uirouter/angular';
+import { OpSpotModule } from 'core-app/spot/spot.module';
import { CurrentUserModule } from 'core-app/core/current-user/current-user.module';
import { IconModule } from 'core-app/shared/components/icon/icon.module';
import { AttributeHelpTextModule } from 'core-app/shared/components/attribute-help-texts/attribute-help-text.module';
@@ -85,6 +86,8 @@ import { OpFormFieldComponent } from './components/forms/form-field/form-field.c
import { OpFormBindingDirective } from './components/forms/form-field/form-binding.directive';
import { OpOptionListComponent } from './components/option-list/option-list.component';
import { OpSidemenuComponent } from './components/sidemenu/sidemenu.component';
+import { OpProjectIncludeComponent } from './components/project-include/project-include.component';
+import { OpProjectListComponent } from './components/project-include/project-list.component';
import { ViewsResourceService } from 'core-app/core/state/views/views.service';
export function bootstrapModule(injector:Injector) {
@@ -117,6 +120,7 @@ export function bootstrapModule(injector:Injector) {
CommonModule,
// Angular Forms
FormsModule,
+ OpSpotModule,
// Angular CDK
PortalModule,
DragDropModule,
@@ -148,6 +152,8 @@ export function bootstrapModule(injector:Injector) {
DynamicBootstrapModule,
OpenprojectPrincipalRenderingModule,
+ OpSpotModule,
+
DatePickerModule,
FocusModule,
OpDateTimeComponent,
@@ -188,6 +194,8 @@ export function bootstrapModule(injector:Injector) {
OpFormBindingDirective,
OpOptionListComponent,
OpSidemenuComponent,
+ OpProjectIncludeComponent,
+ OpProjectListComponent,
],
providers: [
StaticQueriesService,
@@ -245,6 +253,8 @@ export function bootstrapModule(injector:Injector) {
OpFormBindingDirective,
OpOptionListComponent,
OpSidemenuComponent,
+ OpProjectIncludeComponent,
+ OpProjectListComponent,
],
})
export class OPSharedModule {
diff --git a/frontend/src/global_styles/layout/_toolbar.sass b/frontend/src/global_styles/layout/_toolbar.sass
index c1c10e6bea2..c3e7ea765f0 100644
--- a/frontend/src/global_styles/layout/_toolbar.sass
+++ b/frontend/src/global_styles/layout/_toolbar.sass
@@ -128,7 +128,6 @@ $nm-color-success-background: #d8fdd1
> li
margin-right: 2px
- button,
.button
// Overwrite Foundastion's default padding. Let line-height fix vertical
// center
@@ -156,7 +155,6 @@ $nm-color-success-background: #d8fdd1
font-size: 14px
line-height: 1
- button,
.button,
input[type=text],
input[type=number],
@@ -164,7 +162,6 @@ $nm-color-success-background: #d8fdd1
@include toolbar-element-sizing
border: 1px solid var(--toolbar-item--border-color)
- button,
.button,
.toolbar-input--affix
background: var(--toolbar-item--bg-color)
diff --git a/modules/calendar/spec/features/calendar_project_include_spec.rb b/modules/calendar/spec/features/calendar_project_include_spec.rb
new file mode 100644
index 00000000000..4c38f83d274
--- /dev/null
+++ b/modules/calendar/spec/features/calendar_project_include_spec.rb
@@ -0,0 +1,85 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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.
+#++
+
+require 'spec_helper'
+require 'features/work_packages/project_include/project_include_shared_examples'
+require_relative '../support/pages/calendar'
+
+describe 'Calendar project include', type: :feature, js: true do
+ shared_let(:enabled_modules) { %w[work_package_tracking calendar_view] }
+ shared_let(:permissions) do
+ %i[view_work_packages view_calendar edit_work_packages add_work_packages save_queries manage_public_queries]
+ end
+
+ it_behaves_like 'has a project include dropdown' do
+ let(:work_package_view) { ::Pages::Calendar.new project }
+ let(:dropdown) { ::Components::ProjectIncludeComponent.new }
+
+ it 'correctly filters work packages by project' do
+ dropdown.expect_count 1
+
+ # Make sure the filter gets set once
+ dropdown.toggle!
+ dropdown.expect_open
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+
+ work_package_view.expect_event task
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug, present: false
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task, present: false
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(sub_sub_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 2
+
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 3
+
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task
+
+ page.refresh
+
+ work_package_view.expect_event task
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task
+ end
+ end
+end
diff --git a/modules/team_planner/spec/features/shared_context.rb b/modules/team_planner/spec/features/shared_context.rb
index fdbfa13b94d..286e7ada5f5 100644
--- a/modules/team_planner/spec/features/shared_context.rb
+++ b/modules/team_planner/spec/features/shared_context.rb
@@ -41,7 +41,8 @@ shared_context 'with team planner full access' do
member_in_project: project,
member_with_permissions: %w[
view_work_packages edit_work_packages add_work_packages
- view_team_planner manage_team_planner save_queries manage_public_queries
+ view_team_planner manage_team_planner
+ save_queries manage_public_queries
]
end
diff --git a/modules/team_planner/spec/features/team_planner_project_include_spec.rb b/modules/team_planner/spec/features/team_planner_project_include_spec.rb
new file mode 100644
index 00000000000..47038acaa0f
--- /dev/null
+++ b/modules/team_planner/spec/features/team_planner_project_include_spec.rb
@@ -0,0 +1,125 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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.
+#++
+
+require 'spec_helper'
+require 'features/work_packages/project_include/project_include_shared_examples'
+require_relative '../support/pages/team_planner'
+
+describe 'Team planner project include', type: :feature, js: true do
+ before do
+ with_enterprise_token(:team_planner_view)
+ end
+
+ shared_let(:enabled_modules) { %w[work_package_tracking team_planner_view] }
+ shared_let(:permissions) do
+ %w[view_work_packages edit_work_packages add_work_packages
+ view_team_planner manage_team_planner
+ save_queries manage_public_queries]
+ end
+
+ it_behaves_like 'has a project include dropdown' do
+ let(:work_package_view) { Pages::TeamPlanner.new(project) }
+ let(:dropdown) { ::Components::ProjectIncludeComponent.new }
+
+ it 'correctly filters work packages by project' do
+ dropdown.expect_count 1
+
+ # Make sure the filter gets set once
+ dropdown.toggle!
+ dropdown.expect_open
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+
+ work_package_view.expect_empty_state
+ work_package_view.expect_assignee(user, present: false)
+ work_package_view.expect_assignee(other_user, present: false)
+
+ retry_block do
+ work_package_view.click_add_user
+ page.find('[data-qa-selector="tp-add-assignee"] input')
+ work_package_view.select_user_to_add user.name
+ end
+
+ retry_block do
+ work_package_view.click_add_user
+ page.find('[data-qa-selector="tp-add-assignee"] input')
+ work_package_view.select_user_to_add other_user.name
+ end
+
+ work_package_view.expect_assignee user
+ work_package_view.expect_assignee other_user
+
+ work_package_view.within_lane(user) do
+ work_package_view.expect_event task
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug, present: false
+ end
+
+ work_package_view.within_lane(other_user) do
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task, present: false
+ end
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(sub_sub_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 2
+
+ work_package_view.within_lane(user) do
+ work_package_view.expect_event task
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug
+ end
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 3
+
+ work_package_view.within_lane(other_user) do
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task
+ end
+
+ page.refresh
+
+ work_package_view.within_lane(other_user) do
+ work_package_view.expect_event other_task
+ work_package_view.expect_event other_other_task
+ end
+
+ work_package_view.within_lane(user) do
+ work_package_view.expect_event task
+ work_package_view.expect_event sub_bug, present: false
+ work_package_view.expect_event sub_sub_bug
+ end
+ end
+ end
+end
diff --git a/spec/features/work_packages/project_include/project_include_shared_examples.rb b/spec/features/work_packages/project_include/project_include_shared_examples.rb
new file mode 100644
index 00000000000..b28af6171d4
--- /dev/null
+++ b/spec/features/work_packages/project_include/project_include_shared_examples.rb
@@ -0,0 +1,297 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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.
+#++
+
+require 'spec_helper'
+
+shared_examples 'has a project include dropdown', type: :feature, js: true do
+ let(:dropdown) { ::Components::ProjectIncludeComponent.new }
+
+ shared_let(:project) do
+ create(:project, name: 'Parent', enabled_module_names: enabled_modules)
+ end
+
+ shared_let(:sub_project) do
+ create(:project, name: 'Child', parent: project, enabled_module_names: enabled_modules)
+ end
+ shared_let(:sub_sub_project) do
+ create(:project, name: 'Grandchild', parent: sub_project, enabled_module_names: enabled_modules)
+ end
+ shared_let(:other_project) do
+ create(:project, name: 'Other project', enabled_module_names: enabled_modules)
+ end
+
+ shared_let(:user) do
+ create :user,
+ member_in_projects: [project, sub_project, sub_sub_project, other_project],
+ member_with_permissions: permissions
+ end
+
+ shared_let(:other_user) do
+ create :user,
+ firstname: 'Other',
+ lastname: 'User',
+ member_in_projects: [project, other_project, sub_project, sub_sub_project],
+ member_with_permissions: permissions
+ end
+
+ current_user { user }
+
+ shared_let(:type_task) { create :type_task }
+ shared_let(:type_bug) { create :type_bug }
+ shared_let(:closed_status) { create :status, is_closed: true }
+
+ shared_let(:task) do
+ create :work_package,
+ project: project,
+ type: type_task,
+ assigned_to: user,
+ start_date: Time.zone.today - 2.day,
+ due_date: Time.zone.today + 1.day,
+ subject: 'A task for ' + user.name
+ end
+
+ shared_let(:sub_bug) do
+ create :work_package,
+ project: sub_project,
+ type: type_bug,
+ assigned_to: user,
+ start_date: Time.zone.today - 10.days,
+ due_date: Time.zone.today + 20.days,
+ subject: 'A bug in sub-project for ' + user.name
+ end
+
+ shared_let(:sub_sub_bug) do
+ create :work_package,
+ project: sub_sub_project,
+ type: type_bug,
+ assigned_to: user,
+ start_date: Time.zone.today - 1.day,
+ due_date: Time.zone.today + 2.days,
+ subject: 'A bug in sub-sub-project for ' + user.name
+ end
+
+ shared_let(:other_task) do
+ create :work_package,
+ project: project,
+ type: type_task,
+ assigned_to: other_user,
+ start_date: Time.zone.today,
+ due_date: Time.zone.today + 2.days,
+ subject: 'A task for the other user'
+ end
+
+ shared_let(:other_other_task) do
+ create :work_package,
+ project: other_project,
+ type: type_task,
+ assigned_to: other_user,
+ start_date: Time.zone.today - 2.day,
+ due_date: Time.zone.today + 4.day,
+ subject: 'A task for the other user in other-project'
+ end
+
+ before do
+ project.types << type_bug
+ project.types << type_task
+ sub_project.types << type_bug
+ sub_project.types << type_task
+ sub_sub_project.types << type_bug
+ sub_sub_project.types << type_task
+ other_project.types << type_bug
+ other_project.types << type_task
+
+ login_as current_user
+ work_package_view.visit!
+ end
+
+ it 'can add and remove projects' do
+ dropdown.expect_count 1
+ dropdown.toggle!
+ dropdown.expect_open
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id)
+
+ dropdown.toggle_checkbox(project.id)
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.toggle_checkbox(sub_sub_project.id)
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+
+ dropdown.toggle_checkbox(sub_sub_project.id)
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id)
+
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+ dropdown.expect_count 2
+
+ dropdown.toggle!
+
+ dropdown.toggle_checkbox(sub_sub_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+ dropdown.expect_count 3
+
+ page.refresh
+
+ dropdown.expect_count 3
+
+ dropdown.toggle!
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+
+ dropdown.toggle_checkbox(sub_sub_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+ dropdown.expect_count 2
+ end
+
+ it 'can clear the selection' do
+ dropdown.expect_count 1
+ dropdown.toggle!
+ dropdown.expect_open
+
+ dropdown.toggle_checkbox(project.id)
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.toggle_checkbox(sub_sub_project.id)
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+ dropdown.expect_count 3
+
+ dropdown.toggle!
+
+ dropdown.click_button 'Clear selection'
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id)
+
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+ dropdown.expect_count 1
+ end
+
+ it 'filter projects in the list' do
+ dropdown.expect_count 1
+ dropdown.toggle!
+ dropdown.expect_open
+
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.toggle_checkbox(sub_sub_project.id)
+
+ retry_block do
+ dropdown.search sub_sub_project.name
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_no_checkbox(other_project.id)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+ end
+
+ retry_block do
+ dropdown.search other_project.name
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_no_checkbox(project.id)
+ dropdown.expect_no_checkbox(sub_project.id)
+ dropdown.expect_no_checkbox(sub_sub_project.id)
+ end
+
+ retry_block do
+ dropdown.search ''
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+ end
+
+ retry_block do
+ dropdown.set_filter_selected true
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+ end
+
+ retry_block do
+ dropdown.set_filter_selected false
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.set_filter_selected true
+
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+
+ dropdown.expect_no_checkbox(other_project.id)
+ end
+
+ retry_block do
+ dropdown.search other_project.name
+ dropdown.expect_no_checkbox(project.id)
+ dropdown.expect_no_checkbox(other_project.id)
+ dropdown.expect_no_checkbox(sub_project.id)
+ dropdown.expect_no_checkbox(sub_sub_project.id)
+ end
+
+ retry_block do
+ dropdown.search ''
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+
+ dropdown.expect_no_checkbox(other_project.id)
+ end
+
+ retry_block do
+ dropdown.set_filter_selected false
+ dropdown.expect_checkbox(project.id, true)
+ dropdown.expect_checkbox(other_project.id)
+ dropdown.expect_checkbox(sub_project.id)
+ dropdown.expect_checkbox(sub_sub_project.id, true)
+ end
+ end
+end
diff --git a/spec/features/work_packages/table/work_packages_table_project_include_spec.rb b/spec/features/work_packages/table/work_packages_table_project_include_spec.rb
new file mode 100644
index 00000000000..698612bfa80
--- /dev/null
+++ b/spec/features/work_packages/table/work_packages_table_project_include_spec.rb
@@ -0,0 +1,75 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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.
+#++
+
+require 'spec_helper'
+require_relative '../project_include/project_include_shared_examples'
+
+describe 'Calendar project include', type: :feature, js: true do
+ shared_let(:enabled_modules) { %w[work_package_tracking] }
+ shared_let(:permissions) { %i[view_work_packages edit_work_packages add_work_packages save_queries manage_public_queries] }
+
+ it_behaves_like 'has a project include dropdown' do
+ shared_let(:work_package_view) { Pages::WorkPackagesTable.new(project) }
+
+ it 'correctly filters work packages by project' do
+ dropdown.expect_count 1
+
+ # Make sure the filter gets set once
+ dropdown.toggle!
+ dropdown.expect_open
+ dropdown.click_button 'Apply'
+ dropdown.expect_closed
+
+ work_package_view.expect_work_package_listed(task, other_task)
+ work_package_view.ensure_work_package_not_listed!(sub_bug, sub_sub_bug, other_other_task)
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(sub_sub_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 2
+
+ work_package_view.expect_work_package_listed(task, other_task, sub_sub_bug)
+ work_package_view.ensure_work_package_not_listed!(sub_bug, other_other_task)
+
+ dropdown.toggle!
+ dropdown.toggle_checkbox(other_project.id)
+ dropdown.click_button 'Apply'
+ dropdown.expect_count 3
+
+ work_package_view.expect_work_package_listed(task, other_task, sub_sub_bug, other_other_task)
+ work_package_view.ensure_work_package_not_listed!(sub_bug)
+
+ page.refresh
+
+ work_package_view.expect_work_package_listed(task, other_task, sub_sub_bug, other_other_task)
+ work_package_view.ensure_work_package_not_listed!(sub_bug)
+ end
+ end
+end
diff --git a/spec/support/components/project_include_component.rb b/spec/support/components/project_include_component.rb
new file mode 100644
index 00000000000..e0d1f385d0a
--- /dev/null
+++ b/spec/support/components/project_include_component.rb
@@ -0,0 +1,105 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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.
+#++
+
+module Components
+ class ProjectIncludeComponent
+ include Capybara::DSL
+ include RSpec::Matchers
+
+ def initialize; end
+
+ def toggle!
+ page.find("[data-qa-selector='project-include-button']").click
+ end
+
+ def expect_open
+ expect(page).to have_selector("[data-qa-selector='project-include-list']")
+ end
+
+ def expect_count(count)
+ expect(page).to have_selector("[data-qa-selector='project-include-button'] .badge", text: count)
+ end
+
+ def toggle_checkbox(project_id)
+ page.find("[data-qa-project-include-id='#{project_id}']").click
+ end
+
+ def set_filter_selected(filter)
+ within_body do
+ page.find("label.spot-toggle--option", text: filter ? 'Only selected' : 'All projects').click
+ end
+ end
+
+ def expect_checkbox(project_id, checked = false)
+ page.find(
+ "[data-qa-project-include-id='#{project_id}'][data-qa-project-include-checked='#{checked ? '1' : '0'}']",
+ wait: 10
+ )
+ end
+
+ def expect_no_checkbox(project_id)
+ unless page.has_no_selector?("[data-qa-project-include-id='#{project_id}']")
+ raise "Expected not to find #{project_id}"
+ end
+ end
+
+ def search(text)
+ within_body do
+ fill_in "project-include-search",
+ with: text,
+ fill_options: { clear: :backspace }
+ end
+ end
+
+ def expect_closed
+ expect(page).to have_no_selector("[data-qa-selector='project-include-list']")
+ end
+
+ def click_button(text)
+ within_body do
+ page.find('button', text: text).click
+ end
+ end
+
+ def within_body(&block)
+ page.within(body_selector, &block)
+ end
+
+ def body_element
+ page.find(selector + ' .spot-drop-modal--body')
+ end
+
+ def body_selector
+ selector + ' .spot-drop-modal--body'
+ end
+
+ def selector
+ '.op-project-include'
+ end
+ end
+end