From 237bd6affb9108ed77f1027c2481f9dcd07cc152 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 4 Jun 2013 23:59:08 +0400 Subject: [PATCH] #156: update UI of MassBuild#new BuildList#new --- .../javascripts/extra/autocomplete-form.js | 52 +++++++++++++++ app/assets/javascripts/extra/build_list.js | 63 +++---------------- app/assets/javascripts/extra/mass_build.js | 2 +- app/assets/stylesheets/design/custom.scss | 11 +++- app/controllers/autocompletes_controller.rb | 42 +++++++++++++ .../platforms/mass_builds_controller.rb | 52 ++++++++------- .../projects/build_lists_controller.rb | 61 +++++++++--------- app/models/ability.rb | 2 +- app/models/build_list.rb | 5 +- app/models/mass_build.rb | 23 +++---- app/models/project.rb | 5 +- app/views/platforms/base/_sidebar.html.haml | 2 +- .../platforms/mass_builds/_form.html.haml | 25 -------- .../_repos_or_list_choice.html.haml | 8 --- .../platforms/mass_builds/index.html.haml | 2 +- app/views/platforms/mass_builds/new.html.haml | 34 ++++++++++ .../projects/build_lists/_extra.html.haml | 9 --- .../build_lists/_extra_form.html.haml | 13 ---- app/views/projects/build_lists/new.html.haml | 6 +- app/views/shared/_autocomplete_form.html.haml | 33 ++++++++++ .../_extra_build_lists.en.html.haml | 0 .../_extra_build_lists.ru.html.haml | 0 .../_extra_repositories.en.html.haml} | 0 .../_extra_repositories.ru.html.haml} | 0 config/locales/models/build_list.en.yml | 2 +- config/locales/models/build_list.ru.yml | 2 +- config/locales/models/mass_build.en.yml | 2 +- config/locales/models/mass_build.ru.yml | 2 +- config/routes.rb | 4 +- ...ra_repos_and_build_lists_to_mass_build.rb} | 8 ++- db/schema.rb | 35 ++++++----- 31 files changed, 290 insertions(+), 215 deletions(-) create mode 100644 app/assets/javascripts/extra/autocomplete-form.js delete mode 100644 app/views/platforms/mass_builds/_form.html.haml delete mode 100644 app/views/platforms/mass_builds/_repos_or_list_choice.html.haml create mode 100644 app/views/platforms/mass_builds/new.html.haml delete mode 100644 app/views/projects/build_lists/_extra.html.haml delete mode 100644 app/views/projects/build_lists/_extra_form.html.haml create mode 100644 app/views/shared/_autocomplete_form.html.haml rename app/views/{projects/build_lists/docs => shared/autocomplete_docs}/_extra_build_lists.en.html.haml (100%) rename app/views/{projects/build_lists/docs => shared/autocomplete_docs}/_extra_build_lists.ru.html.haml (100%) rename app/views/{projects/build_lists/docs/_extra_repos.en.html.haml => shared/autocomplete_docs/_extra_repositories.en.html.haml} (100%) rename app/views/{projects/build_lists/docs/_extra_repos.ru.html.haml => shared/autocomplete_docs/_extra_repositories.ru.html.haml} (100%) rename db/migrate/{20130603124853_add_save_to_platform_to_mass_build.rb => 20130603124853_add_extra_repos_and_build_lists_to_mass_build.rb} (65%) diff --git a/app/assets/javascripts/extra/autocomplete-form.js b/app/assets/javascripts/extra/autocomplete-form.js new file mode 100644 index 000000000..797d35938 --- /dev/null +++ b/app/assets/javascripts/extra/autocomplete-form.js @@ -0,0 +1,52 @@ +$(document).ready(function() { + // // TODO: Refactor this handler!! It's too complicated. + // $('#build_list_save_to_repository_id, #build_for_platform').change(function() { + // var selected_option = $(this).find('option:selected'); + // var platform_id = selected_option.attr('platform_id') || selected_option.val(); + // var path = '/build_lists/autocomplete_to_extra_repos_and_builds?platform_id=' + platform_id; + // $('#extra_repos').attr('data-autocomplete', (path + '&search_repos=true')); + // $('#extra_build_lists').attr('data-autocomplete', path); + // }); + + + $('.autocomplete-form .button.add').click(function() { + var form = $(this).parent(); + var field = form.attr('field'); + var subject = $('#' + field + '_field'); + if (!subject.val()) { return false; } + var name = form.attr('subject_class') + '[' + field + ']' + '[]'; + var path = $('#' + field + '_field_path').val(); + var label = $('#' + field + '_field_label').val(); + + var tr = '' + + '' + + '' + label + '' + + '' + + '' + + '' + + ' ' + + '' + + ''; + + form.find('table tbody').append($(tr)); + form.find('.autocomplete').val(''); + return false; + }); + + $(document).on('click', '.autocomplete-form .delete', function() { + $(this).parent().parent().remove(); + }); + + $('.autocomplete-form .dialog').dialog({ + autoOpen: false, + resizable: false, + width: 500 + }); + + $('.autocomplete-form .icon-question-sign').click(function() { + var field = $(this).parent().attr('field'); + var dialog = $('#' + field + '_dialog'); + if (dialog.is(':visible')) { dialog.dialog('close'); } else { dialog.dialog('open'); } + }); + +}); diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index ab7ac4784..7f1b64ae8 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -10,10 +10,10 @@ $(document).ready(function() { var all_repositories = $('.all_platforms input'); all_repositories.removeAttr('checked'); var auto_create_container = $('#build_list_auto_create_container'); - var extra_repos = $('#extra-repos'); + var extra_repos = $('.autocomplete-form.extra_repositories'); - updateExtraReposOrBuildLists('repos'); - updateExtraReposOrBuildLists('build_lists'); + updateExtraReposAndBuildLists(platform_id); + $('.autocomplete-form table tbody').empty(); if (build_platform.size() == 0) { all_repositories.removeAttr('disabled'); auto_create_container.removeAttr('checked'); @@ -36,41 +36,10 @@ $(document).ready(function() { build_list_auto_publish.removeAttr('checked').attr('disabled', 'disabled'); auto_create_container.attr('checked', 'checked'); } - - var path = '/build_lists/autocomplete_to_extra_repos_and_builds?platform_id=' + platform_id; - $('#extra_repos').attr('data-autocomplete', (path + '&search_repos=true')); - $('#extra_build_lists').attr('data-autocomplete', path); }); $('#build_list_save_to_repository_id').trigger('change'); - $('#extra-repos > .button').click(function() { - updateExtraReposOrBuildLists('repos'); - return false; - }); - - $('#extra-build-lists > .button').click(function() { - updateExtraReposOrBuildLists('build-lists'); - return false; - }); - - $(document).on('click', '#extra-repos .delete, #extra-repos-dialog .delete', function() { - $(this).parent().parent().remove(); - }); - - $('#extra-repos-dialog, #extra-build-lists-dialog').dialog({ - autoOpen: false, - resizable: false, - width: 500 - }); - - $('#extra-repos .icon-question-sign').click(function() { - showOrHideDialog($('#extra-repos-dialog')); - }); - $('#extra-build-lists .icon-question-sign').click(function() { - showOrHideDialog($('#extra-build-lists-dialog')); - }); - var ownership_btn = $('.btn.ownership'); ownership_btn.click(function() { @@ -107,26 +76,12 @@ $(document).ready(function() { }); }); -function showOrHideDialog(dialog) { - if (dialog.is(':visible')) { dialog.dialog('close'); } else { dialog.dialog('open'); } -} - -function updateExtraReposOrBuildLists(term) { - var path = '/build_lists/update_extra_repos_and_builds'; - var container_id = ''; - if (term == 'repos') { - path += '?update_repos=true'; - container_id = '#extra-repos'; - } else { - container_id = '#extra-build-lists'; - } - $.get(path, $('#new_build_list').serialize()). - done(function(data) { - var container = $(container_id); - container.find('table tbody').html(data); - container.find('.ui-autocomplete-input').val(''); - }); - +function updateExtraReposAndBuildLists(save_to_platform_id) { + $.each($('.autocomplete-form'), function() { + var form = $(this); + var path = form.attr('path') + '?platform_id=' + save_to_platform_id; + form.find('.autocomplete').attr('data-autocomplete', path); + }); } function setBranchSelected(selected_option) { diff --git a/app/assets/javascripts/extra/mass_build.js b/app/assets/javascripts/extra/mass_build.js index 177cea13f..8a7c1ee84 100644 --- a/app/assets/javascripts/extra/mass_build.js +++ b/app/assets/javascripts/extra/mass_build.js @@ -1,5 +1,5 @@ $(document).ready(function() { - var projects_list = $('.form.mass_build #projects_list'); + var projects_list = $('.form.mass_build #mass_build_projects_list'); var repositories = $(".form.mass_build .left input:checkbox"); repositories.click(function(){ if (this.checked){ diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index c5f501b3c..fd1c69aab 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -571,6 +571,7 @@ table.tablesorter tr td.buttons a span.delete, span.delete { background: image-url('x.png') no-repeat 0 0 transparent; width: 12px; + height: 12px; display: inline-block; cursor: pointer; } @@ -1839,18 +1840,22 @@ table#myTable thead tr.search th form.button_to div input { } -#extra-repos, #extra-build-lists { +.autocomplete-form { width: 330px; .actions { width: 15px; } h3 { display: inline-block; } + .tablesorter { + width: auto; + min-width: 250px; + } } -#extra-repos-dialog, #extra-build-lists-dialog { +#extra_repositories_dialog, #extra_build_lists_dialog { font-size: 12px; text-align: left; p { margin: 0; } } -#ui-dialog-title-extra-repos-dialog, #ui-dialog-title-extra-build-lists-dialog { +#ui-dialog-title-extra_repositories_dialog, #ui-dialog-title-extra_build_lists_dialog { font-size: 14px; } diff --git a/app/controllers/autocompletes_controller.rb b/app/controllers/autocompletes_controller.rb index cbffc074a..e19655f31 100644 --- a/app/controllers/autocompletes_controller.rb +++ b/app/controllers/autocompletes_controller.rb @@ -4,4 +4,46 @@ class AutocompletesController < ApplicationController autocomplete :group, :uname autocomplete :user, :uname + autocomplete :user, :uname + + def autocomplete_extra_build_list + bl = BuildList.where(:id => params[:term]).published_container.accessible_by(current_ability, :read) + bl = bl.where(:save_to_platform_id => save_to_platform.id) if save_to_platform.main? + bl = bl.first + results << { :id => bl.id, + :value => bl.id, + :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})", + :path => build_list_path(bl) + } if bl + render json: results.to_json + end + + def autocomplete_extra_repositories + # Only personal repositories can be attached to the build + Platform.includes(:repositories).personal.search(params[:term]) + .accessible_by(current_ability, :read) + .search_order.limit(5).each do |platform| + + platform.repositories.each do |repository| + label = "#{platform.name}/#{repository.name}" + results << { :id => repository.id, + :label => label, + :value => label, + :path => platform_repository_path(platform, repository) + } + end + end if save_to_platform.personal? + render json: results.to_json + end + + protected + + def save_to_platform + @save_to_platform ||= Platform.find(params[:platform_id]) + end + + def results + @results ||= [] + end + end diff --git a/app/controllers/platforms/mass_builds_controller.rb b/app/controllers/platforms/mass_builds_controller.rb index 455e62c8a..3eaee2c94 100644 --- a/app/controllers/platforms/mass_builds_controller.rb +++ b/app/controllers/platforms/mass_builds_controller.rb @@ -1,33 +1,44 @@ #class MassBuildsController < ApplicationController class Platforms::MassBuildsController < Platforms::BaseController + # before_filter :authenticate_user! + # skip_before_filter :authenticate_user!, :only => [:index, :get_list] if APP_CONFIG['anonymous_access'] + + # load_and_authorize_resource :platform + # load_and_authorize_resource + + # skip_load_and_authorize_resource :only => [:index, :create] + # skip_load_and_authorize_resource :platform, :only => [:cancel, :failed_builds_list, :publish] + # skip_authorize_resource :platform, :only => [:index, :create] + + + + NESTED_ACTIONS = [:index, :new, :create] + before_filter :authenticate_user! skip_before_filter :authenticate_user!, :only => [:index, :get_list] if APP_CONFIG['anonymous_access'] - load_and_authorize_resource :platform - load_and_authorize_resource + # before_filter :find_mass_build, :only => [:publish, :cancel] - skip_load_and_authorize_resource :only => [:index, :create] - skip_load_and_authorize_resource :platform, :only => [:cancel, :failed_builds_list, :publish] - skip_authorize_resource :platform, :only => [:index, :create] + load_and_authorize_resource :platform, :only => NESTED_ACTIONS + load_and_authorize_resource :mass_build, :through => :platform, :only => NESTED_ACTIONS, :shallow => true + load_and_authorize_resource :except => NESTED_ACTIONS + + + def new + end def create - @auto_publish_selected, @use_save_to_repository = params[:auto_publish].present?, params[:use_save_to_repository].present? - mass_build = @platform.mass_builds.new(:arches => params[:arches], - :auto_publish => @auto_publish_selected, - :use_save_to_repository => @use_save_to_repository, - :projects_list => params[:projects_list], - :build_for_platform_id => Platform.main.where(:id => params[:build_for_platform]).first.try(:id) - ) - mass_build.user = current_user - authorize! :create, mass_build + @mass_build = @platform.mass_builds.build(params[:mass_build]) do |mb| + mb.arches = params[:arches] + mb.user = current_user + end - if mass_build.save + if @mass_build.save redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success")) else - @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) - flash[:warning] = mass_build.errors.full_messages.join('. ') - flash[:error] = t("flash.platform.build_all_error") - render :index + flash[:warning] = @mass_build.errors.full_messages.join('. ') + flash[:error] = t('flash.platform.build_all_error') + render :action => :new end end @@ -41,8 +52,7 @@ class Platforms::MassBuildsController < Platforms::BaseController end def index - @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) - @auto_publish_selected = @use_save_to_repository = true + @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) end def cancel diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 1da4941f4..79790fe51 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -34,7 +34,6 @@ class Projects::BuildListsController < Projects::BaseController end def new - # @build_list = BuildList.new # @build_list already created by CanCan end def create @@ -114,37 +113,37 @@ class Projects::BuildListsController < Projects::BaseController } end - def autocomplete_to_extra_repos_and_builds - results, save_to_platform = [], Platform.find(params[:platform_id]) - if params[:search_repos].present? && save_to_platform.personal? - # Only personal repositories can be attached to the build - platforms = Platform.includes(:repositories).personal.search(params[:term]). - accessible_by(current_ability, :read).search_order.limit(5) - platforms.each{ |p| p.repositories.each{ |r| results << {:id => r.id, :label => "#{p.name}/#{r.name}", :value => "#{p.name}/#{r.name}"} } } - elsif params[:search_repos].blank? - bl = BuildList.where(:id => params[:term]).published_container.accessible_by(current_ability, :read) - bl = bl.where(:save_to_platform_id => save_to_platform.id) if save_to_platform.main? - bl = bl.first - results << {:id => bl.id, :value => bl.id, :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl - end - render json: results.to_json - end + # def autocomplete_to_extra_repos_and_builds + # results, save_to_platform = [], Platform.find(params[:platform_id]) + # if params[:search_repos].present? && save_to_platform.personal? + # # Only personal repositories can be attached to the build + # platforms = Platform.includes(:repositories).personal.search(params[:term]). + # accessible_by(current_ability, :read).search_order.limit(5) + # platforms.each{ |p| p.repositories.each{ |r| results << {:id => r.id, :label => "#{p.name}/#{r.name}", :value => "#{p.name}/#{r.name}"} } } + # elsif params[:search_repos].blank? + # bl = BuildList.where(:id => params[:term]).published_container.accessible_by(current_ability, :read) + # bl = bl.where(:save_to_platform_id => save_to_platform.id) if save_to_platform.main? + # bl = bl.first + # results << {:id => bl.id, :value => bl.id, :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl + # end + # render json: results.to_json + # end - def update_extra_repos_and_builds - results, save_to_repository = [], Repository.find(params[:build_list][:save_to_repository_id]) - if params[:update_repos].present? - extra_repos = params[:build_list][:extra_repositories] || [] - extra_repos << params[:extra_repos] if params[:extra_repos].present? - results = Repository.where(:id => extra_repos).accessible_by(current_ability, :read) if save_to_repository.platform.personal? - results |= [save_to_repository] if save_to_repository.platform.personal? - else - extra_bls = params[:build_list][:extra_build_lists] || [] - extra_bls << params[:extra_build_lists] if params[:extra_build_lists].present? - results = BuildList.where(:id => extra_bls).published_container.accessible_by(current_ability, :read) - results = results.where(:save_to_platform_id => save_to_repository.platform_id) if save_to_repository.platform.main? - end - render :partial => 'extra', :collection => results - end + # def update_extra_repos_and_builds + # results, save_to_repository = [], Repository.find(params[:build_list][:save_to_repository_id]) + # if params[:update_repos].present? + # extra_repos = params[:build_list][:extra_repositories] || [] + # extra_repos << params[:extra_repos] if params[:extra_repos].present? + # results = Repository.where(:id => extra_repos).accessible_by(current_ability, :read) if save_to_repository.platform.personal? + # results |= [save_to_repository] if save_to_repository.platform.personal? + # else + # extra_bls = params[:build_list][:extra_build_lists] || [] + # extra_bls << params[:extra_build_lists] if params[:extra_build_lists].present? + # results = BuildList.where(:id => extra_bls).published_container.accessible_by(current_ability, :read) + # results = results.where(:save_to_platform_id => save_to_repository.platform_id) if save_to_repository.platform.main? + # end + # render :partial => 'extra', :collection => results + # end protected diff --git a/app/models/ability.rb b/app/models/ability.rb index 56a4e6173..ece0426d6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -78,7 +78,7 @@ class Ability can([:read, :create, :edit, :destroy, :update], Hook) {|hook| can?(:edit, hook.project)} - can [:autocomplete_to_extra_repos_and_builds, :update_extra_repos_and_builds], BuildList + # can [:autocomplete_to_extra_repos_and_builds, :update_extra_repos_and_builds], BuildList can [:read, :log, :owned, :everything], BuildList, :user_id => user.id can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 7c48dc9c2..a80f5f690 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -484,8 +484,8 @@ class BuildList < ActiveRecord::Base def prepare_extra_build_lists bls = BuildList.where(:id => extra_build_lists).published_container.accessible_by(current_ability, :read) - if save_to_platform && save_to_platform.main? - bls = bls.where(:save_to_platform_id => save_to_platform.id) + if save_to_platform + bls = bls.where(:save_to_platform_id => save_to_platform.id) if save_to_platform.main? if save_to_platform.distrib_type == 'rhel' bls = bls.where(' (build_lists.arch_id = ? AND projects.publish_i686_into_x86_64 is not true) OR @@ -494,7 +494,6 @@ class BuildList < ActiveRecord::Base else bls = bls.where(:arch_id => arch_id) end - end self.extra_build_lists = bls.pluck('build_lists.id') end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 515ef1f21..0dfd8a576 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -1,22 +1,25 @@ class MassBuild < ActiveRecord::Base - belongs_to :build_for_platform, :class_name => 'Platform' + belongs_to :build_for_platform, :class_name => 'Platform', :conditions => {:platform_type => 'main'} belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :user has_many :build_lists, :dependent => :destroy + serialize :extra_repositories, Array + serialize :extra_build_lists, Array + scope :recent, order("#{table_name}.created_at DESC") scope :by_platform, lambda { |platform| where(:save_to_platform_id => platform.id) } scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) attr_accessor :arches - attr_accessible :arches, :auto_publish, :projects_list, :use_save_to_repository, :build_for_platform_id + attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id, + :extra_repositories, :extra_build_lists validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true validates_inclusion_of :auto_publish, :in => [true, false] - after_create :build_all - before_validation :set_data, :on => :create - before_validation :set_build_for_platform, :on => :create + after_commit :build_all + before_validation :set_data, :on => :create COUNT_STATUSES = [ :build_lists, @@ -54,7 +57,7 @@ class MassBuild < ActiveRecord::Base end end end - later :build_all, :queue => :clone_build + # later :build_all, :queue => :clone_build def generate_failed_builds_list report = "" @@ -100,15 +103,9 @@ class MassBuild < ActiveRecord::Base end end - def set_build_for_platform - if save_to_platform && save_to_platform.main? - self.build_for_platform = save_to_platform - self.use_save_to_repository = true - end - end - def set_data self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}" self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") + self.build_for_platform = save_to_platform if save_to_platform && save_to_platform.main? end end diff --git a/app/models/project.rb b/app/models/project.rb index 57b3872ae..e886176e6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -170,9 +170,10 @@ class Project < ActiveRecord::Base bl.user = user bl.auto_publish = auto_publish bl.include_repos = include_repos - bl.extra_repositories = [repository_id] if save_to_platform.personal? && mass_build.use_save_to_repository? + bl.extra_repositories = mass_build.extra_repositories + bl.extra_build_lists = mass_build.extra_build_lists bl.priority = priority - bl.mass_build_id = mass_build.try(:id) + bl.mass_build_id = mass_build.id bl.save_to_repository_id = repository_id end build_list.save diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index e8c95b594..691f1934b 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -14,7 +14,7 @@ %li{:class => (act == :index && contr == :maintainers) ? 'active' : nil} = link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform) - if can?(:show, @platform) - %li{:class => (contr == :mass_builds && [:index, :create].include?(act)) ? 'active' : ''} + %li{:class => (contr == :mass_builds) ? 'active' : ''} = link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform) - if can? :read, @platform.products.build %li{:class => (contr == :products) ? 'active' : ''} diff --git a/app/views/platforms/mass_builds/_form.html.haml b/app/views/platforms/mass_builds/_form.html.haml deleted file mode 100644 index 172c9044f..000000000 --- a/app/views/platforms/mass_builds/_form.html.haml +++ /dev/null @@ -1,25 +0,0 @@ -= form_for :build, :url => platform_mass_builds_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f| - %section.left - =render 'repos_or_list_choice' - %br - = f.submit t("layout.projects.build_button") - %section.right - %h3= t("activerecord.attributes.build_list.arch") - - Arch.recent.each do |arch| - .lefter - = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" - = label_tag "arches_#{arch.id}", arch.name - .both - - if @platform.personal? - %h3= t('activerecord.attributes.build_list.build_for_platform') - - platforms = Platform.main.select{ |p| p.repository_ids.size > 0 } - = select_tag 'build_for_platform', options_from_collection_for_select(platforms, :id, :name), :include_blank => false - .both - %h3= t("activerecord.attributes.build_list.preferences") - .both - = check_box_tag :auto_publish, true, @auto_publish_selected, :id => 'auto_publish' - = label_tag :auto_publish, t('activerecord.attributes.build_list.auto_publish') - - if @platform.personal? - = check_box_tag :use_save_to_repository, true, @use_save_to_repository, :id => 'auto_publish' - = label_tag :use_save_to_repository, t('activerecord.attributes.mass_build.use_save_to_repository') -.both \ No newline at end of file diff --git a/app/views/platforms/mass_builds/_repos_or_list_choice.html.haml b/app/views/platforms/mass_builds/_repos_or_list_choice.html.haml deleted file mode 100644 index 96512af3d..000000000 --- a/app/views/platforms/mass_builds/_repos_or_list_choice.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%h3=t("layout.mass_builds.repositories") --@platform.repositories.each do |rep| - .both - =check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}", :href => "#{projects_list_platform_repository_path(@platform, rep)}?text=true" - =label_tag "repositories_#{rep.id}", rep.name -%h3=t("layout.mass_builds.projects_list") -=text_area_tag :projects_list, nil - diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index c82ed00b6..6384f8353 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -1,7 +1,7 @@ = render 'platforms/base/submenu' = render 'platforms/base/sidebar' -= render 'form' if can? :create, @platform.mass_builds.new += link_to t('layout.mass_builds.new'), new_platform_mass_build_path(@platform), :class => 'button' if can? :create, @platform.mass_builds.build %table.tablesorter.unbordered{:cellpadding => "0", :cellspacing => "0"} %thead diff --git a/app/views/platforms/mass_builds/new.html.haml b/app/views/platforms/mass_builds/new.html.haml new file mode 100644 index 000000000..9a3549495 --- /dev/null +++ b/app/views/platforms/mass_builds/new.html.haml @@ -0,0 +1,34 @@ +- set_meta_tags :title => [title_object(@platform), t('layout.mass_builds.new')] + += render 'platforms/base/submenu' += render 'platforms/base/sidebar' + += form_for [@platform, @mass_build], :html => { :class => 'form mass_build', :method => :post } do |f| + %section.left + %h3=t('layout.mass_builds.repositories') + - @platform.repositories.each do |rep| + .both + = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}", :href => "#{projects_list_platform_repository_path(@platform, rep)}?text=true" + = label_tag "repositories_#{rep.id}", rep.name + %h3=t('layout.mass_builds.projects_list') + = f.text_area :projects_list + %br + = f.submit t("layout.projects.build_button") + %section.right + %h3= t("activerecord.attributes.build_list.arch") + - Arch.recent.each do |arch| + .lefter + = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" + = label_tag "arches_#{arch.id}", arch.name + .both + - if @platform.personal? + %h3= t('activerecord.attributes.build_list.build_for_platform') + = f.collection_select :build_for_platform_id, Platform.main, :id, :name + .both + = render 'shared/autocomplete_form', :field => :extra_repositories, :field_class => Repository, :placeholder => 'uxteam_personal', :subject => @mass_build, :autocomplete_path => autocomplete_extra_repositories_autocompletes_path + = render 'shared/autocomplete_form', :field => :extra_build_lists, :field_class => BuildList, :placeholder => '1000000', :subject => @mass_build, :autocomplete_path => autocomplete_extra_build_list_autocompletes_path + %h3= t("activerecord.attributes.build_list.preferences") + .both + = f.check_box :auto_publish + = f.label :auto_publish +.both \ No newline at end of file diff --git a/app/views/projects/build_lists/_extra.html.haml b/app/views/projects/build_lists/_extra.html.haml deleted file mode 100644 index 93afd9372..000000000 --- a/app/views/projects/build_lists/_extra.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%tr - - if extra.is_a?(BuildList) - %td= link_to "#{extra.id} (#{extra.project.name} - #{extra.arch.name})", extra - - else - %td= link_to "#{extra.platform.name}/#{extra.name}", [extra.platform, extra] - %td.actions - - field = extra.is_a?(BuildList) ? 'extra_build_lists' : 'extra_repositories' - = hidden_field_tag "build_list[#{field}][]", extra.id - %span.delete   \ No newline at end of file diff --git a/app/views/projects/build_lists/_extra_form.html.haml b/app/views/projects/build_lists/_extra_form.html.haml deleted file mode 100644 index 6a5c099b7..000000000 --- a/app/views/projects/build_lists/_extra_form.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -- html_field = field.to_s.gsub('_', '-') -%div{:id => html_field} - %h3= t("activerecord.attributes.build_list.#{field}") - %span.icon-question-sign - %div{:title => t("activerecord.attributes.build_list.extra_repos"), :id => "#{html_field}-dialog"} - = render "projects/build_lists/docs/#{field}" - .both - = autocomplete_field_tag field, nil, autocomplete_to_extra_repos_and_builds_build_lists_path, :id_element => "##{html_field}_field", :placeholder => placeholder - = hidden_field_tag field, nil, :id => "#{html_field}_field" - = submit_tag t('layout.add'), :class => 'button', :id => 'add' - - %table.tablesorter{:cellpadding => "0", :cellspacing => "0"} - %tbody \ No newline at end of file diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index cc4d9a7c7..ff030d838 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -6,8 +6,6 @@ - Platform.main.each do |pl| - if pl.repository_ids.size > 0 .both - =# check_box_tag "build_for_platforms[]", pl.id, (params[:build_for_platforms]||[]).include?(pl.id.to_s), :class => 'build_bpl_ids', :id => "bpls_#{pl.id}" - =# label_tag "bpls_#{pl.id}", pl.name %div{:id => "build_for_pl_#{pl.id}", :class => 'build_for_pl'}= pl.name .offset25= render 'include_repos', :platform => pl %section.right @@ -23,8 +21,8 @@ %h3= t("activerecord.attributes.build_list.update_type") .lineForm= f.select :update_type, BuildList::UPDATE_TYPES - = render 'extra_form', :field => :extra_repos, :placeholder => 'uxteam_personal' - = render 'extra_form', :field => :extra_build_lists, :placeholder => '1000000' + = render 'shared/autocomplete_form', :field => :extra_repositories, :field_class => Repository, :placeholder => 'uxteam_personal', :subject => @build_list, :autocomplete_path => autocomplete_extra_repositories_autocompletes_path + = render 'shared/autocomplete_form', :field => :extra_build_lists, :field_class => BuildList, :placeholder => '1000000', :subject => @build_list, :autocomplete_path => autocomplete_extra_build_list_autocompletes_path %h3= t("activerecord.attributes.build_list.preferences") - [:auto_publish, :auto_create_container].each do |kind| diff --git a/app/views/shared/_autocomplete_form.html.haml b/app/views/shared/_autocomplete_form.html.haml new file mode 100644 index 000000000..d715a22c9 --- /dev/null +++ b/app/views/shared/_autocomplete_form.html.haml @@ -0,0 +1,33 @@ +/ + Variables: + - subject + - field + - field_class + - autocomplete_path + - placeholder + +- subject_class = subject.class.name.underscore +.autocomplete-form{:subject_class => subject_class, :field => field, :path => autocomplete_path, :class => field} + %h3= t("activerecord.attributes.build_list.#{field}") + %span.icon-question-sign + .dialog{:title => t("activerecord.attributes.build_list.#{field}"), :id => "#{field}_dialog"} + = render "shared/autocomplete_docs/#{field}" + .both + = autocomplete_field_tag field, nil, "#{autocomplete_path}?#{{:platform_id => subject.save_to_platform.try(:id)}.to_param}", :placeholder => placeholder, :class => 'autocomplete', :update_elements => {:id => "##{field}_field", :path => "##{field}_field_path", :label => "##{field}_field_label"} + = hidden_field_tag field, nil, :id => "#{field}_field" + = hidden_field_tag field, nil, :id => "#{field}_field_path" + = hidden_field_tag field, nil, :id => "#{field}_field_label" + = submit_tag t('layout.add'), :class => 'button add' + + %table.tablesorter{:cellpadding => "0", :cellspacing => "0"} + %tbody + - field_class.where(:id => subject.send(field)).each do |extra| + %tr + - if extra.is_a?(BuildList) + %td= link_to "#{extra.id} (#{extra.project.name} - #{extra.arch.name})", extra + - else + %td= link_to "#{extra.platform.name}/#{extra.name}", [extra.platform, extra] + %td.actions + - field = extra.is_a?(BuildList) ? 'extra_build_lists' : 'extra_repositories' + = hidden_field_tag "#{subject_class}[#{field}][]", extra.id + %span.delete   \ No newline at end of file diff --git a/app/views/projects/build_lists/docs/_extra_build_lists.en.html.haml b/app/views/shared/autocomplete_docs/_extra_build_lists.en.html.haml similarity index 100% rename from app/views/projects/build_lists/docs/_extra_build_lists.en.html.haml rename to app/views/shared/autocomplete_docs/_extra_build_lists.en.html.haml diff --git a/app/views/projects/build_lists/docs/_extra_build_lists.ru.html.haml b/app/views/shared/autocomplete_docs/_extra_build_lists.ru.html.haml similarity index 100% rename from app/views/projects/build_lists/docs/_extra_build_lists.ru.html.haml rename to app/views/shared/autocomplete_docs/_extra_build_lists.ru.html.haml diff --git a/app/views/projects/build_lists/docs/_extra_repos.en.html.haml b/app/views/shared/autocomplete_docs/_extra_repositories.en.html.haml similarity index 100% rename from app/views/projects/build_lists/docs/_extra_repos.en.html.haml rename to app/views/shared/autocomplete_docs/_extra_repositories.en.html.haml diff --git a/app/views/projects/build_lists/docs/_extra_repos.ru.html.haml b/app/views/shared/autocomplete_docs/_extra_repositories.ru.html.haml similarity index 100% rename from app/views/projects/build_lists/docs/_extra_repos.ru.html.haml rename to app/views/shared/autocomplete_docs/_extra_repositories.ru.html.haml diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 029633078..1ab8b8cc4 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -7,7 +7,7 @@ en: build_list: bs_id: Id name: Name - extra_repos: Extra repositories + extra_repositories: Extra repositories extra_build_lists: Extra build lists auto_create_container: Create container automatically container_path: Container path diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index a0da99b42..8ec2a2a1c 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -7,7 +7,7 @@ ru: build_list: bs_id: Id name: Название - extra_repos: Дополнительные репозитории + extra_repositories: Дополнительные репозитории extra_build_lists: Дополнительные сборки auto_create_container: Создать контейнер автоматически container_path: Путь до контейнера diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index 931704e45..3226d86a4 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -1,6 +1,7 @@ en: layout: mass_builds: + new: New mass build publish_success: Publish success builds publish_test_failed: Publish test failed builds repositories: Repositories @@ -21,7 +22,6 @@ en: created_at: Created updated_at: Updated arch_names: Architectures - use_save_to_repository: Use personal repository for assembly user: User auto_publish: Auto Publish repositories: Repositories diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 9763dee59..e9c1453de 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -1,6 +1,7 @@ ru: layout: mass_builds: + new: Новая массовая сборка publish_success: Опубликовать успешные сборки publish_test_failed: Опубликовать сборки с проваленными тестами repositories: Репозитории @@ -21,7 +22,6 @@ ru: created_at: Создан updated_at: Обновлен arch_names: Архитектуры - use_save_to_repository: Использовать персональный репозиторий для сборки user: Пользователь auto_publish: Авто Публикация repositories: Репозитории diff --git a/config/routes.rb b/config/routes.rb index f0697e58f..530e41218 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,7 +149,7 @@ Rosa::Application.routes.draw do get :advisories end - resources :mass_builds, :only => [:create, :index] do + resources :mass_builds, :only => [:create, :new, :index] do member do post :cancel post :publish @@ -189,6 +189,8 @@ Rosa::Application.routes.draw do collection do get :autocomplete_user_uname get :autocomplete_group_uname + get :autocomplete_extra_build_list + get :autocomplete_extra_repositories end end diff --git a/db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb b/db/migrate/20130603124853_add_extra_repos_and_build_lists_to_mass_build.rb similarity index 65% rename from db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb rename to db/migrate/20130603124853_add_extra_repos_and_build_lists_to_mass_build.rb index 07948564f..68abdc439 100644 --- a/db/migrate/20130603124853_add_save_to_platform_to_mass_build.rb +++ b/db/migrate/20130603124853_add_extra_repos_and_build_lists_to_mass_build.rb @@ -1,4 +1,4 @@ -class AddSaveToPlatformToMassBuild < ActiveRecord::Migration +class AddExtraReposAndBuildListsToMassBuild < ActiveRecord::Migration class MassBuild < ActiveRecord::Base end @@ -8,12 +8,14 @@ class AddSaveToPlatformToMassBuild < ActiveRecord::Migration change_column :mass_builds, :save_to_platform_id, :integer, :null => false change_column :mass_builds, :platform_id, :integer, :null => false rename_column :mass_builds, :platform_id, :build_for_platform_id - add_column :mass_builds, :use_save_to_repository, :boolean + add_column :mass_builds, :extra_repositories, :text + add_column :mass_builds, :extra_build_lists, :text end def down + remove_column :mass_builds, :extra_repositories + remove_column :mass_builds, :extra_build_lists remove_column :mass_builds, :save_to_platform_id - remove_column :mass_builds, :use_save_to_repository rename_column :mass_builds, :build_for_platform_id, :platform_id end diff --git a/db/schema.rb b/db/schema.rb index 3b70efa2e..662e1dba7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -271,28 +271,29 @@ ActiveRecord::Schema.define(:version => 20130603124853) do add_index "labels", ["project_id"], :name => "index_labels_on_project_id" create_table "mass_builds", :force => true do |t| - t.integer "build_for_platform_id", :null => false + t.integer "build_for_platform_id", :null => false t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "arch_names" t.integer "user_id" - t.boolean "auto_publish", :default => false, :null => false - t.integer "build_lists_count", :default => 0, :null => false - t.integer "build_published_count", :default => 0, :null => false - t.integer "build_pending_count", :default => 0, :null => false - t.integer "build_started_count", :default => 0, :null => false - t.integer "build_publish_count", :default => 0, :null => false - t.integer "build_error_count", :default => 0, :null => false - t.boolean "stop_build", :default => false, :null => false + t.boolean "auto_publish", :default => false, :null => false + t.integer "build_lists_count", :default => 0, :null => false + t.integer "build_published_count", :default => 0, :null => false + t.integer "build_pending_count", :default => 0, :null => false + t.integer "build_started_count", :default => 0, :null => false + t.integer "build_publish_count", :default => 0, :null => false + t.integer "build_error_count", :default => 0, :null => false + t.boolean "stop_build", :default => false, :null => false t.text "projects_list" - t.integer "missed_projects_count", :default => 0, :null => false + t.integer "missed_projects_count", :default => 0, :null => false t.text "missed_projects_list" - t.boolean "new_core", :default => true - t.integer "success_count", :default => 0, :null => false - t.integer "build_canceled_count", :default => 0, :null => false - t.integer "save_to_platform_id", :null => false - t.boolean "use_save_to_repository" + t.boolean "new_core", :default => true + t.integer "success_count", :default => 0, :null => false + t.integer "build_canceled_count", :default => 0, :null => false + t.integer "save_to_platform_id", :null => false + t.text "extra_repositories" + t.text "extra_build_lists" end create_table "platforms", :force => true do |t|