Merge pull request #359 from warpc/344-fix_products_monitoring

[Refs #344] global products monitoring
This commit is contained in:
Vladimir Sharshov 2012-03-30 09:32:07 -07:00
commit e16d825120
14 changed files with 223 additions and 39 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -2,5 +2,7 @@
%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.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)

View File

@ -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'

View File

@ -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

View File

@ -120,14 +120,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
@ -223,13 +215,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

View File

@ -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

View File

@ -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: Информация получена

View File

@ -120,14 +120,6 @@ ru:
branches: Ветки
project_versions: Версии
product_build_lists:
delete: Удалить
action: Действие
statuses:
'0': 'собран'
'1': 'ошибка сборки'
'2': 'собирается'
flash:
settings:
saved: Настройки успешно сохранены
@ -224,13 +216,6 @@ ru:
created_at: Создан
updated_at: Обновлен
product_build_list:
id: Id
product: Продукт
container_path: Контейнер
status: Статус
notified_at: Информация получена
download:
name: Название
version: Версия

View File

@ -58,6 +58,9 @@ Rosa::Application.routes.draw do
end
collection { post :search }
end
resources :product_build_lists, :only => [:index] do
collection { post :search }
end
resources :personal_repositories, :only => [:show] do
member do

View File

@ -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.
@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20120329182602) do
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "arches", :force => true do |t|
@ -351,16 +351,16 @@ ActiveRecord::Schema.define(:version => 20120329182602) do
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience"
t.string "site"
t.string "company"