Created
April 16, 2015 14:18
-
-
Save romulostorel/f99861062bb75f578573 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CalculatorPortal | |
module Products | |
module DefaultProductActions | |
# ACTION | |
def environment | |
init_environment_step | |
raise NotFound, 'variables values not setted' unless @active_simulator_step || | |
!@actual_calculator_step || | |
!@max_contract_possibility || | |
!@contract_connections_number || | |
!@max_of_simultaneous_connections || | |
!@variables | |
@stages = StageFinder.new.find_production | |
@working_hours = {} | |
save_status = false | |
@working_hour_template = Simulator::WorkingHours.new | |
if request.post? | |
save_status = save_simulator | |
load_environment_variables(Simulator) | |
else | |
@connection_qtt = Simulator::ConnectionQuantity.new | |
if edit_step? | |
sim_working_hour = Simulator::WorkingHours.new | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
orders = all_answer_of_question_enum(question_enum: sim_working_hour.enum_of(:week_days), stage_id: stage.id).map { |ans| ans.order }.sort | |
orders.each do |order| | |
working_hour = Simulator::WorkingHours.new | |
working_hour_attrs = { week_days: answer_of_question_enum(question_enum: working_hour.enum_of(:week_days), stage_id: stage.id, order: order).answer, | |
working_hour_range: answer_of_question_enum(question_enum: working_hour.enum_of(:working_hour_range), stage_id: stage.id, order: order).answer, | |
top_hours_of_day: answer_of_question_enum(question_enum: working_hour.enum_of(:top_hours_of_day), stage_id: stage.id, order: order).answer } | |
working_hour.populate working_hour_attrs | |
@working_hours[stage.id] << working_hour | |
end | |
end | |
connection_qtt_attrs = { | |
contract_connections_number: answer_of_question_enum(question_enum: @connection_qtt.enum_of(:contract_connections_number)).answer, | |
max_of_simultaneous_connections: answer_of_question_enum(question_enum: @connection_qtt.enum_of(:max_of_simultaneous_connections)).answer | |
} | |
else | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
working_hour = Simulator::WorkingHours.new | |
working_hour_attrs = if stage.name.eql? 'production' | |
{ week_days: %w(mon tue wed thu fri), | |
working_hour_range: {min: 8, max: 18} } | |
else | |
{ } | |
end | |
working_hour.populate working_hour_attrs | |
working_hour.customer = active_customer | |
working_hour.calculator = active_calculator | |
working_hour.user = active_user | |
working_hour.stage = stage | |
working_hour.save! | |
@working_hours[stage.id] << working_hour | |
end | |
connection_qtt_attrs = { contract_connections_number: @contract_connections_number, | |
max_of_simultaneous_connections: @max_of_simultaneous_connections } | |
end | |
@connection_qtt.populate connection_qtt_attrs | |
end | |
begin | |
#update_calculator_by_step_environment | |
if save_status | |
update_step_at_calculator | |
redirect_to_step :environment_additional and return | |
end | |
rescue => e | |
log = Logger.new(STDOUT) | |
log.error e | |
if e.class == Cloudy::HardwareCalculator::TierTooLarge | |
update_step_at_calculator | |
calculator_repository.update( | |
id: active_calculator.id, | |
source_type: 'special' | |
) | |
redirect_to_step :environment_additional and return if request.post? | |
end | |
end | |
render '/app/views/calculator_portal/products/shared/environment' | |
end | |
# ACTION | |
def environment_additional | |
init_environment_additional_step | |
raise NotFound, 'variables values not setted' unless @active_simulator_step || | |
!@actual_calculator_step || | |
!@max_contract_possibility || | |
!@contract_connections_number || | |
!@max_of_simultaneous_connections || | |
!@variables | |
@stages = StageFinder.new.find_non_production | |
@working_hours = {} | |
save_status = false | |
@working_hour_template = Simulator::WorkingHours.new | |
if request.post? | |
save_status = save_simulator | |
load_environment_additional_variables(Simulator) | |
begin | |
update_calculator_by_step_environment_additional | |
if save_status | |
update_step_at_calculator | |
redirect_to_step :service and return | |
end | |
rescue => e | |
log = Logger.new(STDOUT) | |
log.error e | |
if e.class == Cloudy::HardwareCalculator::TierTooLarge | |
update_step_at_calculator | |
calculator_repository.update( | |
id: active_calculator.id, | |
source_type: 'special' | |
) | |
redirect_to_step :service and return if request.post? | |
end | |
end | |
else # request is GET | |
if edit_step? | |
sim_working_hour = Simulator::WorkingHours.new | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
orders = all_answer_of_question_enum(question_enum: sim_working_hour.enum_of(:week_days), stage_id: stage.id).map { |ans| ans.order }.sort | |
orders.each do |order| | |
working_hour = Simulator::WorkingHours.new | |
working_hour_attrs = { week_days: answer_of_question_enum(question_enum: working_hour.enum_of(:week_days), stage_id: stage.id, order: order).answer, | |
working_hour_range: answer_of_question_enum(question_enum: working_hour.enum_of(:working_hour_range), stage_id: stage.id, order: order).answer, | |
top_hours_of_day: answer_of_question_enum(question_enum: working_hour.enum_of(:top_hours_of_day), stage_id: stage.id, order: order).answer } | |
working_hour.populate working_hour_attrs | |
@working_hours[stage.id] << working_hour | |
end | |
end | |
else | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
working_hour = Simulator::WorkingHours.new | |
working_hour_attrs = if stage.name.eql? 'production' | |
{ week_days: %w(mon tue wed thu fri), | |
working_hour_range: {min: 8, max: 18} } | |
else | |
{ } | |
end | |
working_hour.populate working_hour_attrs | |
working_hour.customer = active_customer | |
working_hour.calculator = active_calculator | |
working_hour.user = active_user | |
working_hour.stage = stage | |
working_hour.save! | |
@working_hours[stage.id] << working_hour | |
end | |
end | |
end | |
render '/app/views/calculator_portal/products/shared/environment_additional' | |
end | |
# ACTION | |
def support | |
init_support_step | |
raise NotFound, "variables values not setted" unless @active_simulator_step || | |
!@actual_calculator_step | |
@supports = SupportFinder.new.find_all_usable | |
if request.post? | |
save_status = save_simulator | |
if save_status | |
update_step_at_calculator | |
redirect_to_step :platform | |
end | |
load_support_variables(Simulator) | |
update_calculator_by_step_support | |
return if save_status | |
else | |
if edit_step? | |
@support_selector = Simulator::SupportSelector.new | |
support_selector_attrs = { support: answer_of_question_enum(question_enum: | |
@support_selector.enum_of(:support)).answer } | |
@support_selector.populate support_selector_attrs | |
else | |
@active_calculator.support = Support.first | |
@active_calculator.save | |
@support_selector = Simulator::SupportSelector.new(support: @supports.first.id) | |
end | |
end | |
render "/app/views/calculator_portal/products/shared/support" | |
end | |
# ACTION | |
def platform | |
init_platform_step | |
raise NotFound, "variables values not setted" unless @active_simulator_step || | |
!@actual_calculator_step | |
if request.post? | |
update_step_at_calculator | |
redirect_to_step :predictability and return | |
end | |
render "/app/views/calculator_portal/products/shared/platform" | |
end | |
# ACTION | |
def confirmation | |
init_confirmation_step | |
raise NotFound, "variables values not setted" unless @active_simulator_step || | |
!@actual_calculator_step | |
if request.post? | |
@active_calculator = calculator_repository.update( | |
id: active_calculator.id, | |
totvs_integration: "0" | |
) | |
if @active_calculator.totvs_terms && @active_calculator.client_terms | |
render "/app/views/calculator_portal/products/shared/proposal" and return | |
end | |
update_step_at_calculator | |
disallow_breadcrumb | |
render "/app/views/calculator_portal/products/shared/finish" | |
else | |
@provider = Provider.aws.first | |
@cost2 = cloudy_product_cost_calculator(cost_repository: CostRepository.new(provider: @provider)) | |
final_values = @cost2.costs(calculator: @active_calculator) | |
@price = define_price final_values, @active_calculator | |
if @active_calculator.totvs_terms && @active_calculator.client_terms | |
redirect = "proposal" | |
end | |
end | |
@totvs_name_product = define_names_totvs(active_calculator) | |
end | |
protected | |
def step_mapper | |
raise NotImplementedError | |
end | |
def init_environment_step | |
raise NotImplementedError | |
end | |
def init_environment_additional_step | |
raise NotImplementedError | |
end | |
def init_support_step | |
raise NotImplementedError | |
end | |
def init_confirmation_step | |
raise NotImplementedError | |
end | |
def load_environment_variables(simulator) | |
@connection_qtt = simulator.modules[:simulator_connection_quantity] | |
total_connections = @connection_qtt.contract_connections_number | |
if total_connections >= active_calculator.minimum_quantity_for_special_project | |
calculator_repository.update( | |
id: active_calculator.id, | |
source_type: "special" | |
) | |
else | |
calculator_repository.update( | |
id: active_calculator.id, | |
source_type: nil | |
) | |
end | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
order = 0 | |
loop do | |
enum_module = "simulator_working_hours_#{stage.id}_#{order}".to_sym | |
break unless simulator.modules.key? enum_module | |
@working_hours[stage.id] << simulator.modules[enum_module] | |
order += 1 | |
end | |
end | |
end | |
def load_environment_additional_variables(simulator) | |
@stages.each do |stage| | |
@working_hours[stage.id] = [] | |
order = 0 | |
loop do | |
enum_module = "simulator_working_hours_#{stage.id}_#{order}".to_sym | |
break unless simulator.modules.key? enum_module | |
@working_hours[stage.id] << simulator.modules[enum_module] | |
order += 1 | |
end | |
end | |
end | |
def load_support_variables(simulator) | |
@support_selector = simulator.modules[:simulator_support_selector] | |
end | |
def load_confirmation_variables(simulator) | |
@accept_term = simulator.modules[:simulator_accepted_term] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment