Merge pull request #3572 from ulferts/fix/fullscreen_routes

Rework work package index/show page routes
pull/3513/head
Stefan Botzenhart 9 years ago
commit e991984042
  1. 29
      config/routes.rb
  2. 23
      frontend/app/routing.js
  3. 93
      spec/features/work_packages/navigation_spec.rb
  4. 20
      spec/routing/work_packages_spec.rb
  5. 61
      spec/support/pages/full_work_package.rb
  6. 1
      spec/support/pages/page.rb
  7. 69
      spec/support/pages/split_work_package.rb
  8. 74
      spec/support/pages/work_packages_table.rb

@ -297,7 +297,11 @@ OpenProject::Application.routes.draw do
resources :calendar, controller: 'calendars', only: [:index] resources :calendar, controller: 'calendars', only: [:index]
end end
resources :work_packages, only: [:new, :create] do # Prevent the /*state route from overriding Rails' new
# view which is being used for e.g. duplicating work packages.
resources :work_packages, only: [:new]
resources :work_packages, only: [:create] do
get :new_type, on: :collection get :new_type, on: :collection
collection do collection do
@ -305,19 +309,8 @@ OpenProject::Application.routes.draw do
match '/report' => 'work_packages/reports#report', via: :get match '/report' => 'work_packages/reports#report', via: :get
end end
# Prevent the /*state route from overriding Rails' new and create
# view which is being used for e.g. duplicating work packages.
get '/new' => 'work_packages#new', on: :collection
post '/' => 'work_packages#create', on: :collection
# states managed by client-side routing on work_package#index # states managed by client-side routing on work_package#index
get '/*state' => 'work_packages#index', on: :collection get '(/*state)' => 'work_packages#index', on: :collection, as: ''
# explicitly define index for preserving the order in which
# the path helpers are created - this otherwise leads to
# link_to { controller: ... } to point to the create_new path
get '/' => 'work_packages#index', on: :collection
get '/create_new' => 'work_packages#index', on: :collection
end end
resources :activity, :activities, only: :index, controller: 'activities' resources :activity, :activities, only: :index, controller: 'activities'
@ -430,7 +423,7 @@ OpenProject::Application.routes.draw do
get '/bulk' => 'bulk#destroy' get '/bulk' => 'bulk#destroy'
end end
resources :work_packages, only: [:show, :edit, :update, :index] do resources :work_packages, only: [:update, :index] do
get :new_type, on: :member get :new_type, on: :member
get :column_data, on: :collection # TODO move to API get :column_data, on: :collection # TODO move to API
@ -454,10 +447,14 @@ OpenProject::Application.routes.draw do
get 'quoted/:id', action: 'quoted', on: :collection get 'quoted/:id', action: 'quoted', on: :collection
get '/edit' => 'work_packages#edit', on: :member # made explicit to avoid conflict with catch-all route # states managed by client-side routing on work_package#index
get 'details/*state' => 'work_packages#index', on: :collection, as: :details
# made explicit to avoid conflict with catch-all client-side route
get '/edit' => 'work_packages#edit', on: :member
# states managed by client-side (angular) routing on work_package#show # states managed by client-side (angular) routing on work_package#show
get '/:id(/:tab)' => 'work_packages#show', on: :collection get '(/*state)' => 'work_packages#show', on: :member, as: ''
end end
resources :versions, only: [:show, :edit, :update, :destroy] do resources :versions, only: [:show, :edit, :update, :destroy] do

