Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:djcp/cohort
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Neufeld committed Jul 2, 2009
2 parents f1c678a + dc75a5c commit 28ce042
Show file tree
Hide file tree
Showing 38 changed files with 278 additions and 205 deletions.
46 changes: 0 additions & 46 deletions app/controllers/admin/saved_search_controller.rb

This file was deleted.

12 changes: 6 additions & 6 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ def index
end
end

#logger.warn("Ferret search string: " + ferret_fields)
logger.warn("Ferret search string: " + ferret_fields)

if params[:export].blank?
if ferret_fields == '* '
@contacts = Contact.paginate(:page => params[:page],:per_page => 50,:include => [:notes, :contact_emails,:tags], :order => sortable_order('contacts',:model => Contact,:field => 'updated_at',:sort_direction => :desc))
else
@contacts = Contact.find_with_ferret(ferret_fields, {:page => params[:page],:per_page => 50},{:order => sortable_order('contacts',:model => Contact,:field => 'updated_at',:sort_direction => :desc) })
@contacts = Contact.find_with_ferret(ferret_fields, {:page => params[:page],:per_page => 50},{:include => [:notes, :contact_emails, :tags], :order => sortable_order('contacts',:model => Contact,:field => 'updated_at',:sort_direction => :desc) })
end
render :layout => (request.xhr? ? false : true)
else
contacts = Contact.find_with_ferret(ferret_fields)
contacts = Contact.find_with_ferret(ferret_fields, {:limit => :all})
columns = Contact.columns.collect{|c|c.name}
if params[:export] == 'csv'
#De-normalize data because csv files can't be hierarchical like XML.
Expand Down Expand Up @@ -107,7 +107,7 @@ def create
@contact = Contact.new
@contact.attributes = params[:contact]
if @contact.save
redirect_to '/' and return
redirect_to :controller => '/admin/dashboard', :action => :dashboard and return
else
render :template => 'contacts/edit' and return
end
Expand Down Expand Up @@ -135,7 +135,7 @@ def update
@contact.attributes = params[:contact]
if @contact.save
flash[:notice] = 'Saved!'
redirect_to '/' and return
redirect_to :controller => '/admin/dashboard', :action => :dashboard and return
else
logger.warn('update failed.')
render :template => 'contacts/edit' and return
Expand All @@ -147,7 +147,7 @@ def destroy
@contact = Contact.find(params[:id])
@contact.destroy
flash[:notice] = 'Gone!'
redirect_to '/' and return
redirect_to :controller => '/admin/dashboard', :action => :dashboard and return
rescue Exception => exc
logger.error "Destroy failed #{exc.message}"
flash[:error] = 'There was an error deleting that item. Sorry!'
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ def everyones
@title = 'Everyone\'s notes'
@alt_title = 'My notes'
@alt_action = :my
index(false,true)
index(false)
end

def my
@title = 'My notes'
@alt_action = :everyones
@alt_title = 'Everyone\'s notes'
index
index(false,true)
end

def index(contact_only = false, all_users = false)
def index(contact_only = false, mine_only = false)
add_to_sortable_columns('notes', :model => Note, :field => :priority, :alias => :priority)
add_to_sortable_columns('notes', :model => Note, :field => :contact_id, :alias => :contact)
add_to_sortable_columns('notes', :model => Note, :field => :follow_up, :alias => :follow_up)
ferret_fields = (params[:q].blank? ? '* ' : "#{params[:q]} ")
if contact_only
#looking for a contact's notes
ferret_fields += "contact_id: #{params[:id]} "
elsif all_users
#looking for everyone's notes. null conditions, just pass in the query. For now.
else
elsif mine_only or params[:my]
#Looking for my notes.
ferret_fields += "user_id: #{@session_user.id} "
else
#looking for everyone's notes. null conditions, just pass in the query. For now.
end
if params[:export].blank?
if ferret_fields == '* '
Expand All @@ -45,7 +45,7 @@ def index(contact_only = false, all_users = false)
#logger.warn('fields to ferret: ' + ferret_fields)
render :action => 'my', :layout => (request.xhr? ? false : true)
else
notes = Note.find_with_ferret(ferret_fields)
notes = Note.find_with_ferret(ferret_fields, {:limit => :all})
columns = Note.columns.collect{|c|c.name}
if params[:export] == 'csv'
additional_columns = ['primary_email','last_name','first_name']
Expand Down
23 changes: 0 additions & 23 deletions app/controllers/saved_search_controller.rb

