made db work on relative paths
This commit is contained in:
parent
b38d0cc149
commit
5ef9f17436
8 changed files with 74 additions and 23 deletions
10
package-lock.json
generated
10
package-lock.json
generated
|
|
@ -6,6 +6,7 @@
|
|||
"": {
|
||||
"dependencies": {
|
||||
"@tauri-apps/plugin-dialog": "^2.2.0",
|
||||
"@tauri-apps/plugin-log": "^2.4.0",
|
||||
"@tauri-apps/plugin-sql": "^2.2.0"
|
||||
}
|
||||
},
|
||||
|
|
@ -28,6 +29,15 @@
|
|||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-log": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-log/-/plugin-log-2.4.0.tgz",
|
||||
"integrity": "sha512-j7yrDtLNmayCBOO2esl3aZv9jSXy2an8MDLry3Ys9ZXerwUg35n1Y2uD8HoCR+8Ng/EUgx215+qOUfJasjYrHw==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-sql": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-sql/-/plugin-sql-2.2.0.tgz",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@tauri-apps/plugin-dialog": "^2.2.0",
|
||||
"@tauri-apps/plugin-log": "^2.4.0",
|
||||
"@tauri-apps/plugin-sql": "^2.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
|
|
@ -156,6 +156,7 @@ dependencies = [
|
|||
"futures",
|
||||
"fuzzy-matcher",
|
||||
"html_tag",
|
||||
"log",
|
||||
"rand 0.9.1",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
|
|||
|
|
@ -36,5 +36,6 @@ confy = "0.6"
|
|||
diff-match-patch-rs = "0.5"
|
||||
rand = "0.9"
|
||||
futures = "0.3"
|
||||
log = "0.4.27"
|
||||
# [profile.dev]
|
||||
# codegen-backend = "cranelift"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
"fs:allow-home-read-recursive",
|
||||
"fs:scope-home-recursive",
|
||||
"fs:read-all",
|
||||
"dialog:default"
|
||||
"dialog:default",
|
||||
"log:default"
|
||||
]
|
||||
}
|
||||
|
|
@ -187,17 +187,28 @@ pub async fn store_diff(
|
|||
|
||||
// 1 insert into file_diffs with parent
|
||||
// 2 make last diff not currennt diff
|
||||
//
|
||||
|
||||
// id INTEGER NOT NULL,
|
||||
// client_id TEXT NOT NULL,
|
||||
// diff_text TEXT NOT NULL,
|
||||
// current_diff BOOLEAN,
|
||||
// FOREIGN KEY (id)
|
||||
// REFERENCES file_diffs (parent_diff_id)
|
||||
// FOREIGN KEY (id)
|
||||
// REFERENCES files (file_id)
|
||||
// parent_diff_id INTEGER,
|
||||
// file_id INTEGER,
|
||||
// FOREIGN KEY (parent_diff_id) REFERENCES file_diffs(id),
|
||||
// FOREIGN KEY (file_id) REFERENCES files(id),
|
||||
// PRIMARY KEY (id, client_id)
|
||||
let file_id = get_file_id(app_handle, relative_file_path, file_name).await?;
|
||||
let parent_diff_id: i32 = sqlx::query_scalar(&format!(
|
||||
"
|
||||
SELECT id from file_diffs
|
||||
WHERE relative_path IS '{relative_file_path}'
|
||||
AND file_name IS '{file_name}'
|
||||
AND working_diff is 1
|
||||
"
|
||||
))
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
let _ = sqlx::query(&format!(
|
||||
"
|
||||
UPDATE file_diffs
|
||||
|
|
@ -209,13 +220,13 @@ pub async fn store_diff(
|
|||
))
|
||||
.execute(&db)
|
||||
.await
|
||||
.map_err(|e| DBError::DatabaseQueryError(e.to_string()))?;
|
||||
.map_err(|e| DBError::DatabaseQueryError(e.to_string()));
|
||||
let _ = sqlx::query(&format!(
|
||||
"
|
||||
INSERT INTO
|
||||
file_diffs (client_id, diff_text, current_diff, file_id)
|
||||
VALUES
|
||||
('{client_id}', '{diff}', 1, );"
|
||||
('{client_id}', '{diff}', 1, {parent_diff_id});"
|
||||
))
|
||||
.execute(&db)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -4,14 +4,20 @@ use html_tag::HtmlTag;
|
|||
use shellexpand;
|
||||
use std::{
|
||||
fs::{self, DirEntry},
|
||||
path::Path,
|
||||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
#[tauri::command]
|
||||
pub async fn dir_tree_html(app_handle: tauri::AppHandle, filter: Vec<String>) -> String {
|
||||
if let Some(basepath) = get_basepath(app_handle.clone()) {
|
||||
add_dir_tree_node(&app_handle, &Path::new(&basepath), &filter)
|
||||
.await
|
||||
.to_html()
|
||||
add_dir_tree_node(
|
||||
&app_handle,
|
||||
&Path::new(&basepath),
|
||||
&filter,
|
||||
&Path::new(&basepath).parent().unwrap_or(Path::new("/")),
|
||||
)
|
||||
.await
|
||||
.to_html()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
|
|
@ -20,6 +26,7 @@ async fn add_dir_tree_node(
|
|||
app_handle: &tauri::AppHandle,
|
||||
path: &Path,
|
||||
filter: &Vec<String>,
|
||||
parent_path: &Path,
|
||||
) -> HtmlTag {
|
||||
let mut html = HtmlTag::new("div")
|
||||
.with_class("filetree-node")
|
||||
|
|
@ -48,24 +55,36 @@ async fn add_dir_tree_node(
|
|||
),
|
||||
),
|
||||
);
|
||||
|
||||
if let Ok(entries) = fs::read_dir(path) {
|
||||
for dir_entry_res in entries {
|
||||
if let Ok(dir_entry) = dir_entry_res {
|
||||
if let Ok(metadata) = fs::metadata(dir_entry.path()) {
|
||||
let absolute_path = dir_entry.path();
|
||||
let relative_path =
|
||||
absolute_path.strip_prefix(parent_path).unwrap_or_else(|_| {
|
||||
log::error!("{:?}:{:?}", path, parent_path);
|
||||
Path::new("/")
|
||||
});
|
||||
if metadata.is_file() {
|
||||
add_file(
|
||||
app_handle,
|
||||
path.to_string_lossy().as_ref(),
|
||||
relative_path.to_string_lossy().as_ref(),
|
||||
dir_entry.file_name().to_string_lossy().as_ref(),
|
||||
)
|
||||
.await;
|
||||
html.add_child(div_from_dir_entry(&dir_entry))
|
||||
html.add_child(div_from_dir_entry(&absolute_path, &relative_path))
|
||||
} else if metadata.is_dir() {
|
||||
html.add_child(
|
||||
Box::pin(add_dir_tree_node(app_handle, &dir_entry.path(), &filter))
|
||||
.await
|
||||
.with_attribute("style", "visibility: hidden; height: 0px;"), // .with_style("visibility", "hidden")
|
||||
// .with_style("height", "0px"),
|
||||
Box::pin(add_dir_tree_node(
|
||||
app_handle,
|
||||
&dir_entry.path(),
|
||||
&filter,
|
||||
parent_path,
|
||||
))
|
||||
.await
|
||||
.with_attribute("style", "visibility: hidden; height: 0px;"), // .with_style("visibility", "hidden")
|
||||
// .with_style("height", "0px"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -75,14 +94,13 @@ async fn add_dir_tree_node(
|
|||
return html;
|
||||
}
|
||||
|
||||
fn div_from_dir_entry(dir_entry: &DirEntry) -> HtmlTag {
|
||||
fn div_from_dir_entry(absolute_path: &Path, relative_path: &Path) -> HtmlTag {
|
||||
let mut file_div = HtmlTag::new("div")
|
||||
.with_class("filetree-node")
|
||||
.with_id(&format!("{}", dir_entry.path().to_string_lossy()))
|
||||
.with_id(&format!("{}", absolute_path.to_string_lossy()))
|
||||
.with_attribute("style", "visibility: hidden; height: 0px;");
|
||||
let mut file_button = HtmlTag::new("button").with_class("filetree-file-button");
|
||||
match dir_entry
|
||||
.path()
|
||||
match relative_path
|
||||
.extension()
|
||||
.unwrap_or_default()
|
||||
.to_string_lossy()
|
||||
|
|
@ -102,7 +120,14 @@ fn div_from_dir_entry(dir_entry: &DirEntry) -> HtmlTag {
|
|||
),
|
||||
};
|
||||
|
||||
file_button.add_child(HtmlTag::new("a").with_body(&dir_entry.file_name().to_string_lossy()));
|
||||
file_button.add_child(
|
||||
HtmlTag::new("a").with_body(
|
||||
&relative_path
|
||||
.file_name()
|
||||
.unwrap_or_default()
|
||||
.to_string_lossy(),
|
||||
),
|
||||
);
|
||||
file_div.add_child(file_button);
|
||||
return file_div;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ pub fn run() {
|
|||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.setup(|app| {
|
||||
// allowed the given directory
|
||||
let scope = app.fs_scope();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue