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]