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
Replace angular sidemenu with rails based Submenu component for the Boards module
Henriette Darge42a72bfe1fb9
diff --git a/app/components/open_project/common/submenu_component.html.erb b/app/components/open_project/common/submenu_component.html.erbindex 6f42ad54916..5b38527ce18 100644--- a/app/components/open_project/common/submenu_component.html.erb+++ b/app/components/open_project/common/submenu_component.html.erb@@ -78,7 +78,11 @@test_selector: "#{@create_btn_options[:module_key]}--create-button",classes: "op-sidebar--footer-action") do |button|button.with_leading_visual_icon(icon: "plus")- I18n.t("label_#{@create_btn_options[:module_key]}")+ if @create_btn_options[:btn_text].present?+ @create_btn_options[:btn_text]+ else+ I18n.t("label_#{@create_btn_options[:module_key]}")+ endend %></div><% end %>diff --git a/frontend/src/app/core/main-menu/submenu.service.ts b/frontend/src/app/core/main-menu/submenu.service.tsnew file mode 100644index 00000000000..941a9cd5cc6--- /dev/null+++ b/frontend/src/app/core/main-menu/submenu.service.ts@@ -0,0 +1,25 @@+import { Injectable } from '@angular/core';+import { TurboElement } from 'core-typings/turbo';+import { StateService } from '@uirouter/core';++@Injectable({ providedIn: 'root' })+export class SubmenuService {+ constructor(protected $state:StateService) {}++ reloadSubmenu():void {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment+ const menuIdentifier:string|undefined = this.$state.current.data.sideMenuOptions?.sidemenuId;++ if (menuIdentifier) {+ const menu = (document.getElementById(menuIdentifier) as HTMLElement&TurboElement);+ const currentSrc = menu.getAttribute('src');++ if (currentSrc && menu) {+ const frameUrl = new URL(currentSrc);++ // Override the frame src to enforce a reload+ menu.setAttribute('src', frameUrl.href);+ }+ }+ }+}diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.tsindex 571d539333e..b57f75b8068 100644--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts@@ -20,7 +20,6 @@ import {CustomDateActionAdminComponent,customDateActionAdminSelector,} from 'core-app/features/work-packages/components/wp-custom-actions/date-action/custom-date-action-admin.component';-import { BoardsMenuComponent, boardsMenuSelector } from 'core-app/features/boards/boards-sidebar/boards-menu.component';import {GlobalSearchWorkPackagesEntryComponent,globalSearchWorkPackagesSelectorEntry,@@ -183,7 +182,6 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [{ selector: globalSearchWorkPackagesSelector, cls: GlobalSearchWorkPackagesComponent },{ selector: homescreenNewFeaturesBlockSelector, cls: HomescreenNewFeaturesBlockComponent },{ selector: customDateActionAdminSelector, cls: CustomDateActionAdminComponent },- { selector: boardsMenuSelector, cls: BoardsMenuComponent },{ selector: globalSearchWorkPackagesSelectorEntry, cls: GlobalSearchWorkPackagesEntryComponent },{ selector: toastsContainerSelector, cls: ToastsContainerComponent },{ selector: sidemenuSelector, cls: OpSidemenuComponent },diff --git a/frontend/src/app/features/boards/board/board-partitioned-page/board-partitioned-page.component.ts b/frontend/src/app/features/boards/board/board-partitioned-page/board-partitioned-page.component.tsindex cc50a353861..f27b4581cbb 100644--- a/frontend/src/app/features/boards/board/board-partitioned-page/board-partitioned-page.component.ts+++ b/frontend/src/app/features/boards/board/board-partitioned-page/board-partitioned-page.component.ts@@ -40,6 +40,7 @@ import {Observable,of,} from 'rxjs';+import { SubmenuService } from 'core-app/core/main-menu/submenu.service';export function boardCardViewHandlerFactory(injector:Injector) {return new CardViewHandlerRegistry(injector);@@ -152,6 +153,7 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {readonly boardFilters:BoardFiltersService,readonly Boards:BoardService,readonly titleService:OpTitleService,+ readonly submenuService:SubmenuService,) {super();}@@ -217,6 +219,7 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {}),finalize(() => {this.toolbarDisabled = false;+ this.reloadSidemenu();this.cdRef.detectChanges();}),).subscribe(() => {@@ -244,4 +247,8 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {protected setPartition(state:Ng2StateDeclaration) {this.currentPartition = (state.data && state.data.partition) ? state.data.partition : '-split';}++ private reloadSidemenu():void {+ this.submenuService.reloadSubmenu();+ }}diff --git a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.html b/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.htmldeleted file mode 100644index 9f431caa7df..00000000000--- a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.html+++ /dev/null@@ -1,22 +0,0 @@-<div- class="op-sidebar--body"->- <op-sidemenu- *ngIf="(boardOptions$ | async) as items"- [items]="items"- >- </op-sidemenu>-</div>--<div class="op-sidebar--footer">- <button- *ngIf="canCreateBoards$ | async"- class="button -primary -expand"- (click)="redirectToNewBoardForm()"- [title]="text.create_new_board"- data-test-selector="sidebar--create-board-button"- >- <span class="spot-icon spot-icon_add"></span>- <span [textContent]="text.board"></span>- </button>-</div>diff --git a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts b/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.tsdeleted file mode 100644index d879f650b6b..00000000000--- a/frontend/src/app/features/boards/boards-sidebar/boards-menu.component.ts+++ /dev/null@@ -1,95 +0,0 @@-import {- Component,- HostBinding,- OnInit,-} from '@angular/core';-import { Observable } from 'rxjs';-import { BoardService } from 'core-app/features/boards/board/board.service';-import { Board } from 'core-app/features/boards/board/board';-import { map } from 'rxjs/operators';-import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { MainMenuNavigationService } from 'core-app/core/main-menu/main-menu-navigation.service';-import { CurrentUserService } from 'core-app/core/current-user/current-user.service';-import { I18nService } from 'core-app/core/i18n/i18n.service';-import { IOpSidemenuItem } from 'core-app/shared/components/sidemenu/sidemenu.component';-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';--export const boardsMenuSelector = 'boards-menu';--@Component({- selector: boardsMenuSelector,- templateUrl: './boards-menu.component.html',-})--export class BoardsMenuComponent extends UntilDestroyedMixin implements OnInit {- @HostBinding('class.op-sidebar') className = true;-- boardOptions$:Observable<IOpSidemenuItem[]> = this- .apiV3Service- .boards- .observeAll()- .pipe(- map((boards:Board[]) => {- const menuItems:IOpSidemenuItem[] = boards.map((board) => ({- title: board.name,- uiSref: 'boards.partitioned.show',- uiParams: {- board_id: board.id,- query_props: undefined,- projects: 'projects',- projectPath: this.currentProject.identifier,- },- uiOptions: { reload: true },- }));-- return menuItems.sort((a, b) => a.title.localeCompare(b.title));- }),- );-- canCreateBoards$ = this- .currentUserService- .hasCapabilities$(- 'boards/create',- this.currentProject.id || null,- )- .pipe(this.untilDestroyed());-- text = {- board: this.I18n.t('js.label_board'),- create_new_board: this.I18n.t('js.boards.create_new'),- };-- constructor(- readonly boardService:BoardService,- readonly apiV3Service:ApiV3Service,- readonly currentProject:CurrentProjectService,- readonly mainMenuService:MainMenuNavigationService,- readonly currentUserService:CurrentUserService,- readonly I18n:I18nService,- readonly pathHelper:PathHelperService,- ) {- super();- }-- ngOnInit():void {- // When activating the boards submenu,- // either initially or through click on the toggle, load the results- this.mainMenuService- .onActivate('boards')- .subscribe(() => {- this.focusBackArrow();- void this.boardService.loadAllBoards();- });- }-- redirectToNewBoardForm():void {- window.location.href = this.pathHelper.newBoardsPath(this.currentProject.identifier);- }-- private focusBackArrow():void {- const buttonArrowLeft = jQuery('*[data-name="boards"] .main-menu--arrow-left-to-project');- buttonArrowLeft.focus();- }-}diff --git a/frontend/src/app/features/boards/openproject-boards.module.ts b/frontend/src/app/features/boards/openproject-boards.module.tsindex 8151a3202c6..e10f851a8d6 100644--- a/frontend/src/app/features/boards/openproject-boards.module.ts+++ b/frontend/src/app/features/boards/openproject-boards.module.ts@@ -36,7 +36,6 @@ import { BoardsRootComponent } from 'core-app/features/boards/boards-root/boardsimport { BoardInlineAddAutocompleterComponent } from 'core-app/features/boards/board/inline-add/board-inline-add-autocompleter.component';import { BoardsToolbarMenuDirective } from 'core-app/features/boards/board/toolbar-menu/boards-toolbar-menu.directive';import { BoardConfigurationModalComponent } from 'core-app/features/boards/board/configuration-modal/board-configuration.modal';-import { BoardsMenuComponent } from 'core-app/features/boards/boards-sidebar/boards-menu.component';import { AddListModalComponent } from 'core-app/features/boards/board/add-list-modal/add-list-modal.component';import { BoardHighlightingTabComponent } from 'core-app/features/boards/board/configuration-modal/tabs/highlighting-tab.component';import { AddCardDropdownMenuDirective } from 'core-app/features/boards/board/add-card-dropdown/add-card-dropdown-menu.directive';@@ -76,7 +75,6 @@ import { OpenprojectAutocompleterModule } from 'core-app/shared/components/autocBoardListComponent,BoardsRootComponent,BoardInlineAddAutocompleterComponent,- BoardsMenuComponent,BoardHighlightingTabComponent,BoardConfigurationModalComponent,BoardsToolbarMenuDirective,diff --git a/frontend/src/app/features/boards/openproject-boards.routes.ts b/frontend/src/app/features/boards/openproject-boards.routes.tsindex 70fd46aae91..a31fad5d05b 100644--- a/frontend/src/app/features/boards/openproject-boards.routes.ts+++ b/frontend/src/app/features/boards/openproject-boards.routes.ts@@ -35,6 +35,12 @@ import { WorkPackageSplitViewComponent } from 'core-app/features/work-packages/rexport const menuItemClass = 'boards-menu-item';+export const sidemenuId = 'boards_sidemenu';+export const sideMenuOptions = {+ sidemenuId,+ hardReloadOnBaseRoute: true,+};+export const BOARDS_ROUTES:Ng2StateDeclaration[] = [{name: 'boards',@@ -45,6 +51,7 @@ export const BOARDS_ROUTES:Ng2StateDeclaration[] = [data: {bodyClasses: 'router--boards-view-base',menuItem: menuItemClass,+ sideMenuOptions,},params: {// Use custom encoder/decoder that ensures validity of URL string@@ -63,6 +70,7 @@ export const BOARDS_ROUTES:Ng2StateDeclaration[] = [parent: 'boards',bodyClasses: 'router--boards-full-view',menuItem: menuItemClass,+ sideMenuOptions,},reloadOnSearch: false,component: BoardPartitionedPageComponent,@@ -73,6 +81,7 @@ export const BOARDS_ROUTES:Ng2StateDeclaration[] = [url: '',data: {baseRoute: 'boards.partitioned.show',+ sideMenuOptions,},views: {'content-left': { component: BoardListContainerComponent },diff --git a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.tsindex 7c682c59487..6f6d1935378 100644--- a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts+++ b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts@@ -54,7 +54,7 @@ import { QueryFormResource } from 'core-app/features/hal/resources/query-form-reimport { WorkPackageStatesInitializationService } from './wp-states-initialization.service';import { WorkPackagesListInvalidQueryService } from './wp-list-invalid-query.service';import { WorkPackagesQueryViewService } from 'core-app/features/work-packages/components/wp-list/wp-query-view.service';-import { TurboElement } from 'core-typings/turbo';+import { SubmenuService } from 'core-app/core/main-menu/submenu.service';export interface QueryDefinition {queryParams:{ query_id?:string|null, query_props?:string|null };@@ -104,6 +104,7 @@ export class WorkPackagesListService {protected wpStatesInitialization:WorkPackageStatesInitializationService,protected wpListInvalidQueryService:WorkPackagesListInvalidQueryService,protected wpQueryView:WorkPackagesQueryViewService,+ protected submenuService:SubmenuService,) { }/**@@ -261,7 +262,7 @@ export class WorkPackagesListService {// Reload the query, and then reload the menuthis.reloadQuery(createdQuery).subscribe(() => {this.states.changes.queries.next(createdQuery.id);- this.reloadSidemenu(createdQuery.id);+ this.reloadSidemenu();});return createdQuery;@@ -312,7 +313,7 @@ export class WorkPackagesListService {if (queryAccessibleByUser) {void this.$state.go('.', { query_id: query.id, query_props: null }, { reload: true });this.states.changes.queries.next(query.id);- this.reloadSidemenu(query.id);+ this.reloadSidemenu();} else {this.navigateToDefaultQuery(query);}@@ -343,7 +344,7 @@ export class WorkPackagesListService {this.toastService.addSuccess(this.I18n.t('js.notice_successful_update'));this.states.changes.queries.next(query.id!);- this.reloadSidemenu(query.id);+ this.reloadSidemenu();});return promise;@@ -457,28 +458,11 @@ export class WorkPackagesListService {void this.loadDefaultQuery(projectId);this.states.changes.queries.next(query.id);- this.reloadSidemenu(null);+ this.reloadSidemenu();}}- private reloadSidemenu(selectedQueryId:string|null):void {- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment- const menuIdentifier:string|undefined = this.$state.current.data.sideMenuOptions?.sidemenuId;-- if (menuIdentifier) {- const menu = (document.getElementById(menuIdentifier) as HTMLElement&TurboElement);- const currentSrc = menu.getAttribute('src');-- if (currentSrc && menu) {- const frameUrl = new URL(currentSrc);-- // Override the frame src to enforce a reload- if (selectedQueryId) {- frameUrl.search = `?query_id=${selectedQueryId}`;- }-- menu.setAttribute('src', frameUrl.href);- }- }+ private reloadSidemenu():void {+ this.submenuService.reloadSubmenu();}}diff --git a/modules/boards/app/controllers/boards/menus_controller.rb b/modules/boards/app/controllers/boards/menus_controller.rbnew file mode 100644index 00000000000..341eb1ed251--- /dev/null+++ b/modules/boards/app/controllers/boards/menus_controller.rb@@ -0,0 +1,44 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-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.+# +++module ::Boards+ class MenusController < ApplicationController+ before_action :find_project_by_project_id,+ :authorize++ def show+ @submenu_menu_items = ::Boards::Menu.new(project: @project, params:).menu_items+ @create_btn_options = if User.current.allowed_in_project?(:manage_board_views, @project)+ { href: new_project_work_package_board_path(@project),+ module_key: "boards",+ btn_text: I18n.t("boards.label_board") }+ end++ render layout: nil+ end+ end+enddiff --git a/modules/boards/app/menus/boards/menu.rb b/modules/boards/app/menus/boards/menu.rbnew file mode 100644index 00000000000..0784b8145c7--- /dev/null+++ b/modules/boards/app/menus/boards/menu.rb@@ -0,0 +1,71 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-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.+# +++module Boards+ class Menu < Submenu+ attr_reader :view_type, :project++ def initialize(project: nil, params: nil)+ @project = project+ @params = params++ super(view_type: nil, project:, params:)+ end++ def global_queries+ Boards::Grid.includes(:project)+ .references(:project)+ .where(project: @project)+ .pluck(:id, :name)+ .map { |id, name| menu_item(query_params(id), name) }+ end++ def starred_queries+ []+ end++ def default_queries+ []+ end++ def custom_queries+ []+ end++ def selected?(query_params)+ query_params[:id].to_s == params[:id]+ end++ def query_params(id)+ { id: }+ end++ def query_path(query_params)+ project_work_package_board_path(project, query_params)+ end+ end+enddiff --git a/modules/boards/app/views/boards/boards/_menu_board.html b/modules/boards/app/views/boards/boards/_menu_board.htmldeleted file mode 100644index 48ddc1b6a3a..00000000000--- a/modules/boards/app/views/boards/boards/_menu_board.html+++ /dev/null@@ -1 +0,0 @@-<boards-menu></boards-menu>diff --git a/modules/boards/app/views/boards/menus/_menu.html.erb b/modules/boards/app/views/boards/menus/_menu.html.erbnew file mode 100644index 00000000000..1c703fff83b--- /dev/null+++ b/modules/boards/app/views/boards/menus/_menu.html.erb@@ -0,0 +1,5 @@+ <%= turbo_frame_tag "boards_sidemenu",+ src: menu_project_work_package_boards_path(@project, **params.permit(:id)),+ target: "_top",+ data: { turbo: false },+ loading: :lazy %>diff --git a/modules/boards/app/views/boards/menus/show.html.erb b/modules/boards/app/views/boards/menus/show.html.erbnew file mode 100644index 00000000000..d4ba132edd1--- /dev/null+++ b/modules/boards/app/views/boards/menus/show.html.erb@@ -0,0 +1,5 @@+<%= turbo_frame_tag "boards_sidemenu" do %>+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @submenu_menu_items,+ searchable: true,+ create_btn_options: @create_btn_options) %>+<% end %>diff --git a/modules/boards/config/routes.rb b/modules/boards/config/routes.rbindex 84550482ad2..545afd77102 100644--- a/modules/boards/config/routes.rb+++ b/modules/boards/config/routes.rb@@ -9,6 +9,9 @@ Rails.application.routes.draw docontroller: "boards/boards",only: %i[index show new create],as: :work_package_boards do+ collection do+ get "menu" => "boards/menus#show"+ endget "(/*state)" => "boards/boards#show", on: :member, as: "", constraints: { id: /\d+/ }endenddiff --git a/modules/boards/lib/open_project/boards/engine.rb b/modules/boards/lib/open_project/boards/engine.rbindex 5c3126ae6c8..8d55c8ba178 100644--- a/modules/boards/lib/open_project/boards/engine.rb+++ b/modules/boards/lib/open_project/boards/engine.rb@@ -28,7 +28,8 @@ module OpenProject::Boardssettings: {} doproject_module :board_view, dependencies: :work_package_tracking, order: 80 dopermission :show_board_views,- { "boards/boards": %i[index show] },+ { "boards/boards": %i[index show],+ "boards/menus": %i[show] },permissible_on: :project,dependencies: :view_work_packages,contract_actions: { boards: %i[read] }@@ -50,7 +51,7 @@ module OpenProject::Boards:board_menu,{ controller: "/boards/boards", action: :index },parent: :boards,- partial: "boards/boards/menu_board",+ partial: "boards/menus/menu",last: true,caption: :"boards.label_boards"diff --git a/modules/boards/spec/features/board_navigation_spec.rb b/modules/boards/spec/features/board_navigation_spec.rbindex 9fa5a359a0f..4a82058f93b 100644--- a/modules/boards/spec/features/board_navigation_spec.rb+++ b/modules/boards/spec/features/board_navigation_spec.rb@@ -106,9 +106,9 @@ RSpec.describe "Work Package boards spec", :js, with_ee: %i[board_view] dopage.find_test_selector("main-menu-toggler--boards", wait: 10).click- subitem = page.find_test_selector("op-sidemenu--item-action--Myboard", wait: 10)+ subitem = page.find_test_selector("op-sidemenu--item-action", text: "My board", wait: 10)# Ends with boards due to lazy route- expect(subitem[:href]).to end_with project_work_package_boards_path(project)+ expect(subitem[:href]).to end_with project_work_package_board_path(project, board_view.id)subitem.clickdiff --git a/modules/boards/spec/features/support/board_index_page.rb b/modules/boards/spec/features/support/board_index_page.rbindex d5f1632fb42..ca3c9e094d4 100644--- a/modules/boards/spec/features/support/board_index_page.rb+++ b/modules/boards/spec/features/support/board_index_page.rb@@ -63,7 +63,7 @@ module Pagesclick_link "Board"endelse- find('[data-test-selector="sidebar--create-board-button"]').click+ find('[data-test-selector="boards--create-button"]').clickendnew_board_page = NewBoard.new