plenty of small fixes
This commit is contained in:
parent
6f683df850
commit
c6f773c777
|
@ -43,9 +43,12 @@ function results()
|
|||
for (const part of parts) {
|
||||
const option = document.createElement('option');
|
||||
option.setAttribute('value', part.id);
|
||||
option.innerHTML = part.name + " (" + part.description + ")";
|
||||
if (part_id == part.id) {
|
||||
option.selected = "selected";
|
||||
option.innerHTML = part.name;
|
||||
if (part.description) {
|
||||
option.innerHTML += " (" + part.description + ")";
|
||||
if (part_id == part.id) {
|
||||
option.selected = "selected";
|
||||
}
|
||||
}
|
||||
results.appendChild(option);
|
||||
}
|
||||
|
|
21
server.rb
21
server.rb
|
@ -120,10 +120,12 @@ def get_part_by_id(id)
|
|||
# add attachments
|
||||
part["attachments"] = []
|
||||
dir = PUBLIC + "/" + ATTACHMENTS + "/" + part["name"]
|
||||
Dir.entries(dir).each do |file|
|
||||
path = dir + "/" + file
|
||||
next unless File.file? path
|
||||
part["attachments"] << ATTACHMENTS + "/" + part["name"] + "/" + file
|
||||
if File.directory?(dir) then
|
||||
Dir.entries(dir).each do |file|
|
||||
path = dir + "/" + file
|
||||
next unless File.file? path
|
||||
part["attachments"] << ATTACHMENTS + "/" + part["name"] + "/" + file
|
||||
end
|
||||
end
|
||||
if parent then
|
||||
part["attachments"] += parent["attachments"]
|
||||
|
@ -261,7 +263,7 @@ post '/part' do
|
|||
next unless part[field]
|
||||
part[field] = nil if part[field].kind_of?(String) and 0 == part[field].length
|
||||
part[field] = part[field].to_i if part[field] and "pincount" == field
|
||||
next if family[field] == part[field]
|
||||
next if family and family[field] == part[field]
|
||||
update = @db.prepare("UPDATE part SET #{field} = ? WHERE id = ?")
|
||||
update.execute(part[field], part["id"])
|
||||
end
|
||||
|
@ -269,7 +271,7 @@ post '/part' do
|
|||
field_ref = ["manufacturer", "package"]
|
||||
field_ref.each do |field|
|
||||
part[field] = nil if part[field] and 0 == part[field].length
|
||||
next if family[field] == part[field]
|
||||
next if family and family[field] == part[field]
|
||||
if part[field] then
|
||||
statement = @db.prepare("SELECT id FROM #{field} WHERE LOWER(name) = ?")
|
||||
ref = statement.execute(part[field].downcase).to_a[0]
|
||||
|
@ -300,8 +302,8 @@ post '/part' do
|
|||
statement = @db.prepare("SELECT id FROM inventory WHERE part = ? AND location = ?")
|
||||
ref_inv = statement.execute(part["id"], ref["id"]).to_a[0]
|
||||
unless ref_inv then
|
||||
insert = @db.prepare("INSERT INTO inventory (part, location) VALUES (?,?)");
|
||||
insert.execute(part["id"], ref["id"])
|
||||
insert = @db.prepare("INSERT INTO inventory (part, location, quantity) VALUES (?,?,?)");
|
||||
insert.execute(part["id"], ref["id"], part["stock"].to_i)
|
||||
end
|
||||
ref_inv = statement.execute(part["id"], ref["id"]).to_a[0]
|
||||
update = @db.prepare("UPDATE inventory SET quantity = ? WHERE id = ?")
|
||||
|
@ -332,7 +334,7 @@ post '/part' do
|
|||
delete.execute(part["id"])
|
||||
if part[field] then
|
||||
part[field].each do |name,values|
|
||||
next if values.empty?
|
||||
next unless values and !values.empty?
|
||||
statement = @db.prepare("SELECT id FROM property WHERE LOWER(name) = ?")
|
||||
ref = statement.execute(name.downcase).to_a[0]
|
||||
unless ref then
|
||||
|
@ -342,6 +344,7 @@ post '/part' do
|
|||
ref = statement.execute(name.downcase).to_a[0]
|
||||
insert = @db.prepare("INSERT INTO property_value (property,part,value) VALUES (?,?,?)");
|
||||
values.each do |value|
|
||||
next if family and family["properties"] and family["properties"][name].include?(value)
|
||||
insert.execute(ref["id"], part["id"], value)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue