Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request Team254#11 from morops/part-update
Browse files Browse the repository at this point in the history
Part update
  • Loading branch information
morops authored Dec 27, 2017
2 parents 4f977b5 + 6ffb7f4 commit 16c3ec4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
5 changes: 2 additions & 3 deletions db/migrations/005_add_material_and_priority_to_parts.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Sequel.migration do
change do
alter_table(:parts) do
add_column :source_material, String, :null => false
add_column :have_material, Integer, :null => false
add_column :mfg_method, String, :null => false
add_column :finish, String, :null => false
add_column :quantity, String, :null => false
add_column :cut_length, String, :null => false
add_column :priority, Integer, :null => false
add_column :drawing_created, Integer, :null => false
end
Expand Down
Binary file added models/.part.rb.swp
Binary file not shown.
24 changes: 17 additions & 7 deletions models/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ class Part < Sequel::Model

# The list of possible part statuses. Key: string stored in database, value: what is displayed to the user.
STATUS_MAP = { "designing" => "Design in progress",
"material" => "Material needs to be ordered",
# "material" => "Material needs to be ordered",
"ordered" => "Waiting for materials",
"drawing" => "Needs drawing",
"ready" => "Ready to manufacture",
"manufacturing" => "Manufacturing in progress",
"outsourced" => "Waiting for outsourced manufacturing",
"welding" => "Waiting for welding",
"scotchbrite" => "Waiting for Scotch-Brite",
"anodize" => "Ready for anodize",
"powder" => "Ready for powder coating",
"coating" => "Waiting for coating",
# "outsourced" => "Waiting for outsourced manufacturing",
# "welding" => "Waiting for welding",
# "scotchbrite" => "Waiting for Scotch-Brite",
# "anodize" => "Ready for anodize",
# "powder" => "Ready for powder coating",
# "coating" => "Waiting for coating",
"assembly" => "Waiting for assembly",
"done" => "Done" }
MFG_MAP = { "manual" => "Manual/hand tools",
"milled" => "Milled",
"turned" => "Turned",
"printed" => "3D Printed",
"outsourced" => "Outsourced" }

FINISH_MAP = { "none" => "None",
"powder_coated" => "Powder coated",
"painted" => "Painted",
"polished" => "Polished" }

# Mapping of priority integer stored in database to what is displayed to the user.
PRIORITY_MAP = { 0 => "High", 1 => "Normal", 2 => "Low" }
Expand Down
17 changes: 11 additions & 6 deletions parts_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ def send_email(to, subject, body)
part = Part.generate_number_and_create(project, params[:type], parent_part)
part.name = params[:name].gsub("\"", "&quot;")
part.status = "designing"
part.source_material = ""
part.have_material = 0
part.mfg_method = "manual"
part.finish = "none"
part.quantity = ""
part.cut_length = ""
part.priority = 1
part.drawing_created = 0
part.save
Expand Down Expand Up @@ -251,10 +250,16 @@ def send_email(to, subject, body)
halt(400, "Invalid status.") unless Part::STATUS_MAP.include?(params[:status])
@part.status = params[:status]
end

if params[:mfg_method]
halt(400, "Invalid manufacturing method.") unless Part::MFG_MAP.include?(params[:mfg_method])
@part.mfg_method = params[:mfg_method]
end
if params[:finish]
halt(400, "Invalid finish type.") unless Part::FINISH_MAP.include?(params[:finish])
@part.finish = params[:finish]
end
@part.notes = params[:notes] if params[:notes]
@part.source_material = params[:source_material] if params[:source_material]
@part.have_material = (params[:have_material] == "on") ? 1 : 0
@part.cut_length = params[:cut_length] if params[:cut_length]
@part.quantity = params[:quantity] if params[:quantity]
@part.drawing_created = (params[:drawing_created] == "on") ? 1 : 0
@part.priority = params[:priority] if params[:priority]
Expand Down
5 changes: 2 additions & 3 deletions views/part.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
</tr>
<tr><td><b>Notes</b></td><td><%= (@part.notes || "").gsub("\n", "<br />") %></td></tr>
<% if @part.type == "part" %>
<tr><td><b>Source material</b></td><td><%= @part.source_material %></td></tr>
<tr><td><b>Have material?</b></td><td><%= (@part.have_material == 1) ? "Yes" : "No" %></td></tr>
<tr><td><b>Material cut length</b></td><td><%= @part.cut_length %></td></tr>
<tr><td><b>Manufacturing method</b></td><td><%= Part::MFG_MAP[@part.mfg_method] %></td></tr>
<tr><td><b>Finish type</b></td><td><%= Part::FINISH_MAP[@part.finish] %></td></tr>
<% end %>
<tr><td><b>Quantity required</b></td><td><%= @part.quantity %></td></tr>
<tr><td><b>Drawing created?</b></td><td><%= (@part.drawing_created == 1) ? "Yes" : "No" %></td></tr>
Expand Down
24 changes: 17 additions & 7 deletions views/part_edit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@
</option>
<% end %>
</select>
<label>Manufacturing Method</label>
<select name="mfg_method">
<% Part::MFG_MAP.each_pair do |key, value| %>
<option value="<%= key %>"<% if @part.mfg_method == key %> selected<% end %>>
<%= value %>
</option>
<% end %>
</select>
<label>Notes</label>
<textarea name="notes" rows="4"><%= @part.notes %></textarea>
<label>Source Material</label>
<input type="text" name="source_material" value="<%= @part.source_material %>" />
<label>Have Material?</b>
<input type="checkbox" name="have_material"<% if @part.have_material == 1 %>checked<% end %>/>
</label>
<label>Material Cut Length</label>
<input type="text" name="cut_length" value="<%= @part.cut_length %>" />
<label>Quantity Required</label>
<input type="text" name="quantity" value="<%= @part.quantity %>" />
<label>Drawing Created?</b>
<input type="checkbox" name="drawing_created"<% if @part.drawing_created == 1 %>checked<% end %>/>
</label>
<label>Finish Type</label>
<select name="finish">
<% Part::FINISH_MAP.each_pair do |key, value| %>
<option value="<%= key %>"<% if @part.finish == key %> selected<% end %>>
<%= value %>
</option>
<% end %>
</select>

<label>Priority</label>
<select name="priority">
<% Part::PRIORITY_MAP.each_pair do |key, value| %>
Expand Down

0 comments on commit 16c3ec4

Please sign in to comment.