From 88d8da339a2e14b34e81705377fd8ac3ed0ba1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 25 Jan 2023 11:22:26 +0100 Subject: [PATCH] display properties --- public/index.html | 4 ++++ public/partdb.js | 36 ++++++++++++++++++++++++++++++++++++ server.rb | 16 ++++++++++++++++ 3 files changed, 56 insertions(+) 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 @@ distributorskupage + + + +
propertyvalue(s)
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|