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

[chore] added drag open behvior for tabs

Eric Schubert5019a6e187bd
diff --git a/frontend/src/app/core/global_search/tabs/global-search-tabs.component.ts b/frontend/src/app/core/global_search/tabs/global-search-tabs.component.ts
index efdd815c4fb..fa4520759bc 100644
--- a/frontend/src/app/core/global_search/tabs/global-search-tabs.component.ts
+++ b/frontend/src/app/core/global_search/tabs/global-search-tabs.component.ts
@@ -31,7 +31,10 @@ import {
Component,
OnDestroy,
Injector,
+ OnInit,
+ ChangeDetectionStrategy,
} from '@angular/core';
+import { StateService } from '@uirouter/core';
import { Subscription } from 'rxjs';
import { GlobalSearchService } from 'core-app/core/global_search/services/global-search.service';
import { ScrollableTabsComponent } from 'core-app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component';
@@ -42,9 +45,10 @@ export const globalSearchTabsSelector = 'global-search-tabs';
@Component({
selector: globalSearchTabsSelector,
templateUrl: '../../../shared/components/tabs/scrollable-tabs/scrollable-tabs.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class GlobalSearchTabsComponent extends ScrollableTabsComponent implements OnDestroy {
+export class GlobalSearchTabsComponent extends ScrollableTabsComponent implements OnInit, OnDestroy {
private currentTabSub:Subscription;
private tabsSub:Subscription;
@@ -53,13 +57,14 @@ export class GlobalSearchTabsComponent extends ScrollableTabsComponent implement
constructor(
readonly globalSearchService:GlobalSearchService,
+ protected readonly $state:StateService,
public injector:Injector,
cdRef:ChangeDetectorRef,
) {
- super(cdRef, injector);
+ super($state, cdRef, injector);
}
- ngOnInit() {
+ ngOnInit():void {
this.currentTabSub = this.globalSearchService
.currentTab$
.subscribe((currentTab) => {
@@ -74,7 +79,7 @@ export class GlobalSearchTabsComponent extends ScrollableTabsComponent implement
});
}
- public clickTab(tab:TabDefinition, event:Event) {
+ public clickTab(tab:TabDefinition, event:Event):void {
super.clickTab(tab, event);
this.globalSearchService.currentTab = tab.id;
diff --git a/frontend/src/app/shared/components/tabs/content-tabs/content-tabs.component.ts b/frontend/src/app/shared/components/tabs/content-tabs/content-tabs.component.ts
index ba0999535f3..0d552e0c76b 100644
--- a/frontend/src/app/shared/components/tabs/content-tabs/content-tabs.component.ts
+++ b/frontend/src/app/shared/components/tabs/content-tabs/content-tabs.component.ts
@@ -58,13 +58,13 @@ export class ContentTabsComponent extends ScrollableTabsComponent {
constructor(
readonly elementRef:ElementRef,
- readonly $state:StateService,
+ protected readonly $state:StateService,
readonly gon:GonService,
cdRef:ChangeDetectorRef,
readonly I18n:I18nService,
public injector:Injector,
) {
- super(cdRef, injector);
+ super($state, cdRef, injector);
const gonTabs = JSON.parse((this.gon.get('contentTabs') as any).tabs);
const currentTab = JSON.parse((this.gon.get('contentTabs') as any).selected);
diff --git a/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.html b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.html
index e3e46bbb9e6..53d84ace646 100644
--- a/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.html
+++ b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.html
@@ -3,10 +3,12 @@
#scrollContainer
class="op-scrollable-tabs--tab-container"
>
- <ul #scrollPane class="op-tab-row" (scroll)="onScroll($event)">
+ <ul #scrollPane class="op-tab-row" (scroll)="onScroll()">
<li
*ngFor="let tab of tabs; trackBy:trackById"
class="op-tab-row--tab"
+ (dragenter)="startDebouncedTabActivation(tab)"
+ (dragleave)="cancelDebouncedTabActivation()"
[attr.data-tab-id]="tab.id"
[attr.data-qa-tab-id]="tab.id"
[attr.data-qa-tab-selected]="tab.id === currentTabId || undefined"
diff --git a/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.sass b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.sass
new file mode 100644
index 00000000000..e6099ccd669
--- /dev/null
+++ b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.sass
@@ -0,0 +1,4 @@
+.op-tab-row--tab
+ .op-tab-row--link
+ *
+ pointer-events: none
\ No newline at end of file
diff --git a/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.ts b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.ts
index 9e519e1a3a6..331be2c6681 100644
--- a/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.ts
+++ b/frontend/src/app/shared/components/tabs/scrollable-tabs/scrollable-tabs.component.ts
@@ -14,10 +14,12 @@ import {
} from '@angular/core';
import { TabDefinition } from 'core-app/shared/components/tabs/tab.interface';
import { trackByProperty } from 'core-app/shared/helpers/angular/tracking-functions';
+import { RawParams, StateService } from '@uirouter/core';
@Component({
templateUrl: 'scrollable-tabs.component.html',
selector: 'op-scrollable-tabs',
+ styleUrls: ['./scrollable-tabs.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
@@ -48,18 +50,24 @@ export class ScrollableTabsComponent implements AfterViewInit, OnChanges {
private pane:Element;
+ private debouncedTabActivationTimeout:NodeJS.Timeout|null;
+
+ private dragTargetStack = 0;
+
constructor(
+ protected readonly $state:StateService,
private cdRef:ChangeDetectorRef,
public injector:Injector,
) { }
ngAfterViewInit():void {
- this.container = this.scrollContainer.nativeElement;
- this.pane = this.scrollPane.nativeElement;
+ this.container = this.scrollContainer.nativeElement as HTMLElement;
+ this.pane = this.scrollPane.nativeElement as HTMLElement;
this.updateScrollableArea();
}
+ // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
ngOnChanges(changes:SimpleChanges):void {
if (this.pane) {
this.updateScrollableArea();
@@ -84,7 +92,49 @@ export class ScrollableTabsComponent implements AfterViewInit, OnChanges {
}
}
- public onScroll(event:any):void {
+ public startDebouncedTabActivation(tab:TabDefinition):void {
+ // 'dragenter' events are always fired before 'dragleave' events. Hence, when dragging directly from one tab to
+ // another, first the dragenter of the new tab is fired, before we get a dragleave from the old one.
+ // Therefor we keep the drag stack, which can raise from 0 to 2. And we only clear the debounced tab activation
+ // completely when we fully leave tabs (which means, drag stack is 0).
+ this.dragTargetStack += 1;
+
+ if (this.debouncedTabActivationTimeout !== null) {
+ this.clearDebouncedTabActivation();
+ }
+
+ this.debouncedTabActivationTimeout = setTimeout(() => {
+ this.currentTabId = tab.id;
+ this.tabSelected.emit(tab);
+
+ const route = this.$state.includes('**.details.*')
+ ? this.$state.$current.name
+ : tab.route;
+
+ if (route) {
+ void this.$state.go(route, tab.routeParams as RawParams);
+ }
+
+ this.debouncedTabActivationTimeout = null;
+ }, 300);
+ }
+
+ public cancelDebouncedTabActivation():void {
+ this.dragTargetStack -= 1;
+
+ if (this.dragTargetStack === 0) {
+ this.clearDebouncedTabActivation();
+ }
+ }
+
+ private clearDebouncedTabActivation():void {
+ if (this.debouncedTabActivationTimeout !== null) {
+ clearTimeout(this.debouncedTabActivationTimeout);
+ this.debouncedTabActivationTimeout = null;
+ }
+ }
+
+ public onScroll():void {
this.determineScrollButtonVisibility();
}