item and location names will be shown instead of their ids
This commit is contained in:
@@ -288,17 +288,18 @@ async function reloadStockTable(itemId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.stock.forEach(st => {
|
for (const st of data.stock) {
|
||||||
|
const locData = await apiRequest(`/api/location?id=${st.location_id}`);
|
||||||
tbody.innerHTML += `
|
tbody.innerHTML += `
|
||||||
<tr>
|
<tr>
|
||||||
<td>${st.location_name || `Location #${st.location_id}`}</td>
|
<td>${locData.name || `Location #${st.location_id}`}</td>
|
||||||
<td><span class="badge success">${st.quantity}</span></td>
|
<td><span class="badge success">${st.quantity}</span></td>
|
||||||
<td style="text-align: right;">
|
<td style="text-align: right;">
|
||||||
<button class="btn btn-secondary danger-btn" style="padding: 0.2rem 0.5rem; font-size: 0.75rem;" onclick="deleteStock(${st.id}, ${itemId})">Del</button>
|
<button class="btn btn-secondary danger-btn" style="padding: 0.2rem 0.5rem; font-size: 0.75rem;" onclick="deleteStock(${st.id}, ${itemId})">Del</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
});
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tbody.innerHTML = '<tr><td colspan="3" style="text-align: center;">Failed to load.</td></tr>';
|
tbody.innerHTML = '<tr><td colspan="3" style="text-align: center;">Failed to load.</td></tr>';
|
||||||
}
|
}
|
||||||
@@ -358,17 +359,19 @@ async function reloadAssociationTable(projectId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.associations.forEach(asc => {
|
for (const asc of data.associations) {
|
||||||
|
const itemData = await apiRequest(`/api/item?id=${asc.item_id}`);
|
||||||
|
console.log(itemData)
|
||||||
tbody.innerHTML += `
|
tbody.innerHTML += `
|
||||||
<tr>
|
<tr>
|
||||||
<td>${asc.item_name || `Item #${asc.item_id}`}</td>
|
<td>${itemData.name || `Item #${asc.item_id}`}</td>
|
||||||
<td><span class="badge success">${asc.quantity}</span></td>
|
<td><span class="badge success">${asc.quantity}</span></td>
|
||||||
<td style="text-align: right;">
|
<td style="text-align: right;">
|
||||||
<button class="btn btn-secondary danger-btn" style="padding: 0.2rem 0.5rem; font-size: 0.75rem;" onclick="deleteAssociation(${asc.id}, ${projectId})">Del</button>
|
<button class="btn btn-secondary danger-btn" style="padding: 0.2rem 0.5rem; font-size: 0.75rem;" onclick="deleteAssociation(${asc.id}, ${projectId})">Del</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
});
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tbody.innerHTML = '<tr><td colspan="3" style="text-align: center;">Failed to load.</td></tr>';
|
tbody.innerHTML = '<tr><td colspan="3" style="text-align: center;">Failed to load.</td></tr>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,34 @@ func Item(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
|
|
||||||
|
idStr := r.URL.Query().Get("id")
|
||||||
|
|
||||||
|
if idStr != "" {
|
||||||
|
id, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Invalid ID parameter", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var item models.Item
|
||||||
|
err = storage.DB.QueryRow("SELECT id, name, category, description, total_quantity FROM items WHERE id = ?", id).Scan(&item.ID, &item.Name, &item.Category, &item.Description, &item.TotalQuantity)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
log.Println("GET [api/locations] " + r.RemoteAddr + ": Location not found (ID " + idStr + ")")
|
||||||
|
http.Error(w, "Location not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("GET [api/item] DB Error: " + err.Error())
|
||||||
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
json.NewEncoder(w).Encode(item)
|
||||||
|
log.Println("GET [api/item] " + r.RemoteAddr + ": Successfully retrieved item ID " + idStr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
i.id, i.name, i.category, i.description,
|
i.id, i.name, i.category, i.description,
|
||||||
|
|||||||
Reference in New Issue
Block a user