@@ -80,7 +91,6 @@
});
const pagination = reactive({
- sortBy: sortByProperty.value,
descending: false,
page: 1,
rowsPerPage: 10,
@@ -97,20 +107,50 @@
return pagination.page > 1;
});
+ function sortBy(property: keyof ItemSummary) {
+ if (sortByProperty.value === property) {
+ pagination.descending = !pagination.descending;
+ } else {
+ pagination.descending = false;
+ }
+ sortByProperty.value = property;
+ }
+
+ function extractSortable(item: ItemSummary, property: keyof ItemSummary): string | number | boolean {
+ const value = item[property];
+ if (typeof value === "string") {
+ // Try parse float
+ const parsed = parseFloat(value);
+ if (!isNaN(parsed)) {
+ return parsed;
+ }
+
+ return value.toLowerCase();
+ }
+
+ if (typeof value !== "number" && typeof value !== "boolean") {
+ return "";
+ }
+
+ return value;
+ }
+
+ function itemSort(a: ItemSummary, b: ItemSummary) {
+ const aLower = extractSortable(a, sortByProperty.value);
+ const bLower = extractSortable(b, sortByProperty.value);
+
+ if (aLower < bLower) {
+ return -1;
+ }
+ if (aLower > bLower) {
+ return 1;
+ }
+ return 0;
+ }
+
const data = computed
(() => {
// sort by property
- let data = [...props.items].sort((a, b) => {
- const aLower = a[sortByProperty.value]?.toLowerCase();
- const bLower = b[sortByProperty.value]?.toLowerCase();
-
- if (aLower < bLower) {
- return -1;
- }
- if (aLower > bLower) {
- return 1;
- }
- return 0;
- });
+ let data = [...props.items].sort(itemSort);
// sort descending
if (pagination.descending) {
diff --git a/frontend/pages/home/index.vue b/frontend/pages/home/index.vue
index 372c0a9..5ce3f0d 100644
--- a/frontend/pages/home/index.vue
+++ b/frontend/pages/home/index.vue
@@ -82,20 +82,7 @@
Recently Added
-
-
-
-
-
-
-
-
-
-
- {{ item.location?.name }}
-
-
-
+
diff --git a/frontend/pages/home/table.ts b/frontend/pages/home/table.ts
index e198bb4..127ecbb 100644
--- a/frontend/pages/home/table.ts
+++ b/frontend/pages/home/table.ts
@@ -1,5 +1,3 @@
-import { TableHeader } from "~~/components/global/Table.types";
-
import { UserClient } from "~~/lib/api/user";
export function itemsTable(api: UserClient) {
@@ -11,31 +9,8 @@ export function itemsTable(api: UserClient) {
return data.items;
});
- const headers = [
- {
- text: "Name",
- sortable: true,
- value: "name",
- },
- {
- text: "Location",
- value: "location.name",
- },
- {
- text: "Warranty",
- value: "warranty",
- align: "center",
- },
- {
- text: "Price",
- value: "purchasePrice",
- align: "center",
- },
- ] as TableHeader[];
-
return computed(() => {
return {
- headers,
items: items.value || [],
};
});
diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue
index f530566..052c6be 100644
--- a/frontend/pages/item/[id]/index.vue
+++ b/frontend/pages/item/[id]/index.vue
@@ -518,11 +518,8 @@
-
- Child Items
-
-
-
+
diff --git a/frontend/pages/label/[id].vue b/frontend/pages/label/[id].vue
index c9ac8ef..de87a4d 100644
--- a/frontend/pages/label/[id].vue
+++ b/frontend/pages/label/[id].vue
@@ -156,11 +156,8 @@
-