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
Scroll to current project in header project select (#11516)
Benjamin Bädorfa8688811d1fb
diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts b/frontend/src/app/shared/components/header-project-select/header-project-select.component.tsindex 41e79e2ab65..222fb17cbf0 100644--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts@@ -55,14 +55,14 @@ import { IProjectData } from 'core-app/shared/components/searchable-project-listexport const headerProjectSelectSelector = 'op-header-project-select';@Component({+ selector: headerProjectSelectSelector,templateUrl: './header-project-select.component.html',+ styleUrls: ['./header-project-select.component.sass'],+ encapsulation: ViewEncapsulation.None,changeDetection: ChangeDetectionStrategy.OnPush,- selector: headerProjectSelectSelector,providers: [SearchableProjectListService,],- encapsulation: ViewEncapsulation.None,- styleUrls: ['./header-project-select.component.sass'],})export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {@HostBinding('class.op-header-project-select') className = true;@@ -140,6 +140,8 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {mergeMap(() => this.searchableProjectListService.fetchingProjects$),);+ private scrollToCurrent = false;+constructor(protected pathHelper:PathHelperService,protected I18n:I18nService,@@ -152,13 +154,20 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {this.projects$.pipe(this.untilDestroyed()).subscribe((projects) => {- this.searchableProjectListService.resetActiveResult(projects);+ if (this.currentProject.id && projects.length && this.scrollToCurrent) {+ this.searchableProjectListService.selectedItemID$.next(parseInt(this.currentProject.id, 10));+ } else {+ this.searchableProjectListService.resetActiveResult(projects);+ }++ this.scrollToCurrent = false;});}toggleDropModal():void {this.dropModalOpen = !this.dropModalOpen;if (this.dropModalOpen) {+ this.scrollToCurrent = true;this.searchableProjectListService.loadAllProjects();}}diff --git a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.htmlindex d242473594b..35c94ae11ac 100644--- a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html+++ b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html@@ -10,11 +10,12 @@class="spot-list--item-action"[ngClass]="{'spot-list--item-action_disabled': project.disabled,- 'spot-list--item-action_active': (searchableProjectListService.activeItemID$ | async) === project.id+ 'spot-list--item-action_active': (searchableProjectListService.selectedItemID$ | async) === project.id}"[title]="project.name"[href]="extendedProjectUrl(project.id)"[attr.data-list-selector]="projectListActionIdentifier"+ [attr.data-project-id]="project.id"><spanclass="spot-list--item-title spot-list--item-title_ellipse-text"@@ -27,7 +28,7 @@[title]="project.name"class="spot-list--item-action spot-list--item-action_disabled"[ngClass]="{- 'spot-list--item-action_active': (searchableProjectListService.activeItemID$ | async) === project.id+ 'spot-list--item-action_active': (searchableProjectListService.selectedItemID$ | async) === project.id}"><spandiff --git a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.ts b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.tsindex 4583136f1ca..2bd3e2a8737 100644--- a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.ts+++ b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.ts@@ -2,12 +2,13 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';import {ChangeDetectionStrategy,Component,+ ElementRef,EventEmitter,HostBinding,Input,+ OnInit,Output,} from '@angular/core';-import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { SearchableProjectListService } from 'core-app/shared/components/searchable-project-list/searchable-project-list.service';import { IProjectData } from 'core-app/shared/components/searchable-project-list/project-data';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';@@ -18,7 +19,7 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.servicetemplateUrl: './header-project-select-list.component.html',styleUrls: ['./header-project-select-list.component.sass'],})-export class OpHeaderProjectSelectListComponent {+export class OpHeaderProjectSelectListComponent implements OnInit {@HostBinding('class.spot-list') classNameList = true;@HostBinding('class.op-header-project-select-list') className = true;@@ -31,23 +32,32 @@ export class OpHeaderProjectSelectListComponent {@Input() searchText = '';- public get currentProjectHref():string|null {- return this.currentProjectService.apiv3Path;- }-public text = {does_not_match_search: this.I18n.t('js.include_projects.tooltip.does_not_match_search'),include_all_selected: this.I18n.t('js.include_projects.tooltip.include_all_selected'),- current_project: this.I18n.t('js.include_projects.tooltip.current_project'),};constructor(readonly I18n:I18nService,- readonly currentProjectService:CurrentProjectService,readonly pathHelper:PathHelperService,readonly searchableProjectListService:SearchableProjectListService,+ readonly elementRef:ElementRef,) { }+ ngOnInit():void {+ if (this.root) {+ this.searchableProjectListService.selectedItemID$.subscribe((selectedItemID) => {+ // We have to push this back once so the component gets time to render the list+ // and we can actually find the element and scroll to it.+ requestAnimationFrame(() => {+ const itemAction = (this.elementRef.nativeElement as HTMLElement)+ .querySelectorAll(`.spot-list--item-action[data-project-id="${selectedItemID || ''}"]`);+ itemAction[0]?.scrollIntoView();+ });+ });+ }+ }+extendedProjectUrl(projectId:string):string {const currentMenuItem = document.querySelector('meta[name="current_menu_item"]') as HTMLMetaElement;const url = this.pathHelper.projectPath(projectId);diff --git a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.tsindex c477fb0765f..04a5fc40982 100644--- a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts+++ b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts@@ -14,6 +14,7 @@ import { HttpClient } from '@angular/common/http';import { KeyCodes } from 'core-app/shared/helpers/keyCodes.enum';import { ID } from '@datorama/akita';import { IProjectData } from './project-data';+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';@Injectable()export class SearchableProjectListService {@@ -28,7 +29,7 @@ export class SearchableProjectListService {this.searchText$.next(val);}- activeItemID$ = new BehaviorSubject<ID|null>(null);+ selectedItemID$ = new BehaviorSubject<ID|null>(null);searchText$ = new BehaviorSubject<string>('');@@ -39,6 +40,7 @@ export class SearchableProjectListService {constructor(readonly http:HttpClient,readonly apiV3Service:ApiV3Service,+ readonly currentProjectService:CurrentProjectService,) { }public loadAllProjects():void {@@ -80,7 +82,7 @@ export class SearchableProjectListService {}onKeydown(event:KeyboardEvent, projects:IProjectData[]):void {- this.activeItemID$+ this.selectedItemID$.pipe(take(1)).subscribe((activeID) => {switch (event.keyCode) {@@ -119,7 +121,7 @@ export class SearchableProjectListService {return null;}- this.activeItemID$.next(findFirstNonDisabledID(projects));+ this.selectedItemID$.next(findFirstNonDisabledID(projects));}private selectPreviousResult(activeID:ID|null, allProjects:IProjectData[]):void {@@ -161,7 +163,7 @@ export class SearchableProjectListService {const foundPreviousID = findPreviousID(activeID, allProjects);if (foundPreviousID !== null) {- this.activeItemID$.next(foundPreviousID);+ this.selectedItemID$.next(foundPreviousID);} else {this.resetActiveResult(allProjects);}@@ -198,7 +200,7 @@ export class SearchableProjectListService {const foundNextID = findNextID(activeID, allProjects);if (foundNextID !== null) {- this.activeItemID$.next(foundNextID);+ this.selectedItemID$.next(foundNextID);} else {this.resetActiveResult(allProjects);}diff --git a/frontend/src/app/spot/styles/sass/components/list.sass b/frontend/src/app/spot/styles/sass/components/list.sassindex 195bf6f185d..86137202387 100644--- a/frontend/src/app/spot/styles/sass/components/list.sass+++ b/frontend/src/app/spot/styles/sass/components/list.sass@@ -23,6 +23,7 @@margin: 0border: 0cursor: pointer+ scroll-margin-top: $spot-spacing-5> *:first-childflex-shrink: 0