Skip to content

Commit

Permalink
Replace angular sidemenu with rails based Submenu component for TeamP…
Browse files Browse the repository at this point in the history
…lanner module
  • Loading branch information
HDinger committed Jun 20, 2024
1 parent 2c0e56d commit 36a1bb8
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 119 deletions.
7 changes: 4 additions & 3 deletions app/components/open_project/common/submenu_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<% top_level_sidebar_menu_items.first.children.each do |menu_item| %>
<li class="op-sidemenu--item" data-filter--filter-list-target="searchItem">
<% selected = menu_item.selected ? 'selected' : '' %>
<a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item.href %>">
<a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item.href %>" data-test-selector="op-sidemenu--item-action">
<span class="op-sidemenu--item-title"><%= menu_item.title %></span>
</a>
</li>
Expand Down Expand Up @@ -60,7 +60,7 @@
<% menu_item.children.each do |child_item| %>
<li class="op-sidemenu--item" data-filter--filter-list-target="searchItem">
<% selected = child_item.selected ? 'selected' : '' %>
<a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item.href %>">
<a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item.href %>" data-test-selector="op-sidemenu--item-action">
<span class="op-sidemenu--item-title"><%= child_item.title %></span>
</a>
</li>
Expand All @@ -75,9 +75,10 @@
<%= render Primer::Beta::Button.new(scheme: :primary,
tag: :a,
href: @create_btn_options[:href],
test_selector: "#{@create_btn_options[:module_key]}--create-button",
classes: "op-sidebar--footer-action") do |button|
button.with_leading_visual_icon(icon: "plus")
@create_btn_options[:text]
I18n.t("label_#{@create_btn_options[:module_key]}")
end %>
</div>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ import {
opInAppNotificationBellSelector,
} from 'core-app/features/in-app-notifications/bell/in-app-notification-bell.component';
import { IanMenuComponent, ianMenuSelector } from 'core-app/features/in-app-notifications/center/menu/menu.component';
import {
opTeamPlannerSidemenuSelector,
TeamPlannerSidemenuComponent,
} from 'core-app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component';
import {
OpModalOverlayComponent,
opModalOverlaySelector,
Expand Down Expand Up @@ -213,7 +209,6 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: headerProjectSelectSelector, cls: OpHeaderProjectSelectComponent },
{ selector: wpOverviewGraphSelector, cls: WorkPackageOverviewGraphComponent },
{ selector: opViewSelectSelector, cls: ViewSelectComponent },
{ selector: opTeamPlannerSidemenuSelector, cls: TeamPlannerSidemenuComponent },
{ selector: triggerActionsEntryComponentSelector, cls: TriggerActionsEntryComponent, embeddable: true },
{ selector: editableQueryPropsSelector, cls: EditableQueryPropsComponent },
{ selector: backupSelector, cls: BackupComponent },
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { TeamPlannerPageComponent } from 'core-app/features/team-planner/team-pl
import { OpSharedModule } from 'core-app/shared/shared.module';
import { AddExistingPaneComponent } from './add-work-packages/add-existing-pane.component';
import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';
import { TeamPlannerSidemenuComponent } from 'core-app/features/team-planner/team-planner/sidemenu/team-planner-sidemenu.component';
import { TeamPlannerViewSelectMenuDirective } from 'core-app/features/team-planner/team-planner/view-select/view-select-menu.directive';

