mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
Add next-previous links to project detail pages. Closes #379
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@470 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
49296539ee
commit
85885f9b9b
7 changed files with 79 additions and 3 deletions
|
|
@ -26,6 +26,8 @@ class ProjectsController < ApplicationController
|
|||
@deferred = @project.deferred_todos
|
||||
@done = @project.done_todos
|
||||
@count = @not_done.size
|
||||
@next_project = @user.projects.next_from(@project)
|
||||
@previous_project = @user.projects.previous_from(@project)
|
||||
end
|
||||
|
||||
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type: application/xml'
|
||||
|
|
|
|||
|
|
@ -9,4 +9,18 @@ module ProjectsHelper
|
|||
}
|
||||
end
|
||||
|
||||
def project_next_prev
|
||||
html = ''
|
||||
unless @previous_project.nil?
|
||||
project_name = truncate(@previous_project.name, 40, "...")
|
||||
html << link_to_project(@previous_project, "« #{project_name}")
|
||||
end
|
||||
html << '|' if @previous_project && @next_project
|
||||
unless @next_project.nil?
|
||||
project_name = truncate(@next_project.name, 40, "...")
|
||||
html << link_to_project(@next_project, "#{project_name} »")
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,6 +37,21 @@ class User < ActiveRecord::Base
|
|||
project.update_attribute(:position, position + 1)
|
||||
end
|
||||
end
|
||||
def projects_in_state_by_position(state)
|
||||
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
|
||||
end
|
||||
def next_from(project)
|
||||
self.offset_from(project, 1)
|
||||
end
|
||||
def previous_from(project)
|
||||
self.offset_from(project, -1)
|
||||
end
|
||||
def offset_from(project, offset)
|
||||
projects = self.projects_in_state_by_position(project.state)
|
||||
position = projects.index(project)
|
||||
return nil if position == 0 && offset < 0
|
||||
projects.at( position + offset)
|
||||
end
|
||||
end
|
||||
has_many :todos,
|
||||
:order => 'completed_at DESC, todos.created_at DESC',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<div id="display_box">
|
||||
<div id="project-next-prev">
|
||||
<%= project_next_prev %>
|
||||
</div>
|
||||
|
||||
<%= render :partial => "projects/project", :locals => { :project => @project, :collapsible => false } %>
|
||||
<%= render :partial => "todos/deferred", :locals => { :deferred => @deferred, :collapsible => false, :append_descriptor => "in this project" } %>
|
||||
|
|
|
|||
|
|
@ -548,6 +548,9 @@ div.project_description {
|
|||
shadowed text */
|
||||
/* text-shadow: rgba(0,0,0,.4) 0px 2px 5px; */
|
||||
}
|
||||
#project-next-prev {
|
||||
text-align:right;
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
form {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
|||
end
|
||||
|
||||
def test_show_exposes_deferred_todos
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
p = projects(:timemachine)
|
||||
get :show, :id => p.to_param
|
||||
show p
|
||||
assert_not_nil assigns['deferred']
|
||||
assert_equal 1, assigns['deferred'].size
|
||||
|
||||
|
|
@ -32,6 +31,16 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
|||
assert_equal 2, assigns['deferred'].size
|
||||
end
|
||||
|
||||
def test_show_exposes_next_project_in_same_state
|
||||
show projects(:timemachine)
|
||||
assert_equal(projects(:moremoney), assigns['next_project'])
|
||||
end
|
||||
|
||||
def test_show_exposes_previous_project_in_same_state
|
||||
show projects(:moremoney)
|
||||
assert_equal(projects(:timemachine), assigns['previous_project'])
|
||||
end
|
||||
|
||||
def test_create_project_via_ajax_increments_number_of_projects
|
||||
assert_ajax_create_increments_count 'My New Project'
|
||||
end
|
||||
|
|
@ -190,5 +199,11 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
|||
get :index, { :format => "txt", :token => users(:admin_user).word }
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
private
|
||||
def show(project)
|
||||
@request.session['user_id'] = project.user_id
|
||||
get :show, :id => project.to_param
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class UserTest < Test::Unit::TestCase
|
||||
fixtures :users, :preferences
|
||||
fixtures :users, :preferences, :projects, :todos
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
|
|
@ -150,6 +150,30 @@ class UserTest < Test::Unit::TestCase
|
|||
assert_nil User.authenticate(@admin_user.login, "abracadabra")
|
||||
assert_not_nil User.authenticate(@admin_user.login, "foobar")
|
||||
end
|
||||
|
||||
def test_projects_next_project
|
||||
moremoney = projects(:moremoney)
|
||||
next_project = @admin_user.projects.next_from(moremoney)
|
||||
assert_equal projects(:gardenclean), next_project
|
||||
end
|
||||
|
||||
def test_projects_previous_project
|
||||
moremoney = projects(:moremoney)
|
||||
previous_project = @admin_user.projects.previous_from(moremoney)
|
||||
assert_equal projects(:timemachine), previous_project
|
||||
end
|
||||
|
||||
def test_projects_next_project_nil
|
||||
gardenclean = projects(:gardenclean)
|
||||
next_project = @admin_user.projects.next_from(gardenclean)
|
||||
assert_nil next_project
|
||||
end
|
||||
|
||||
def test_projects_previous_project_nil
|
||||
timemachine = projects(:timemachine)
|
||||
previous_project = @admin_user.projects.previous_from(timemachine)
|
||||
assert_nil previous_project
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue