Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalized categorization (working for account and contacts)
- Loading branch information
jose-gordo
committed
Sep 2, 2009
1 parent
8382b94
commit 0c50e3d
Showing
48 changed files
with
220 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
class AccountCategory < ActiveRecord::Base | ||
belongs_to :account | ||
belongs_to :category | ||
validates_presence_of :account_id, :category_id | ||
belongs_to :category_account | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,31 @@ | ||
class Category < ActiveRecord::Base | ||
has_many :accounts, :through => :account_categories | ||
has_many :account_categories, :dependent => :destroy | ||
acts_as_tree :order => "name" | ||
|
||
def self.root_nodes | ||
find(:all, :conditions => 'parent_id IS NULL') | ||
end | ||
|
||
def self.find_children(start_id = nil) | ||
start_id.to_i == 0 ? root_nodes : find(start_id).direct_children | ||
end | ||
|
||
def leaf | ||
unknown? || children_count == 0 | ||
end | ||
|
||
def to_json_with_leaf(options = {}) | ||
self.to_json_without_leaf(options.merge(:methods => :leaf)) | ||
end | ||
|
||
alias_method_chain :to_json, :leaf | ||
|
||
def ancestors_name | ||
if parent | ||
parent.ancestors_name + parent.name + ':' | ||
parent.ancestors_name + parent.text + ' - ' | ||
else | ||
"" | ||
end | ||
end | ||
def long_name | ||
ancestors_name + name | ||
end | ||
ancestors_name + text | ||
end | ||
end | ||
|
||
# has_many :account_categories, :dependent => :destroy | ||
# has_many :categories, :through => :account_categories, :uniq => true | ||
# belongs_to :user | ||
# belongs_to :account | ||
# belongs_to :assignee, :class_name => "User", :foreign_key => :assigned_to | ||
# has_one :account_issue, :dependent => :destroy | ||
# has_one :account, :through => :account_issue | ||
# has_many :activities, :as => :subject, :order => 'created_at DESC' | ||
# | ||
# simple_column_search :name, :match => :middle, :escape => lambda { |query| query.gsub(/[^\w\s\-]/, "").strip } | ||
# | ||
# named_scope :with_ticket, lambda { |ticket| { :conditions => ["bug_ticket LIKE ?", ticket] } } | ||
# named_scope :with_priority, lambda { |priority| { :conditions => ["priority LIKE ?", priority] } } | ||
# named_scope :only_priorities, lambda { |filters| { :conditions => [ "priority IN (?)", filters ] } } | ||
# named_scope :only_statuses, lambda { |filters| { :conditions => [ "status IN (?)", filters ] } } | ||
# | ||
# named_scope :with_status, lambda { |status| { :conditions => ["status = ?", status] } } | ||
# named_scope :unresolved, :conditions => [ "status = ?", 0 ] | ||
# named_scope :pending, :conditions => [ "status IS IN ?", [0,1] ] | ||
# named_scope :resolved, :conditions => [ "status = ?", 2 ] | ||
# | ||
# uses_user_permissions | ||
# acts_as_commentable | ||
# acts_as_paranoid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class CategoryAccount < Category | ||
has_many :accounts, :through => :account_categories | ||
has_many :account_categories | ||
|
||
acts_as_nested_set | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class CategoryContact < Category | ||
has_many :contacts, :through => :contact_categories | ||
has_many :contact_categories | ||
|
||
acts_as_nested_set | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ContactCategory < ActiveRecord::Base | ||
belongs_to :contact | ||
belongs_to :category_contact | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module ContactCategoryAssociations | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
has_many :contact_categories, :dependent => :destroy | ||
has_many :category_contacts, :through => :contact_categories, :uniq => true | ||
end | ||
end | ||
|
||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2>Listing categories</h2> | ||
|
||
<%= link_to 'New category', new_category_path %> | ||
|
||
<br /> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
|
||
<% @categories.each do |category| %> | ||
<tr> | ||
<td><%=h category.text %></td> | ||
<td><%= link_to 'Show', category %></td> | ||
<td><%= link_to 'Edit', edit_category_path(category) %></td> | ||
<td><%= link_to 'Destroy', category, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>Listing categories</h2> | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
app/views/admin/categories/Copy of _select_categories.rhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= | ||
collection_select('account', | ||
'category_ids', | ||
all_categories, | ||
:id, | ||
:long_name, | ||
{}, | ||
{:multiple => true, :size => '10'} | ||
) | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%br | ||
.subtitle#create_issue_title Categories | ||
.remote#create_issue{ hidden } | ||
.list#issues | ||
|
||
= collection_select get_category_model, get_category_model_ids, all_categories, :id, :long_name, { }, { :multiple => true, :size => '10' } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%br | ||
.subtitle#create_issue_title Categories | ||
.remote#create_issue{ hidden } | ||
.list#issues | ||
|
||
= show_categories(eval(get_category_instance_variable)) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Editing category</h1> | ||
|
||
<% form_for(@category) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :parent_id %><br /> | ||
<%= render(:partial => "select_categories") %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Update' %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Show', {:admin, @category} %> | | ||
<%= link_to 'Back', category_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2>Listing categories</h2> | ||
|
||
<table> | ||
<% @categories.each do |category| %> | ||
<tr> | ||
<td><%=h category.text %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateContactCategories < ActiveRecord::Migration | ||
def self.up | ||
create_table :contact_categories, :force => true do |t| | ||
t.integer :contact_id | ||
t.integer :category_contact_id | ||
t.datetime :deleted_at | ||
t.timestamps | ||
end | ||
add_index :contact_categories, [:contact_id, :category_contact_id] | ||
add_index :contact_categories, :category_contact_id | ||
end | ||
|
||
def self.down | ||
drop_table :contact_categories | ||
end | ||
end |
8 changes: 4 additions & 4 deletions
8
...090820135746_create_account_categories.rb → ...090901135751_create_account_categories.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.