From 20691dabc5527eea3e7511f85ba8ce1311a37330 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 18 Feb 2013 19:43:30 +0400 Subject: [PATCH] #757: add migration, update UI, JS --- app/assets/javascripts/extra/build_list.js | 12 +++++++++ app/assets/stylesheets/design/custom.scss | 5 ++++ .../projects/build_lists_controller.rb | 19 ++++++++++++++ app/models/build_list.rb | 3 ++- .../projects/build_lists/_extra.html.haml | 7 +++++ app/views/projects/build_lists/new.html.haml | 26 ++++++++++++++----- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + config/routes.rb | 6 ++++- ...positories_and_containers_to_build_list.rb | 7 +++++ db/schema.rb | 5 +++- 11 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 app/views/projects/build_lists/_extra.html.haml create mode 100644 db/migrate/20130218135847_add_extra_repositories_and_containers_to_build_list.rb diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index 3680da92a..6e79070ab 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -34,6 +34,18 @@ $(document).ready(function() { }); $('#build_list_save_to_repository_id').trigger('change'); + + $('#extra-repos-and-containers #add').click(function() { + var id = $('#extra_repo_field').val(); + if (id.length > 0) { + $.get("/build_lists/add_extra", { extra_id: id }) + .done(function(data) { + $("#extra-repos-and-containers table tbody").append(data); + }); + } + return false; + }); + }); function setBranchSelected(selected_option) { diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 2cba2c275..217765b4f 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1785,3 +1785,8 @@ div.right.slim { font-size: 10px; } } + +#extra-repos-and-containers { + width: 330px; + .actions { width: 50px; } +} \ No newline at end of file diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 3cc8338f8..4df6fd763 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -112,6 +112,25 @@ class Projects::BuildListsController < Projects::BaseController } end + def autocomplete_to_extra + platforms = Platform.includes(:repositories).search(params[:term]).search_order.limit(5) + results = [] + platforms.each{ |p| p.repositories.each{ |r| results << {id: r.id, label: "#{p.name}/#{r.name}", value: "#{p.name}/#{r.name}"} } } + + bl = BuildList.where(id: params[:term]).first + results << {id: "#{bl.id}-build-list", value: bl.id, label: 'Build list'} if bl + render json: results.to_json + end + + def add_extra + if params[:extra_id] =~ /-build-list$/ + subject = BuildList.find(params[:extra_id].gsub(/-build-list$/, '')) + else + subject = Repository.find params[:extra_id] + end + render partial: 'extra', locals: {subject: subject} + end + protected def find_build_list diff --git a/app/models/build_list.rb b/app/models/build_list.rb index bf53a6b51..db06733ab 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -47,7 +47,8 @@ class BuildList < ActiveRecord::Base attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash, :arch_id, :project_id, :save_to_repository_id, :update_type, - :save_to_platform_id, :project_version, :use_save_to_repository + :save_to_platform_id, :project_version, :use_save_to_repository, + :auto_create_container, :extra_repositories, :extra_containers LIVE_TIME = 4.week # for unpublished MAX_LIVE_TIME = 3.month # for published diff --git a/app/views/projects/build_lists/_extra.html.haml b/app/views/projects/build_lists/_extra.html.haml new file mode 100644 index 000000000..ec6b3776a --- /dev/null +++ b/app/views/projects/build_lists/_extra.html.haml @@ -0,0 +1,7 @@ +%tr + - if subject.is_a?(BuildList) + %td= link_to subject.id, subject + - else + %td= link_to "#{subject.platform.name}/#{subject.name}", [subject.platform, subject] + %td.actions + %span.delete   \ 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 b401a5a2c..a2f5044a4 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -22,13 +22,27 @@ = label_tag "arches_#{arch.id}", arch.name %h3= t("activerecord.attributes.build_list.update_type") .lineForm= f.select :update_type, BuildList::UPDATE_TYPES + + + + #extra-repos-and-containers + %h3= t("activerecord.attributes.build_list.extra_repos") + = autocomplete_field_tag 'extra_repos', nil, autocomplete_to_extra_build_lists_path, :id_element => '#extra_repo_field' + = hidden_field_tag 'extra_repo', nil, :id => 'extra_repo_field' + = submit_tag t("layout.add"), :class => 'button', :id => 'add' + %table.tablesorter{:cellpadding => "0", :cellspacing => "0"} + %tbody + - Repository.where(id: @build_list.extra_repositories).each do |repo| + = render 'extra', subject: repo + + - BuildList.where(id: @build_list.extra_containers).each do |bl| + = render 'extra', subject: bl + %h3= t("activerecord.attributes.build_list.preferences") - .both - = f.check_box :auto_publish - = f.label :auto_publish - .both - = f.check_box :use_save_to_repository - = f.label :use_save_to_repository + - [:auto_publish, :auto_create_container, :use_save_to_repository].each do |kind| + .both + = f.check_box kind + = f.label kind %br = f.submit t("layout.projects.build_button") diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 9b4682266..9eec6dcf4 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -7,6 +7,7 @@ en: build_list: bs_id: Id name: Name + extra_repos: Extra repositories and containers container_path: Container path status: Status project_id: Project diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 1cf1026a1..a98e52ef8 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -7,6 +7,7 @@ ru: build_list: bs_id: Id name: Название + extra_repos: Дополнительные репозитории и контейнеры container_path: Путь до контейнера status: Статус project_id: Проект diff --git a/config/routes.rb b/config/routes.rb index 855f05137..55afb2f2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -220,7 +220,11 @@ Rosa::Application.routes.draw do put :create_container get :log end - collection { post :search } + collection { + get :autocomplete_to_extra + get :add_extra + post :search + } end resources :projects, :only => [:index, :new, :create] diff --git a/db/migrate/20130218135847_add_extra_repositories_and_containers_to_build_list.rb b/db/migrate/20130218135847_add_extra_repositories_and_containers_to_build_list.rb new file mode 100644 index 000000000..7e5a417cc --- /dev/null +++ b/db/migrate/20130218135847_add_extra_repositories_and_containers_to_build_list.rb @@ -0,0 +1,7 @@ +class AddExtraRepositoriesAndContainersToBuildList < ActiveRecord::Migration + def change + add_column :build_lists, :auto_create_container, :boolean + add_column :build_lists, :extra_repositories, :text + add_column :build_lists, :extra_containers, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index adaee4672..e083402bc 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 => 20130214101404) do +ActiveRecord::Schema.define(:version => 20130218135847) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -134,6 +134,9 @@ ActiveRecord::Schema.define(:version => 20130214101404) do t.string "last_published_commit_hash" t.integer "container_status" t.boolean "use_save_to_repository", :default => true + t.boolean "auto_create_container" + t.text "extra_repositories" + t.text "extra_containers" end add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"