display distributors
This commit is contained in:
parent
ccac519870
commit
5c713ffe8b
|
@ -30,6 +30,10 @@
|
|||
<div class="name">family:</div><div class="justify"><input class="full" type="text" id="part_family"></div>
|
||||
<div class="name"><a id="url_datasheet">datasheet</a>:</div><div class="justify"><input class="full" type="text" id="part_datasheet"></div>
|
||||
<div class="name"><a id="url_page">page</a>:</div><div class="justify"><input class="full" type="text" id="part_page"></div>
|
||||
<table>
|
||||
<thead><tr><th>distributor</th><th>sku</th><th>page</th></tr></thead>
|
||||
<tbody id="distributors"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -79,6 +79,30 @@ function select()
|
|||
a.href = part[field];
|
||||
}
|
||||
}
|
||||
// set distributors
|
||||
const distributors = document.getElementById('distributors');
|
||||
distributors.innerHTML = null;
|
||||
for (const distributor of part["distributors"]) {
|
||||
const tr = document.createElement('tr');
|
||||
const td_name = document.createElement('td');
|
||||
td_name.innerText = distributor.name;
|
||||
tr.appendChild(td_name);
|
||||
const td_sku = document.createElement('td');
|
||||
const input = document.createElement('input');
|
||||
input.type = "text";
|
||||
input.style.width = "95%";
|
||||
if (distributor.sku) {
|
||||
input.value = distributor.sku;
|
||||
}
|
||||
td_sku.appendChild(input);
|
||||
tr.appendChild(td_sku);
|
||||
const td_url = document.createElement('td');
|
||||
if (distributor.url) {
|
||||
td_url.innerHTML = "<a href='" + distributor.url + "'>link</a>";
|
||||
}
|
||||
tr.appendChild(td_url);
|
||||
distributors.appendChild(tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
16
server.rb
16
server.rb
|
@ -76,6 +76,22 @@ def get_part_by_id(id)
|
|||
part[k] ||= v
|
||||
end
|
||||
end
|
||||
# add all distributors
|
||||
distributors = @db.query("SELECT * FROM distributor").to_a
|
||||
statement = @db.prepare("SELECT * FROM distribution WHERE part = ?")
|
||||
distributions = statement.execute(id).to_a
|
||||
distributors.each do |distributor|
|
||||
distributions.each do |distribution|
|
||||
if distribution["distributor"] == distributor["id"] then
|
||||
distributor["sku"] = distribution["sku"]
|
||||
distributor["url"] = distributor["product_page"].gsub("%s", distribution["sku"])
|
||||
end
|
||||
end
|
||||
distributor.delete("id")
|
||||
distributor.delete("homepage")
|
||||
distributor.delete("product_page")
|
||||
end
|
||||
part["distributors"] = distributors
|
||||
# clean up
|
||||
delete = ["parent"]
|
||||
delete.each do |k|
|
||||
|
|
Loading…
Reference in New Issue