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
Create routes for new gantt module. Therefore the some logic from the WorkPackagesController was extracted into a helper to avoid doubling it
Henriette Dargedae1754549f3
diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rbindex 0635b21b775..44db62d46fe 100644--- a/app/controllers/work_packages_controller.rb+++ b/app/controllers/work_packages_controller.rb@@ -30,6 +30,7 @@ class WorkPackagesController < ApplicationControllerinclude QueriesHelperinclude PaginationHelperinclude Layout+ include WorkPackagesControllerHelperaccept_key_auth :index, :show@@ -116,49 +117,12 @@ class WorkPackagesController < ApplicationControllerjournals: }end- def atom_list- render_feed(@work_packages,- title: "#{@project || Setting.app_title}: #{I18n.t(:label_work_package_plural)}")- end-privatedef authorize_on_work_packagedeny_access(not_found: true) unless work_packageend- def protect_from_unauthorized_export- if (supported_list_formats + %w[atom]).include?(params[:format]) && !user_allowed_to_export?- deny_access- false- end- end-- def user_allowed_to_export?- User.current.allowed_in_any_work_package?(:export_work_packages, in_project: @project)- end-- def supported_list_formats- ::Exports::Register.list_formats(WorkPackage).map(&:to_s)- end-- def supported_single_formats- ::Exports::Register.single_formats(WorkPackage).map(&:to_s)- end-- def load_and_validate_query- @query ||= retrieve_query(@project)- @query.name = params[:title] if params[:title].present?-- unless @query.valid?- # Ensure outputting an html response- request.format = 'html'- render_400(message: @query.errors.full_messages.join(". "))- end- rescue ActiveRecord::RecordNotFound- render_404- end-def per_page_paramcase params[:format]when 'atom'diff --git a/app/helpers/work_packages_controller_helper.rb b/app/helpers/work_packages_controller_helper.rbnew file mode 100644index 00000000000..8189508469f--- /dev/null+++ b/app/helpers/work_packages_controller_helper.rb@@ -0,0 +1,66 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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 WorkPackagesControllerHelper+ def protect_from_unauthorized_export+ if (supported_list_formats + %w[atom]).include?(params[:format]) && !user_allowed_to_export?+ deny_access+ false+ end+ end++ def user_allowed_to_export?+ User.current.allowed_in_any_work_package?(:export_work_packages, in_project: @project)+ end++ def supported_list_formats+ ::Exports::Register.list_formats(WorkPackage).map(&:to_s)+ end++ def supported_single_formats+ ::Exports::Register.single_formats(WorkPackage).map(&:to_s)+ end++ def load_and_validate_query+ @query ||= retrieve_query(@project)+ @query.name = params[:title] if params[:title].present?++ unless @query.valid?+ # Ensure outputting an html response+ request.format = 'html'+ render_400(message: @query.errors.full_messages.join(". "))+ end+ rescue ActiveRecord::RecordNotFound+ render_404+ end++ def atom_list+ render_feed(@work_packages,+ title: "#{@project || Setting.app_title}: #{I18n.t(:label_work_package_plural)}")+ end+enddiff --git a/frontend/src/app/features/work-packages/openproject-work-package-routes.module.ts b/frontend/src/app/features/work-packages/openproject-work-package-routes.module.tsindex a5a7176fde7..a5011392f29 100644--- a/frontend/src/app/features/work-packages/openproject-work-package-routes.module.ts+++ b/frontend/src/app/features/work-packages/openproject-work-package-routes.module.ts@@ -30,6 +30,7 @@ import { NgModule } from '@angular/core';import { UIRouterModule } from '@uirouter/angular';import { WORK_PACKAGES_ROUTES } from 'core-app/features/work-packages/routing/work-packages-routes';import { OpenprojectWorkPackagesModule } from 'core-app/features/work-packages/openproject-work-packages.module';+import { WORK_PACKAGES_GANTT_ROUTES } from 'core-app/features/work-packages/routing/work-packages-gantt-routes';/*** Separate module for work package routes because WP modules@@ -44,7 +45,7 @@ import { OpenprojectWorkPackagesModule } from 'core-app/features/work-packages/oOpenprojectWorkPackagesModule,// Routes for /work_packages- UIRouterModule.forChild({ states: WORK_PACKAGES_ROUTES }),+ UIRouterModule.forChild({ states: [...WORK_PACKAGES_ROUTES, ...WORK_PACKAGES_GANTT_ROUTES] }),],})export class OpenprojectWorkPackageRoutesModule {diff --git a/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.tsnew file mode 100644index 00000000000..7656d2e30dc--- /dev/null+++ b/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts@@ -0,0 +1,86 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-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 { WorkPackageSplitViewComponent } from 'core-app/features/work-packages/routing/wp-split-view/wp-split-view.component';+import { Ng2StateDeclaration } from '@uirouter/angular';+import { WorkPackagesBaseComponent } from 'core-app/features/work-packages/routing/wp-base/wp--base.component';+import { WorkPackageListViewComponent } from 'core-app/features/work-packages/routing/wp-list-view/wp-list-view.component';+import { WorkPackageViewPageComponent } from 'core-app/features/work-packages/routing/wp-view-page/wp-view-page.component';+import { makeSplitViewRoutes } from 'core-app/features/work-packages/routing/split-view-routes.template';++export const menuItemClass = 'gantt-menu-item';++export const WORK_PACKAGES_GANTT_ROUTES:Ng2StateDeclaration[] = [+ {+ name: 'gantt',+ parent: 'optional_project',+ url: '/gantt?query_id&query_props&start_onboarding_tour',+ redirectTo: 'gantt.partitioned.list',+ views: {+ '!$default': { component: WorkPackagesBaseComponent },+ },+ data: {+ bodyClasses: 'router--work-packages-base',+ menuItem: menuItemClass,+ },+ params: {+ query_id: { type: 'query', dynamic: true },+ // Use custom encoder/decoder that ensures validity of URL string+ query_props: { type: 'opQueryString' },+ // Optional initial tour param+ start_onboarding_tour: { type: 'query', squash: true, value: undefined },+ },+ },+ {+ name: 'gantt.partitioned',+ component: WorkPackageViewPageComponent,+ url: '',+ data: {+ // This has to be empty to avoid inheriting the parent bodyClasses+ bodyClasses: '',+ },+ },+ {+ name: 'gantt.partitioned.list',+ url: '',+ reloadOnSearch: false,+ views: {+ 'content-left': { component: WorkPackageListViewComponent },+ },+ data: {+ bodyClasses: 'router--work-packages-partitioned-split-view',+ menuItem: menuItemClass,+ partition: '-left-only',+ },+ },+ ...makeSplitViewRoutes(+ 'gantt.partitioned.list',+ menuItemClass,+ WorkPackageSplitViewComponent,+ ),+];diff --git a/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts b/frontend/src/app/shared/components/op-view-select/op-static-queries.service.tsindex 8c20c3bbb65..654a440db50 100644--- a/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts+++ b/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts@@ -164,8 +164,7 @@ export class StaticQueriesService {},{title: this.text.gantt,- // TODO: GANTT- uiSref: 'work-packages',+ uiSref: 'gantt',uiParams: {query_id: '',query_props: '{"c":["id","type","subject","status","startDate","dueDate","duration"],"tv":true,"tzl":"auto","tll":"{\\"left\\":\\"startDate\\",\\"right\\":\\"dueDate\\",\\"farRight\\":\\"subject\\"}","hi":true,"g":"","t":"startDate:asc","f":[{"n":"status","o":"o","v":[]}]}',diff --git a/modules/gantt/app/controllers/gantt/gantt_controller.rb b/modules/gantt/app/controllers/gantt/gantt_controller.rbindex 57c73096eba..a779c17e5d5 100644--- a/modules/gantt/app/controllers/gantt/gantt_controller.rb+++ b/modules/gantt/app/controllers/gantt/gantt_controller.rb@@ -1,5 +1,31 @@module ::Gantt- class GanttController < BaseController+ class GanttController < ApplicationController+ include Layout+ include WorkPackagesControllerHelper++ accept_key_auth :index++ before_action :find_optional_project, :protect_from_unauthorized_export, only: :index++ before_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }+menu_item :gantt+ def index+ respond_to do |format|+ format.html do+ render :index,+ locals: { query: @query, project: @project, menu_name: project_or_global_menu },+ layout: 'angular/angular'+ end++ format.any(*supported_list_formats) do+ export_list(request.format.symbol)+ end++ format.atom do+ atom_list+ end+ end+ endendenddiff --git a/modules/gantt/app/views/gantt/gantt/index.html.erb b/modules/gantt/app/views/gantt/gantt/index.html.erbnew file mode 100644index 00000000000..8cf4d680be5--- /dev/null+++ b/modules/gantt/app/views/gantt/gantt/index.html.erb@@ -0,0 +1,36 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 2012-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.++++#%>++<% html_title(t('label_gantt')) -%>+<%= call_hook(:view_work_packages_index_bottom, { project: project, query: query }) %>++<% content_for :header_tags do %>+ <%= auto_discovery_link_tag(:atom, {query_id: query, format: 'atom', page: nil, key: User.current.rss_key}, title: t(:label_gantt)) %>+ <%= auto_discovery_link_tag(:atom, {controller: '/journals', action: 'index', query_id: query, format: 'atom', page: nil, key: User.current.rss_key}, title: t(:label_changes_details)) %>+<% end %>diff --git a/modules/gantt/config/routes.rb b/modules/gantt/config/routes.rbindex 4b187994b18..f6ec732fac9 100644--- a/modules/gantt/config/routes.rb+++ b/modules/gantt/config/routes.rb@@ -1,2 +1,21 @@-# OpenProject::Application.routes.draw do-# end+OpenProject::Application.routes.draw do+ scope 'projects/:project_id', as: 'project' do+ resources :gantt, controller: 'gantt/gantt', only: [:index] do+ collection do+ # states managed by client-side routing on work_package#index+ get '(/*state)' => 'gantt/gantt#index', as: ''+ get '/create_new' => 'gantt/gantt#index', as: 'new_split'+ end+ end+ end++ resources :gantt, controller: 'gantt/gantt', only: [:index] do+ collection do+ # states managed by client-side routing on work_package#index+ get 'details/*state' => 'gantt/gantt#index', as: :details++ # states managed by client-side (angular) routing on work_package#show+ get '/' => 'gantt/gantt#index', as: 'index'+ end+ end+enddiff --git a/modules/gantt/lib/open_project/gantt/engine.rb b/modules/gantt/lib/open_project/gantt/engine.rbindex 0580af7535e..fffb334d0db 100644--- a/modules/gantt/lib/open_project/gantt/engine.rb+++ b/modules/gantt/lib/open_project/gantt/engine.rb@@ -53,7 +53,7 @@ module OpenProject::Gantt# menu :global_menu,# :gantt,- # { controller: '/work_packages', action: 'index' },+ # { controller: '/gantt/gantt', action: 'index' },# caption: :label_gantt,# icon: 'view-timeline',# html: {@@ -62,7 +62,7 @@ module OpenProject::Ganttmenu :project_menu,:gantt,- { controller: '/work_packages', action: 'index' },+ { controller: '/gantt/gantt', action: 'index' },caption: :label_gantt,after: :work_packages,if: ->(project) { project.module_enabled?(:gantt) },@@ -73,7 +73,7 @@ module OpenProject::Ganttmenu :project_menu,:gantt_query_select,- { controller: '/work_packages', action: 'index' },+ { controller: '/gantt/gantt', action: 'index' },parent: :gantt,partial: 'gantt/gantt/menu',last: true,@@ -82,7 +82,7 @@ module OpenProject::Gantt# menu :top_menu,# :gantt,- # { controller: '/work_packages', action: 'index' },+ # { controller: '/gantt/gantt', action: 'index' },# caption: :label_gantt,# icon: 'view-timeline',# html: {