@ -32,8 +32,6 @@ angular.module('openproject')
'$stateProvider', '$stateProvider',
'$urlRouterProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) { function($stateProvider, $urlRouterProvider) {
var wpListStateCfg;
// redirect to default activity tab when user lands at /work_packages/:id // redirect to default activity tab when user lands at /work_packages/:id
// TODO: Preserve #note-4 part of the URL. // TODO: Preserve #note-4 part of the URL.
$urlRouterProvider.when('/work_packages/{id}', '/work_packages/{id}/activity'); $urlRouterProvider.when('/work_packages/{id}', '/work_packages/{id}/activity');
@ -71,7 +69,7 @@ angular.module('openproject')
var wsPromise = WorkPackageService.getWorkPackage($stateParams.workPackageId); var wsPromise = WorkPackageService.getWorkPackage($stateParams.workPackageId);
wsPromise.catch(function(){ wsPromise.catch(function(){
location.href = '/projects' location.href = '/projects';
}); });
return wsPromise; return wsPromise;
@ -110,10 +108,16 @@ angular.module('openproject')
controllerAs: 'watchers' controllerAs: 'watchers'
}) })
.state('work-packages.list', wpListStateCfg = { .state('work-packages.list', {
url: '/projects/{projectPath}/work_packages?query_id&query_props', url: '/{projects}/{projectPath}/work_packages?query_id&query_props',
controller: 'WorkPackagesListController', controller: 'WorkPackagesListController',
templateUrl: '/templates/work_packages.list.html', templateUrl: '/templates/work_packages.list.html',
params: {
// value: null makes the parameter optional
// squash: true avoids duplicate slashes when the paramter is not provided
projectPath: { value: null, squash: true },
projects: { value: null, squash: true }
},
reloadOnSearch: false, reloadOnSearch: false,
// HACK // HACK
// This is to avoid problems with the css depending on which page the // This is to avoid problems with the css depending on which page the
@ -123,15 +127,12 @@ angular.module('openproject')
// states, we need to remove the trigger used in the CSS The correct fix // states, we need to remove the trigger used in the CSS The correct fix
// would be to alter the CSS. // would be to alter the CSS.
onEnter: function(){ onEnter: function(){
jQuery('body').addClass('action-index'); angular.element('body').addClass('action-index');
}, },
onExit: function(){ onExit: function(){
jQuery('body').removeClass('action-index'); angular.element('body').removeClass('action-index');
} }
}) })
.state('work-packages.list-all', _.extend(_.clone(wpListStateCfg), {
url: '/work_packages?query_id&query_props'
}))
.state('work-packages.list.new', { .state('work-packages.list.new', {
url: '/create_new?type', url: '/create_new?type',
controller: 'WorkPackageNewController', controller: 'WorkPackageNewController',

@ -0,0 +1,93 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
RSpec.feature 'Work package navigation' do
let(:user) { FactoryGirl.create(:admin) }
let(:project) { FactoryGirl.create(:project) }
let(:work_package) { FactoryGirl.build(:work_package, project: project) }
before do
work_package.save!
allow(User).to receive(:current).and_return(user)
end
scenario 'all different angular based work package views', js: true do
# deep link global work package index
global_work_packages = Pages::WorkPackagesTable.new
global_work_packages.visit!
global_work_packages.expect_work_package_listed(work_package)
# open details pane for work package
split_work_package = global_work_packages.open_split_view(work_package)
split_work_package.expect_subject
split_work_package.expect_current_path
# open work package full screen
full_work_package = global_work_packages.open_full_screen(work_package)
full_work_package.expect_subject
full_work_package.expect_current_path
# deep link work package details pane
split_work_package.visit!
split_work_package.expect_subject
# deep link work package show
full_work_package.visit!
full_work_package.expect_subject
# deep link project work packages
project_work_packages = Pages::WorkPackagesTable.new(project)
project_work_packages.visit!
project_work_packages.expect_work_package_listed(work_package)
# open project work package details pane
split_project_work_package = project_work_packages.open_split_view(work_package)
split_project_work_package.expect_subject
split_project_work_package.expect_current_path
# open work package full screen
full_work_package = project_work_packages.open_full_screen(work_package)
full_work_package.expect_subject
full_work_package.expect_current_path
end
end

@ -43,7 +43,7 @@ describe WorkPackagesController, type: :routing do
it 'should connect GET /work_packages/:id/overview to work_packages#show' do it 'should connect GET /work_packages/:id/overview to work_packages#show' do
expect(get('/work_packages/1/overview')) expect(get('/work_packages/1/overview'))
.to route_to(controller: 'work_packages', .to route_to(controller: 'work_packages',
action: 'show', id: '1', tab: 'overview') action: 'show', id: '1', state: 'overview')
end end
it 'should connect GET /projects/:project_id/work_packages/:id/overview to work_packages#index' do it 'should connect GET /projects/:project_id/work_packages/:id/overview to work_packages#index' do
@ -54,6 +54,22 @@ describe WorkPackagesController, type: :routing do
state: '2/overview') state: '2/overview')
end end
it 'should connect GET /work_packages/details/:state to work_packages#index' do
expect(get('/work_packages/details/5/overview'))
.to route_to(controller: 'work_packages',
action: 'index',
state: '5/overview')
end
it 'should connect GET /projects/:project_id/work_packages/details/:id/:state' +
' to work_packages#index' do
expect(get('/projects/1/work_packages/details/2/overview'))
.to route_to(controller: 'work_packages',
action: 'index',
project_id: '1',
state: 'details/2/overview')
end
context 'when "/work_packages/:param1/:param2" is called with param1 being something other than an id' do context 'when "/work_packages/:param1/:param2" is called with param1 being something other than an id' do
it 'falls back to the default action' do it 'falls back to the default action' do
expect(get('/work_packages/quoted/1')) expect(get('/work_packages/quoted/1'))
@ -93,7 +109,7 @@ describe WorkPackagesController, type: :routing do
id: '1') id: '1')
end end
it 'should connect POST /projects/:project_id/work_packages to work_packages#new' do it 'should connect POST /projects/:project_id/work_packages to work_packages#create' do
expect(post('/projects/1/work_packages')).to route_to(controller: 'work_packages', expect(post('/projects/1/work_packages')).to route_to(controller: 'work_packages',
action: 'create', action: 'create',
project_id: '1') project_id: '1')