@NgModule({
Expand All @@ -23,7 +22,6 @@ import { TeamPlannerViewSelectMenuDirective } from 'core-app/features/team-plann
TeamPlannerPageComponent,
AddAssigneeComponent,
AddExistingPaneComponent,
TeamPlannerSidemenuComponent,
TeamPlannerViewSelectMenuDirective,
],
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ import { WorkPackagesBaseComponent } from 'core-app/features/work-packages/routi
import { TeamPlannerPageComponent } from 'core-app/features/team-planner/team-planner/page/team-planner-page.component';
import { TeamPlannerComponent } from 'core-app/features/team-planner/team-planner/planner/team-planner.component';

export const sidemenuId = 'team_planner_sidemenu';
export const sideMenuOptions = {
sidemenuId,
hardReloadOnBaseRoute: true,
defaultQuery: 'new',
};

export const TEAM_PLANNER_ROUTES:Ng2StateDeclaration[] = [
{
name: 'team_planner',
Expand All @@ -56,12 +63,14 @@ export const TEAM_PLANNER_ROUTES:Ng2StateDeclaration[] = [
redirectTo: 'team_planner.page.show',
data: {
bodyClasses: 'router--team-planner',
sideMenuOptions,
},
},
{
name: 'team_planner.page.show',
data: {
baseRoute: 'team_planner.page.show',
sideMenuOptions,
},
views: {
'content-left': { component: TeamPlannerComponent },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def searchable
def with_create_button
render_with_template(template: "open_project/common/submenu_preview/playground",
locals: { sidebar_menu_items: menu_items, searchable: true,
create_btn_options: { href: "/#", text: "User" } })
create_btn_options: { href: "/#", module_key: "user" } })
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MenusController < ApplicationController
def show
@submenu_menu_items = ::Calendar::Menu.new(project: @project, params:).menu_items
@create_btn_options = if User.current.allowed_in_project?(:manage_calendars, @project)
{ href: new_project_calendars_path(@project), text: I18n.t("label_calendar") }
{ href: new_project_calendars_path(@project), module_key: "calendar" }
end

render layout: nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -- 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 ::TeamPlanner
class MenusController < ApplicationController
before_action :find_project_by_project_id,
:authorize

def show
@submenu_menu_items = ::TeamPlanner::Menu.new(project: @project, params:).menu_items
if User.current.allowed_in_project?(:manage_team_planner, @project) &&
EnterpriseToken.allows_to?(:team_planner_view)
@create_btn_options = { href: new_project_team_planners_path(@project), module_key: "team_planner" }
end

render layout: nil
end
end
end
56 changes: 56 additions & 0 deletions modules/team_planner/app/menus/team_planner/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -- 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 TeamPlanner
class Menu < Submenu
attr_reader :view_type, :project

def initialize(project: nil, params: nil)
@view_type = "team_planner"
@project = project
@params = params

super(view_type:, project:, params:)
end

def default_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_team_planner_path(project, query_params)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_frame_tag "team_planner_sidemenu",
src: menu_project_team_planners_path(@project, **params.permit(:id)),
target: '_top',
data: { turbo: false },
loading: :lazy %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_frame_tag "team_planner_sidemenu" do %>
<%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @submenu_menu_items,
searchable: true,
create_btn_options: @create_btn_options) %>
<% end %>

This file was deleted.

1 change: 1 addition & 0 deletions modules/team_planner/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
only: %i[index destroy],
as: :team_planners do
collection do
get "menu" => "team_planner/menus#show"
get "/upsale", to: "team_planner/team_planner#upsale", as: :upsale
get "/new", to: "team_planner/team_planner#show", as: :new
end
Expand Down
5 changes: 3 additions & 2 deletions modules/team_planner/lib/open_project/team_planner/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Engine < ::Rails::Engine
settings: {} do
project_module :team_planner_view, dependencies: :work_package_tracking, enterprise_feature: true do
permission :view_team_planner,
{ "team_planner/team_planner": %i[index show upsale overview] },
{ "team_planner/team_planner": %i[index show upsale overview],
"team_planner/menus": %i[show] },
permissible_on: :project,
dependencies: %i[view_work_packages],
contract_actions: { team_planner: %i[read] }
Expand Down Expand Up @@ -80,7 +81,7 @@ class Engine < ::Rails::Engine
:team_planner_menu,
{ controller: "/team_planner/team_planner", action: :index },
parent: :team_planner_view,
partial: "team_planner/team_planner/menu",
partial: "team_planner/menus/menu",
last: true,
caption: :"team_planner.label_team_planner_plural"

Expand Down
10 changes: 5 additions & 5 deletions modules/team_planner/spec/features/query_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
let(:team_planner) { Pages::TeamPlanner.new project }
let(:work_package_page) { Pages::WorkPackagesTable.new project }
let(:query_title) { Components::WorkPackages::QueryTitle.new }
let(:query_menu) { Components::WorkPackages::QueryMenu.new }
let(:query_menu) { Components::Submenu.new }
let(:filters) { team_planner.filters }

current_user { user }
Expand Down Expand Up @@ -114,8 +114,8 @@

it "shows only team planner queries" do
# Go to team planner where no query is shown, only the create option
query_menu.expect_no_menu_entry
expect(page).to have_test_selector("team-planner--create-button")
query_menu.expect_no_items
expect(page).to have_test_selector("team_planner--create-button")

# Change filter
filters.open
Expand All @@ -128,11 +128,11 @@
team_planner.expect_and_dismiss_toaster(message: I18n.t("js.notice_successful_create"))

# The saved query appears in the side menu...
query_menu.expect_menu_entry "I am your Query"
query_menu.expect_item "I am your Query"

# .. but not in the work packages module
work_package_page.visit!
query_menu.expect_menu_entry_not_visible "I am your Query"
query_menu.expect_no_item "I am your Query"
end

it_behaves_like "module specific query view management" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
end

it "can create an action through the sidebar" do
find_test_selector("team-planner--create-button").click
find_test_selector("team_planner--create-button").click

team_planner.expect_no_toaster
team_planner.expect_title
Expand Down
Loading

0 comments on commit 36a1bb8

Please sign in to comment.