This patchset creates a "logs/" page that displays event history. It should work even without soft deletion implemented; although once soft deletion is implemented, the changes will automatically be reflected.
Mainn
--- src/config/routes.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/config/routes.rb b/src/config/routes.rb index a95389f..265f752 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -156,6 +156,10 @@ Conductor::Application.routes.draw do post :filter, :on => :collection end
+ resources :logs do + post :filter, :on => :collection + end + resources :config_servers do member do get 'test'
--- src/app/controllers/logs_controller.rb | 116 ++++++++++++++++++++++++++++++++ 1 files changed, 116 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/logs_controller.rb
diff --git a/src/app/controllers/logs_controller.rb b/src/app/controllers/logs_controller.rb new file mode 100644 index 0000000..1a65f46 --- /dev/null +++ b/src/app/controllers/logs_controller.rb @@ -0,0 +1,116 @@ +# +# Copyright 2011 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class LogsController < ApplicationController + before_filter :require_user + + def index + clear_breadcrumbs + save_breadcrumb(logs_path) + + load_headers + load_options + load_logs + respond_to do |format| + format.html + end + end + + def filter + redirect_to_original({"source_type" => params[:source_type], "pool_select" => params[:pool_select], "provider_select" => params[:provider_select], "owner_id" => params[:owner_id]}) + end + + protected + + def load_logs + @source_type = params[:source_type].nil? ? "" : params[:source_type] + @pool_select = params[:pool_select].nil? ? "" : params[:pool_select] + @provider_select = params[:pool_select].nil? ? "" : params[:provider_select] + @owner_id = params[:owner_id].nil? ? "" : params[:owner_id] + + conditions = [] + if ( @source_type != "" ) + conditions += ["source_type = ?", @source_type] + end + + @events = Event.unscoped.find(:all, + :include => {:source => [:pool_family, :pool, :owner]}, + :conditions => conditions + ) + + @events = @events.find_all{|event| + match = true + if ( @provider_select != "" ) + provider_option, provider_option_id = @provider_select.split(":") + if ( provider_option == "provider" ) + if ( event.source.provider_account.provider.id.to_s != provider_option_id ) + match = false + end + elsif ( provider_option == "provider_account" ) + if ( event.source.provider_account.id.to_s != provider_option_id ) + match = false + end + end + end + if ( @pool_select != "" && match ) + pool_option, pool_option_id = @pool_select.split(":") + if ( pool_option == "pool_family" ) + if ( event.source.pool_family_id.to_s != pool_option_id ) + match = false + end + elsif ( pool_option == "pool" ) + if ( event.source.pool_id.to_s != pool_option_id ) + match = false + end + end + end + if ( @owner_id != "" && match ) + if ( event.source.owner_id.to_s != @owner_id ) + match = false + end + end + match + } + + @events = @events.paginate(:page => params[:page], :per_page => PER_PAGE) + end + + def load_options + @source_type_options = [[t('logs.options.default_event_types'), ""], t('logs.options.deployment_event_type'), t('logs.options.instance_event_type')] + @pool_options = [[t('logs.options.default_pools'), ""]] + PoolFamily.find(:all, :include => :pools, :order => "name", :select => ["id", "name"]).each do |pool_family| + @pool_options << [pool_family.name, "pool_family:" + pool_family.id.to_s] + @pool_options += pool_family.pools.map{|x| [" -- " + x.name, "pool:" + x.id.to_s]} + end + @provider_options = [[t('logs.options.default_providers'), ""]] + Provider.find(:all, :include => :provider_accounts, :order => "name", :select => ["id", "name"]).each do |provider| + @provider_options << [provider.name, "provider:" + provider.id.to_s] + @provider_options += provider.provider_accounts.map{|x| [" -- " + x.name, "provider_account:" + x.id.to_s]} + end + @owner_options = [[t('logs.options.default_users'), ""]] + User.find(:all, :order => "login", :select => ["id", "login"]).map{|x| [x.login, x.id]} + end + + def load_headers + @header = [ + { :name => t('logs.index.event_time'), :sortable => false }, + { :name => t('logs.index.deployment'), :sortable => false }, + { :name => t('logs.index.pool'), :sortable => false }, + { :name => t('logs.index.provider'), :sortable => false }, + { :name => t('logs.index.owner'), :sortable => false }, + { :name => t('logs.index.summary'), :sortable => false }, + ] + end +end
On 04/25/2012 04:43 PM, Tzu-Mainn Chen wrote:
src/app/controllers/logs_controller.rb | 116 ++++++++++++++++++++++++++++++++ 1 files changed, 116 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/logs_controller.rb
diff --git a/src/app/controllers/logs_controller.rb b/src/app/controllers/logs_controller.rb new file mode 100644 index 0000000..1a65f46 --- /dev/null +++ b/src/app/controllers/logs_controller.rb @@ -0,0 +1,116 @@ +# +# Copyright 2011 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#
+class LogsController< ApplicationController
- before_filter :require_user
- def index
- clear_breadcrumbs
- save_breadcrumb(logs_path)
- load_headers
- load_options
- load_logs
- respond_to do |format|
format.html
- end
- end
- def filter
- redirect_to_original({"source_type" => params[:source_type], "pool_select" => params[:pool_select], "provider_select" => params[:provider_select], "owner_id" => params[:owner_id]})
- end
- protected
- def load_logs
- @source_type = params[:source_type].nil? ? "" : params[:source_type]
- @pool_select = params[:pool_select].nil? ? "" : params[:pool_select]
- @provider_select = params[:pool_select].nil? ? "" : params[:provider_select]
^ shouldn't be params[:provider_select]?
- @owner_id = params[:owner_id].nil? ? "" : params[:owner_id]
- conditions = []
- if ( @source_type != "" )
there is no need to use brackets for simple conditions
conditions += ["source_type = ?", @source_type]
- end
- @events = Event.unscoped.find(:all,
:include => {:source => [:pool_family, :pool, :owner]},
:conditions => conditions
)
- @events = @events.find_all{|event|
match = true
if ( @provider_select != "" )
provider_option, provider_option_id = @provider_select.split(":")
if ( provider_option == "provider" )
if ( event.source.provider_account.provider.id.to_s != provider_option_id )
provider_account can be nil (if an account is deleted, instances are kept)
match = false
end
elsif ( provider_option == "provider_account" )
if ( event.source.provider_account.id.to_s != provider_option_id )
match = false
end
end
end
if ( @pool_select != ""&& match )
pool_option, pool_option_id = @pool_select.split(":")
if ( pool_option == "pool_family" )
if ( event.source.pool_family_id.to_s != pool_option_id )
match = false
end
elsif ( pool_option == "pool" )
if ( event.source.pool_id.to_s != pool_option_id )
match = false
end
end
end
if ( @owner_id != ""&& match )
if ( event.source.owner_id.to_s != @owner_id )
match = false
end
end
match
- }
you could probably get rid of the whole nested 'if-else' structure by using 'next', for example:
@events.find_all do |event| next if @owner_id && event.source.owner_id.to_s != @owner_id next if pool_option == "pool" && event.source.pool_id.to_s != pool_option_id ... end
- @events = @events.paginate(:page => params[:page], :per_page => PER_PAGE)
paginate_collection method defined in application controller can be used (it takes care of boundaries)
- end
- def load_options
- @source_type_options = [[t('logs.options.default_event_types'), ""], t('logs.options.deployment_event_type'), t('logs.options.instance_event_type')]
- @pool_options = [[t('logs.options.default_pools'), ""]]
- PoolFamily.find(:all, :include => :pools, :order => "name", :select => ["id", "name"]).each do |pool_family|
@pool_options<< [pool_family.name, "pool_family:" + pool_family.id.to_s]
@pool_options += pool_family.pools.map{|x| [" -- " + x.name, "pool:" + x.id.to_s]}
- end
- @provider_options = [[t('logs.options.default_providers'), ""]]
- Provider.find(:all, :include => :provider_accounts, :order => "name", :select => ["id", "name"]).each do |provider|
@provider_options<< [provider.name, "provider:" + provider.id.to_s]
@provider_options += provider.provider_accounts.map{|x| [" -- " + x.name, "provider_account:" + x.id.to_s]}
- end
- @owner_options = [[t('logs.options.default_users'), ""]] + User.find(:all, :order => "login", :select => ["id", "login"]).map{|x| [x.login, x.id]}
- end
- def load_headers
- @header = [
{ :name => t('logs.index.event_time'), :sortable => false },
{ :name => t('logs.index.deployment'), :sortable => false },
{ :name => t('logs.index.pool'), :sortable => false },
{ :name => t('logs.index.provider'), :sortable => false },
{ :name => t('logs.index.owner'), :sortable => false },
{ :name => t('logs.index.summary'), :sortable => false },
- ]
- end
+end
Hi Mainn, this is not proper review, only few notes: - permissions checks are missing - we should filter only records accessible by current user - it would be nice to add a test which covers this new feature, if possible
(+ some notes inline)
Anyway it's a good start, Jan
--- src/app/views/logs/index.html.haml | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 src/app/views/logs/index.html.haml
diff --git a/src/app/views/logs/index.html.haml b/src/app/views/logs/index.html.haml new file mode 100644 index 0000000..1823f1c --- /dev/null +++ b/src/app/views/logs/index.html.haml @@ -0,0 +1,31 @@ += render :partial => 'layouts/admin_nav' + +%section.admin-content-section + %header + %h2#users.users= @title + + .content#tab + - content_for :filter_controls do + %li + = label_tag "source_type", t('filter_table.viewing') + = hidden_field_tag :current_path, request.fullpath + = select_tag "source_type", options_for_select(@source_type_options, @source_type) + = select_tag "pool_select", options_for_select(@pool_options, @pool_select) + = select_tag "provider_select", options_for_select(@provider_options, @provider_select) + = select_tag "owner_id", options_for_select(@owner_options, @owner_id) + = restful_submit_tag t("filter_table.apply_filters"), "index", filter_logs_path, 'POST', :class => 'button', :id => 'apply_logs_filter' + %span.label.badge.dark= @events.count + + = filter_table(@header, @events) do |event| + - source = event.source + - provider_account = source.provider_account + %tr{:class => cycle('nostripe','stripe')} + %td= event.event_time.strftime("%d-%b-%Y %H:%M:%S") + %td= link_to source.name, source + %td= source.pool_family.name + "/" + source.pool.name + - if provider_account.nil? + %td= t('logs.index.not_available') + - else + %td= provider_account.provider.name + "/" + provider_account.name + %td= source.owner.login + %td= event.summary
--- src/config/locales/en.yml | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index f6d3623..11793d3 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -10,6 +10,23 @@ en: other: "%{count} hours" search: no_results: "No matching results." + logs: + options: + default_users: All Users + default_event_types: All Event Types + deployment_event_type: Deployment + instance_event_type: Instance + default_pools: All Pools + default_providers: All Providers + index: + not_available: N/A + event_time: Time + deployment: Deployment/Instance + pool: Pool + provider: Provider + owner: Owner + summary: Summary + details: Details users: users: "Users" return_to: "Return to:"
aeolus-devel@lists.fedorahosted.org