This file was deleted.

80 changes: 80 additions & 0 deletions app/controllers/saved_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class SavedSearchesController < ApplicationController
before_filter :is_admin

protect_from_forgery :except => [:auto_complete_for_saved_search_category, :auto_complete_for_saved_search_name]

auto_complete_for :saved_search, :category
auto_complete_for :saved_search, :name

def index
add_to_sortable_columns('searches', :model => SavedSearch, :field => :category, :alias => :category)
add_to_sortable_columns('searches', :model => SavedSearch, :field => :name, :alias => :name)
@saved_searches = SavedSearch.paginate(:page => params[:page], :per_page => 50, :order => sortable_order('searches', :model => SavedSearch, :field => :category, :sort_direction => :desc))
end

def new
@saved_search = SavedSearch.new(:search_url => params[:search_url], :user => @session_user)
render :template => 'saved_searches/edit' and return
end

def create
@saved_search = SavedSearch.new(:search_url => params[:search_url], :user => @session_user)
@saved_search.attributes = params[:saved_search]
@saved_search.search_url = CGI.unescapeHTML(params[:saved_search][:search_url])
if @saved_search.save
flash[:notice] = "We've added that saved search."
redirect_to @saved_search.search_url and return
else
render :template => 'saved_searches/edit'
end
end

def show
@saved_search = SavedSearch.find(params[:id])
rescue Exception => exc
flash[:error] = "There was an error when we looked for that tag: #{exc.message}"
redirect_to :action => :index and return
end

def edit
@saved_search = SavedSearch.find(params[:id])
render :template => 'saved_searches/edit' and return
end

def update
@saved_search = SavedSearch.find(params[:id])
@saved_search.attributes = params[:saved_search]
@saved_search.search_url = CGI.unescapeHTML(params[:saved_search][:search_url])
if @saved_search.save
flash[:notice] = "we've added that saved search."
redirect_to @saved_search.search_url and return
else
render :template => 'saved_searches/edit'
end
end

def destroy
@saved_search = SavedSearch.find(params[:id])
@saved_search.destroy
flash[:notice] = 'Gone!'
redirect_to :action => :index and return
rescue Exception => exc
logger.error "Destroy failed #{exc.message}"
flash[:error] = 'There was an error deleting that item. Sorry!'
end

def run
begin
ss = SavedSearch.find_by_name params[:id]
ss or raise Exception, "couldn't find that saved search"
SavedSearchRun.create(:saved_search => ss)
session[:saved_search_ran] = ss
redirect_to ss.search_url
rescue Exception => exc
logger.error "Couldn't view that saved search: #{exc.message}"
flash[:error] = 'There was an error with that saved search. Sorry!'
redirect_to :action => :index
end
end

end
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def index
end

def new
@tag = Tag.new
@tag = Tag.new(:parent_id => params[:parent_id])
render :template => 'tags/edit' and return
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def sorted_class(sortable_name,data_name,prefix="")

