Skip to content

Commit

Permalink
Entries now loaded 25 at a time. More loaded by link at the bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesu committed Feb 24, 2010
1 parent 5dab9ce commit a482245
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/controllers/entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class EntriesController < ApplicationController
before_filter :find_entry, :except => [:index, :new, :create, :report]

def index
@entries = (@project || @logged_user).entries.find(:all)
last_id = (params[:last_id] || '0').to_i
@entries = (@project || @logged_user).entries.find(:all,
:conditions => last_id > 0 ? ['id < ?', last_id] : {},
:limit => 25,
:order => 'start_date DESC')
@last_entry = @entries.length > 0 ? @entries[-1].id : 0
end

def new
Expand Down
24 changes: 22 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@ def index

def entries
@projects = @logged_user.projects
@entries = @logged_user.entries.find(:all, :conditions => {:project_id => @logged_user.project_ids}, :order => 'start_date DESC')
last_id = (params[:last_id] || '0').to_i
conds = if last_id > 0
['project_id IN (?) AND id < ?', @logged_user.project_ids, last_id]
else
['project_id IN (?)', @logged_user.project_ids]
end

@entries = @logged_user.entries.find(:all,
:conditions => conds,
:limit => 25,
:order => 'start_date DESC')
@last_entry = @entries.length > 0 ? @entries[-1].id : 0

respond_to do |f|
f.html {render 'entries/index'}
f.js {render 'entries/index'}
end
end

Expand Down Expand Up @@ -57,9 +70,16 @@ def destroy
end

def show
@entries = @project.entries
last_id = (params[:last_id] || '0').to_i
@entries = @project.entries.find(:all,
:conditions => last_id > 0 ? ['id < ?', last_id] : {},
:limit => 25,
:order => 'start_date DESC')
@last_entry = @entries.length > 0 ? @entries[-1].id : 0

respond_to do |f|
f.html {render 'entries/index'}
f.js {render 'entries/index'}
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ def destroy
end

def show
@entries = @service.entries
last_id = (params[:last_id] || '0').to_i
@entries = @service.entries.find(:all,
:conditions => last_id > 0 ? ['id < ?', last_id] : {},
:limit => 25,
:order => 'start_date DESC')
@last_entry = @entries.length > 0 ? @entries[-1].id : 0

respond_to do |f|
f.html {render 'entries/index'}
f.js {render 'entries/index'}
end
end

Expand Down
13 changes: 13 additions & 0 deletions app/helpers/entries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ def entry_service_tag(tag)
"<span class=\"service\">\##{tag}</span>"
end

def more_entries_link(num, last_id)
path_name = if @project
project_path(@project, :last_id => last_id)
elsif @service
service_path(@service, :last_id => last_id)
elsif @projects
entries_projects_path(:last_id => last_id)
else
entries_path(:last_id => last_id)
end
link_to_remote t('.display_x_more_entries', :num => num), :url => path_name, :method => :get
end

def entry_bar_report(id, values, labels)
js_labels = labels.map{|l| "'#{l}'"}
"<div id=\"#{id}\" style=\"width:300px; height: 200px;\"></div>" +
Expand Down
2 changes: 2 additions & 0 deletions app/views/entries/_more.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#entries_more.hint
= more_entries_link(num, @last_entry)
2 changes: 2 additions & 0 deletions app/views/entries/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#entries
= render :partial => 'entries/entry', :collection => @entries
- if @entries.length >= 25
= render :partial => 'entries/more', :locals => {:num => 25}

- content_for :js_templates do
= "Timer.init();"
10 changes: 10 additions & 0 deletions app/views/entries/index.js.rjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@entries.each do |entry|
page.insert_html :before, "entries_more", :partial => 'entries/entry', :object => entry
page.call "Timer.register", entry.id unless entry.terminated?
end

if @entries.length < 25
page.remove "entries_more"
else
page.replace "entries_more", :partial => 'entries/more', :locals => {:num => 25}
end
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ en:
what_in_project: "What are you doing in {{project}}?"
what_in_service: "What {{service}} are you working on?"
what_status: "What are you doing? (<a href=\"/taglist.html\" target=\"_blank\">Help?</a>)"
more:
display_x_more_entries: "Display {{num}} more entries"
projects:
create: Create
update: Update
Expand Down

0 comments on commit a482245

Please sign in to comment.