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