[refs #223] some refactoring

This commit is contained in:
Alexander Machehin 2012-04-14 00:26:34 +06:00
parent 89756ded0c
commit 42967381b6
2 changed files with 13 additions and 34 deletions

View File

@ -66,22 +66,16 @@ class BuildList < ActiveRecord::Base
scope :scoped_to_project_version, lambda {|project_version| where(:project_version => project_version) } scope :scoped_to_project_version, lambda {|project_version| where(:project_version => project_version) }
scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) } scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) }
scope :for_creation_date_period, lambda{|start_date, end_date| scope :for_creation_date_period, lambda{|start_date, end_date|
if start_date && end_date scoped = BuildList.scoped
where(["#{table_name}.created_at BETWEEN ? AND ?", start_date, end_date]) scoped = scoped.where(["created_at >= ?", start_date]) if start_date
elsif start_date && !end_date scoped = scoped.where(["created_at <= ?", end_date]) if end_date
where(["#{table_name}.created_at >= ?", start_date]) scoped
elsif !start_date && end_date
where(["#{table_name}.created_at <= ?", end_date])
end
} }
scope :for_notified_date_period, lambda{|start_date, end_date| scope :for_notified_date_period, lambda{|start_date, end_date|
if start_date && end_date scoped = BuildList.scoped
where(["updated_at BETWEEN ? AND ?", start_date, end_date]) scoped = scoped.where(["updated_at >= ?", start_date]) if start_date
elsif start_date && !end_date scoped = scoped.where(["updated_at <= ?", end_date]) if end_date
where(["updated_at >= ?", start_date]) scoped
elsif !start_date && end_date
where(["updated_at <= ?", end_date])
end
} }
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")} scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")}

View File

@ -22,26 +22,11 @@
%h3= t("layout.activity_feed.my_builds_by_day") %h3= t("layout.activity_feed.my_builds_by_day")
%table{:cellpadding => "0", :cellspacing => "0"} %table{:cellpadding => "0", :cellspacing => "0"}
%tbody %tbody
%tr - ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state|
%td.first %tr
= link_to t("layout.build_lists.statuses.#{:build_published}"), build_lists_path(:filter => {:status => BuildList::BUILD_PUBLISHED, :updated_at => midnight}) %td.first
%td= BuildList.for_status(BuildList::BUILD_PUBLISHED).for_user(current_user).for_notified_date_period(midnight, nil).count = link_to t("layout.build_lists.statuses.#{state.demodulize.downcase}"), build_lists_path(:filter => {:status => state.constantize, :updated_at => midnight})
%tr %td= BuildList.for_status(state.constantize).for_user(current_user).for_notified_date_period(midnight, nil).count
%td.first
= link_to t("layout.build_lists.statuses.#{:success}"), build_lists_path(:filter => {:status => BuildServer::SUCCESS, :updated_at => midnight})
%td= BuildList.for_status(BuildServer::SUCCESS).for_user(current_user).for_notified_date_period(midnight, nil).count
%tr
%td.first
= link_to t("layout.build_lists.statuses.#{:build_started}"), build_lists_path(:filter => {:status => BuildServer::BUILD_STARTED, :updated_at => midnight})
%td= BuildList.for_status(BuildServer::BUILD_STARTED).for_user(current_user).for_notified_date_period(midnight, nil).count
%tr
%td.first
= link_to t("layout.build_lists.statuses.#{:build_pending}"), build_lists_path(:filter => {:status => BuildList::BUILD_PENDING, :updated_at => midnight})
%td= BuildList.for_status(BuildList::BUILD_PENDING).for_user(current_user).for_notified_date_period(midnight, nil).count
%tr
%td.first
= link_to t("layout.build_lists.statuses.#{:build_error}"), build_lists_path(:filter => {:status => BuildServer::BUILD_ERROR, :updated_at => midnight})
%td= BuildList.for_status(BuildServer::BUILD_ERROR).for_user(current_user).for_notified_date_period(midnight, nil).count
%tr %tr
%td.first %td.first
= link_to t("layout.activity_feed.all_my_builds"), build_lists_path = link_to t("layout.activity_feed.all_my_builds"), build_lists_path