-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chargeback Rates non explorer #7039
Changes from 2 commits
c083fc0
0fbdb08
67c3abf
c59b978
c21e705
23884bf
67f8ef2
b85a562
ae4dbbf
1f3cfe3
0a4ced8
750b140
1e81bda
b98126b
7922c22
f78f984
bf3fb4d
5e9422a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ class ChargebackRateController < ApplicationController | |
after_action :cleanup_action | ||
after_action :set_session_data | ||
|
||
include Mixins::GenericListMixin | ||
include Mixins::GenericSessionMixin | ||
include Mixins::GenericFormMixin | ||
include Mixins::GenericShowMixin | ||
include Mixins::BreadcrumbsMixin | ||
|
||
CB_X_BUTTON_ALLOWED_ACTIONS = { | ||
|
@@ -14,64 +17,66 @@ class ChargebackRateController < ApplicationController | |
'chargeback_rates_new' => :cb_rate_edit | ||
}.freeze | ||
|
||
def x_button | ||
generic_x_button(CB_X_BUTTON_ALLOWED_ACTIONS) | ||
end | ||
|
||
def x_show | ||
@explorer = true | ||
@record = identify_record(params[:id], ChargebackRate) | ||
nodeid = x_build_node_id(@record) | ||
params[:id] = "xx-#{@record.rate_type}_#{nodeid}" | ||
params[:tree] = x_active_tree.to_s | ||
tree_select | ||
redirect_to :action => 'explorer' unless request.xml_http_request? # Ajax request means in explorer | ||
end | ||
def button | ||
@edit = session[:edit] # Restore @edit for adv search box | ||
@refresh_div = "main_div" # Default div for button.rjs to refresh | ||
action = params[:pressed] | ||
|
||
def tree_select | ||
self.x_active_tree = :cb_rates_tree | ||
self.x_node = params[:id] | ||
get_node_info(x_node) | ||
replace_right_cell if request.xml_http_request? # Ajax request means in explorer | ||
end | ||
unless CB_X_BUTTON_ALLOWED_ACTIONS.key?(action) | ||
raise ActionController::RoutingError, _('invalid button action') | ||
end | ||
|
||
def explorer | ||
@breadcrumbs = [] | ||
@explorer = true | ||
build_accordions_and_trees | ||
send_action = CB_X_BUTTON_ALLOWED_ACTIONS[action] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this to just
|
||
send(send_action) | ||
|
||
@right_cell_text ||= _("All Chargeback Rates") | ||
set_form_locals if @in_a_form | ||
session[:changed] = false | ||
return if performed? | ||
|
||
render :layout => "application" unless request.xml_http_request? | ||
if params[:pressed].ends_with?("_copy", "_edit", "_new") && @flash_array.nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're testing |
||
if @flash_array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One line above you test against the |
||
show_list | ||
replace_gtl_main_div | ||
else | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to :action => @refresh_partial, :id => @redirect_id, :pressed => params[:pressed] | ||
end | ||
end | ||
elsif params[:pressed].ends_with?("_delete") | ||
javascript_redirect(:action => 'show_list', :flash_msg => @flash_array[0][:message]) | ||
elsif @refresh_div == "main_div" && @lastaction == "show_list" | ||
replace_gtl_main_div | ||
else | ||
render_flash unless performed? | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general this huge if-else thing isn't really clean, I think we should do something like on other non-explorer controllers. This is from def button
@edit = session[:edit] # Restore @edit for adv search box
params[:display] = @display if %w[vms instances images].include?(@display)
params[:page] = @current_page unless @current_page.nil? # Save current page for list refresh
@refresh_div = "main_div"
case params[:pressed]
when 'cloud_network_delete'
delete_networks
javascript_redirect(previous_breadcrumb_url)
when "cloud_network_edit"
javascript_redirect(:action => "edit", :id => checked_item_id)
when "cloud_network_new"
javascript_redirect(:action => "new")
else
super
end
end I would prefer something like this even if it goes against my suggestion above about |
||
end | ||
|
||
def set_form_locals | ||
@x_edit_buttons_locals = {:action_url => 'cb_rate_edit'} | ||
def show_list | ||
super | ||
# only need these gtl type buttons on the screen | ||
@gtl_buttons = %w[view_list view_tree] | ||
cb_rates_build_tree if @gtl_type == 'tree' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we want to keep this a little bit cleaner, what about defining them similarly to the I need to dig a little more, because my fulltext search on |
||
end | ||
|
||
# Show the main Schedules list view | ||
def cb_rates_list | ||
@gtl_type = "list" | ||
@explorer = true | ||
if params[:ppsetting] # User selected new per page value | ||
@items_per_page = params[:ppsetting].to_i # Set the new per page value | ||
@settings.store_path(:perpage, @gtl_type.to_sym, @items_per_page) # Set the per page setting for this gtl type | ||
def tree_select | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, I'd like to get rid of this method, because it's tied to the explorer-trees. However, as long as we don't have @brumik's new react trees merged, it should be fine. Can you please add a |
||
id = parse_nodetype_and_id(params[:id]).last | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to :action => 'show', :id => id | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
@sortcol = session[:rates_sortcol].nil? ? 0 : session[:rates_sortcol].to_i | ||
@sortdir = session[:rates_sortdir].nil? ? "ASC" : session[:rates_sortdir] | ||
|
||
@view, @pages = get_view(ChargebackRate, :named_scope => [[:with_rate_type, x_node.split('-').last]]) # Get the records (into a view) and the paginator | ||
|
||
@current_page = @pages[:current] unless @pages.nil? # save the current page number | ||
session[:rates_sortcol] = @sortcol | ||
session[:rates_sortdir] = @sortdir | ||
|
||
update_gtl_div('cb_rates_list') if pagination_or_gtl_request? && @show_list | ||
end | ||
|
||
def cb_rate_edit | ||
@_params[:id] ||= find_checked_items[0] | ||
rate = new_rate_edit? ? ChargebackRate.new : ChargebackRate.find(params[:id]) | ||
if params[:pressed] == 'chargeback_rates_edit' && rate.default? | ||
skateman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
add_flash(_("Default Chargeback Rate \"%{name}\" cannot be edited.") % {:name => rate.description}, :error) | ||
return | ||
end | ||
@redirect_id = params[:id] if params[:id] | ||
@refresh_partial = "edit" | ||
end | ||
|
||
def edit | ||
assert_privileges(params[:pressed]) if params[:pressed] | ||
case params[:button] | ||
when "cancel" | ||
|
@@ -80,13 +85,12 @@ def cb_rate_edit | |
else | ||
add_flash(_("Add of new Chargeback Rate was cancelled by the user")) | ||
end | ||
get_node_info(x_node) | ||
@edit = session[:edit] = nil # clean out the saved info | ||
session[:changed] = false | ||
replace_right_cell | ||
javascript_redirect(:action => @lastaction, :id => params[:id], :flash_msg => @flash_array[0][:message]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
when "save", "add" | ||
id = params[:button] == "save" ? params[:id] : "new" | ||
return unless load_edit("cbrate_edit__#{id}", "replace_cell__chargeback_rate") | ||
return unless load_edit("cbrate_edit__#{id}") | ||
|
||
@rate = params[:button] == "add" ? ChargebackRate.new : ChargebackRate.find(params[:id]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have some kind of pattern of setting |
||
if @edit[:new][:description].nil? || @edit[:new][:description] == "" | ||
|
@@ -117,8 +121,7 @@ def cb_rate_edit | |
end | ||
@edit = session[:edit] = nil # clean out the saved info | ||
session[:changed] = @changed = false | ||
get_node_info(x_node) | ||
replace_right_cell(:replace_trees => [:cb_rates]) | ||
javascript_redirect(:action => @lastaction, :id => params[:id], :flash_msg => @flash_array[0][:message]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here... |
||
else | ||
@rate.errors.each do |field, msg| | ||
add_flash("#{field.to_s.capitalize} #{msg}", :error) | ||
|
@@ -134,32 +137,25 @@ def cb_rate_edit | |
@changed = session[:changed] = (@edit[:new] != @edit[:current]) | ||
javascript_flash | ||
end | ||
|
||
when "reset", nil # displaying edit from for actions: new, edit or copy | ||
@in_a_form = true | ||
@_params[:id] ||= find_checked_items[0] | ||
session[:changed] = params[:pressed] == 'chargeback_rates_copy' | ||
|
||
@rate = new_rate_edit? ? ChargebackRate.new : ChargebackRate.find(params[:id]) | ||
skateman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@record = @rate | ||
|
||
if params[:pressed] == 'chargeback_rates_edit' && @rate.default? | ||
render_flash(_("Default Chargeback Rate \"%{name}\" cannot be edited.") % {:name => @rate.description}, :error) | ||
return | ||
end | ||
|
||
cb_rate_set_form_vars | ||
|
||
add_flash(_("All changes have been reset"), :warning) if params[:button] == "reset" | ||
|
||
replace_right_cell | ||
if params[:button] == "reset" | ||
add_flash(_("All changes have been reset"), :warning) | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.replace("form_div", :partial => "edit") | ||
page << "miqSparkle(false);" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why aren't you using |
||
end | ||
end | ||
end | ||
end | ||
|
||
# AJAX driven routine to check for changes in ANY field on the form | ||
def cb_rate_form_field_changed | ||
return unless load_edit("cbrate_edit__#{params[:id]}", "replace_cell__chargeback") | ||
|
||
return unless load_edit("cbrate_edit__#{params[:id]}") | ||
cb_rate_get_form_vars | ||
render :update do |page| | ||
page << javascript_prologue | ||
|
@@ -170,15 +166,6 @@ def cb_rate_form_field_changed | |
end | ||
end | ||
|
||
def cb_rate_show | ||
@display = "main" | ||
if @record.nil? | ||
flash_to_session(_('Error: Record no longer exists in the database'), :error) | ||
redirect_to(:action => 'cb_rates_list') | ||
return | ||
end | ||
end | ||
|
||
# Delete all selected or single displayed action(s) | ||
def cb_rates_delete | ||
assert_privileges("chargeback_rates_delete") | ||
|
@@ -190,18 +177,13 @@ def cb_rates_delete | |
end | ||
else # showing 1 rate, delete it | ||
cb_rate = ChargebackRate.find_by(:id => params[:id]) | ||
self.x_node = x_node.split('_').first | ||
if cb_rate.nil? | ||
add_flash(_("Chargeback Rate no longer exists"), :error) | ||
else | ||
rates.push(params[:id]) | ||
end | ||
end | ||
process_cb_rates(rates, 'destroy') if rates.present? | ||
|
||
cb_rates_list | ||
@right_cell_text = _("%<typ>s Chargeback Rates") % {:typ => x_node.split('-').last} | ||
replace_right_cell(:replace_trees => [:cb_rates]) | ||
end | ||
|
||
# Add a new tier at the end | ||
|
@@ -240,9 +222,7 @@ def cb_tier_remove | |
|
||
# Delete tier record | ||
@edit[:new][:tiers][detail_index].delete_at(tier_to_remove_index.to_i) | ||
|
||
@changed = session[:changed] = true | ||
|
||
render :update do |page| | ||
page << javascript_prologue | ||
page.replace_html("chargeback_rate_edit_form", :partial => "cb_rate_edit_table") | ||
|
@@ -256,43 +236,8 @@ def title | |
|
||
private ############################ | ||
|
||
def features | ||
[ | ||
{ | ||
:role => "chargeback_rates", | ||
:name => :cb_rates, | ||
:title => _("Rates") | ||
} | ||
].map { |hsh| ApplicationController::Feature.new_with_hash(hsh) } | ||
end | ||
|
||
def get_node_info(node, show_list = true) | ||
@show_list = show_list | ||
node = valid_active_node(node) | ||
if node == "root" | ||
@record = nil | ||
@right_cell_text = _("All Chargeback Rates") | ||
elsif ["xx-Compute", "xx-Storage"].include?(node) | ||
@record = nil | ||
@right_cell_text = case node | ||
when "xx-Compute" then _("Compute Chargeback Rates") | ||
when "xx-Storage" then _("Storage Chargeback Rates") | ||
end | ||
cb_rates_list | ||
else | ||
@record = ChargebackRate.find(parse_nodetype_and_id(node).last) | ||
@sb[:action] = nil | ||
@right_cell_text = case @record.rate_type | ||
when "Compute" then _("Compute Chargeback Rate \"%{name}\"") % {:name => @record.description} | ||
when "Storage" then _("Storage Chargeback Rate \"%{name}\"") % {:name => @record.description} | ||
end | ||
cb_rate_show | ||
end | ||
{:view => @view, :pages => @pages} | ||
end | ||
|
||
def cb_rates_build_tree | ||
TreeBuilderChargebackRates.new("cb_rates_tree", @sb) | ||
@tree = TreeBuilderChargebackRates.new("tree", @sb) | ||
end | ||
|
||
# Common Schedule button handler routines | ||
|
@@ -308,7 +253,7 @@ def cb_rate_set_form_vars | |
@edit[:new][:tiers] = [] | ||
@edit[:new][:num_tiers] = [] | ||
@edit[:new][:description] = @rate.description | ||
@edit[:new][:rate_type] = @rate.rate_type || x_node.split('-').last | ||
@edit[:new][:rate_type] = @rate.rate_type || "Compute" | ||
@edit[:new][:details] = [] | ||
|
||
tiers = [] | ||
|
@@ -369,6 +314,7 @@ def cb_rate_set_form_vars | |
# Get variables from edit form | ||
def cb_rate_get_form_vars | ||
@edit[:new][:description] = params[:description] if params[:description] | ||
@edit[:new][:rate_type] = params[:rate_type] if params[:rate_type] | ||
if params[:currency] | ||
@edit[:new][:currency] = params[:currency].to_i | ||
rate_detail_currency = Currency.find(params[:currency]) | ||
|
@@ -421,64 +367,7 @@ def cb_rate_set_record_vars | |
end | ||
|
||
def new_rate_edit? | ||
params[:id] == 'new' || params[:pressed] == 'chargeback_rates_new' | ||
end | ||
|
||
def replace_right_cell(options = {}) | ||
replace_trees = Array(options[:replace_trees]) | ||
replace_trees = @replace_trees if @replace_trees # get_node_info might set this | ||
@explorer = true | ||
c_tb = build_toolbar(center_toolbar_filename) | ||
|
||
# Build a presenter to render the JS | ||
presenter = ExplorerPresenter.new(:active_tree => x_active_tree) | ||
reload_trees_by_presenter(presenter, [cb_rates_build_tree]) if replace_trees.include?(:cb_rates) | ||
|
||
# FIXME | ||
# if params[:action].ends_with?("_delete") | ||
# page << "miqTreeActivateNodeSilently('#{x_active_tree.to_s}', '<%= x_node %>');" | ||
# end | ||
# presenter[:select_node] = x_node if params[:action].ends_with?("_delete") | ||
presenter[:osf_node] = x_node | ||
|
||
if c_tb.present? | ||
presenter.reload_toolbars(:center => c_tb) | ||
end | ||
presenter.set_visibility(c_tb.present?, :toolbar) | ||
presenter.update(:main_div, r[:partial => 'rates_tabs']) | ||
|
||
if @record || @in_a_form || | ||
(@pages && (@items_per_page == ONE_MILLION || @pages[:items] == 0)) | ||
if %w[chargeback_rates_copy chargeback_rates_edit chargeback_rates_new].include?(@sb[:action]) | ||
presenter.hide(:toolbar) | ||
# incase it was hidden for summary screen, and incase there were no records on show_list | ||
presenter.show(:paging_div, :form_buttons_div).remove_paging | ||
locals = {:record_id => @edit[:rec_id]} | ||
locals[:action_url] = 'cb_rate_edit' | ||
presenter.update(:form_buttons_div, r[:partial => 'layouts/x_edit_buttons', :locals => locals]) | ||
else | ||
# Added so buttons can be turned off even tho div is not being displayed it still pops up Abandon changes box when trying to change a node on tree after saving a record | ||
presenter.hide(:buttons_on).show(:toolbar).hide(:paging_div) | ||
presenter.hide(:form_buttons_div) if params[:button] | ||
end | ||
else | ||
presenter.hide(:form_buttons_div) | ||
if x_node == "root" | ||
presenter.hide(:toolbar).remove_paging | ||
end | ||
presenter.show(:paging_div) | ||
end | ||
|
||
presenter[:record_id] = determine_record_id_for_presenter | ||
|
||
presenter[:clear_gtl_list_grid] = @gtl_type && @gtl_type != 'list' | ||
|
||
presenter[:right_cell_text] = @right_cell_text | ||
presenter[:lock_sidebar] = @in_a_form && @edit | ||
|
||
presenter.update(:breadcrumbs, r[:partial => 'layouts/breadcrumbs']) | ||
|
||
render :json => presenter.for_render | ||
!params[:id].present? || params[:id] == 'new' || params[:pressed] == 'chargeback_rates_new' | ||
skateman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def display_detail_errors(detail, errors) | ||
|
@@ -507,6 +396,7 @@ def breadcrumbs_options | |
:breadcrumbs => [ | ||
{:title => _("Overview")}, | ||
{:title => _("Chargeback")}, | ||
{:title => _("Rates"), :url => controller_url}, | ||
], | ||
} | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ def show_main | |
:url => "/#{controller_name}/show_list?page=#{@current_page}&refresh=y"}, | ||
true) | ||
|
||
drop_breadcrumb(:name => _("%{name} (Summary)") % {:name => @record.name}, | ||
drop_breadcrumb(:name => _("%{name} (Summary)") % {:name => @record.respond_to?(:name) ? @record.name : @record.description}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we have a helper for |
||
:url => show_link(@record)) | ||
@showtype = "main" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why is this extra complexity necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skateman because
ChargebackRate
record does not have name field. Previously we did not have download buttons on the Chargeback Rates list view because we did not render gtl view toolbar on the screen.