def create_compact_object_widget(object_type, object, action)
widget = "<div>"
indicator = "#{icon(object_type.to_sym)} #{object_type.pluralize} #{'(<span id="contact-' + object_type + '-count-' + object.id.to_s + '">' + object.send(object_type.pluralize).count.to_s + '</span>)'}"
indicator = "#{icon(object_type.to_sym)} #{object_type.pluralize} #{'(<span id="contact-' + object_type + '-count-' + object.id.to_s + '">' + object.send(object_type.pluralize).length.to_s + '</span>)'}"
widget += link_to_function(indicator,"Modalbox.show('#{url_for(:controller => '/contacts', :action => action, :id => object.id, :context => 'modalbox')}',{title: '#{object_type.titleize.pluralize} for #{h object.name_for_display}', width: '800'})")
widget += "</div>"
end
Expand Down
30 changes: 25 additions & 5 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Contact < ActiveRecord::Base
# Many validations are handled by the redhill schema_validations plugin.
acts_as_ferret(:single_index => true, :additional_fields => [:my_tags, :my_tag_ids, :my_emails, :my_notes, :my_addresses], :remote => true)
acts_as_ferret(:single_index => true, :additional_fields => [:my_tags, :my_tag_ids, :my_emails, :my_notes, :my_addresses, :my_urls], :remote => true)
acts_as_freetaggable
include CohortArInstanceMixin
extend CohortArClassMixin
Expand All @@ -16,7 +16,7 @@ class Contact < ActiveRecord::Base
:reject_if => proc { |attributes| attributes['email'].blank? }

accepts_nested_attributes_for :contact_addresses, :allow_destroy => true,
:reject_if => proc { |attributes| attributes['street1'].blank? }
:reject_if => proc { |attributes| (attributes['city'].blank? or attributes['country'].blank?) ? true : false }

accepts_nested_attributes_for :contact_urls, :allow_destroy => true,
:reject_if => proc { |attributes| attributes['url'].blank? }
Expand All @@ -35,10 +35,20 @@ def primary_email
end

def get_primary_email
pe = self.contact_emails.find(:first, :order => 'is_primary desc, id')
pe = nil

self.contact_emails.collect do |ce|
if ce.is_primary == true
return ce
end
pe = ce
end

return pe
end

def get_non_primary_emails
#seems tortured, but will skip running additional SQL when the contact_email object have already been populated.
pe = get_primary_email
npes = self.contact_emails.collect do|npe|
if npe != pe
Expand All @@ -54,7 +64,14 @@ def primary_phone
end

def get_primary_phone
pp = self.contact_phones.find(:first, :order => 'is_primary desc, id')
pp = nil
self.contact_phones.collect do |cp|
if cp.is_primary == true
return cp
end
pp = cp
end
return pp
end

def my_tags
Expand All @@ -65,7 +82,6 @@ def my_notes
self.notes.collect{|n| n.note}.join(' ')
end


def my_tag_ids
self.tags.collect{|t| t.id}.join(' ')
end
Expand All @@ -78,4 +94,8 @@ def my_addresses
self.contact_addresses.collect{|ca| "#{ca.street1} #{ca.street2} #{ca.city} #{ca.state} #{ca.zip} #{ca.country}"}.join(' ')
end

def my_urls
self.contact_urls.collect{|cu| "#{cu.url}"}.join(' ')
end

end
2 changes: 1 addition & 1 deletion app/models/saved_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class SavedSearch < ActiveRecord::Base
belongs_to :user
has_many :saved_search_runs

validates_format_of :name, :with => /^[a-z\d\-\., ]+$/i, :message => 'should contain only letters, numbers, spaces, and the following characters: , - . '
validates_format_of :name, :with => /^[a-z\d\-\, ]+$/i, :message => 'should contain only letters, numbers, spaces, hyphens and commas.'

def self.select_options(global_search = true,user_id = nil)
category_conditions = []
Expand Down
26 changes: 0 additions & 26 deletions app/views/admin/saved_search/edit.html.erb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/contacts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</tr>
<% end %>
</table>
<p><strong>City and Country are required on new addresses.</strong></p>
</div>

<h2 id="flyout-contact-contact-info" class="toggle shown">Contact Info</h2>
Expand Down
1 change: 1 addition & 0 deletions app/views/contacts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div id="contacts-update">
<h1>Contacts</h1>
<% unless @contacts.blank? %>
<%= will_paginate @contacts, :params => {:q => params[:q]} %>
<div id="admin-list">
<table border="0" width="100%">
<tr class="table-header">
Expand Down
Loading

0 comments on commit 28ce042

Please sign in to comment.