@ -0,0 +1,61 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'support/pages/page'
module Pages
class FullWorkPackage < Page
attr_reader :work_package
def initialize(work_package)
@work_package = work_package
end
def expect_subject
within(container) do
expect(page).to have_content(work_package.subject)
end
end
def expect_current_path
current_path = URI.parse(current_url).path
expect(current_path).to eql path
end
private
def container
find('.work-packages--show-view')
end
def path
work_package_path(work_package.id, "activity")
end
end
end

@ -30,6 +30,7 @@ module Pages
class Page class Page
include Capybara::DSL include Capybara::DSL
include RSpec::Matchers include RSpec::Matchers
include OpenProject::StaticRouting::UrlHelpers
def current_page? def current_page?
URI.parse(current_url).path == path URI.parse(current_url).path == path

@ -0,0 +1,69 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'support/pages/page'
module Pages
class SplitWorkPackage < Page
attr_reader :work_package,
:project
def initialize(work_package, project = nil)
@work_package = work_package
@project = project
end
def expect_subject
within(details_container) do
expect(page).to have_content(work_package.subject)
end
end
def expect_current_path
current_path = URI.parse(current_url).path
expect(current_path).to eql path
end
private
def details_container
find('.work-packages--details')
end
def path
state = "#{work_package.id}/overview"
if project
project_work_packages_path(project, "details/#{state}")
else
details_work_packages_path(state)
end
end
end
end

@ -0,0 +1,74 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'support/pages/page'
module Pages
class WorkPackagesTable < Page
attr_reader :project
def initialize(project = nil)
@project = project
end
def expect_work_package_listed(work_package)
within(table_container) do
expect(page).to have_content(work_package.subject)
end
end
def open_split_view(work_package)
split_page = SplitWorkPackage.new(work_package, project)
page.driver.browser.mouse.double_click(row(work_package).native)
split_page
end
def open_full_screen(work_package)
row(work_package).find_link(work_package.subject).click
FullWorkPackage.new(work_package)
end
private
def path
project ? project_work_packages_path(project) : work_packages_path
end
def table_container
find('#content .work-package-table--container')
end
def row(work_package)
table_container.find("#work-package-#{work_package.id}")
end
end
end
Loading…
Cancel
Save