[refs #194] tags -> labels

This commit is contained in:
Alexander Machehin 2012-02-22 02:28:04 +06:00
parent 0ce76207af
commit ecb29d1762
10 changed files with 51 additions and 21 deletions

View File

@ -8,7 +8,8 @@ class Issue < ActiveRecord::Base
has_many :comments, :as => :commentable, :dependent => :destroy #, :finder_sql => proc { "comments.commentable_id = '#{self.id}' AND comments.commentable_type = '#{self.class.name}'"} has_many :comments, :as => :commentable, :dependent => :destroy #, :finder_sql => proc { "comments.commentable_id = '#{self.id}' AND comments.commentable_type = '#{self.class.name}'"}
has_many :subscribes, :as => :subscribeable, :dependent => :destroy #, :finder_sql => proc { "subscribes.subscribeable_id = '#{self.id}' AND subscribes.subscribeable_type = '#{self.class.name}'"} has_many :subscribes, :as => :subscribeable, :dependent => :destroy #, :finder_sql => proc { "subscribes.subscribeable_id = '#{self.id}' AND subscribes.subscribeable_type = '#{self.class.name}'"}
has_many :tags, :dependent => :destroy has_many :labels, :through => :labelings
has_many :labelings
validates :title, :body, :project_id, :presence => true validates :title, :body, :project_id, :presence => true

View File

@ -1,8 +1,7 @@
class Tag < ActiveRecord::Base class Label < ActiveRecord::Base
belongs_to :issue has_many :labelings
has_many :issues, :through => :labelings
validates :name, :color, :presence => true validates :name, :color, :presence => true
validates :color, :format => { :with => /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, :message => I18n.t('layout.issues.invalid_labels')} validates :color, :format => { :with => /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, :message => I18n.t('layout.issues.invalid_labels')}
before_create {|t| t.project_id = t.issue.project_id}
end end

7
app/models/labeling.rb Normal file
View File

@ -0,0 +1,7 @@
class Labeling < ActiveRecord::Base
belongs_to :issue
belongs_to :project
belongs_to :label
#before_create {|t| t.project_id = t.issue.project_id}
end

View File

@ -17,6 +17,8 @@ class Project < ActiveRecord::Base
has_many :relations, :as => :target, :dependent => :destroy has_many :relations, :as => :target, :dependent => :destroy
has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User'
has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' has_many :groups, :through => :relations, :source => :object, :source_type => 'Group'
has_many :labelings
has_many :labels, :through => :labelings
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ }
validates :owner, :presence => true validates :owner, :presence => true
@ -61,7 +63,7 @@ class Project < ActiveRecord::Base
end end
end end
def build_for(platform, user) def build_for(platform, user)
build_lists.create do |bl| build_lists.create do |bl|
bl.pl = platform bl.pl = platform
bl.bpl = platform bl.bpl = platform

View File

@ -35,6 +35,9 @@ en:
by: by by: by
labels: Labels labels: Labels
invalid_labels: Invalid hex color code invalid_labels: Invalid hex color code
new_label: New label name
label_custom_color: Custom color
label_manage: Manage
flash: flash:
issue: issue:

View File

@ -35,6 +35,9 @@ ru:
by: by:
labels: Метки labels: Метки
invalid_labels: Неверный hex код invalid_labels: Неверный hex код
new_label: Название новой метки
label_custom_color: Свой цвет
label_manage: Управление
flash: flash:
issue: issue:

View File

@ -119,6 +119,10 @@ Rosa::Application.routes.draw do
resources :issues do resources :issues do
resources :comments, :only => [:edit, :create, :update, :destroy] resources :comments, :only => [:edit, :create, :update, :destroy]
resources :subscribes, :only => [:create, :destroy] resources :subscribes, :only => [:create, :destroy]
collection do
post :create_label
post :delete_label
end
end end
resource :repo, :controller => "git/repositories", :only => [:show] resource :repo, :controller => "git/repositories", :only => [:show]
resources :build_lists, :only => [:index, :new, :create] resources :build_lists, :only => [:index, :new, :create]

View File

@ -0,0 +1,21 @@
class CreateLabels < ActiveRecord::Migration
def change
create_table :labels do |t|
t.string :name, :null => false
t.string :color, :null => false
t.timestamps
end
create_table :labelings do |t|
t.references :label, :null => false
t.references :issue
t.references :project
t.timestamps
end
add_index :labelings, :issue_id
add_index :labelings, :project_id
end
end

View File

@ -1,15 +0,0 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name, :null => false
t.string :color, :null => false
t.integer :issue_id, :null => false
t.integer :project_id, :null => false
t.timestamps
end
add_index :tags, :issue_id
add_index :tags, :project_id
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Tag do
pending "add some examples to (or delete) #{__FILE__}"
end