Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ziteh committed Jul 18, 2024
2 parents 49eef41 + f8710dd commit bfdd8c4
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 257 deletions.
30 changes: 28 additions & 2 deletions elebox-core/src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion elebox-core/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion elebox-tauri/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion elebox-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions elebox-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ fn update_part(path: tauri::State<DbPath>, ori_name: &str, new_item: Part) -> Re
}

#[tauri::command(rename_all = "snake_case")]
fn del_part(path: tauri::State<DbPath>, item: &str) -> Result<String, String> {
fn del_part(path: tauri::State<DbPath>, name: &str) -> Result<String, String> {
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")]
Expand Down
5 changes: 0 additions & 5 deletions elebox-tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
title="Manufacturers"
:to="{ name: 'mfrs' }"
></v-list-item>
<v-list-item
prepend-icon="mdi-file-tree"
title="Tree"
:to="{ name: 'tree' }"
></v-list-item>
<v-list-item
prepend-icon="mdi-cog"
title="Settings"
Expand Down
9 changes: 9 additions & 0 deletions elebox-tauri/src/components/CategoryField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
6 changes: 1 addition & 5 deletions elebox-tauri/src/components/ManufacturerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ onMounted(list);
<tr v-for="(m, i) in mfrs" :key="i">
<td>
{{ m.name }}
<a
v-if="m.url !== '' && m.url !== undefined"
:title="m.url"
:href="m.url"
target="_blank"
<a v-if="m.url" :title="m.url" :href="m.url" target="_blank"
><v-icon>mdi-open-in-new</v-icon>
</a>
</td>
Expand Down
36 changes: 30 additions & 6 deletions elebox-tauri/src/components/PackageField.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<script setup lang="ts">
import { onMounted, ref, reactive } from "vue";
import { onMounted, ref } from "vue";
import { DbPackage as Db } from "../db_cmd_package";
import { PkgType } from "../interface"; // TODO to db_cmd_package
const props = defineProps<{ origin_name?: string }>();
const pkg = ref<Db.Package>({ name: "", pkg_type: "", alias: "" });
const pkg = ref<Db.Package>({ name: "", pkg_type: PkgType.Smt, alias: "" });
const pkg_type_input = ref<string>("SMT");
function setPkgType(input: string): PkgType {
// --noImplicitAny
// pkg.value.pkg_type = PkgType[pkg_type.value as keyof typeof PkgType];
if (input === "SMT") {
return PkgType.Smt;
} else if (input === "THT") {
return PkgType.Tht;
}
return PkgType.Others;
}
async function add() {
if (pkg.value === undefined) {
console.warn("undefined");
return;
}
pkg.value.pkg_type = setPkgType(pkg_type_input.value);
await Db.add(pkg.value);
}
Expand All @@ -19,18 +35,26 @@ async function update() {
return;
}
pkg.value.pkg_type = setPkgType(pkg_type_input.value);
await Db.update(props.origin_name, pkg.value);
}
async function get(name: string) {
const data = await Db.get(name);
pkg.value = data as Db.Package;
if (pkg.value.pkg_type == PkgType.Smt) {
pkg_type_input.value = "SMT";
} else if (pkg.value.pkg_type == PkgType.Tht) {
pkg_type_input.value = "THT";
} else {
pkg_type_input.value = "Others";
}
}
onMounted(() => {
if (props.origin_name !== undefined) {
get(props.origin_name);
pkg.value.pkg_type = pkg.value.pkg_type.toUpperCase(); // TODO no effect
}
});
</script>
Expand All @@ -43,22 +67,22 @@ 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
></v-select>
<v-text-field
label="Name"
variant="outlined"
v-model="pkg.name"
v-model.trim="pkg.name"
placeholder="SOT-23"
:rules="[(v: any) => !!v || 'Required']"
required
></v-text-field>
<v-text-field
label="Alias"
variant="outlined"
v-model="pkg.alias"
v-model.trim="pkg.alias"
placeholder=""
></v-text-field>

Expand Down
106 changes: 71 additions & 35 deletions elebox-tauri/src/components/PartCustomField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const props = defineProps<{
const custom_field = ref<CustomField>({
name: props.name,
field_type: props.field_type,
field_type: props.field_type || "Normal",
value: props.value,
});
Expand All @@ -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 });
}
</script>

<template>
<v-select
label="Type"
:items="['Normal', 'Link']"
variant="outlined"
v-model="custom_field.field_type"
></v-select>
<v-text-field
label="Name"
variant="outlined"
v-model.trim="custom_field.name"
placeholder=""
></v-text-field>
<v-text-field
label="Value"
variant="outlined"
v-model.trim="custom_field.value"
placeholder=""
></v-text-field>
<v-form @submit.prevent>
<v-row class="ma-2 ga-8">
<v-select
v-if="props.create"
label="Type"
:items="['Normal', 'Link']"
variant="outlined"
v-model="custom_field.field_type"
:rules="[(v: any) => !!v || 'Required']"
required
:readonly="!props.create"
></v-select>
<v-text-field
v-else
label="Type"
variant="outlined"
v-model.trim="custom_field.field_type"
required
readonly
></v-text-field>
<v-text-field
label="Name"
variant="outlined"
v-model.trim="custom_field.name"
placeholder=""
:rules="[(v: any) => !!v || 'Required']"
required
:readonly="!props.create"
></v-text-field>
<v-text-field
label="Value"
variant="outlined"
v-model.trim="custom_field.value"
placeholder=""
:readonly="!props.create"
:dirty="!props.create"
></v-text-field>

<v-btn
v-if="!props.create"
density="comfortable"
icon="mdi-trash-can-outline"
title="Delete"
@click="emitDel()"
></v-btn>
<v-btn
v-if="props.create"
density="comfortable"
icon="mdi-plus"
title="Add"
color="green"
@click="emitAdd()"
></v-btn>
<v-btn
v-if="props.create"
density="comfortable"
icon="mdi-plus"
title="Add"
color="green"
type="submit"
@click="emitAdd()"
></v-btn>
<v-btn
v-else
density="comfortable"
icon="mdi-trash-can-outline"
title="Delete"
type="submit"
@click="emitDel()"
></v-btn>
</v-row>
</v-form>
</template>
15 changes: 6 additions & 9 deletions elebox-tauri/src/components/PartDel.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<script setup lang="ts">
import { invoke } from "@tauri-apps/api/tauri";
import { DbPart as Db } from "../db_cmd_part";
defineProps({
part: String,
});
const props = defineProps<{ part: string }>();
async function partDel(part: string) {
console.debug(`Part delete: ${part}`);
await invoke("part_del", { part });
async function remove() {
await Db.remove(props.part);
}
</script>

<template>
<v-btn
density="comfortable"
icon="mdi-trash-can-outline"
:title="`Delete: ${part}`"
@click="partDel(part!)"
:title="`Delete: ${props.part}`"
@click="remove"
></v-btn>
</template>
Loading

0 comments on commit bfdd8c4

Please sign in to comment.