diff --git a/app/models/issue.rb b/app/models/issue.rb index d01063c8d..90f01e1b1 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 :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 diff --git a/app/models/tag.rb b/app/models/label.rb similarity index 62% rename from app/models/tag.rb rename to app/models/label.rb index 4f8268ba8..16a01c91a 100644 --- a/app/models/tag.rb +++ b/app/models/label.rb @@ -1,8 +1,7 @@ -class Tag < ActiveRecord::Base - belongs_to :issue +class Label < ActiveRecord::Base + has_many :labelings + has_many :issues, :through => :labelings 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')} - - before_create {|t| t.project_id = t.issue.project_id} end diff --git a/app/models/labeling.rb b/app/models/labeling.rb new file mode 100644 index 000000000..899853d7d --- /dev/null +++ b/app/models/labeling.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 68bdc9f62..0cc719c2e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,6 +17,8 @@ class Project < ActiveRecord::Base has_many :relations, :as => :target, :dependent => :destroy has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' 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 :owner, :presence => true @@ -61,7 +63,7 @@ class Project < ActiveRecord::Base end end - def build_for(platform, user) + def build_for(platform, user) build_lists.create do |bl| bl.pl = platform bl.bpl = platform diff --git a/config/locales/issues/issues.en.yml b/config/locales/issues/issues.en.yml index 8b56638d8..def827d15 100644 --- a/config/locales/issues/issues.en.yml +++ b/config/locales/issues/issues.en.yml @@ -35,6 +35,9 @@ en: by: by labels: Labels invalid_labels: Invalid hex color code + new_label: New label name + label_custom_color: Custom color + label_manage: Manage flash: issue: diff --git a/config/locales/issues/issues.ru.yml b/config/locales/issues/issues.ru.yml index ae35430c6..b4bdc595e 100644 --- a/config/locales/issues/issues.ru.yml +++ b/config/locales/issues/issues.ru.yml @@ -35,6 +35,9 @@ ru: by: labels: Метки invalid_labels: Неверный hex код + new_label: Название новой метки + label_custom_color: Свой цвет + label_manage: Управление flash: issue: diff --git a/config/routes.rb b/config/routes.rb index cf410d285..0ece275be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,6 +119,10 @@ Rosa::Application.routes.draw do resources :issues do resources :comments, :only => [:edit, :create, :update, :destroy] resources :subscribes, :only => [:create, :destroy] + collection do + post :create_label + post :delete_label + end end resource :repo, :controller => "git/repositories", :only => [:show] resources :build_lists, :only => [:index, :new, :create] diff --git a/db/migrate/20120220175615_create_labels.rb b/db/migrate/20120220175615_create_labels.rb new file mode 100644 index 000000000..18275962f --- /dev/null +++ b/db/migrate/20120220175615_create_labels.rb @@ -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 diff --git a/db/migrate/20120220175615_create_tags.rb b/db/migrate/20120220175615_create_tags.rb deleted file mode 100644 index e693bbb32..000000000 --- a/db/migrate/20120220175615_create_tags.rb +++ /dev/null @@ -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 diff --git a/spec/models/labels_spec.rb b/spec/models/labels_spec.rb new file mode 100644 index 000000000..af7e7325e --- /dev/null +++ b/spec/models/labels_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Tag do + pending "add some examples to (or delete) #{__FILE__}" +end