diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/categories_controller.rb (renamed from app/controllers/question_categories_controller.rb) | 2 | ||||
-rw-r--r-- | app/models/answer.rb | 2 | ||||
-rw-r--r-- | app/models/category.rb (renamed from app/models/question_category.rb) | 4 | ||||
-rw-r--r-- | app/models/question.rb | 18 | ||||
-rw-r--r-- | app/models/question_group.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 8 | ||||
-rw-r--r-- | app/models/user_category.rb | 6 | ||||
-rw-r--r-- | app/models/user_mailer.rb | 2 | ||||
-rw-r--r-- | app/viewhints/user_hints.rb | 2 | ||||
-rw-r--r-- | app/views/categories/show.dryml (renamed from app/views/question_categories/show.dryml) | 0 | ||||
-rw-r--r-- | app/views/question_groups/category.dryml | 2 | ||||
-rw-r--r-- | app/views/taglibs/nav.dryml | 2 | ||||
-rw-r--r-- | app/views/taglibs/pages.dryml | 4 |
13 files changed, 28 insertions, 28 deletions
diff --git a/app/controllers/question_categories_controller.rb b/app/controllers/categories_controller.rb index ec63105..c5749f9 100644 --- a/app/controllers/question_categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -12,7 +12,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -class QuestionCategoriesController < ApplicationController +class CategoriesController < ApplicationController hobo_model_controller diff --git a/app/models/answer.rb b/app/models/answer.rb index 73e7750..b214ebb 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -45,7 +45,7 @@ class Answer < ActiveRecord::Base :joins => :owner, :conditions => { 'users.mentor_id', mentor } } } named_scope :in_category, lambda { |category| { - :joins => :question, :conditions => { 'questions.question_category_id', category} } } + :joins => :question, :conditions => { 'questions.category_id', category} } } named_scope :with_feedback, lambda { |opt| { :conditions => { :feedback => opt } } } diff --git a/app/models/question_category.rb b/app/models/category.rb index e67810c..a52a50d 100644 --- a/app/models/question_category.rb +++ b/app/models/category.rb @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # Questions are arranged in categories. Recruit should answer question in some # categories. -class QuestionCategory < ActiveRecord::Base +class Category < ActiveRecord::Base hobo_model # Don't put anything above this @@ -34,6 +34,6 @@ class QuestionCategory < ActiveRecord::Base # Array of arrays [Category name, Category id], includes also # ['All Categories', nil] array. def self.as_select_opts - [['All Categories', nil]] + QuestionCategory.all(:select => 'name, id').collect{ |q| [q.name, q.id]} + [['All Categories', nil]] + self.all(:select => 'name, id').collect{ |q| [q.name, q.id]} end end diff --git a/app/models/question.rb b/app/models/question.rb index b8cfed6..a660de6 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -39,7 +39,7 @@ class Question < ActiveRecord::Base #maybe add a page for not complete questions belongs_to :user, :creator => true - belongs_to :question_category + belongs_to :category belongs_to :question_group has_many :answers has_one :reference_answer, :class_name => "Answer", :conditions => ["answers.reference = ?", true] @@ -58,7 +58,7 @@ class Question < ActiveRecord::Base return true if new_record? # when it's not new record allow changing only some properties - return only_changed?(:title, :content, :documentation, :question_category) + return only_changed?(:title, :content, :documentation, :category) end false @@ -89,7 +89,7 @@ class Question < ActiveRecord::Base end named_scope :unanswered_ungrouped, lambda { |uid|{ - :joins => {:question_category => :user_categories}, + :joins => {:category => :user_categories}, :conditions => [ 'user_categories.user_id = ? AND questions.question_group_id IS NULL ' + 'AND NOT EXISTS (' + 'SELECT * FROM answers WHERE answers.owner_id = ? AND answers.question_id = questions.id)', @@ -109,7 +109,7 @@ class Question < ActiveRecord::Base :conditions => ['questions.id != ?', id]}} named_scope :ungrouped_questions_of_user, lambda { |user_id|{ - :joins => {:question_category => :user_categories}, + :joins => {:category => :user_categories}, :conditions => ['user_categories.user_id = ? AND questions.question_group_id IS NULL', user_id]}} named_scope :grouped_questions_of_user, lambda { |user_id|{ @@ -120,7 +120,7 @@ class Question < ActiveRecord::Base :conditions => { :user_id => user_id, :approved => false }}} named_scope :unanswered, lambda { |uid|{ - :joins => {:question_category => {:user_categories => :user}}, + :joins => {:category => {:user_categories => :user}}, :conditions => [ 'users.id = ? AND NOT EXISTS ( ' + 'SELECT * FROM answers WHERE answers.owner_id = ? AND answers.question_id = questions.id)', uid, uid]}} @@ -183,9 +183,9 @@ class Question < ActiveRecord::Base protected # Sends notification about new question (TODO: check for group). def notify_new_question - # If question category isn't assigned don't try to access it - if question_category && approved - for user in question_category.users + # If category isn't assigned don't try to access it + if category && approved + for user in category.users UserMailer.delay.deliver_new_question(user, self) end end @@ -193,7 +193,7 @@ class Question < ActiveRecord::Base # Sends notification about new question (TODO: check for group). def notify_approved_question - if question_category && !approved_was && approved + if category && !approved_was && approved notify_new_question end end diff --git a/app/models/question_group.rb b/app/models/question_group.rb index 81d738b..4ecd037 100644 --- a/app/models/question_group.rb +++ b/app/models/question_group.rb @@ -32,12 +32,12 @@ class QuestionGroup < ActiveRecord::Base include Permissions::AnyoneCanViewAdminCanChange named_scope :in_category, lambda { |cid| { - :joins => :questions, :conditions => ['questions.question_category_id = ?', cid], + :joins => :questions, :conditions => ['questions.category_id = ?', cid], :group => 'question_groups.id, question_groups.name, question_groups.description, question_groups.created_at, question_groups.updated_at'}} named_scope :unassociated_in_category, lambda { |uid, cid| { - :joins => :questions, :conditions => ['questions.question_category_id = ? AND NOT EXISTS + :joins => :questions, :conditions => ['questions.category_id = ? AND NOT EXISTS (SELECT user_question_groups.* FROM user_question_groups INNER JOIN questions ON questions.id = user_question_groups.question_id WHERE (user_question_groups.user_id = ? AND questions.question_group_id = question_groups.id))', cid, uid], diff --git a/app/models/user.rb b/app/models/user.rb index 071c708..ca7af6c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,7 +37,7 @@ class User < ActiveRecord::Base has_many :user_categories has_many :user_question_groups - has_many :question_categories, :through => :user_categories, :accessible => true, :uniq => true + has_many :categories, :through => :user_categories, :accessible => true, :uniq => true has_many :grouped_questions, :through => :user_question_groups has_many :answers, :foreign_key => :owner_id has_many :answered_questions, :through => :answers, :class_name => "Question", :source => :question @@ -49,8 +49,8 @@ class User < ActiveRecord::Base named_scope :mentorless_recruits, :conditions => { :role => 'recruit', :mentor_id => nil} named_scope :recruits_answered_all, :conditions => "role = 'recruit' AND NOT EXISTS (SELECT questions.id FROM questions - INNER JOIN question_categories cat ON questions.question_category_id = cat.id INNER JOIN - user_categories ON user_categories.question_category_id = cat.id WHERE + INNER JOIN categories cat ON questions.category_id = cat.id INNER JOIN + user_categories ON user_categories.category_id = cat.id WHERE user_categories.user_id = users.id AND questions.question_group_id IS NULL AND NOT EXISTS ( SELECT answers.id FROM answers WHERE answers.question_id = questions.id AND answers.owner_id = users.id)) AND NOT EXISTS @@ -224,7 +224,7 @@ class User < ActiveRecord::Base return mentor_picked_up_or_resigned? if mentor_changed? # make sure recruiters change only what they are allowed to - return false unless only_changed?(:question_categories, :role, :nick) + return false unless only_changed?(:categories, :role, :nick) # and make sure change to role wasn't changed or was promotion of recruit # to mentor or demotion of mentor to recruit diff --git a/app/models/user_category.rb b/app/models/user_category.rb index 3f60283..e4b8b51 100644 --- a/app/models/user_category.rb +++ b/app/models/user_category.rb @@ -28,9 +28,9 @@ class UserCategory < ActiveRecord::Base end belongs_to :user, :null => false - belongs_to :question_category, :null => false + belongs_to :category, :null => false - validates_uniqueness_of :user_id, :scope => :question_category_id + validates_uniqueness_of :user_id, :scope => :category_id multi_permission :create, :update, :destroy do return true if acting_user.role.is_recruiter? @@ -48,7 +48,7 @@ class UserCategory < ActiveRecord::Base end def before_create - for group in QuestionGroup.unassociated_in_category(user, question_category).all + for group in QuestionGroup.unassociated_in_category(user, category).all chosen_question = rand(group.questions.count) UserQuestionGroup.create! :user => user, :question => (Question.all :limit => 1, :offset => chosen_question, :conditions => {:question_group_id => group.id})[0] diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index b405c8e..4acaff2 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -32,7 +32,7 @@ class UserMailer < ActionMailer::Base def new_question(user, question) common(user, "New question") - @body = { :title=> question.title, :category => question.question_category, + @body = { :title=> question.title, :category => question.category, :id => question.id} end diff --git a/app/viewhints/user_hints.rb b/app/viewhints/user_hints.rb index 91e3516..635f09e 100644 --- a/app/viewhints/user_hints.rb +++ b/app/viewhints/user_hints.rb @@ -13,5 +13,5 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. class UserHints < Hobo::ViewHints - children :answers, :question_categories, :project_acceptances + children :answers, :categories, :project_acceptances end diff --git a/app/views/question_categories/show.dryml b/app/views/categories/show.dryml index 8744afd..8744afd 100644 --- a/app/views/question_categories/show.dryml +++ b/app/views/categories/show.dryml diff --git a/app/views/question_groups/category.dryml b/app/views/question_groups/category.dryml index 8ac016b..0242002 100644 --- a/app/views/question_groups/category.dryml +++ b/app/views/question_groups/category.dryml @@ -2,7 +2,7 @@ <content-body:> <form action="/question_groups/category"> <%= - select("id", nil, QuestionCategory.as_select_opts, {:include_blank => false, :selected => params['id']._?[0].to_i}) + select("id", nil, Category.as_select_opts, {:include_blank => false, :selected => params['id']._?[0].to_i}) %> <submit label="view in this category"/> </form> diff --git a/app/views/taglibs/nav.dryml b/app/views/taglibs/nav.dryml index 6dad653..1c25680 100644 --- a/app/views/taglibs/nav.dryml +++ b/app/views/taglibs/nav.dryml @@ -1,7 +1,7 @@ <def tag="main-nav"> <navigation class="main-nav" merge-attrs param="default"> <nav-item href="#{base_url}/">Home</nav-item> - <nav-item with="&QuestionCategory"><ht key="question_categories.nav_item">Question Categories</ht></nav-item> + <nav-item with="&Category"><ht key="categories.nav_item">Question Categories</ht></nav-item> <nav-item with="&QuestionGroup" action="category"><ht key="question_groups.nav_item">Question Groups</ht></nav-item> <nav-item href="&suggest_questions_questions_path" unless="¤t_user.administrator?"><ht key="questions.nav_item">Suggest Questions</ht></nav-item> <nav-item href="&approve_questions_questions_path" if="¤t_user.questions_to_approve.count > 0"><ht key="questions.nav_item">Approve Questions</ht></nav-item> diff --git a/app/views/taglibs/pages.dryml b/app/views/taglibs/pages.dryml index 06d29ba..79de5b3 100644 --- a/app/views/taglibs/pages.dryml +++ b/app/views/taglibs/pages.dryml @@ -18,7 +18,7 @@ <section class="users recruits" if="&this.role.is_recruit?"> - <if:question_categories> + <if:categories> You are currently assigned to categories: <collection/> View questions: @@ -53,7 +53,7 @@ <unless test="&this.recruits.empty?"> Check <a with="&Answer" action="my_recruits">answers</a> of recruits you mentor. You also can view answers of the recruits you mentor in categories: - <collection with="&QuestionCategory.all"> + <collection with="&Category.all"> <a href="/answers/my_recruits_cat/#{this.id}"><name/></a> </collection> </unless> |