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

Exclude learn more link on mobile layout Introduce a base class to reuse mobile layout inference

Kabiru Mwenjafc3d8a5b30d8
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rb
index 26dbd3f91e4..21501794a5d 100644
--- a/app/components/work_packages/activities_tab/index_component.rb
+++ b/app/components/work_packages/activities_tab/index_component.rb
@@ -50,22 +50,20 @@ module WorkPackages
attr_reader :work_package, :filter, :last_server_timestamp, :deferred
def wrapper_data_attributes
- stimulus_controller = activities_tab_index_stimulus_controller
-
{
test_selector: "op-wp-activity-tab",
- controller: stimulus_controller,
+ controller: [base_controller, index_stimulus_controller].join(" "),
"application-target": "dynamic",
- "#{stimulus_controller}-update-streams-path-value": update_streams_work_package_activities_path(work_package),
- "#{stimulus_controller}-sorting-value": journal_sorting,
- "#{stimulus_controller}-filter-value": filter,
- "#{stimulus_controller}-user-id-value": User.current.id,
- "#{stimulus_controller}-work-package-id-value": work_package.id,
- "#{stimulus_controller}-polling-interval-in-ms-value": polling_interval,
- "#{stimulus_controller}-notification-center-path-name-value": notifications_path,
- "#{stimulus_controller}-show-conflict-flash-message-url-value": show_conflict_flash_message_work_packages_path,
- "#{stimulus_controller}-last-server-timestamp-value": last_server_timestamp,
- "#{stimulus_controller}-unsaved-changes-confirmation-message-value": unsaved_changes_confirmation_message
+ "#{base_controller}-notification-center-path-name-value": notifications_path,
+ "#{index_stimulus_controller}-update-streams-path-value": update_streams_work_package_activities_path(work_package),
+ "#{index_stimulus_controller}-sorting-value": journal_sorting,
+ "#{index_stimulus_controller}-filter-value": filter,
+ "#{index_stimulus_controller}-user-id-value": User.current.id,
+ "#{index_stimulus_controller}-work-package-id-value": work_package.id,
+ "#{index_stimulus_controller}-polling-interval-in-ms-value": polling_interval,
+ "#{index_stimulus_controller}-show-conflict-flash-message-url-value": show_conflict_flash_message_work_packages_path,
+ "#{index_stimulus_controller}-last-server-timestamp-value": last_server_timestamp,
+ "#{index_stimulus_controller}-unsaved-changes-confirmation-message-value": unsaved_changes_confirmation_message
}
end
@@ -77,7 +75,7 @@ module WorkPackages
controller: stimulus_controller,
"application-target": "dynamic",
"#{stimulus_controller}-target": "formContainer",
- action: "#{activities_tab_index_stimulus_controller}:onSubmit-end@window->#{stimulus_controller}#onSubmitEnd",
+ action: "#{index_stimulus_controller}:onSubmit-end@window->#{stimulus_controller}#onSubmitEnd",
"#{stimulus_controller}-highlight-class": "work-packages-activities-tab-journals-new-component--journal-notes-body__restricted-comment", # rubocop:disable Layout/LineLength
"#{stimulus_controller}-hidden-class": "d-none"
}
@@ -96,7 +94,8 @@ module WorkPackages
User.current.allowed_in_work_package?(:add_work_package_notes, @work_package)
end
- def activities_tab_index_stimulus_controller = "work-packages--activities-tab--index"
+ def base_controller = "work-packages--activities-tab--base"
+ def index_stimulus_controller = "work-packages--activities-tab--index"
def unsaved_changes_confirmation_message
I18n.t("activities.work_packages.activity_tab.unsaved_changes_confirmation_message")
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts
new file mode 100644
index 00000000000..7463ea48b10
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/base.controller.ts
@@ -0,0 +1,57 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 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.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export class BaseController extends Controller {
+ static values = {
+ notificationCenterPathName: { type: String, default: '/notifications' },
+ };
+
+ declare readonly notificationCenterPathNameValue:string;
+
+ private readonly MOBILE_BREAKPOINT = 1279;
+ private readonly MOBILE_BREAKPOINT_WITHIN_SPLIT_SCREENS = 1013;
+
+ public isMobile():boolean {
+ if (this.isWithinNotificationCenter() || this.isWithinSplitScreen()) {
+ return window.innerWidth < this.MOBILE_BREAKPOINT_WITHIN_SPLIT_SCREENS;
+ }
+ return window.innerWidth < this.MOBILE_BREAKPOINT;
+ }
+
+ public isWithinNotificationCenter():boolean {
+ return window.location.pathname.includes(this.notificationCenterPathNameValue);
+ }
+
+ public isWithinSplitScreen():boolean {
+ return window.location.pathname.includes('work_packages/details');
+ }
+}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index 19718287c8a..69f8d6af2a2 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -28,7 +28,7 @@
* ++
*/
-import { Controller } from '@hotwired/stimulus';
+import { BaseController } from './base.controller';
import {
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
@@ -47,7 +47,7 @@ interface CustomEventWithIdParam extends Event {
};
}
-export default class IndexController extends Controller {
+export default class IndexController extends BaseController {
static values = {
updateStreamsPath: String,
sorting: String,
@@ -55,7 +55,7 @@ export default class IndexController extends Controller {
filter: String,
userId: Number,
workPackageId: Number,
- notificationCenterPathName: String,
+ notificationCenterPathName: { type: String, default: '/notifications' },
lastServerTimestamp: String,
showConflictFlashMessageUrl: String,
unsavedChangesConfirmationMessage: String,
@@ -77,7 +77,6 @@ export default class IndexController extends Controller {
declare lastServerTimestampValue:string;
declare intervallId:number;
declare pollingIntervalInMsValue:number;
- declare notificationCenterPathNameValue:string;
declare filterValue:string;
declare userIdValue:number;
declare workPackageIdValue:number;
@@ -521,22 +520,6 @@ export default class IndexController extends Controller {
return document.querySelector(`[data-anchor-${activityAnchorName}-id="${activityId}"]`);
}
- // Code Maintenance: Get rid of this JS based view port checks when activities are rendered in fully primierized activity tab in all contexts
- private isMobile():boolean {
- if (this.isWithinNotificationCenter() || this.isWithinSplitScreen()) {
- return window.innerWidth < 1013;
- }
- return window.innerWidth < 1279;
- }
-
- private isWithinNotificationCenter():boolean {
- return window.location.pathname.includes(this.notificationCenterPathNameValue);
- }
-
- private isWithinSplitScreen():boolean {
- return window.location.pathname.includes('work_packages/details');
- }
-
private setCssClasses() {
if (this.isWithinNotificationCenter()) {
this.element.classList.add('work-packages-activities-tab-index-component--within-notification-center');
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
index e118897a116..303a1eeccc3 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
@@ -28,9 +28,9 @@
* ++
*/
-import { Controller } from '@hotwired/stimulus';
+import { BaseController } from './base.controller';
-export default class RestrictedCommentController extends Controller {
+export default class RestrictedCommentController extends BaseController {
static targets = ['restrictedCheckbox', 'formContainer', 'learnMoreLink'];
static classes = ['highlight', 'hidden'];
@@ -46,12 +46,15 @@ export default class RestrictedCommentController extends Controller {
}
toggleBackgroundColor():void {
- if (this.restrictedCheckboxTarget.checked) {
- this.formContainerTarget.classList.add(this.highlightClass);
- this.learnMoreLinkTarget.classList.remove(this.hiddenClass);
- } else {
- this.formContainerTarget.classList.remove(this.highlightClass);
- this.learnMoreLinkTarget.classList.add(this.hiddenClass);
- }
+ const isChecked = this.restrictedCheckboxTarget.checked;
+
+ this.formContainerTarget.classList.toggle(this.highlightClass, isChecked);
+ this.toggleLearnMoreLink(isChecked);
+ }
+
+ private toggleLearnMoreLink(isChecked:boolean):void {
+ if (this.isMobile()) return; // hidden on mobile
+
+ this.learnMoreLinkTarget.classList.toggle(this.hiddenClass, !isChecked);
}
}