display properties
This commit is contained in:
parent
a5b294b708
commit
88d8da339a
|
@ -36,6 +36,10 @@
|
||||||
<thead><tr><th>distributor</th><th>sku</th><th>page</th></tr></thead>
|
<thead><tr><th>distributor</th><th>sku</th><th>page</th></tr></thead>
|
||||||
<tbody id="distributors"></tbody>
|
<tbody id="distributors"></tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<table>
|
||||||
|
<thead><tr><th>property</th><th>value(s)</th></tr></thead>
|
||||||
|
<tbody id="properties"></tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -103,6 +103,42 @@ function select()
|
||||||
tr.appendChild(td_url);
|
tr.appendChild(td_url);
|
||||||
distributors.appendChild(tr);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
server.rb
16
server.rb
|
@ -99,6 +99,22 @@ def get_part_by_id(id)
|
||||||
part["location"] = inventory["location"]
|
part["location"] = inventory["location"]
|
||||||
part["stock"] = inventory["stock"]
|
part["stock"] = inventory["stock"]
|
||||||
end
|
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
|
# clean up
|
||||||
delete = ["parent"]
|
delete = ["parent"]
|
||||||
delete.each do |k|
|
delete.each do |k|
|
||||||
|
|
Loading…
Reference in New Issue