From 71c41cb723373c7425183f98fcc9e42fb390c848 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 11 Feb 2015 01:35:12 +0300 Subject: [PATCH] #452: Show only main platforms which user used as default on BuildLists#new page --- app/helpers/build_lists_helper.rb | 12 ++++++++++-- app/models/user_builds_setting.rb | 3 +-- .../_extra_params_and_preferences.html.slim | 9 ++++++--- app/views/users/settings/builds_settings.html.slim | 4 +--- config/locales/models/user_builds_setting.en.yml | 2 -- config/locales/models/user_builds_setting.ru.yml | 2 -- .../20150210192749_create_user_builds_settings.rb | 1 - db/schema.rb | 5 ++--- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index 659cae82c..a6157decf 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -214,6 +214,8 @@ module BuildListsHelper def save_to_repositories(project, params) project.repositories.map do |r| + # Show only main platforms which user used as default. + next if r.platform.main? && current_user_platforms.present? && current_user_platforms.exclude?(r.platform.id) { id: r.id, name: "#{r.platform.name}/#{r.name}", @@ -224,11 +226,13 @@ module BuildListsHelper default_arches: ( r.platform.platform_arch_settings.by_default.pluck(:arch_id).presence || Arch.where(name: Arch::DEFAULT).pluck(:id) ) } - end.sort_by { |e| e[:name] } + end.compact.sort_by { |e| e[:name] } end def new_build_list_platforms(params) availables_main_platforms.map do |pl| + # Show only main platforms which user used as default. + next if current_user_platforms.present? && current_user_platforms.exclude?(pl.id) platform = { id: pl.id, name: pl.name, repositories: [] } Repository.custom_sort(pl.repositories).each do |repo| platform[:repositories] << { id: repo.id, @@ -237,7 +241,11 @@ module BuildListsHelper checked: is_repository_checked(repo, params) } end platform - end + end.compact + end + + def current_user_platforms + @current_user_platforms ||= (current_user.builds_setting.try(:platforms) || []).select(&:present?).map(&:to_i) end def include_repos(params) diff --git a/app/models/user_builds_setting.rb b/app/models/user_builds_setting.rb index 85264ad40..3cba6be9b 100644 --- a/app/models/user_builds_setting.rb +++ b/app/models/user_builds_setting.rb @@ -5,7 +5,6 @@ class UserBuildsSetting < ActiveRecord::Base validates :user, presence: true - attr_accessible :platforms, - :use_extra_tests + attr_accessible :platforms end diff --git a/app/views/projects/build_lists/new_build/_extra_params_and_preferences.html.slim b/app/views/projects/build_lists/new_build/_extra_params_and_preferences.html.slim index 00dfa1e79..8468a198e 100644 --- a/app/views/projects/build_lists/new_build/_extra_params_and_preferences.html.slim +++ b/app/views/projects/build_lists/new_build/_extra_params_and_preferences.html.slim @@ -29,7 +29,10 @@ h4.offset10= t("activerecord.attributes.build_list.preferences") = f.check_box kind, checked: checked = BuildList.human_attribute_name kind -- selected = params[:build_list].try(:[], :external_nodes) ? {selected: params[:build_list][:external_nodes]} : {} +- selected = params[:build_list].try(:[], :external_nodes) +- selected = current_user.builds_setting.try(:external_nodes) if selected.nil? +- selected = selected && { selected: selected } || {} = f.label :external_nodes -= f.select :external_nodes, external_nodes, selected.merge(include_blank: true), - class: 'form-control' += f.select :external_nodes, external_nodes, + selected.merge(include_blank: true), + class: 'form-control' diff --git a/app/views/users/settings/builds_settings.html.slim b/app/views/users/settings/builds_settings.html.slim index d5b52dbe7..31903109a 100644 --- a/app/views/users/settings/builds_settings.html.slim +++ b/app/views/users/settings/builds_settings.html.slim @@ -6,8 +6,7 @@ .row = simple_form_for @user.builds_setting, url: builds_settings_settings_path, - wrapper: :horizontal_form, - wrapper_mappings: { boolean: :horizontal_boolean } do |f| + wrapper: :horizontal_form do |f| fieldset legend @@ -29,7 +28,6 @@ .col-sm-8 = f.input :external_nodes, collection: external_nodes, include_blank: true - = f.input :use_extra_tests, as: :boolean .clearfix hr diff --git a/config/locales/models/user_builds_setting.en.yml b/config/locales/models/user_builds_setting.en.yml index e637ff187..6eb473d76 100644 --- a/config/locales/models/user_builds_setting.en.yml +++ b/config/locales/models/user_builds_setting.en.yml @@ -11,10 +11,8 @@ en: user_builds_setting: platforms: "Platforms" external_nodes: "External nodes" - use_extra_tests: "Use extra tests" # placeholders: hints: user_builds_setting: platforms: "Select a platforms that you'd like to use." external_nodes: "Select the type of nodes that you'd like to use." - use_extra_tests: "Uncheck this to disable extra tests." diff --git a/config/locales/models/user_builds_setting.ru.yml b/config/locales/models/user_builds_setting.ru.yml index de05e0b57..39e3f4bae 100644 --- a/config/locales/models/user_builds_setting.ru.yml +++ b/config/locales/models/user_builds_setting.ru.yml @@ -11,10 +11,8 @@ ru: user_builds_setting: platforms: "Платформы" external_nodes: "Дополнительные ноды" - use_extra_tests: "Использовать дополнительные тесты" # placeholders: hints: user_builds_setting: platforms: "Выберите платформы, которые вы хотели бы использовать." external_nodes: "Выберите ноды, которые вы хотели бы использовать." - use_extra_tests: "Снимите тут, чтобы отключить дополнительные тесты." diff --git a/db/migrate/20150210192749_create_user_builds_settings.rb b/db/migrate/20150210192749_create_user_builds_settings.rb index 0be678c69..1974852e3 100644 --- a/db/migrate/20150210192749_create_user_builds_settings.rb +++ b/db/migrate/20150210192749_create_user_builds_settings.rb @@ -3,7 +3,6 @@ class CreateUserBuildsSettings < ActiveRecord::Migration create_table :user_builds_settings do |t| t.integer :user_id, null: false t.text :platforms, null: false, default: [], array: true - t.boolean :use_extra_tests, null: false, default: true t.string :external_nodes end diff --git a/db/schema.rb b/db/schema.rb index c84ab0f56..1101a8ce0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -629,9 +629,8 @@ ActiveRecord::Schema.define(version: 20150210192749) do end create_table "user_builds_settings", force: true do |t| - t.integer "user_id", null: false - t.text "platforms", default: [], null: false, array: true - t.boolean "use_extra_tests", default: true, null: false + t.integer "user_id", null: false + t.text "platforms", default: [], null: false, array: true t.string "external_nodes" t.index ["user_id"], :name => "index_user_builds_settings_on_user_id", :unique => true end