diff --git a/public/index.html b/public/index.html
index e917281..a03a5d3 100644
--- a/public/index.html
+++ b/public/index.html
@@ -36,6 +36,10 @@
distributor | sku | page |
+
diff --git a/public/partdb.js b/public/partdb.js
index 80d3dac..3c87109 100644
--- a/public/partdb.js
+++ b/public/partdb.js
@@ -103,6 +103,42 @@ function select()
tr.appendChild(td_url);
distributors.appendChild(tr);
}
+ // add properties
+ const properties = document.getElementById('properties');
+ properties.innerHTML = null;
+ for (const prop in part["properties"]) {
+ const tr = document.createElement('tr');
+ let td = document.createElement('td');
+ let input = document.createElement('input');
+ input.type = "text";
+ input.style.width = "95%";
+ input.value = prop;
+ td.appendChild(input);
+ tr.appendChild(td);
+ td = document.createElement('td');
+ input = document.createElement('input');
+ input.type = "text";
+ input.style.width = "95%";
+ input.value = part["properties"][prop].join(",");
+ td.appendChild(input);
+ tr.appendChild(td);
+ properties.appendChild(tr);
+ }
+ // add empty property field
+ let tr = document.createElement('tr');
+ let td = document.createElement('td');
+ let input = document.createElement('input');
+ input.type = "text";
+ input.style.width = "95%";
+ td.appendChild(input);
+ tr.appendChild(td);
+ td = document.createElement('td');
+ input = document.createElement('input');
+ input.type = "text";
+ input.style.width = "95%";
+ td.appendChild(input);
+ tr.appendChild(td);
+ properties.appendChild(tr);
}
}
}
diff --git a/server.rb b/server.rb
index 1e8e9a0..c1c9062 100755
--- a/server.rb
+++ b/server.rb
@@ -99,6 +99,22 @@ def get_part_by_id(id)
part["location"] = inventory["location"]
part["stock"] = inventory["stock"]
end
+ # add properties
+ part["properties"] = {}
+ family = id
+ statement = @db.prepare("SELECT property.name AS name, property_value.value AS value FROM property_value JOIN property ON property.id = property_value.property WHERE property_value.part = ?")
+ family_stmt = @db.prepare("SELECT family FROM part WHERE id = ?")
+ while family do
+ statement.execute(family).each do |row|
+ part["properties"][row["name"]] ||= []
+ part["properties"][row["name"]] << row["value"]
+ end
+ results = family_stmt.execute(family)
+ family = nil
+ results.each do |row|
+ family = row["id"]
+ end
+ end
# clean up
delete = ["parent"]
delete.each do |k|