Skip to content

Commit

Permalink
Improving views and implemented some validations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorali committed Jun 9, 2011
1 parent b226a09 commit bdf0a55
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
8 changes: 4 additions & 4 deletions app/controllers/facilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def buy
end

def buy_facility
@facility = Facility.find(params[:buy_facility][:id])
@planet = Planet.find(params[:buy_facility][:planet])
if current_squad.credits >= @facility.price
current_squad.buy @facility, 1, @planet
unless params[:buy_facility][:id].empty? || params[:buy_facility][:planet].empty?
@facility = Facility.find(params[:buy_facility][:id])
@planet = Planet.find(params[:buy_facility][:planet])
current_squad.buy @facility, 1, @planet if current_squad.credits >= @facility.price
end
redirect_to :fleets
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/facility_fleets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def edit
@planet = @facility.planet
if @facility.producing_unit.present?
@producing_capacity = @facility.generic_unit.price / 4
@current_producing_unit_status = @facility.balance / @facility.producing_unit.price.to_f * 100
@current_producing_unit_status = (@facility.balance / @facility.producing_unit.price.to_f * 100).round(2)
else
@producing_capacity = 0
@current_producing_unit_status = 0
Expand Down
8 changes: 4 additions & 4 deletions app/views/facilities/buy.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="planet_content">
Buy Facility
<h2> <%= @planet.name %> </h2>
<%= simple_form_for :buy_facility, :url => url_for(:controller => 'facilities', :action => 'buy_facility') do |f| %>
<%= f.input :id, :collection => @facilities, :label => 'Facility: ' %>
<%= f.input :planet, :collection => @planet, :label => 'Planet: ' %>
<%= f.button :submit %>
<%= f.input :id, :collection => @facilities, :label => 'Choose a Facility: ' %>
<%= f.input :planet, :collection => @planet, :label => 'Confirm Planet: ' %>
<%= f.submit 'Build it' %>
<% end %>
</div>
<div class="map">
Expand Down
7 changes: 4 additions & 3 deletions app/views/facility_fleets/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<br>
<% if @facility.producing_unit.present? %>
Capacity : $ <%= @producing_capacity %>
( <%= @producing_capacity / @facility.producing_unit.price.to_f %> <%= @facility.producing_unit.name %>s / round )
( <%= (@producing_capacity / @facility.producing_unit.price.to_f).round(2) %> <%= @facility.producing_unit.name %>s / round )
<br>
Current Balance: $ <%= @facility.balance %>
<br>
Constructing: <%= @facility.producing_unit.name %> ( <%= @current_producing_unit_status %>% done )
Constructing: <%= @facility.producing_unit.name %>
<%= "( #{@current_producing_unit_status}% done )" if @facility.producing_unit.is_a? CapitalShip %>
<% else %>
Producing Capacity: $ <%= @producing_capacity %>
<br>
Expand All @@ -18,7 +19,7 @@
<br>
<%= simple_form_for @facility do |f| %>
<%= f.input :producing_unit, :collection => @units, :label => 'Producing Unit: ' %>
<%= f.button :submit %>
<%= f.submit 'Change Unit' %>
<% end %>
</div>
<div class="map">
Expand Down
1 change: 1 addition & 0 deletions app/views/generic_fleets/_facilities.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
( <% if @round.move && fleet.squad == @squad %>
<% if fleet.producing_unit.present? %>
<%= link_to "#{fleet.producing_unit.name}", edit_facility_fleet_path(fleet) %>
<%= link_to "#{(fleet.balance / fleet.producing_unit.price.to_f * 100).round(2)}%" if fleet.producing_unit.is_a? CapitalShip %>
<% else %>
<%= link_to 'inactive', edit_facility_fleet_path(fleet) %>
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/generic_fleets/_move_fleets.html.erb

This file was deleted.

6 changes: 3 additions & 3 deletions app/views/generic_fleets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<div class="planet_content">
<% @planets.each do |planet| %>
<h2> <%= planet.name %> </h2>
<%= link_to 'move fleets', move_planet_path(planet) if @round.move %>
<%= link_to '/ buy facility', buy_facility_path(planet) if @round.move && planet.squad == @squad %>
<%= link_to 'post results', planet_results_path(planet) if @round.attack %>
<%= link_to '[move fleets] ', move_planet_path(planet) if @round.move %>
<%= link_to ' [build facility] ', buy_facility_path(planet) if @round.move && planet.squad == @squad %>
<%= link_to '[post results] ', planet_results_path(planet) if @round.attack %>
<p>
<span style=font-weight:bold><%= "Income: $ #{planet.credits}" if planet.credits_per_turn.present? && planet.credits_per_turn > 0 %></span>
<p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/planets/move.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= f.input :quantity, :collection => 1..fleet.quantity, :label => 'Quantity: ' %>
<%= f.input :destination, :collection => @routes, :label => 'Destination: ' %>
<%= f.hidden_field :id %>
<%= f.button :submit %>
<%= f.submit 'Move it' %>
<% end %>
<br>
<% end %>
Expand Down
8 changes: 0 additions & 8 deletions app/views/planets/results.html.erb

This file was deleted.

0 comments on commit bdf0a55

Please sign in to comment.