From 13ac01e925715b02a27a4a6185ac10e66fa04c24 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 17 Jul 2024 21:08:09 +0800 Subject: [PATCH 01/18] feat(tauri): combine category list and tree page --- elebox-tauri/src/App.vue | 5 ----- elebox-tauri/src/router.ts | 5 ----- elebox-tauri/src/views/CategoriesTree.vue | 4 +--- elebox-tauri/src/views/Category.vue | 15 ++++++++++++++- elebox-tauri/src/views/Part.vue | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/elebox-tauri/src/App.vue b/elebox-tauri/src/App.vue index c046190..ae69481 100644 --- a/elebox-tauri/src/App.vue +++ b/elebox-tauri/src/App.vue @@ -28,11 +28,6 @@ title="Manufacturers" :to="{ name: 'mfrs' }" > - import("./views/ManufacturerEdit.vue"), }, - { - path: "/tree", - name: "tree", - component: () => import("./views/CategoriesTree.vue"), - }, ], }); diff --git a/elebox-tauri/src/views/CategoriesTree.vue b/elebox-tauri/src/views/CategoriesTree.vue index f1b0753..7d8a1a1 100644 --- a/elebox-tauri/src/views/CategoriesTree.vue +++ b/elebox-tauri/src/views/CategoriesTree.vue @@ -19,7 +19,5 @@ onMounted(async () => { diff --git a/elebox-tauri/src/views/Category.vue b/elebox-tauri/src/views/Category.vue index 99a237b..75dbabb 100644 --- a/elebox-tauri/src/views/Category.vue +++ b/elebox-tauri/src/views/Category.vue @@ -1,11 +1,24 @@ diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 5c6b4fa..14b55ed 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -137,7 +137,7 @@ function handleSupplierAdd(data: { new: Supplier }) { const route = useRoute(); onMounted(() => { - origin_name.value = route.params.origin_name; + origin_name.value = route.params.origin_name; // FIXME if (origin_name.value !== undefined && origin_name.value !== "") { getPart(origin_name.value); } From 460aadba63f064b7735e072e93f19f930b98a49c Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 17 Jul 2024 21:33:02 +0800 Subject: [PATCH 02/18] feat(tauri): make Vuetify button don't uppercase --- elebox-tauri/src/styles.css | 78 ++++----------------------------- elebox-tauri/src/views/Home.vue | 17 +++---- 2 files changed, 15 insertions(+), 80 deletions(-) diff --git a/elebox-tauri/src/styles.css b/elebox-tauri/src/styles.css index 69718bb..b3bc395 100644 --- a/elebox-tauri/src/styles.css +++ b/elebox-tauri/src/styles.css @@ -19,90 +19,30 @@ --light: #f6f6f6; } -.container { +/* .container { margin: 0; padding-top: 3vh; display: flex; flex-direction: column; justify-content: center; text-align: center; -} +} */ -.row { +/* .row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; -} +} */ -.field { +/* .field { display: flex; flex-direction: column; align-items: flex-start; -} - - -table { - text-align: left; - border-collapse: collapse; -} - -th, -td { - border: 1px solid #c1c1c1; - padding: 3px 10px; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} +} */ -a:hover { - color: #535bf2; -} - -h1 { - text-align: center; -} - -input, -button, -select, -textarea { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - color: #0f0f0f; - background-color: #ffffff; - transition: border-color 0.25s; - box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2); -} - -button { - cursor: pointer; -} - -button:hover { - border-color: #396cd8; -} - -button:active { - border-color: #396cd8; - background-color: #e8e8e8; -} - -input, -button { - outline: none; -} - -#greet-input { - margin-right: 5px; +.v-btn{ + text-transform: none; } @media (prefers-color-scheme: dark) { @@ -126,4 +66,4 @@ button { button:active { background-color: #0f0f0f69; } -} \ No newline at end of file +} diff --git a/elebox-tauri/src/views/Home.vue b/elebox-tauri/src/views/Home.vue index b121e1b..c81d5c8 100644 --- a/elebox-tauri/src/views/Home.vue +++ b/elebox-tauri/src/views/Home.vue @@ -6,6 +6,7 @@ import { DbPart } from "../db_cmd_part"; import PartQty from "../components/PartQty.vue"; import PartDel from "../components/PartDel.vue"; import ItemEditButton from "../components/ItemEditButton.vue"; +import "../styles.css"; let parts = reactive([]); @@ -55,7 +56,10 @@ onMounted(getParts); - + {{ p.name }} @@ -67,16 +71,7 @@ onMounted(getParts); {{ p.package }} {{ p.mfr }} - - - + From 7a1219283274e7aded56f7a04636927a004ee938 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 17 Jul 2024 21:52:00 +0800 Subject: [PATCH 03/18] fix(tauri): origin_name init value --- elebox-tauri/src/views/Part.vue | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 14b55ed..ec331f9 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -10,7 +10,7 @@ import { DbCategory } from "../db_cmd_category"; import { DbManufacturer as DbMfr } from "../db_cmd_manufacturer"; import { DbPackage } from "../db_cmd_package"; -const origin_name = ref(); +const origin_name = ref(""); const part = ref({ name: "", quantity: 0, @@ -20,6 +20,7 @@ const part = ref({ }); const favorite = ref(); +const alert = ref(false); const new_custom_field = ref({ name: "", @@ -137,8 +138,11 @@ function handleSupplierAdd(data: { new: Supplier }) { const route = useRoute(); onMounted(() => { - origin_name.value = route.params.origin_name; // FIXME - if (origin_name.value !== undefined && origin_name.value !== "") { + if ( + route.params.origin_name !== undefined && + route.params.origin_name !== "" + ) { + origin_name.value = route.params.origin_name; // FIXME getPart(origin_name.value); } From 800a2c17669c4554ee4de2a4431c123a2dd9a740 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 17 Jul 2024 22:08:56 +0800 Subject: [PATCH 04/18] fix(tauri): add required rule for part custom field and supplier --- elebox-tauri/src/components/PartCustomField.vue | 7 +++++++ elebox-tauri/src/components/PartSupplier.vue | 2 ++ 2 files changed, 9 insertions(+) diff --git a/elebox-tauri/src/components/PartCustomField.vue b/elebox-tauri/src/components/PartCustomField.vue index 950c1df..9bbd28f 100644 --- a/elebox-tauri/src/components/PartCustomField.vue +++ b/elebox-tauri/src/components/PartCustomField.vue @@ -15,6 +15,8 @@ const custom_field = ref({ value: props.value, }); +const empty = ref(false); + const emit = defineEmits(["update", "add", "del"]); watch([custom_field], ([new_custom_field]) => { @@ -28,6 +30,7 @@ function emitDel() { function emitAdd() { // Required value if (!custom_field.value.field_type || !custom_field.value.name) { + empty.value = true; return; } @@ -41,12 +44,16 @@ function emitAdd() { :items="['Normal', 'Link']" variant="outlined" v-model="custom_field.field_type" + :rules="[(v: any) => !!v || 'Required']" + required > Date: Wed, 17 Jul 2024 22:14:35 +0800 Subject: [PATCH 05/18] feat(tauri): make added custom field and supplier readonly --- elebox-tauri/src/components/PartCustomField.vue | 3 +++ elebox-tauri/src/components/PartSupplier.vue | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/elebox-tauri/src/components/PartCustomField.vue b/elebox-tauri/src/components/PartCustomField.vue index 9bbd28f..c282a27 100644 --- a/elebox-tauri/src/components/PartCustomField.vue +++ b/elebox-tauri/src/components/PartCustomField.vue @@ -46,6 +46,7 @@ function emitAdd() { v-model="custom_field.field_type" :rules="[(v: any) => !!v || 'Required']" required + :readonly="!props.create" > -import { ref, watch } from "vue"; +import { readonly, ref, watch } from "vue"; import { Supplier } from "../interface"; const props = defineProps<{ @@ -45,12 +45,14 @@ function emitAdd() { placeholder="" :rules="[(v: any) => !!v || 'Required']" required + :readonly="!props.create" > Date: Thu, 18 Jul 2024 07:04:52 +0800 Subject: [PATCH 06/18] fix(tauri): add pkg_type enum --- elebox-tauri/src/components/PackageField.vue | 36 ++++++++-- elebox-tauri/src/interface.ts | 73 +++++++++++--------- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/elebox-tauri/src/components/PackageField.vue b/elebox-tauri/src/components/PackageField.vue index 27f4509..d7b0ccf 100644 --- a/elebox-tauri/src/components/PackageField.vue +++ b/elebox-tauri/src/components/PackageField.vue @@ -1,9 +1,24 @@ @@ -43,14 +67,14 @@ onMounted(() => { label="Type" :items="['SMT', 'THT', 'Others']" variant="outlined" - v-model="pkg.pkg_type" + v-model="pkg_type_input" :rules="[(v: any) => !!v || 'Required']" required > { diff --git a/elebox-tauri/src/interface.ts b/elebox-tauri/src/interface.ts index 8a01e20..36883a2 100644 --- a/elebox-tauri/src/interface.ts +++ b/elebox-tauri/src/interface.ts @@ -1,54 +1,59 @@ - export interface CustomField { - name: string; - field_type: string; // TODO enum - value: string; + name: string; + field_type: string; // TODO enum + value: string; } export interface Supplier { - name: string; - link: string; - price?: number; - note: string; + name: string; + link: string; + price?: number; + note: string; } export interface Part { - name: string; - quantity: number; - category: string; - package?: string; - package_detail?: string; - mfr?: string; - location?: string; - alias?: string; - description?: string; - mfr_no?: string; - datasheet_link?: string; - product_link?: string; - image_link?: string; - custom_fields: CustomField[]; - suppliers: Supplier[]; + name: string; + quantity: number; + category: string; + package?: string; + package_detail?: string; + mfr?: string; + location?: string; + alias?: string; + description?: string; + mfr_no?: string; + datasheet_link?: string; + product_link?: string; + image_link?: string; + custom_fields: CustomField[]; + suppliers: Supplier[]; } export interface Category { - name: string; - parent?: string; - alias?: string; + name: string; + parent?: string; + alias?: string; +} + +export enum PkgType { + Smt = "Smt", + Tht = "Tht", + Others = "Others", } export interface Package { - name: string; - pkg_type: string; // TODO enum - alias?: string; + name: string; + pkg_type: PkgType; + alias?: string; } export interface Manufacturer { - name: string; - alias?: string; - url?: string; + name: string; + alias?: string; + url?: string; } export interface TreeNode { - name: string; - children: TreeNode[]; + name: string; + children: TreeNode[]; } From ace667746f4c8140503d4a3701a490ffbbbed739 Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 07:29:20 +0800 Subject: [PATCH 07/18] fix(core): mfr update method --- elebox-core/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elebox-core/src/db.rs b/elebox-core/src/db.rs index a29eba9..1e22457 100644 --- a/elebox-core/src/db.rs +++ b/elebox-core/src/db.rs @@ -347,7 +347,7 @@ impl<'a> Database for JammDatabase<'a> { } fn update_mfr(&self, ori_name: &str, new: &DbManufacturer) { - if let Some(id) = self.get_package_id(ori_name) { + if let Some(id) = self.get_mfr_id(ori_name) { self.update_item(MFR_BUCKET, &id, new); } } From 69fd32ac3bddc7a755704a0b22e4e62e018b34ad Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 07:29:51 +0800 Subject: [PATCH 08/18] fix(tauri): mfr list url check, including `null` --- elebox-tauri/src/components/ManufacturerList.vue | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/elebox-tauri/src/components/ManufacturerList.vue b/elebox-tauri/src/components/ManufacturerList.vue index b12cc33..0dc7818 100644 --- a/elebox-tauri/src/components/ManufacturerList.vue +++ b/elebox-tauri/src/components/ManufacturerList.vue @@ -30,11 +30,7 @@ onMounted(list); {{ m.name }} - mdi-open-in-new From ff9adc153ff38353c6cbf12c092a802d169421f4 Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 07:47:54 +0800 Subject: [PATCH 09/18] feat(tauri): let category can remove parent when update --- elebox-tauri/src/components/CategoryField.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/elebox-tauri/src/components/CategoryField.vue b/elebox-tauri/src/components/CategoryField.vue index 90ca1bd..c3b65b7 100644 --- a/elebox-tauri/src/components/CategoryField.vue +++ b/elebox-tauri/src/components/CategoryField.vue @@ -21,13 +21,22 @@ async function update() { return; } + if (category.value.parent === "") { + category.value.parent = undefined; // To root + } + await Db.update(props.origin_name, category.value); await list(); } async function list() { const data = await Db.list(); + + if (props.origin_name) { + data.splice(0, 0, { name: "" }); // Root + } Object.assign(categories, data); + console.debug(`get categories: ${categories.length}`); } From 0168f319f7a6d92b16e5669d5fba7558b1c56e5b Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 18:41:10 +0800 Subject: [PATCH 10/18] feat(core): add category parent normalize --- elebox-core/src/category.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/elebox-core/src/category.rs b/elebox-core/src/category.rs index 34248bf..8b02b8b 100644 --- a/elebox-core/src/category.rs +++ b/elebox-core/src/category.rs @@ -87,7 +87,20 @@ impl<'a> CategoryManager<'a> { )); } - let db_category = self.to_db_category(new_category)?; + // Normalize + let mut cat = Category { + name: new_category.name.clone(), + alias: new_category.alias.clone(), + parent: match &new_category.parent { + Some(p) => match p.as_str() { + "" => None, + _ => Some(p.to_string()), + }, + None => None, + }, + }; + + let db_category = self.to_db_category(&cat)?; self.db.update_category(ori_name, &db_category); Ok(()) } @@ -127,7 +140,20 @@ impl<'a> CategoryManager<'a> { )); } - let db_category = self.to_db_category(category)?; + // Normalize + let mut cat = Category { + name: category.name.clone(), + alias: category.alias.clone(), + parent: match &category.parent { + Some(p) => match p.as_str() { + "" => None, + _ => Some(p.to_string()), + }, + None => None, + }, + }; + + let db_category = self.to_db_category(&cat)?; self.db.add_category(&db_category); Ok(()) } From 5e3434f39be6fde00ff8eb708e673d087f5695a7 Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 19:07:17 +0800 Subject: [PATCH 11/18] feat(tauri): make custom field and supplier as form --- .../src/components/PartCustomField.vue | 102 +++++++++++------- elebox-tauri/src/components/PartSupplier.vue | 101 +++++++++-------- 2 files changed, 116 insertions(+), 87 deletions(-) diff --git a/elebox-tauri/src/components/PartCustomField.vue b/elebox-tauri/src/components/PartCustomField.vue index c282a27..dc20ffc 100644 --- a/elebox-tauri/src/components/PartCustomField.vue +++ b/elebox-tauri/src/components/PartCustomField.vue @@ -11,7 +11,7 @@ const props = defineProps<{ const custom_field = ref({ name: props.name, - field_type: props.field_type, + field_type: props.field_type || "Normal", value: props.value, }); @@ -34,50 +34,70 @@ function emitAdd() { return; } + if (custom_field.value.value) { + custom_field.value.value = ""; + } + emit("add", { new: custom_field.value }); } diff --git a/elebox-tauri/src/components/PartSupplier.vue b/elebox-tauri/src/components/PartSupplier.vue index 6e275b5..eee1901 100644 --- a/elebox-tauri/src/components/PartSupplier.vue +++ b/elebox-tauri/src/components/PartSupplier.vue @@ -38,51 +38,60 @@ function emitAdd() { From b118f8b7e690f87b5a6431cc2c8295d316916f6e Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 19:07:51 +0800 Subject: [PATCH 12/18] feat(tauri): modify custom field and supplier layout (gap) --- elebox-tauri/src/views/Part.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index ec331f9..17adee6 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -268,9 +268,9 @@ onMounted(() => { > - + - + { @del="handleCustomFieldDel" /> - + { - + { @del="handleSupplierDel" /> - + Date: Thu, 18 Jul 2024 19:13:03 +0800 Subject: [PATCH 13/18] feat(tauri): remove default 0 quantity of part --- elebox-tauri/src/views/Part.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 17adee6..f2e615b 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -19,6 +19,7 @@ const part = ref({ suppliers: [], }); +const qty_input = ref(undefined); const favorite = ref(); const alert = ref(false); @@ -42,6 +43,12 @@ let custom_fields = reactive([]); let suppliers = reactive([]); async function newPart() { + if (origin_name.value === undefined || qty_input.value === undefined) { + return; + } + + part.value.quantity = qty_input.value; + if ( part.value.name === "" || part.value.category === "" || @@ -55,10 +62,12 @@ async function newPart() { } async function updatePart() { - if (origin_name.value === undefined) { + if (origin_name.value === undefined || qty_input.value === undefined) { return; } + part.value.quantity = qty_input.value; + if ( part.value.name === "" || part.value.category === "" || @@ -88,6 +97,7 @@ async function getPackages() { async function getPart(name: string) { const data = await DbPart.get(name); part.value = data as DbPart.Part; + qty_input.value = part.value.quantity; Object.assign(custom_fields, part.value.custom_fields); Object.assign(suppliers, part.value.suppliers); } @@ -153,7 +163,7 @@ onMounted(() => { From 1b09aeb0c7dedc72c1b206e39a0c003737b7fff3 Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 20:07:41 +0800 Subject: [PATCH 16/18] fix(tauri): add and update part missing custom field and supplier --- elebox-tauri/src/views/Part.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 0da25c5..7e5893f 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -47,7 +47,7 @@ async function newPart() { return; } - part.value.quantity = qty_input.value; + part.value.quantity = Math.trunc(qty_input.value); if ( part.value.name === "" || @@ -57,7 +57,8 @@ async function newPart() { return; } - part.value.quantity = Math.trunc(part.value.quantity); + part.value.custom_fields = custom_fields; + part.value.suppliers = suppliers; await DbPart.add(part.value); } @@ -66,7 +67,7 @@ async function updatePart() { return; } - part.value.quantity = qty_input.value; + part.value.quantity = Math.trunc(qty_input.value); if ( part.value.name === "" || @@ -76,6 +77,8 @@ async function updatePart() { return; } + part.value.custom_fields = custom_fields; + part.value.suppliers = suppliers; await DbPart.update(origin_name.value, part.value); } From 8681d1ae7156b0ab87e15ad978352128cabdce0e Mon Sep 17 00:00:00 2001 From: ziteh Date: Thu, 18 Jul 2024 20:14:45 +0800 Subject: [PATCH 17/18] feat(tauri): add empty item for Mfr and package for remove --- elebox-tauri/src/views/Part.vue | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 7e5893f..7ea5386 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -1,7 +1,7 @@