From 69303561f4ad2a08efe8a77feace5553502fa2b4 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Sat, 5 May 2012 16:43:10 +0600 Subject: [PATCH 1/2] [refs #434] add build priority to users --- app/controllers/projects/build_lists_controller.rb | 2 +- .../20120505101650_add_build_priority_to_users.rb | 11 +++++++++++ db/schema.rb | 8 +++----- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20120505101650_add_build_priority_to_users.rb diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 25c8e8562..35b3026ac 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -48,7 +48,7 @@ class Projects::BuildListsController < Projects::BaseController @build_list.commit_hash = @project.git_repository.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last || @build_list.project_version).first.id if @build_list.project_version @build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user @build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.bpl.repository_ids.include? ir.to_i} - @build_list.priority = 100 # User builds more priority than mass rebuild with zero priority + @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :bpl => bpl.name, :pl => @build_list.pl} if @build_list.save notices << t("flash.build_list.saved", flash_options) diff --git a/db/migrate/20120505101650_add_build_priority_to_users.rb b/db/migrate/20120505101650_add_build_priority_to_users.rb new file mode 100644 index 000000000..45e2efae3 --- /dev/null +++ b/db/migrate/20120505101650_add_build_priority_to_users.rb @@ -0,0 +1,11 @@ +class AddBuildPriorityToUsers < ActiveRecord::Migration + def up + add_column :users, :build_priority, :integer, :default => 50 + User.update_all :build_priority => 50 + end + + def down + remove_column :users, :build_priority + end + +end diff --git a/db/schema.rb b/db/schema.rb index 4a8dbd269..ed9a86346 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120425190938) do +ActiveRecord::Schema.define(:version => 20120505101650) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -342,13 +342,11 @@ ActiveRecord::Schema.define(:version => 20120425190938) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.string "authentication_token" + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" From 614f8cd5f9281895820dec533cf0ac145818b83e Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Sat, 5 May 2012 19:15:49 +0300 Subject: [PATCH 2/2] Refactor active menu detection. Refs #433 --- app/helpers/application_helper.rb | 4 ++++ app/views/layouts/menu/_top.html.haml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d22a381b0..e429b3b53 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,6 +17,10 @@ module ApplicationHelper end end + def top_menu_class(base) + (controller_name.include?('build_lists') ? controller_name : params[:controller]).include?(base.to_s) ? 'active' : nil + end + def title_object object name = object.class == Group ? object.uname : object.name object_name = t "activerecord.models.#{object.class.name.downcase}" diff --git a/app/views/layouts/menu/_top.html.haml b/app/views/layouts/menu/_top.html.haml index 552c34fa0..e5ed2e1c0 100644 --- a/app/views/layouts/menu/_top.html.haml +++ b/app/views/layouts/menu/_top.html.haml @@ -2,6 +2,6 @@ %ul - (collection = t which_menu).each do |base, title| - if can? :index, base.to_s.classify.constantize - %li= link_to title, send(:"#{namespace}#{base}_path"), :class => params[:controller].include?(base.to_s) ? 'active' : '' + %li= link_to title, send(:"#{namespace}#{base}_path"), :class => top_menu_class(base) - if current_user.try(:admin?) and which_menu == 'top_menu' - %li= link_to t('admins_menu_header'), admin_users_path, :class => t('admins_menu').has_key?(controller_name.to_sym) ? 'active' : '' + %li= link_to t('admins_menu_header'), admin_users_path, :class => top_menu_class('admin')