Skip to content

Commit

Permalink
Export links now respect search queries. Added a permalink to enable …
Browse files Browse the repository at this point in the history
…links back to the exact page with search intact.
  • Loading branch information
steveyken committed Jul 28, 2012
1 parent 4881214 commit a6d5fe3
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 31 deletions.
7 changes: 5 additions & 2 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ class TasksController < ApplicationController
before_filter :require_user
before_filter :set_current_tab, :only => [ :index, :show ]
before_filter :update_sidebar, :only => :index

# GET /tasks
#----------------------------------------------------------------------------
def index
@view = params[:view] || "pending"
@tasks = Task.find_all_grouped(@current_user, @view)

respond_with(@tasks)
respond_with @tasks do |format|
format.xls { render :layout => 'header' }
format.csv { render :csv => @tasks.map(&:second).flatten }
end
end

# GET /tasks/1
Expand Down
23 changes: 12 additions & 11 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,24 @@ def shown_on_landing_page?
#----------------------------------------------------------------------------
def links_to_export
token = @current_user.single_access_token
path = if controller.controller_name == 'home'
activities_path
elsif controller.class.to_s.starts_with?("Admin::")
send("admin_#{controller.controller_name}_path")
else
send("#{controller.controller_name}_path")
end

url_params = {:action => :index}
url_params.merge!(:query => params[:query]) unless params[:query].blank?
url_params.merge!(:q => params[:q]) unless params[:q].blank?
url_params.merge!(:view => @view) unless @view.blank? # tasks

exports = %w(xls csv).map do |format|
link_to(format.upcase, "#{path}.#{format}", :title => I18n.t(:"to_#{format}"))
link_to(format.upcase, url_params.merge(:format => format), :title => I18n.t(:"to_#{format}"))
end

feeds = %w(rss atom).map do |format|
link_to(format.upcase, "#{path}.#{format}?authentication_credentials=#{token}", :title => I18n.t(:"to_#{format}"))
link_to(format.upcase, url_params.merge(:format => format, :authentication_credentials => token), :title => I18n.t(:"to_#{format}"))
end

links = %W(perm).map do |format|
link_to(format.upcase, url_params, :title => I18n.t(:"to_#{format}"))
end

(exports + feeds).join(' | ')
(exports + feeds + links).join(' | ')
end

def template_fields(f, type)
Expand Down
16 changes: 0 additions & 16 deletions app/helpers/tasks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,6 @@ def link_to_task_complete(pending, bucket)
onclick << remote_function(:url => complete_task_path(pending), :method => :put, :with => "'bucket=#{bucket}'")
end

# Helper to display XLS, CSV, RSS, and ATOM links for tasks.
#----------------------------------------------------------------------------
def links_to_task_export(view)
token = @current_user.single_access_token

exports = %w(xls csv).map do |format|
link_to(format.upcase, "#{tasks_path}.#{format}?view=#{view}", :title => I18n.t(:"to_#{format}"))
end
feeds = %w(rss atom).map do |format|
link_to(format.upcase, "#{tasks_path}.#{format}?view=#{view}&authentication_credentials=#{token}", :title => I18n.t(:"to_#{format}"))
end

(exports + feeds).join(' | ')
end

# Task summary for RSS/ATOM feed.
#----------------------------------------------------------------------------
def task_summary(task)
Expand Down Expand Up @@ -173,4 +158,3 @@ def reschedule(id)
end

end

1 change: 1 addition & 0 deletions app/views/accounts/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:accounts].replace_html :partial => "shared/empty"
end
page[:paginate].replace_html :partial => "shared/paginate"
page[:export].replace_html render(:partial => "shared/export")
1 change: 0 additions & 1 deletion app/views/admin/groups/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
= render "shared/empty"

#paginate= render "shared/paginate"
#export= render "shared/export"
1 change: 1 addition & 0 deletions app/views/admin/users/index.js.rjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
page[:users].replace_html render :partial => "admin/users/user", :collection => @users
page[:paginate].replace_html :partial => "shared/paginate"
page[:export].replace_html render(:partial => "shared/export")
1 change: 1 addition & 0 deletions app/views/campaigns/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:campaigns].replace_html :partial => "shared/empty"
end
page[:paginate].replace_html :partial => "shared/paginate"
page[:export].replace_html render(:partial => "shared/export")
1 change: 1 addition & 0 deletions app/views/contacts/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:contacts].replace_html render(:partial => "shared/empty")
end
page[:paginate].replace_html render(:partial => "shared/paginate")
page[:export].replace_html render(:partial => "shared/export")
1 change: 1 addition & 0 deletions app/views/home/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:activities].replace_html t(:no_activity_records)
end
# page[:paginate].replace_html render(:partial => "shared/paginate")
page[:export].replace_html render(:partial => "shared/export")
1 change: 1 addition & 0 deletions app/views/leads/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:leads].replace_html :partial => "shared/empty"
end
page[:paginate].replace_html :partial => "shared/paginate"
page[:export].replace_html render(:partial => "shared/export")
1 change: 1 addition & 0 deletions app/views/opportunities/index.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ else
page[:opportunities].replace_html :partial => "shared/empty"
end
page[:paginate].replace_html :partial => "shared/paginate"
page[:export].replace_html render(:partial => "shared/export")
2 changes: 1 addition & 1 deletion app/views/tasks/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
- if @tasks.values.flatten.blank?
= render "empty"

#export= raw links_to_task_export(@view)
#export= render "shared/export"
29 changes: 29 additions & 0 deletions app/views/tasks/index.xls.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
xml.Worksheet 'ss:Name' => I18n.t(:tab_tasks) do
xml.Table do
unless @tasks.empty?
# Header.
xml.Row do
columns = %w{name due date_created date_updated completed user assigned_to category background_info}

for column in columns
xml.Cell do
xml.Data I18n.t(column), 'ss:Type' => 'String'
end
end
end

# Rows.
for t in @tasks.map(&:second).flatten
xml.Row do
values = [t.name, I18n.t(t.computed_bucket), t.created_at, t.updated_at, t.completed_at, t.user.try(:name), t.assignee.try(:name), t.category, t.background_info]

for value in values
xml.Cell do
xml.Data value, 'ss:Type' => "#{value.respond_to?(:abs) ? 'Number' : 'String'}"
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions config/locales/en-US_fat_free_crm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ en-US:
to_csv: Export to comma-delimited file format (including deleted records)
to_rss: RSS feed
to_atom: Atom feed
to_perm: Permalink

# Dropbox.
#----------------------------------------------------------------------------
Expand Down

0 comments on commit a6d5fe3

Please sign in to comment.