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

Use data-selectors to be more future proof and take care that automatic scrolling also works on split screens

Henriette Dargedfee86cccf5e
diff --git a/frontend/src/app/features/work-packages/components/wp-activity/revision/revision-activity.component.html b/frontend/src/app/features/work-packages/components/wp-activity/revision/revision-activity.component.html
index e517866d7d1..1dc5af0851f 100644
--- a/frontend/src/app/features/work-packages/components/wp-activity/revision/revision-activity.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-activity/revision/revision-activity.component.html
@@ -1,6 +1,7 @@
<div
class="work-package-details-activities-activity-contents"
*ngIf="workPackage"
+ [attr.data-notification-selector]="hasUnreadNotification ? 'notification-activity' : null"
>
<div class="comments-number">
<span
diff --git a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.html b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.html
index 1dce3d57075..5ed72e0cefc 100644
--- a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.html
@@ -1,6 +1,7 @@
<div
class="op-user-activity work-package-details-activities-activity-contents"
*ngIf="workPackage"
+ [attr.data-notification-selector]="hasUnreadNotification ? 'notification-activity' : null"
(mouseenter)="focus()"
(mouseleave)="blur()"
>
diff --git a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.sass b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.sass
index af5d36d7257..c95b2506db0 100644
--- a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.sass
+++ b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.sass
@@ -16,7 +16,3 @@
&--avatar
flex-shrink: 0
-
- &--unread-notification-bubble
- &_scrolled
- scroll-margin-top: 200px
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts
index 38835cc3f15..f538eba51a9 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts
@@ -42,6 +42,7 @@ import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';
+import { take } from 'rxjs/internal/operators/take';
@Directive()
export class ActivityPanelBaseController extends UntilDestroyedMixin implements OnInit {
@@ -68,6 +69,8 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
showAll: this.I18n.t('js.label_activity_show_all'),
};
+ private additionalScrollMargin = 200;
+
constructor(
readonly apiV3Service:APIV3Service,
readonly I18n:I18nService,
@@ -94,7 +97,13 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
void this.wpActivity.require(this.workPackage).then((activities:HalResource[]) => {
this.updateActivities(activities);
this.cdRef.detectChanges();
- this.scrollToUnreadNotification();
+ this.storeService.query.hasNotifications$
+ .pipe(take(1))
+ .subscribe((hasNotification) => {
+ if (hasNotification) {
+ this.scrollToUnreadNotification();
+ }
+ });
});
});
}
@@ -141,22 +150,22 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
}
protected scrollToUnreadNotification():void {
+ const unreadNotifications = document.querySelectorAll("[data-notification-selector='notification-activity']");
// scroll to the unread notification only if there is no deep link
- if (window.location.href.indexOf('activity#') > -1) {
- return;
- }
- const unreadNotifications = document.querySelectorAll('.comments-number--bubble');
- const unreadNotificationsLength = unreadNotifications?.length;
- if (!unreadNotificationsLength) {
+ if (window.location.href.indexOf('activity#') > -1 || unreadNotifications.length === 0) {
return;
}
- if (this.reverse) {
- unreadNotifications[unreadNotificationsLength - 1].classList.add('op-user-activity--unread-notification-bubble_scrolled');
- document.getElementsByClassName('tabcontent')[0].scrollTop = (jQuery(unreadNotifications[unreadNotificationsLength - 1]).closest('.op-user-activity')[0] as HTMLElement).offsetTop;
- } else {
- unreadNotifications[0].classList.add('op-user-activity--unread-notification-bubble_scrolled');
- document.getElementsByClassName('tabcontent')[0].scrollTop = (jQuery(unreadNotifications[0]).closest('.op-user-activity')[0] as HTMLElement).offsetTop;
+
+ const notificationElement = unreadNotifications[this.reverse ? unreadNotifications.length - 1 : 0] as HTMLElement;
+ const scrollContainer = document.querySelectorAll("[data-notification-selector='notification-scroll-container']")[0];
+
+ let scrollOffset = notificationElement.offsetTop - (scrollContainer as HTMLElement).offsetTop;
+ if (!this.reverse) {
+ // In normal order we leave same space for context
+ // In reversed order, the context is below and thus no additional space needed
+ scrollOffset -= this.additionalScrollMargin;
}
+ scrollContainer.scrollTop = scrollOffset;
}
public toggleComments():void {
diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
index dcde90f9dad..991369eb9e6 100644
--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
@@ -63,7 +63,9 @@
<div class="work-packages--panel-inner">
<span class="hidden-for-sighted" tabindex="-1" opAutofocus [textContent]="focusAnchorLabel"></span>
<op-wp-tabs [workPackage]="workPackage" view="full"></op-wp-tabs>
- <div class="tabcontent" ui-view>
+ <div class="tabcontent"
+ data-notification-selector='notification-scroll-container'
+ ui-view>
</div>
</div>
diff --git a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.html b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.html
index 08463a9e725..4911cc63d82 100644
--- a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.html
+++ b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.html
@@ -33,7 +33,10 @@
</div>
</div>
- <div class="work-package-details-tab" ui-view></div>
+ <div class="work-package-details-tab"
+ data-notification-selector='notification-scroll-container'
+ ui-view>
+ </div>
</edit-form>
</div>
diff --git a/frontend/src/global_styles/layout/work_packages/_full_view.sass b/frontend/src/global_styles/layout/work_packages/_full_view.sass
index 859efdb2fb0..37b4b6c29ca 100644
--- a/frontend/src/global_styles/layout/work_packages/_full_view.sass
+++ b/frontend/src/global_styles/layout/work_packages/_full_view.sass
@@ -106,7 +106,7 @@
display: grid
grid-template-rows: auto 1fr
height: 100%
- padding: 0 0 10px 15px
+ padding: 5px 0 10px 15px
.tabcontent
height: 100%
diff --git a/frontend/src/global_styles/layout/work_packages/_mobile.sass b/frontend/src/global_styles/layout/work_packages/_mobile.sass
index 22f1220693c..6921a053085 100644
--- a/frontend/src/global_styles/layout/work_packages/_mobile.sass
+++ b/frontend/src/global_styles/layout/work_packages/_mobile.sass
@@ -33,7 +33,7 @@
#main
#content-wrapper
- padding: 0 15px 10px 15px
+ padding: 10px 15px
&.nomenus
top: 0
padding: 0