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(()) } 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); } } diff --git a/elebox-tauri/package.json b/elebox-tauri/package.json index 41ec1ca..a131835 100644 --- a/elebox-tauri/package.json +++ b/elebox-tauri/package.json @@ -1,7 +1,7 @@ { "name": "elebox", "private": true, - "version": "1.0.0-beta.1", + "version": "1.0.0-beta.2", "type": "module", "scripts": { "tauri dev": "tauri dev", diff --git a/elebox-tauri/src-tauri/Cargo.toml b/elebox-tauri/src-tauri/Cargo.toml index 77f7cb7..48de272 100644 --- a/elebox-tauri/src-tauri/Cargo.toml +++ b/elebox-tauri/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elebox" -version = "1.0.0-beta.1" +version = "1.0.0-beta.2" license = "MIT OR Apache-2.0" description = "Lightweight personal electronic parts inventory management tool" repository = "https://github.com/ziteh/elebox" diff --git a/elebox-tauri/src-tauri/src/main.rs b/elebox-tauri/src-tauri/src/main.rs index c5a2a63..00b831d 100644 --- a/elebox-tauri/src-tauri/src/main.rs +++ b/elebox-tauri/src-tauri/src/main.rs @@ -50,11 +50,11 @@ fn update_part(path: tauri::State, ori_name: &str, new_item: Part) -> Re } #[tauri::command(rename_all = "snake_case")] -fn del_part(path: tauri::State, item: &str) -> Result { +fn del_part(path: tauri::State, name: &str) -> Result { let p = GET!(path); let db = elebox_core::JammDatabase::new(&p); let mgr = elebox_core::PartManager::new(&db); - mgr.delete(item).map_err(|e| e.to_string()) + mgr.delete(name).map_err(|e| e.to_string()) } #[tauri::command(rename_all = "snake_case")] 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' }" > - {{ m.name }} - mdi-open-in-new 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/components/PartCustomField.vue b/elebox-tauri/src/components/PartCustomField.vue index 950c1df..80dbdc4 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, }); @@ -31,43 +31,79 @@ function emitAdd() { return; } - emit("add", { new: custom_field.value }); + const clone: CustomField = { + name: custom_field.value.name, + field_type: custom_field.value.field_type, + value: custom_field.value.value ?? "", + }; + + // Clear + custom_field.value = { + name: "", + field_type: "Normal", + value: "", + }; + + emit("add", { new: clone }); } diff --git a/elebox-tauri/src/components/PartDel.vue b/elebox-tauri/src/components/PartDel.vue index e7eb4c0..d84f409 100644 --- a/elebox-tauri/src/components/PartDel.vue +++ b/elebox-tauri/src/components/PartDel.vue @@ -1,13 +1,10 @@ @@ -15,7 +12,7 @@ async function partDel(part: string) { diff --git a/elebox-tauri/src/components/PartSupplier.vue b/elebox-tauri/src/components/PartSupplier.vue index 8f10dc5..9a574b9 100644 --- a/elebox-tauri/src/components/PartSupplier.vue +++ b/elebox-tauri/src/components/PartSupplier.vue @@ -1,5 +1,5 @@ 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[]; } diff --git a/elebox-tauri/src/router.ts b/elebox-tauri/src/router.ts index 2c63f95..447abbe 100644 --- a/elebox-tauri/src/router.ts +++ b/elebox-tauri/src/router.ts @@ -58,10 +58,5 @@ export default createRouter({ name: "update_manufacturer", component: () => import("./views/ManufacturerEdit.vue"), }, - { - path: "/tree", - name: "tree", - component: () => import("./views/CategoriesTree.vue"), - }, ], }); 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/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/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 }} - - - + diff --git a/elebox-tauri/src/views/Part.vue b/elebox-tauri/src/views/Part.vue index 5c6b4fa..7ea5386 100644 --- a/elebox-tauri/src/views/Part.vue +++ b/elebox-tauri/src/views/Part.vue @@ -1,7 +1,7 @@