Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added address info to xls export #113

Closed
wants to merge 6 commits into from

3 participants

@create-philipp-ullmann
Collaborator
  • Added address info to xls export of contacts, leads and accounts.
  • Moved rendering of xls export into a view with xml builder.
  • Created layout file for xls export.
  • Added internationalization to xls export of contacts, leads and accounts.

Feedback to existing export:

  • It's a better practice to move view logic into views and out of models.
  • xls and csv export is too generic.
  • I would avoid to add methods to a core ruby class (Array). This could lead to curious bugs, if for example a gem also adds methods with the same name.
@ndbroadbent
Owner

Hi, this looks great, thanks!

I was wondering if I could request that when you submit pull requests, could you please select "merge into the 'master' branch"?

i.e. your pull requests look like this:

merge 6 commits into fatfreecrm:9a94d39 from create-mediadesign:41c39ba

But it would be more helpful if they could be:

merge 6 commits into fatfreecrm:master ...

(Because otherwise, Github tells us "This pull request cannot be automatically merged.")

Thanks very much for your contributions!

@create-philipp-ullmann
Collaborator

Hi,

next time I will try to merge into the master branch. But I don't know if it is possible, because I must select a commit range, in order to exclude commits not suitable for the base project. But I will try!

@ndbroadbent
Owner

Ah, I see! We usually solve this problem by creating a branch, and only adding the relevant commits to that branch. You can even use the git cherry-pick feature for this.

I will try to merge in your changes ASAP (a lot has changed in FFCRM recently, so the merge might be a little bit difficult)

@steveyken
Owner

@ndbroadbent Did this commit make it in yet? Looking forward to having it :) Thanks @create-philipp-ullmann

@create-philipp-ullmann
Collaborator

Next week.

@create-philipp-ullmann
Collaborator

Manual merge into master branch

@steveyken
Owner

