From c6d30b7ff34629c0895b941033061d3b809d33e8 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 28 Mar 2012 17:51:04 +0400 Subject: [PATCH 1/3] [refs #344] Add link to product into product build lists list --- app/views/product_build_lists/_product_build_list.html.haml | 1 + app/views/products/show.html.haml | 1 + db/schema.rb | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index a39f7ea7d..927206e4a 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -2,5 +2,6 @@ %td= product_build_list.id %td= product_build_list.human_status %td= link_to nil, product_build_list.container_path + %td= link_to product_build_list.product, platform_product_path(product_build_list.product.platform, product_build_list.product) %td= link_to image_tag('x.png'), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => :delete, :confirm => t("layout.confirm") if can? :destroy, product_build_list %td= l(product_build_list.notified_at, :format => :long) diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index 01b827878..eff1b089c 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -23,6 +23,7 @@ %th= t("activerecord.attributes.product_build_list.id") %th= t("activerecord.attributes.product_build_list.status") %th= t("activerecord.attributes.product_build_list.container_path") + %th= t("layout.product_build_lists.product") %th= t("layout.product_build_lists.action") %th= t("activerecord.attributes.product_build_list.notified_at") %tbody= render @product.product_build_lists.default_order diff --git a/db/schema.rb b/db/schema.rb index d0380d139..fe45f84a7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120321130436) do +ActiveRecord::Schema.define(:version => 20120326142636) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false From 086d4fca679a206d2f4ddd50210cfe78a7560609 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 28 Mar 2012 17:53:49 +0400 Subject: [PATCH 2/3] [refs #344] Fix product name into table --- app/views/product_build_lists/_product_build_list.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index 927206e4a..0b561e800 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -2,6 +2,6 @@ %td= product_build_list.id %td= product_build_list.human_status %td= link_to nil, product_build_list.container_path - %td= link_to product_build_list.product, platform_product_path(product_build_list.product.platform, product_build_list.product) + %td= link_to product_build_list.product.name, platform_product_path(product_build_list.product.platform, product_build_list.product) %td= link_to image_tag('x.png'), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => :delete, :confirm => t("layout.confirm") if can? :destroy, product_build_list %td= l(product_build_list.notified_at, :format => :long) From d3c2bac22663a8c4e262e52bcff03c9c026bb703 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 30 Mar 2012 15:26:28 +0400 Subject: [PATCH 3/3] [refs #344] Add product buils list filter and search --- .../product_build_lists_controller.rb | 21 +++++++ app/models/product_build_list.rb | 28 ++++++++- app/models/product_build_list/filter.rb | 57 +++++++++++++++++++ app/views/build_lists/_submenu.html.haml | 2 +- .../product_build_lists/_filter.html.haml | 29 ++++++++++ .../_product_build_list.html.haml | 1 + app/views/product_build_lists/index.html.haml | 19 +++++++ config/locales/en.yml | 15 ----- .../locales/models/product_build_list.en.yml | 30 ++++++++++ .../locales/models/product_build_list.ru.yml | 30 ++++++++++ config/locales/ru.yml | 15 ----- config/routes.rb | 3 + 12 files changed, 216 insertions(+), 34 deletions(-) create mode 100644 app/models/product_build_list/filter.rb create mode 100644 app/views/product_build_lists/_filter.html.haml create mode 100644 app/views/product_build_lists/index.html.haml create mode 100644 config/locales/models/product_build_list.en.yml create mode 100644 config/locales/models/product_build_list.ru.yml diff --git a/app/controllers/product_build_lists_controller.rb b/app/controllers/product_build_lists_controller.rb index 6936b1d11..0792f1e4c 100644 --- a/app/controllers/product_build_lists_controller.rb +++ b/app/controllers/product_build_lists_controller.rb @@ -4,6 +4,7 @@ class ProductBuildListsController < ApplicationController load_and_authorize_resource :platform, :only => [:create, :destroy] load_and_authorize_resource :product, :through => :platform, :only => [:create, :destroy] load_and_authorize_resource :product_build_list, :through => :product, :only => [:create, :destroy] + load_and_authorize_resource :only => [:index] before_filter :authenticate_product_builder!, :only => [:status_build] before_filter :find_product_build_list, :only => [:status_build] @@ -27,6 +28,26 @@ class ProductBuildListsController < ApplicationController redirect_to [@platform, @product] end +# def index +# @product_build_lists = ProductBuildList.paginate :page => params[:page] +# end + + def search + new_params = {:filter => {}} + params[:filter].each do |k,v| + new_params[:filter][k] = v unless v.empty? + end + #redirect_to @product ? product_build_lists_path(@product, new_params) : product_build_lists_path(new_params) + redirect_to product_build_lists_path(new_params) + end + + def index + #@action_url = @product ? search_product_build_lists_path(@product) : search_build_lists_path + @action_url = search_product_build_lists_path + @filter = ProductBuildList::Filter.new(@product, current_user, params[:filter] || {}) + @product_build_lists = @filter.find.recent.paginate :page => params[:page] + end + protected def find_product_build_list diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index 24ee0afab..5bd145ee8 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -4,12 +4,26 @@ class ProductBuildList < ActiveRecord::Base BUILD_COMPLETED = 0 BUILD_FAILED = 1 + STATUSES = [ BUILD_STARTED, + BUILD_COMPLETED, + BUILD_FAILED + ] + + HUMAN_STATUSES = { BUILD_STARTED => :build_started, + BUILD_COMPLETED => :build_completed, + BUILD_FAILED => :build_failed + } + belongs_to :product validates :product, :status, :presence => true validates :status, :inclusion => { :in => [BUILD_STARTED, BUILD_COMPLETED, BUILD_FAILED] } scope :default_order, order('notified_at DESC') + scope :for_status, lambda {|status| where(:status => status) } + scope :for_user, lambda { |user| where(:user_id => user.id) } + scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")} + scope :recent, order("#{table_name}.updated_at DESC") attr_accessor :base_url @@ -20,14 +34,22 @@ class ProductBuildList < ActiveRecord::Base "/downloads/#{product.platform.name}/product/#{id}/" end - def human_status - I18n.t("layout.product_build_lists.statuses.#{status}") - end +# def human_status +# I18n.t("layout.product_build_lists.statuses.#{status}") +# end def event_log_message {:product => product.name}.inspect end + def self.human_status(status) + I18n.t("layout.product_build_lists.statuses.#{HUMAN_STATUSES[status]}") + end + + def human_status + self.class.human_status(status) + end + protected def xml_rpc_create diff --git a/app/models/product_build_list/filter.rb b/app/models/product_build_list/filter.rb new file mode 100644 index 000000000..847d53c76 --- /dev/null +++ b/app/models/product_build_list/filter.rb @@ -0,0 +1,57 @@ +# -*- encoding : utf-8 -*- +class ProductBuildList::Filter + def initialize(product, user, options = {}) + @product = product + @user = user + set_options(options) + end + + def find + product_build_lists = @product ? @product.product_build_lists : ProductBuildList.scoped + + if @options[:id] + product_build_lists = product_build_lists.where(:id => @options[:id]) + else + product_build_lists = product_build_lists.accessible_by(::Ability.new(@user), @options[:ownership].to_sym) if @options[:ownership] + product_build_lists = product_build_lists.for_status(@options[:status]) if @options[:status] + product_build_lists = product_build_lists.scoped_to_product_name(@options[:product_name]) if @options[:product_name] + end + + product_build_lists + end + + def respond_to?(name) + return true if @options.has_key?(name) + super + end + + def method_missing(name, *args, &block) + @options.has_key?(name) ? @options[name] : super + end + + private + + def set_options(options) + @options = HashWithIndifferentAccess.new(options.reverse_merge({ + :ownership => nil, + :status => nil, + :id => nil, + :product_name => nil + })) + + @options[:ownership] = @options[:ownership].presence || (@product ? 'index' : 'owned') + @options[:status] = @options[:status].present? ? @options[:status].to_i : nil + @options[:id] = @options[:id].presence + @options[:product_name] = @options[:product_name].presence + end + + #def build_date_from_params(field_name, params) + # if params["#{field_name}(1i)"].present? || params["#{field_name}(2i)"].present? || params["#{field_name}(3i)"].present? + # Date.civil((params["#{field_name}(1i)"].presence || Date.today.year).to_i, + # (params["#{field_name}(2i)"].presence || Date.today.month).to_i, + # (params["#{field_name}(3i)"].presence || Date.today.day).to_i) + # else + # nil + # end + #end +end diff --git a/app/views/build_lists/_submenu.html.haml b/app/views/build_lists/_submenu.html.haml index dfb52a499..ec22631d9 100644 --- a/app/views/build_lists/_submenu.html.haml +++ b/app/views/build_lists/_submenu.html.haml @@ -8,4 +8,4 @@ %nav %ul %li= link_to t('layout.projects.list_header'), build_lists_path, :class => (params[:controller] == 'build_lists' ? 'active' : nil) - %li= link_to t('layout.products.list_header'), '#' + %li= link_to t('layout.products.list_header'), product_build_lists_path, :class => (params[:controller] == 'product_build_lists' ? 'active' : nil) diff --git a/app/views/product_build_lists/_filter.html.haml b/app/views/product_build_lists/_filter.html.haml new file mode 100644 index 000000000..a84c227c7 --- /dev/null +++ b/app/views/product_build_lists/_filter.html.haml @@ -0,0 +1,29 @@ +- content_for :sidebar do + = form_for :filter, :url => @action_url, :html => { :method => :post, :class => :form } do |f| + .bordered.nopadding + %h3= t("layout.product_build_lists.ownership.header") + .table + .lefter= f.radio_button :ownership, 'owned', :class => 'niceRadio', :id => 'myradio1' + .lefter= t("layout.product_build_lists.ownership.owned") + .both + - unless @product + .table + .lefter= f.radio_button :ownership, 'related', :class => 'niceRadio', :id => 'myradio2' + .lefter= t("layout.product_build_lists.ownership.related") + .both + .table + .lefter= f.radio_button :ownership, 'index', :class => 'niceRadio', :id => 'myradio3' + .lefter= t("layout.product_build_lists.ownership.index") + .both + %br + = f.submit t("layout.search.header") + .block + %h3.small= t("activerecord.attributes.product_build_list.status") + .lineForm.aside= f.select :status, ProductBuildList::STATUSES.collect{|status| [ProductBuildList.human_status(status), status]}, {:include_blank => true, :selected => @filter.status}, {:class => 'sel80 aside', :id => 'status', :tabindex => 2} + %h3.small= t("layout.product_build_lists.product_name_search") + = f.text_field :product_name + %h3.small= t("layout.product_build_lists.id_search") + = f.text_field :id + %br + %br + = f.submit t("layout.search.header") diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index 0b561e800..ac8dcf130 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -3,5 +3,6 @@ %td= product_build_list.human_status %td= link_to nil, product_build_list.container_path %td= link_to product_build_list.product.name, platform_product_path(product_build_list.product.platform, product_build_list.product) + -#%td= link_to product_build_list.user.try(:fullname), product_build_list.user %td= link_to image_tag('x.png'), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => :delete, :confirm => t("layout.confirm") if can? :destroy, product_build_list %td= l(product_build_list.notified_at, :format => :long) diff --git a/app/views/product_build_lists/index.html.haml b/app/views/product_build_lists/index.html.haml new file mode 100644 index 000000000..940bc107f --- /dev/null +++ b/app/views/product_build_lists/index.html.haml @@ -0,0 +1,19 @@ +/ #myTable +%table.tablesorter{:cellpadding => "0", :cellspacing => "0"} + %thead + %tr + -#%th.lpadding16= t("activerecord.attributes.product_build_list.bs_id") + %th.lpadding16= t("activerecord.attributes.product_build_list.id") + %th.lpadding16= t("activerecord.attributes.product_build_list.status") + %th.lpadding16= t("activerecord.attributes.product_build_list.container_path") + %th.lpadding16= t("activerecord.attributes.product_build_list.product") + -#%th.lpadding16= t("activerecord.attributes.product_build_list.user") + %th= t("layout.product_build_lists.action") + %th.lpadding16= t("activerecord.attributes.product_build_list.notified_at") + %tbody= render @product_build_lists +.both + += will_paginate @product_build_lists + += render 'product_build_lists/filter' += render @product ? 'products/submenu' : 'build_lists/submenu' diff --git a/config/locales/en.yml b/config/locales/en.yml index eefa2d4e0..085701d7f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -140,14 +140,6 @@ en: branches: Branches project_versions: Versions - product_build_lists: - delete: Delete - action: Action - statuses: - '0': 'build' - '1': 'build error' - '2': 'build in progress' - flash: settings: saved: Settings saved success @@ -270,13 +262,6 @@ en: created_at: Created updated_at: Updated - product_build_list: - id: Id - product: Product - container_path: Container - status: Status - notified_at: Notified at - download: name: Name version: Version diff --git a/config/locales/models/product_build_list.en.yml b/config/locales/models/product_build_list.en.yml new file mode 100644 index 000000000..1e047e4aa --- /dev/null +++ b/config/locales/models/product_build_list.en.yml @@ -0,0 +1,30 @@ +en: + layout: + product_build_lists: + delete: Delete + action: Action + id_search: 'Id search' + statuses: + '0': 'build' + '1': 'build error' + '2': 'build in progress' + build_failed: Build failed + build_started: Build in progress + build_completed: Build + + ownership: + header: Build list ownership + owned: My + related: Related + index: All + + activerecord: + attributes: + product_build_list: + id: Id + product: Product + container_path: Container + status: Status + notified_at: Notified at + user: User + notified_at: Notified at diff --git a/config/locales/models/product_build_list.ru.yml b/config/locales/models/product_build_list.ru.yml new file mode 100644 index 000000000..c422df74a --- /dev/null +++ b/config/locales/models/product_build_list.ru.yml @@ -0,0 +1,30 @@ +ru: + layout: + product_build_lists: + delete: Удалить + action: Действие + id_search: 'Поиск по Id' + statuses: + '0': 'собран' + '1': 'ошибка сборки' + '2': 'собирается' + build_failed: Ошибка сборки + build_started: Собирается + build_completed: Собран + + ownership: + header: Принадлежность заданий + owned: Мне + related: Связанные со мной + index: Все + + activerecord: + attributes: + product_build_list: + id: Id + product: Продукт + container_path: Контейнер + status: Статус + user: Пользователь + notified_at: Информация получена + diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 8989582d7..2e11c7e36 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -140,14 +140,6 @@ ru: branches: Ветки project_versions: Версии - product_build_lists: - delete: Удалить - action: Действие - statuses: - '0': 'собран' - '1': 'ошибка сборки' - '2': 'собирается' - flash: settings: saved: Настройки успешно сохранены @@ -270,13 +262,6 @@ ru: created_at: Создан updated_at: Обновлен - product_build_list: - id: Id - product: Продукт - container_path: Контейнер - status: Статус - notified_at: Информация получена - download: name: Название version: Версия diff --git a/config/routes.rb b/config/routes.rb index 44906e335..3e629f9b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,9 @@ Rosa::Application.routes.draw do end collection { post :search } end + resources :product_build_lists, :only => [:index] do + collection { post :search } + end resources :auto_build_lists, :only => [:index, :create, :destroy]