thanks! and useful for showing how builder works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 app/controllers/accounts_controller.rb
@@ -22,7 +22,10 @@ class AccountsController < BaseController
#----------------------------------------------------------------------------
def index
@accounts = get_accounts(:page => params[:page])
- respond_with(@accounts)
+
+ respond_with @accounts do |format|
+ format.xls { render :layout => 'header' }
+ end
end
# GET /accounts/1
View
5 app/controllers/contacts_controller.rb
@@ -23,7 +23,10 @@ class ContactsController < BaseController
#----------------------------------------------------------------------------
def index
@contacts = get_contacts(:page => params[:page])
- respond_with(@contacts)
+
+ respond_with @contacts do |format|
+ format.xls { render :layout => 'header' }
+ end
end
# GET /contacts/1
View
5 app/controllers/leads_controller.rb
@@ -22,7 +22,10 @@ class LeadsController < BaseController
#----------------------------------------------------------------------------
def index
@leads = get_leads(:page => params[:page])
- respond_with(@leads)
+
+ respond_with @leads do |format|
+ format.xls { render :layout => 'header' }
+ end
end
# GET /leads/1
View
35 app/views/accounts/index.xls.builder
@@ -0,0 +1,35 @@
+xml.Worksheet 'ss:Name' => I18n.t(:tab_accounts) do
+ xml.Table do
+ unless @accounts.empty?
+ # Header.
+ xml.Row do
+ columns = %w{user assigned_to name email phone fax website background_info access phone_toll_free rating category date_created date_updated
+ street1 street2 city state zipcode country address}
+
+ for column in columns
+ xml.Cell do
+ xml.Data I18n.t(column), 'ss:Type' => 'String'
+ end
+ end
+ end
+
+ # Contact rows.
+ for a in @accounts
+ xml.Row do
+ ba = a.billing_address
+ values = [a.user.try(:name), a.assignee.try(:name), a.name, a.email, a.phone, a.fax, a.website, a.background_info, a.access, a.toll_free_phone, a.rating, a.category, a.created_at, a.updated_at]
+
+ unless ba.nil?
+ values.concat [ba.street1, ba.street2, ba.city, ba.state, ba.zipcode, ba.country, ba.full_address]
+ end
+
+ 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
View
35 app/views/contacts/index.xls.builder
@@ -0,0 +1,35 @@
+xml.Worksheet 'ss:Name' => I18n.t(:tab_contacts) do
+ xml.Table do
+ unless @contacts.empty?
+ # Header.
+ xml.Row do
+ columns = %w{lead job_title name email alt_email phone mobile fax born_on background_info blog linked_in facebook twitter skype date_created date_updated assigned_to access department source do_not_call
+ street1 street2 city state zipcode country address}
+
+ for column in columns
+ xml.Cell do
+ xml.Data I18n.t(column), 'ss:Type' => 'String'
+ end
+ end
+ end
+
+ # Contact rows.
+ for c in @contacts
+ xml.Row do
+ a = c.business_address
+ values = [c.lead.try(:name), c.title, c.name, c.email, c.alt_email, c.phone, c.mobile, c.fax, c.born_on, c.background_info, c.blog, c.linkedin, c.facebook, c.twitter, c.skype, c.created_at, c.updated_at, c.assignee.try(:name), c.access, c.department, c.source, c.do_not_call]
+
+ unless a.nil?
+ values.concat [a.street1, a.street2, a.city, a.state, a.zipcode, a.country, a.full_address]
+ end
+
+ 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
View
8 app/views/layouts/header.xls.builder
@@ -0,0 +1,8 @@
+xml.instruct!
+xml.Workbook 'xmlns:x' => 'urn:schemas-microsoft-com:office:excel',
+ 'xmlns:ss' => 'urn:schemas-microsoft-com:office:spreadsheet',
+ 'xmlns:html' => 'http://www.w3.org/TR/REC-html40',
+ 'xmlns' => 'urn:schemas-microsoft-com:office:spreadsheet',
+ 'xmlns:o' => 'urn:schemas-microsoft-com:office:office' do
+ xml << yield
+end
View
35 app/views/leads/index.xls.builder
@@ -0,0 +1,35 @@
+xml.Worksheet 'ss:Name' => I18n.t(:tab_leads) do
+ xml.Table do
+ unless @leads.empty?
+ # Header.
+ xml.Row do
+ columns = %w{user campaign job_title name email alt_email phone mobile company background_info blog linked_in facebook twitter skype date_created date_updated assigned_to access source status rating do_not_call
+ street1 street2 city state zipcode country address}
+
+ for column in columns
+ xml.Cell do
+ xml.Data I18n.t(column), 'ss:Type' => 'String'
+ end
+ end
+ end
+
+ # Contact rows.
+ for l in @leads
+ xml.Row do
+ a = l.business_address
+ values = [l.user.try(:name), l.campaign.try(:name), l.title, l.name, l.email, l.alt_email, l.phone, l.mobile, l.company, l.background_info, l.blog, l.linkedin, l.facebook, l.twitter, l.skype, l.created_at, l.updated_at, l.assignee.try(:name), l.access, l.source, l.status, l.rating, l.do_not_call]
+
+ unless a.nil?
+ values.concat [a.street1, a.street2, a.city, a.state, a.zipcode, a.country, a.full_address]
+ end
+
+ 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
View
3  config/locales/de_fat_free_crm.yml
@@ -11,6 +11,7 @@ de:
about_thank_you: "Danke, dass Sie Fat Free CRM benutzen! Wir schätzen Ihre Hilfe und hoffen, Sie finden Gefallen an der Software."
about_twitter: "Twitter updates"
about_user_group: "Diskussionsgruppe für Benutzer"
+ access: Zugang
account: Firma
account_name: Firmenname
account_permissions_intro: "Standardmäßig haben nur Sie Zugriff auf die Firma. Sie können den Zugriff später ändern."
@@ -126,6 +127,7 @@ de:
before: "vor"
billing_address: "Rechnungsadresse"
blog: "Website/Blog"
+ born_on: "Geboren am"
brief: "kurz"
budget: "Budget"
budget_label: "Budget (€)"
@@ -478,6 +480,7 @@ de:
related: "re:"
remember_me: "Erinnere mich"
reset_password: "Passwort zurücksetzen"
+ reports_to: Berichtet an
revenue: "Umsatz"
revenue_label: "Umsatz (€)"
revenue_number: "%{value} Umsatz"
View
3  config/locales/en-US_fat_free_crm.yml
@@ -261,6 +261,9 @@ en-US:
user: User
username: Username
yahoo: Yahoo IM
+ born_on: Born on
+ reports_to: Reports to
+ access: Access
# Views -> Authenticate.
#----------------------------------------------------------------------------
Something went wrong with that request. Please try again.