Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f0999772 | ||
|
|
39f8845119 | ||
|
|
e7023752f1 | ||
|
|
746071125a | ||
|
|
bb673ed7c7 | ||
|
|
98c8093961 | ||
|
|
a4d77196d0 | ||
|
|
4187344a29 | ||
|
|
d3c28179b6 | ||
|
|
3cd7c12baa | ||
|
|
306febc514 | ||
|
|
80785ff9e6 | ||
|
|
9e28b05167 | ||
|
|
97c76350e1 | ||
|
|
99b3818181 | ||
|
|
3fcbd235cf | ||
|
|
dcf7352553 | ||
|
|
11b38479c1 | ||
|
|
51c8d7be74 | ||
|
|
8f789facd7 | ||
|
|
e676898135 | ||
|
|
9917702c4c | ||
|
|
0332e40feb | ||
|
|
eb6c9c5084 | ||
|
|
17e06256c1 | ||
|
|
4d0788e0f5 | ||
|
|
4ca7aa7044 |
Generated
+298
@@ -24,6 +24,17 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8eb277bec05f56a0e0591f155a484cbd0f4f07ff2905051a48c72f004f7ed58"
|
||||||
|
dependencies = [
|
||||||
|
"cipher",
|
||||||
|
"cpubits",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.8.12"
|
version = "0.8.12"
|
||||||
@@ -62,6 +73,12 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alsa"
|
name = "alsa"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -386,6 +403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hybrid-array",
|
"hybrid-array",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -457,6 +475,15 @@ version = "1.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bzip2"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
|
||||||
|
dependencies = [
|
||||||
|
"libbz2-rs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "calloop"
|
name = "calloop"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
@@ -595,6 +622,16 @@ dependencies = [
|
|||||||
"half",
|
"half",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.6.1"
|
version = "4.6.1"
|
||||||
@@ -668,6 +705,12 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cmov"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "codespan-reporting"
|
name = "codespan-reporting"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
@@ -730,6 +773,12 @@ dependencies = [
|
|||||||
"tiny-keccak",
|
"tiny-keccak",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "constant_time_eq"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@@ -868,6 +917,12 @@ dependencies = [
|
|||||||
"windows 0.62.2",
|
"windows 0.62.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpubits"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -980,6 +1035,15 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b29fccfdaeb0f9bd90da5759b1d0eaa2f6cfcfe90960124cfc83141ed4e111fd"
|
checksum = "b29fccfdaeb0f9bd90da5759b1d0eaa2f6cfcfe90960124cfc83141ed4e111fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ctutils"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
|
||||||
|
dependencies = [
|
||||||
|
"cmov",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cursor-icon"
|
name = "cursor-icon"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -998,6 +1062,18 @@ version = "0.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
|
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deflate64"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
@@ -1007,6 +1083,8 @@ dependencies = [
|
|||||||
"block-buffer",
|
"block-buffer",
|
||||||
"const-oid",
|
"const-oid",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
|
"ctutils",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1043,6 +1121,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
|
"block2 0.6.2",
|
||||||
|
"libc",
|
||||||
"objc2 0.6.3",
|
"objc2 0.6.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1244,6 +1324,7 @@ checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
|
"zlib-rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1675,6 +1756,8 @@ version = "0.17.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"allocator-api2",
|
||||||
|
"equivalent",
|
||||||
"foldhash 0.2.0",
|
"foldhash 0.2.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1717,6 +1800,15 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hmac"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -2175,6 +2267,15 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.12.0"
|
version = "2.12.0"
|
||||||
@@ -2213,11 +2314,15 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"criterion",
|
"criterion",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"hashbrown 0.17.1",
|
||||||
"hex",
|
"hex",
|
||||||
"iced",
|
"iced",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
"mimalloc",
|
||||||
"rand",
|
"rand",
|
||||||
|
"rayon",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"rfd",
|
||||||
"rhai",
|
"rhai",
|
||||||
"rodio",
|
"rodio",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
@@ -2225,6 +2330,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"zip",
|
||||||
"zstd",
|
"zstd",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2369,6 +2475,12 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libbz2-rs-sys"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.189"
|
version = "0.2.189"
|
||||||
@@ -2391,6 +2503,15 @@ version = "0.2.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libmimalloc-sys"
|
||||||
|
version = "0.1.49"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
@@ -2479,6 +2600,15 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lzma-rust2"
|
||||||
|
version = "0.16.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca93e534d1142d1d0dcca6d25fe302508a5dfb40b302802904577725ea0b695b"
|
||||||
|
dependencies = [
|
||||||
|
"sha2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mach2"
|
name = "mach2"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -2536,6 +2666,15 @@ dependencies = [
|
|||||||
"paste",
|
"paste",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mimalloc"
|
||||||
|
version = "0.1.52"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
|
||||||
|
dependencies = [
|
||||||
|
"libmimalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
@@ -2654,6 +2793,15 @@ dependencies = [
|
|||||||
"jni-sys 0.3.0",
|
"jni-sys 0.3.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "no-std-compat"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
|
||||||
|
dependencies = [
|
||||||
|
"spin",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -2664,6 +2812,12 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-derive"
|
name = "num-derive"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -3280,6 +3434,16 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pbkdf2"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"hmac",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
@@ -3396,6 +3560,12 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pollster"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portable-atomic"
|
name = "portable-atomic"
|
||||||
version = "1.13.1"
|
version = "1.13.1"
|
||||||
@@ -3420,6 +3590,18 @@ dependencies = [
|
|||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppmd-rust"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "presser"
|
name = "presser"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -3779,6 +3961,33 @@ dependencies = [
|
|||||||
"zune-jpeg",
|
"zune-jpeg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rfd"
|
||||||
|
version = "0.17.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220"
|
||||||
|
dependencies = [
|
||||||
|
"block2 0.6.2",
|
||||||
|
"dispatch2",
|
||||||
|
"js-sys",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"objc2 0.6.3",
|
||||||
|
"objc2-app-kit 0.3.2",
|
||||||
|
"objc2-core-foundation",
|
||||||
|
"objc2-foundation 0.3.2",
|
||||||
|
"percent-encoding",
|
||||||
|
"pollster",
|
||||||
|
"raw-window-handle",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"wayland-backend",
|
||||||
|
"wayland-client",
|
||||||
|
"wayland-protocols",
|
||||||
|
"web-sys",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rgb"
|
name = "rgb"
|
||||||
version = "0.8.53"
|
version = "0.8.53"
|
||||||
@@ -3796,6 +4005,7 @@ checksum = "dd4dd0f8c36625202a4ba553c416c19b719947cd2a31d1bda06126e4a5727daf"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
|
"no-std-compat",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rhai_codegen",
|
"rhai_codegen",
|
||||||
@@ -4162,6 +4372,17 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -4381,6 +4602,12 @@ dependencies = [
|
|||||||
"x11rb",
|
"x11rb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spirv"
|
name = "spirv"
|
||||||
version = "0.3.0+sdk-1.3.268.0"
|
version = "0.3.0+sdk-1.3.268.0"
|
||||||
@@ -4743,6 +4970,26 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"js-sys",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde_core",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiny-keccak"
|
name = "tiny-keccak"
|
||||||
version = "2.0.2"
|
version = "2.0.2"
|
||||||
@@ -4997,6 +5244,12 @@ dependencies = [
|
|||||||
"core_maths",
|
"core_maths",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typed-path"
|
||||||
|
version = "0.12.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.20.0"
|
version = "1.20.0"
|
||||||
@@ -6437,12 +6690,57 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zip"
|
||||||
|
version = "8.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b"
|
||||||
|
dependencies = [
|
||||||
|
"aes",
|
||||||
|
"bzip2",
|
||||||
|
"constant_time_eq",
|
||||||
|
"crc32fast",
|
||||||
|
"deflate64",
|
||||||
|
"flate2",
|
||||||
|
"getrandom 0.4.1",
|
||||||
|
"hmac",
|
||||||
|
"indexmap",
|
||||||
|
"lzma-rust2",
|
||||||
|
"memchr",
|
||||||
|
"pbkdf2",
|
||||||
|
"ppmd-rust",
|
||||||
|
"sha1",
|
||||||
|
"time",
|
||||||
|
"typed-path",
|
||||||
|
"zeroize",
|
||||||
|
"zopfli",
|
||||||
|
"zstd",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zlib-rs"
|
||||||
|
version = "0.6.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
|
checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zopfli"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"crc32fast",
|
||||||
|
"log",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.13.3"
|
version = "0.13.3"
|
||||||
|
|||||||
+17
-8
@@ -10,7 +10,7 @@ rand = "0.10.2"
|
|||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
serde = { version = "1.0.229", features = ["derive"] }
|
serde = { version = "1.0.229", features = ["derive"] }
|
||||||
serde_json = "1.0.151"
|
serde_json = "1.0.151"
|
||||||
rhai = "1.25.1"
|
rhai = { version = "1.25.1", features = ["sync"] }
|
||||||
chrono = "0.4.45"
|
chrono = "0.4.45"
|
||||||
rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
||||||
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
|
||||||
@@ -19,16 +19,25 @@ sha2 = "0.11.0"
|
|||||||
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros"] }
|
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
zstd = "0.13.3"
|
zstd = "0.13.3"
|
||||||
|
zip = "8.6.0"
|
||||||
[dev-dependencies]
|
rfd = "0.17.2"
|
||||||
criterion = "0.8.2"
|
mimalloc = "0.1.52"
|
||||||
|
hashbrown = "0.17.1"
|
||||||
[[bench]]
|
rayon = "1.12.0"
|
||||||
name = "split_bench" # Имя файла в benches/ без расширения
|
|
||||||
harness = false # Отключаем стандартный тестовый раннер
|
|
||||||
|
|
||||||
[profile.super-release]
|
[profile.super-release]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
lto = true
|
lto = true
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
strip = true
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = { version = "0.8.2", features = ["html_reports"] }
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "map_bench"
|
||||||
|
harness = false
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
use std::collections::HashMap as StdHashMap;
|
||||||
|
use std::hint::black_box;
|
||||||
|
|
||||||
|
use hashbrown::HashMap as BrownHashMap;
|
||||||
|
|
||||||
|
const SIZES: [usize; 3] = [5, 10, 50];
|
||||||
|
const QUERY_COUNT: usize = 4096;
|
||||||
|
|
||||||
|
/// Детерминированный ключ ~17 символов, например "key_9e3779b9_0042".
|
||||||
|
fn make_key(i: u64) -> String {
|
||||||
|
let h = i.wrapping_mul(0x9E37_79B9_7F4A_7C15);
|
||||||
|
format!("key_{:08x}_{:04}", h & 0xFFFF_FFFF, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для длинных ключей (пути/URL) замени на:
|
||||||
|
// fn make_key(i: u64) -> String {
|
||||||
|
// format!(
|
||||||
|
// "/api/v2/users/{i}/settings/visibility_{:08x}",
|
||||||
|
// i.wrapping_mul(0x9E37_79B9)
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn make_vec(n: usize) -> Vec<(String, u64)> {
|
||||||
|
(0..n as u64).map(|i| (make_key(i), i)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_std_map(data: &[(String, u64)]) -> StdHashMap<String, u64> {
|
||||||
|
data.iter().map(|(k, v)| (k.clone(), *v)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_brown_map(data: &[(String, u64)]) -> BrownHashMap<String, u64> {
|
||||||
|
data.iter().map(|(k, v)| (k.clone(), *v)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_queries(n: usize, with_misses: bool) -> Vec<String> {
|
||||||
|
let keys: Vec<String> = (0..n as u64).map(make_key).collect();
|
||||||
|
let missing = "__missing_key__".to_string();
|
||||||
|
|
||||||
|
(0..QUERY_COUNT)
|
||||||
|
.map(|i| {
|
||||||
|
if with_misses && i % 16 == 15 {
|
||||||
|
missing.clone()
|
||||||
|
} else {
|
||||||
|
let idx = i.wrapping_mul(2_654_435_761) % n;
|
||||||
|
keys[idx].clone()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_std(map: &StdHashMap<String, u64>, queries: &[String]) -> u64 {
|
||||||
|
let mut sum = 0u64;
|
||||||
|
for q in queries {
|
||||||
|
match map.get(black_box(q.as_str())) {
|
||||||
|
Some(v) => sum = sum.wrapping_add(*v),
|
||||||
|
None => sum = sum.wrapping_add(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
black_box(sum)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_brown(map: &BrownHashMap<String, u64>, queries: &[String]) -> u64 {
|
||||||
|
let mut sum = 0u64;
|
||||||
|
for q in queries {
|
||||||
|
match map.get(black_box(q.as_str())) {
|
||||||
|
Some(v) => sum = sum.wrapping_add(*v),
|
||||||
|
None => sum = sum.wrapping_add(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
black_box(sum)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_vec(data: &[(String, u64)], queries: &[String]) -> u64 {
|
||||||
|
let mut sum = 0u64;
|
||||||
|
for q in queries {
|
||||||
|
let q = black_box(q);
|
||||||
|
match data.iter().find(|(k, _)| k == q) {
|
||||||
|
Some((_, v)) => sum = sum.wrapping_add(*v),
|
||||||
|
None => sum = sum.wrapping_add(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
black_box(sum)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench(c: &mut Criterion) {
|
||||||
|
let mut group = c.benchmark_group("map_vs_vec_str");
|
||||||
|
|
||||||
|
for n in SIZES {
|
||||||
|
let vec_data = make_vec(n);
|
||||||
|
let std_map = make_std_map(&vec_data);
|
||||||
|
let brown_map = make_brown_map(&vec_data);
|
||||||
|
|
||||||
|
let queries_hit = make_queries(n, false);
|
||||||
|
let queries_mixed = make_queries(n, true);
|
||||||
|
|
||||||
|
// std::collections::HashMap (SipHash)
|
||||||
|
group.bench_function(format!("std_hashmap_hit/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_std(black_box(&std_map), black_box(&queries_hit)))
|
||||||
|
});
|
||||||
|
group.bench_function(format!("std_hashmap_mixed/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_std(black_box(&std_map), black_box(&queries_mixed)))
|
||||||
|
});
|
||||||
|
|
||||||
|
// hashbrown (SwissTable + foldhash)
|
||||||
|
group.bench_function(format!("hashbrown_hit/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_brown(black_box(&brown_map), black_box(&queries_hit)))
|
||||||
|
});
|
||||||
|
group.bench_function(format!("hashbrown_mixed/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_brown(black_box(&brown_map), black_box(&queries_mixed)))
|
||||||
|
});
|
||||||
|
|
||||||
|
// Vec<(String, u64)>, линейный поиск
|
||||||
|
group.bench_function(format!("vec_linear_hit/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_vec(black_box(&vec_data), black_box(&queries_hit)))
|
||||||
|
});
|
||||||
|
group.bench_function(format!("vec_linear_mixed/{n}"), |b| {
|
||||||
|
b.iter(|| lookup_vec(black_box(&vec_data), black_box(&queries_mixed)))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, bench);
|
||||||
|
criterion_main!(benches);
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
||||||
|
|
||||||
fn bench_split(c: &mut Criterion) {
|
|
||||||
let input = "data_1";
|
|
||||||
|
|
||||||
c.bench_function("split_with_comma", |b| {
|
|
||||||
b.iter(|| {
|
|
||||||
// black_box запрещает компилятору оптимизировать результат
|
|
||||||
black_box(split_with_coma(black_box(input)))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_split_new(c: &mut Criterion) {
|
|
||||||
let input = "data_1";
|
|
||||||
|
|
||||||
c.bench_function("split_with_comma gpt", |b| {
|
|
||||||
b.iter(|| {
|
|
||||||
// black_box запрещает компилятору оптимизировать результат
|
|
||||||
black_box(split_with_coma(black_box(input)))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
|
||||||
ts.split(',')
|
|
||||||
.map(|ts| ts.to_lowercase().trim().to_string())
|
|
||||||
.filter(|t| !t.is_empty())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_split_with_coma(ts: &str) -> Vec<String> {
|
|
||||||
ts.split(',')
|
|
||||||
.map(|s| s.trim()) // 0 аллокаций, просто срез
|
|
||||||
.filter(|s| !s.is_empty()) // отбрасываем пустые до аллокации
|
|
||||||
.map(|s| s.to_lowercase()) // 1 аллокация на валидный токен
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Можно добавить несколько бенчмарков в группу
|
|
||||||
criterion_group!(benches, bench_split, bench_split_new);
|
|
||||||
criterion_main!(benches);
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
use crate::lang::SetOrderMode;
|
use crate::lang::{DeckSettings, OrderMode};
|
||||||
use crate::repetitions::CardSetSettings;
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
pub fn load_sets(connection: &Connection) -> Vec<DeckSettings> {
|
||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
.prepare("SELECT id, name, forward, backward, filter FROM card_set")
|
.prepare("SELECT id, name, forward, backward, filter FROM card_set")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let iter = stmt
|
let iter = stmt
|
||||||
.query_map([], |row| {
|
.query_map([], |row| {
|
||||||
Ok(CardSetSettings {
|
Ok(DeckSettings {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
name: row.get(1)?,
|
name: row.get(1)?,
|
||||||
forward: row.get(2)?,
|
forward: row.get(2)?,
|
||||||
@@ -16,7 +16,7 @@ pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
|||||||
filter: row.get(4)?,
|
filter: row.get(4)?,
|
||||||
count: None,
|
count: None,
|
||||||
worst_words_list: None,
|
worst_words_list: None,
|
||||||
open_mode: SetOrderMode::Default,
|
open_mode: OrderMode::Default,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -29,7 +29,7 @@ pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
|||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_set(set: &mut CardSetSettings, connection: &Connection) {
|
pub fn add_set(set: &mut DeckSettings, connection: &Connection) {
|
||||||
let index = connection
|
let index = connection
|
||||||
.query_row(
|
.query_row(
|
||||||
"INSERT INTO card_set (name, forward, backward, filter) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
"INSERT INTO card_set (name, forward, backward, filter) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||||
@@ -43,12 +43,12 @@ pub fn add_set(set: &mut CardSetSettings, connection: &Connection) {
|
|||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {println!("{}", e); 0});
|
.unwrap_or_else(|e| {println!("{}", e); 0});
|
||||||
|
|
||||||
set.id = index;
|
set.id = index.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_card_set(set: &mut CardSetSettings, connection: &Connection) {
|
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) {
|
||||||
if set.id == 0 {
|
if !set.id.is_valid() {
|
||||||
add_set(set, &connection);
|
add_set(set, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
@@ -65,8 +65,8 @@ pub fn update_card_set(set: &mut CardSetSettings, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_set(set: &CardSetSettings, connection: &Connection) {
|
pub fn delete_set(set: &DeckSettings, connection: &Connection) {
|
||||||
if set.id == 0 {
|
if !set.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use crate::lang::CardStatistics;
|
use crate::lang::{CardStatistics, DeckSettings};
|
||||||
use crate::repetitions::CardSetSettings;
|
use rusqlite::{params, Connection};
|
||||||
use rusqlite::Connection;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<CardStatistics> {
|
pub fn load_stats_of_deck(set: &DeckSettings, connection: &Connection) -> Vec<CardStatistics> {
|
||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
.prepare("SELECT id, word_id, score, last_opened FROM card_stats WHERE set_id = ?1")
|
.prepare("SELECT id, word_id, score, last_opened FROM card_stats WHERE set_id = ?1")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -27,66 +26,40 @@ pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<
|
|||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
|
pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection) {
|
||||||
let inserting = stat
|
let time = Instant::now();
|
||||||
.iter()
|
let tx = connection.transaction().unwrap();
|
||||||
.map(|stat| {
|
let count = stats.len();
|
||||||
format!(
|
|
||||||
"({}, {}, {}, {})",
|
|
||||||
stat.word_id.to_string(),
|
|
||||||
stat.set_id.to_string(),
|
|
||||||
stat.score.to_string(),
|
|
||||||
stat.last_open.timestamp().to_string()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
let query = format!(
|
|
||||||
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES {}",
|
|
||||||
inserting
|
|
||||||
);
|
|
||||||
let count = connection.execute(query.as_str(), ());
|
|
||||||
|
|
||||||
if count.is_err() {
|
{
|
||||||
println!("{}", count.unwrap_err());
|
let mut stmt = tx
|
||||||
return;
|
.prepare(
|
||||||
}
|
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4)",
|
||||||
|
|
||||||
let last_index: u32 = connection
|
|
||||||
.query_one(
|
|
||||||
"SELECT seq from sqlite_sequence WHERE name == ?1",
|
|
||||||
("card_stats".to_string(),),
|
|
||||||
|row| row.get(0),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let start_index = last_index - (count.unwrap() as u32) + 1;
|
for stat in stats.iter() {
|
||||||
|
stmt.execute(params![
|
||||||
let mut index = 0;
|
stat.word_id,
|
||||||
for id in start_index..=last_index {
|
stat.set_id,
|
||||||
stat[index].id = id;
|
stat.score,
|
||||||
index += 1;
|
stat.last_open.timestamp()
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
let last_index: u32 = tx.last_insert_rowid() as u32;
|
||||||
// let time = Instant::now();
|
tx.commit().unwrap();
|
||||||
// let index = connection
|
|
||||||
// .query_row(
|
let start_index = last_index - (count as u32) + 1;
|
||||||
// "INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
|
||||||
// (
|
for (index, id) in (start_index..=last_index).enumerate() {
|
||||||
// &stat.word_id,
|
stats[index].id = id.into();
|
||||||
// &stat.set_id,
|
}
|
||||||
// &stat.score,
|
|
||||||
// &stat.last_open.timestamp(),
|
println!("Added {} cards for {:?}", stats.len(), time.elapsed());
|
||||||
// ),
|
}
|
||||||
// |row| row.get(0)
|
|
||||||
// )
|
|
||||||
// .unwrap_or_else(|e| {println!("{}", e); 0});
|
|
||||||
//
|
|
||||||
// stat.id = index;
|
|
||||||
// println!("Added stat: {}", time.elapsed().as_millis());
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
@@ -104,7 +77,7 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
||||||
if stat.id == 0 {
|
if !stat.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use std::fs;
|
|
||||||
use crate::dictionary::app_data_dir;
|
use crate::dictionary::app_data_dir;
|
||||||
use crate::lang::WordOpenMode;
|
use crate::lang::{Id, WordOpenMode};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
use std::fs;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn get_history_of_set(id: u32) -> Vec<HistoryItem> {
|
pub fn get_history_of_set(id: Id) -> Vec<HistoryItem> {
|
||||||
let app_dir = history_dir();
|
let app_dir = history_dir();
|
||||||
let head = app_dir.clone().join(format!("set_{}_history.csv", id));
|
let head = app_dir.clone().join(format!("set_{}_history.csv", id));
|
||||||
let mut lines = Vec::new();
|
let mut lines = Vec::new();
|
||||||
@@ -32,7 +32,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
|||||||
if let [time, word, mode, before, after] = string.split(';').collect::<Vec<&str>>()[..] {
|
if let [time, word, mode, before, after] = string.split(';').collect::<Vec<&str>>()[..] {
|
||||||
items.push(HistoryItem {
|
items.push(HistoryItem {
|
||||||
timestamp: DateTime::from_timestamp(time.parse().unwrap(), 0).unwrap(),
|
timestamp: DateTime::from_timestamp(time.parse().unwrap(), 0).unwrap(),
|
||||||
word_id: word.parse::<u32>().unwrap(),
|
word_id: word.parse::<Id>().unwrap(),
|
||||||
mode: match mode.parse::<u8>().unwrap() {
|
mode: match mode.parse::<u8>().unwrap() {
|
||||||
2 => WordOpenMode::Hard,
|
2 => WordOpenMode::Hard,
|
||||||
3 => WordOpenMode::Ok,
|
3 => WordOpenMode::Ok,
|
||||||
@@ -48,7 +48,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
|||||||
items
|
items
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_note(set_id: u32, item: HistoryItem) {
|
pub fn push_note(set_id: Id, item: HistoryItem) {
|
||||||
let app_dir = history_dir();
|
let app_dir = history_dir();
|
||||||
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
|
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ pub fn push_note(set_id: u32, item: HistoryItem) {
|
|||||||
item.before,
|
item.before,
|
||||||
item.after
|
item.after
|
||||||
);
|
);
|
||||||
writeln!(&mut file, "{}", line_str.to_string()).unwrap();
|
writeln!(&mut file, "{}", line_str).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn history_dir() -> PathBuf {
|
pub fn history_dir() -> PathBuf {
|
||||||
@@ -84,7 +84,7 @@ pub fn history_dir() -> PathBuf {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HistoryItem {
|
pub struct HistoryItem {
|
||||||
pub timestamp: DateTime<Utc>,
|
pub timestamp: DateTime<Utc>,
|
||||||
pub word_id: u32,
|
pub word_id: Id,
|
||||||
pub mode: WordOpenMode,
|
pub mode: WordOpenMode,
|
||||||
pub before: u8,
|
pub before: u8,
|
||||||
pub after: u8,
|
pub after: u8,
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
use hashbrown::HashMap;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ImportGroup {
|
||||||
|
pub id: u64,
|
||||||
|
pub name: String,
|
||||||
|
pub fields: Vec<String>,
|
||||||
|
pub length: u64,
|
||||||
|
pub mapping: HashMap<String, String>,
|
||||||
|
pub imported: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportNote {
|
||||||
|
pub tags: String,
|
||||||
|
pub fields: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_groups(connection: &Connection) -> ImportData {
|
||||||
|
let json_models: String = connection
|
||||||
|
.query_one("select models from col", (), |row| row.get(0))
|
||||||
|
.unwrap();
|
||||||
|
let raw: Value = serde_json::from_str(json_models.as_str()).unwrap();
|
||||||
|
let sets = raw.as_object().unwrap();
|
||||||
|
let mut total_data = ImportData(vec![]);
|
||||||
|
|
||||||
|
let mut count_stmt = connection
|
||||||
|
.prepare("select mid, count(id) from notes group by mid")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let counts = count_stmt
|
||||||
|
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||||
|
.unwrap()
|
||||||
|
.map(|x| x.unwrap())
|
||||||
|
.collect::<Vec<(i64, i64)>>();
|
||||||
|
|
||||||
|
for (_, collection) in sets {
|
||||||
|
let fields = collection["flds"]
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||||
|
.collect();
|
||||||
|
let mut group = ImportGroup {
|
||||||
|
id: collection["id"].as_u64().unwrap(),
|
||||||
|
name: collection["name"].as_str().unwrap().to_string(),
|
||||||
|
fields,
|
||||||
|
mapping: Default::default(),
|
||||||
|
length: 0,
|
||||||
|
imported: false,
|
||||||
|
};
|
||||||
|
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
||||||
|
group.length = *count as u64
|
||||||
|
}
|
||||||
|
println!("{:?}", group);
|
||||||
|
total_data.0.push(group);
|
||||||
|
}
|
||||||
|
total_data
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Vec<ImportNote> {
|
||||||
|
let mut count_stmt = connection
|
||||||
|
.prepare("select tags, flds from notes where mid == ?1;")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
count_stmt
|
||||||
|
.query_map((group_id as i64,), |row| {
|
||||||
|
Ok(ImportNote {
|
||||||
|
tags: row.get(0)?,
|
||||||
|
fields: row
|
||||||
|
.get::<usize, String>(1)?
|
||||||
|
.split('')
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.map(|x| x.unwrap())
|
||||||
|
.collect::<Vec<ImportNote>>()
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
pub(crate) mod card_sets;
|
pub(crate) mod card_sets;
|
||||||
pub(crate) mod card_stats;
|
pub(crate) mod card_stats;
|
||||||
pub(crate) mod history;
|
pub(crate) mod history;
|
||||||
|
pub(crate) mod import;
|
||||||
pub(crate) mod settings;
|
pub(crate) mod settings;
|
||||||
pub(crate) mod sqlite;
|
pub(crate) mod sqlite;
|
||||||
pub(crate) mod voice;
|
pub(crate) mod voice;
|
||||||
pub(crate) mod words;
|
|
||||||
pub(crate) mod web_api;
|
pub(crate) mod web_api;
|
||||||
|
pub(crate) mod words;
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ pub fn get_setting(key: String, connection: &Connection) -> Option<String> {
|
|||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
.prepare("SELECT value FROM settings WHERE id = ?1")
|
.prepare("SELECT value FROM settings WHERE id = ?1")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
|
let mut iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
|
||||||
|
|
||||||
for row in iter {
|
if let Some(row) = iter.next()
|
||||||
if let Ok(value) = row {
|
&& let Ok(value) = row
|
||||||
|
{
|
||||||
return Some(value);
|
return Some(value);
|
||||||
}
|
}
|
||||||
return None;
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::dictionary::app_data_dir;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use tokio::fs::{File, OpenOptions};
|
use tokio::fs::{File, OpenOptions};
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use zstd::{Decoder, Encoder, DEFAULT_COMPRESSION_LEVEL};
|
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
||||||
|
|
||||||
// const API_URL: &str = "http://127.0.0.1:8089/";
|
// const API_URL: &str = "http://127.0.0.1:8089/";
|
||||||
const API_URL: &str = "https://learning.micialware.ru/";
|
const API_URL: &str = "https://learning.micialware.ru/";
|
||||||
@@ -17,15 +17,22 @@ pub async fn send_data(id: String) {
|
|||||||
let id_url = format!("{api_url}upload/stream/{id}");
|
let id_url = format!("{api_url}upload/stream/{id}");
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let new_version = client.post(&id_url).body(data).send().await.unwrap().text().await.unwrap();
|
let new_version = client
|
||||||
|
.post(&id_url)
|
||||||
|
.body(data)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
set_local_version(new_version.parse::<u32>().unwrap()).await;
|
set_local_version(new_version.parse::<u32>().unwrap()).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compress(data: Vec<u8>) -> Vec<u8> {
|
fn compress(data: Vec<u8>) -> Vec<u8> {
|
||||||
let mut encoder = Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).unwrap();
|
let mut encoder = Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).unwrap();
|
||||||
io::copy(&mut &data[..], &mut encoder).unwrap();
|
io::copy(&mut &data[..], &mut encoder).unwrap();
|
||||||
let compressed = encoder.finish().unwrap();
|
encoder.finish().unwrap()
|
||||||
compressed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load_data(id: String, temp: bool) {
|
pub async fn load_data(id: String, temp: bool) {
|
||||||
@@ -50,7 +57,14 @@ pub async fn load_data(id: String, temp: bool) {
|
|||||||
tokio::fs::write(db_file, data).await.unwrap();
|
tokio::fs::write(db_file, data).await.unwrap();
|
||||||
|
|
||||||
let version_url = format!("{API_URL}{id}/version");
|
let version_url = format!("{API_URL}{id}/version");
|
||||||
let version = client.get(&version_url).send().await.unwrap().text().await.unwrap();
|
let version = client
|
||||||
|
.get(&version_url)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
set_local_version(version.parse::<u32>().unwrap()).await;
|
set_local_version(version.parse::<u32>().unwrap()).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,25 +98,44 @@ pub async fn get_web_version(key: &str) -> Result<u32, reqwest::Error> {
|
|||||||
let id_url = format!("{API_URL}{key}/version");
|
let id_url = format!("{API_URL}{key}/version");
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let version = client.get(&id_url).send().await?.text().await?;
|
let version = client.get(&id_url).send().await?.text().await?;
|
||||||
return Ok(version.parse::<u32>().unwrap());
|
println!("version: {}", version);
|
||||||
|
Ok(version.parse::<u32>().unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_local_version() -> u32 {
|
pub async fn get_local_version() -> u32 {
|
||||||
let file = app_data_dir().join("data.meta");
|
let file = app_data_dir().join("data.meta");
|
||||||
if file.exists() {
|
if file.exists() {
|
||||||
let mut data = String::new();
|
let mut data = String::new();
|
||||||
File::open(file.clone()).await.unwrap().read_to_string(&mut data).await.unwrap();
|
File::open(file.clone())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.read_to_string(&mut data)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
return data.parse::<u32>().unwrap();
|
return data.parse::<u32>().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = OpenOptions::new().write(true).create(true).open(file).await.unwrap();
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(file)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
file.write_all("0".as_bytes()).await.unwrap();
|
file.write_all("0".as_bytes()).await.unwrap();
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_local_version(version: u32) {
|
pub async fn set_local_version(version: u32) {
|
||||||
let file_path = app_data_dir().join("data.meta");
|
let file_path = app_data_dir().join("data.meta");
|
||||||
let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(file_path).await.unwrap();
|
let mut file = OpenOptions::new()
|
||||||
file.write_all(version.to_string().as_bytes()).await.unwrap();
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(file_path)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
file.write_all(version.to_string().as_bytes())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+45
-12
@@ -1,12 +1,11 @@
|
|||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{WordData, WordGroup};
|
||||||
use rusqlite::Connection;
|
use rusqlite::{params, Connection};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||||
let index = connection
|
let index = connection
|
||||||
.query_row(
|
.query_row(
|
||||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5\
|
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id",
|
||||||
) RETURNING id",
|
|
||||||
(
|
(
|
||||||
&word.key,
|
&word.key,
|
||||||
&word.value,
|
&word.value,
|
||||||
@@ -21,12 +20,46 @@ pub fn add_word(word: &mut WordData, connection: &Connection) {
|
|||||||
0
|
0
|
||||||
});
|
});
|
||||||
|
|
||||||
word.id = index;
|
word.id = index.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_words(words: &mut [WordData], connection: &mut Connection) {
|
||||||
|
let tx = connection.transaction().unwrap();
|
||||||
|
let count = words.len();
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut stmt = tx
|
||||||
|
.prepare(
|
||||||
|
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
for word in words.iter() {
|
||||||
|
stmt.execute(params![
|
||||||
|
word.key,
|
||||||
|
word.value,
|
||||||
|
word.tags,
|
||||||
|
serde_json::to_string(&word.additional).unwrap(),
|
||||||
|
word.group_id
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let last_index: u32 = tx.last_insert_rowid() as u32;
|
||||||
|
tx.commit().unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
let start_index = last_index - (count as u32) + 1;
|
||||||
|
|
||||||
|
for (index, id) in (start_index..=last_index).enumerate() {
|
||||||
|
words[index].id = id.into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||||
if word.id == 0 {
|
if !word.id.is_valid() {
|
||||||
add_word(word, &connection);
|
add_word(word, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
@@ -47,7 +80,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_word(word: &WordData, connection: &Connection) {
|
pub fn delete_word(word: &WordData, connection: &Connection) {
|
||||||
if word.id == 0 {
|
if !word.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
@@ -117,16 +150,16 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) {
|
|||||||
0
|
0
|
||||||
});
|
});
|
||||||
|
|
||||||
group.id = index;
|
group.id = index.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||||
if group.id == 0 {
|
if !group.id.is_valid() {
|
||||||
add_group(group, &connection);
|
add_group(group, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE word_group SET name = ?1 WHERE id = ?5",
|
"UPDATE word_group SET name = ?1 WHERE id = ?2",
|
||||||
(&group.name, &group.id),
|
(&group.name, &group.id),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
@@ -137,7 +170,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
||||||
if group.id == 0 {
|
if !group.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
+131
-103
@@ -1,22 +1,24 @@
|
|||||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||||
use crate::dictionary::DictionaryMessage::*;
|
use crate::dictionary::DictionaryMessage::*;
|
||||||
use crate::dictionary_test::DictionaryQuizState;
|
use crate::dictionary_test::DictionaryQuizState;
|
||||||
|
use crate::import::ImportState;
|
||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{WordData, WordGroup};
|
||||||
use crate::navigation::Page::Word;
|
use crate::navigation::Page::{Import, Word};
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::word::WordState;
|
use crate::word::WordState;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
|
use hashbrown::{HashMap, HashSet};
|
||||||
use iced::alignment::Vertical::Center;
|
use iced::alignment::Vertical::Center;
|
||||||
use iced::widget::button::Style;
|
use iced::widget::button::Style;
|
||||||
use iced::widget::button::{danger, text};
|
use iced::widget::button::{danger, text};
|
||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
use iced::widget::text_input::default;
|
use iced::widget::text_input::default;
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{Border, Color, Length, Shadow, Task};
|
use iced::{Border, Color, Shadow, Task};
|
||||||
|
use iced_core::Length::Fill;
|
||||||
use rand::random_range;
|
use rand::random_range;
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -59,15 +61,17 @@ pub enum DictionaryMessage {
|
|||||||
DeleteGroup,
|
DeleteGroup,
|
||||||
ChangeDirection,
|
ChangeDirection,
|
||||||
TrySave(usize),
|
TrySave(usize),
|
||||||
|
ToImport,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||||
fn navigate(&self, message: &DictionaryMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &DictionaryMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
return Some(Page::PreviousPage);
|
return Some(Page::PreviousPage);
|
||||||
}
|
}
|
||||||
if let Test = message {
|
if let Test = message
|
||||||
if self.include_map.iter().any(|x| *x) {
|
&& self.include_map.iter().any(|x| *x)
|
||||||
|
{
|
||||||
let mut words = vec![];
|
let mut words = vec![];
|
||||||
let dict = &self.state.lock().unwrap().dictionary;
|
let dict = &self.state.lock().unwrap().dictionary;
|
||||||
|
|
||||||
@@ -85,7 +89,6 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
self.no_typing,
|
self.no_typing,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let WordAction(index) = message {
|
if let WordAction(index) = message {
|
||||||
let word: WordData;
|
let word: WordData;
|
||||||
{
|
{
|
||||||
@@ -93,44 +96,30 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
let dict = &state.dictionary;
|
let dict = &state.dictionary;
|
||||||
word = dict[*index].clone();
|
word = dict[*index].clone();
|
||||||
}
|
}
|
||||||
if word.id != 0 {
|
if word.id.is_valid() {
|
||||||
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let ToImport = message {
|
||||||
|
return Some(Import(ImportState::new(self.state.clone())));
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
let len = self.state.lock().unwrap().dictionary.len();
|
||||||
|
|
||||||
|
self.include_map = vec![false; len];
|
||||||
|
self.tag_map = Default::default();
|
||||||
|
self.update_tags();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DictionaryState {
|
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
|
||||||
let len = state.lock().unwrap().dictionary.len();
|
|
||||||
|
|
||||||
let mut result = DictionaryState {
|
|
||||||
include_map: vec![false; len],
|
|
||||||
selected_group_index: 0,
|
|
||||||
state,
|
|
||||||
tag_map: HashMap::new(),
|
|
||||||
reverse: false,
|
|
||||||
search: "".to_string(),
|
|
||||||
no_typing: true,
|
|
||||||
reverse_list: true,
|
|
||||||
auto_save_queue: HashMap::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
result.update_tags();
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
NewWord => {
|
NewWord => {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
let mut word = WordData::new();
|
let mut word = WordData::new();
|
||||||
word.group_id = state.word_groups[self.selected_group_index].id.clone();
|
word.group_id = state.word_groups[self.selected_group_index].id;
|
||||||
|
|
||||||
let dict = &mut state.dictionary;
|
let dict = &mut state.dictionary;
|
||||||
dict.push(word);
|
dict.push(word);
|
||||||
@@ -161,12 +150,11 @@ impl DictionaryState {
|
|||||||
v = v[..v.len() - 2].to_string()
|
v = v[..v.len() - 2].to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
while v.contains(",,") {
|
while let Some(index) = v.find(",,") {
|
||||||
let index = v.find(",,").unwrap();
|
|
||||||
v.remove(index);
|
v.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
dict.get_mut(i).unwrap().tags = v;
|
dict[i].tags = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_tags();
|
self.update_tags();
|
||||||
@@ -183,7 +171,7 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
Include(i, b) => self.include_map[i] = b,
|
Include(i, b) => self.include_map[i] = b,
|
||||||
IncludeTag(t, v) => {
|
IncludeTag(t, v) => {
|
||||||
let index: u32;
|
let index;
|
||||||
{
|
{
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
index = state.word_groups[self.selected_group_index].id;
|
index = state.word_groups[self.selected_group_index].id;
|
||||||
@@ -208,7 +196,7 @@ impl DictionaryState {
|
|||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
|
|
||||||
state.word_groups.push(WordGroup {
|
state.word_groups.push(WordGroup {
|
||||||
id: 0,
|
id: 0.into(),
|
||||||
name: format!("Группа слов {}", random_range(100..1000)),
|
name: format!("Группа слов {}", random_range(100..1000)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -222,18 +210,16 @@ impl DictionaryState {
|
|||||||
SaveGroup => {
|
SaveGroup => {
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
let group = &mut state
|
let mut group = state
|
||||||
.word_groups
|
.word_groups[self.selected_group_index]
|
||||||
.get(self.selected_group_index)
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
update_group(group, connection);
|
update_group(&mut group, connection);
|
||||||
state.word_groups[self.selected_group_index] = group.clone();
|
state.word_groups[self.selected_group_index] = group;
|
||||||
}
|
}
|
||||||
SelectGroup(i) => {
|
SelectGroup(i) => {
|
||||||
self.selected_group_index = i;
|
self.selected_group_index = i;
|
||||||
let index: u32;
|
let index;
|
||||||
{
|
{
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
index = state.word_groups[i].id;
|
index = state.word_groups[i].id;
|
||||||
@@ -244,16 +230,24 @@ impl DictionaryState {
|
|||||||
if self.selected_group_index == 0 {
|
if self.selected_group_index == 0 {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
|
|
||||||
if let Some(group) = state.word_groups.get(self.selected_group_index) {
|
if let Some(group) = state.word_groups.get(self.selected_group_index) {
|
||||||
|
let remove_group_id = group.id;
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
|
|
||||||
delete_group(group, connection);
|
delete_group(group, connection);
|
||||||
state.word_groups.remove(self.selected_group_index);
|
state.word_groups.remove(self.selected_group_index);
|
||||||
|
state
|
||||||
|
.dictionary
|
||||||
|
.retain(|word| word.group_id != remove_group_id);
|
||||||
self.selected_group_index = 0;
|
self.selected_group_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_tags()
|
||||||
|
}
|
||||||
ChangeDirection => {
|
ChangeDirection => {
|
||||||
self.reverse_list = !self.reverse_list;
|
self.reverse_list = !self.reverse_list;
|
||||||
}
|
}
|
||||||
@@ -267,17 +261,61 @@ impl DictionaryState {
|
|||||||
self.save_word(word_index);
|
self.save_word(word_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ToImport => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
|
back_overlay(
|
||||||
|
row![
|
||||||
|
iced::widget::column![
|
||||||
|
self.groups_panel(),
|
||||||
|
row![horizontal().width(8), self.words_list(),],
|
||||||
|
row![
|
||||||
|
button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||||
|
horizontal().width(Fill),
|
||||||
|
button("Импорт").style(text).on_press(ToImport),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
.spacing(5),
|
||||||
|
self.filters(),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into(),
|
||||||
|
Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DictionaryState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||||
|
let len = state.lock().unwrap().dictionary.len();
|
||||||
|
|
||||||
|
let mut result = DictionaryState {
|
||||||
|
include_map: vec![false; len],
|
||||||
|
selected_group_index: 0,
|
||||||
|
state,
|
||||||
|
tag_map: HashMap::new(),
|
||||||
|
reverse: false,
|
||||||
|
search: "".to_string(),
|
||||||
|
no_typing: true,
|
||||||
|
reverse_list: true,
|
||||||
|
auto_save_queue: HashMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
result.update_tags();
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
fn save_word(&mut self, i: usize) {
|
fn save_word(&mut self, i: usize) {
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
let word = &mut state.dictionary.get(i).unwrap().clone();
|
let word = &mut state.dictionary[i].clone();
|
||||||
|
|
||||||
update_word(word, &connection);
|
update_word(word, connection);
|
||||||
state.dictionary[i] = word.clone();
|
state.dictionary[i] = word.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,50 +329,32 @@ impl DictionaryState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
|
||||||
back_overlay(
|
|
||||||
row![
|
|
||||||
iced::widget::column![
|
|
||||||
self.groups_panel(),
|
|
||||||
row![horizontal().width(8), self.words_list(),],
|
|
||||||
button("Добавить слово").style(jl_button).on_press(NewWord),
|
|
||||||
]
|
|
||||||
.spacing(5),
|
|
||||||
self.filters(),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
let mut col = Column::new().width(Length::Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
|
|
||||||
let mut range = (0..self.include_map.len()).collect::<Vec<_>>();
|
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
let group_id = state.word_groups[self.selected_group_index].id;
|
let group_id = state.word_groups[self.selected_group_index].id;
|
||||||
let dict = &mut state.dictionary.clone();
|
|
||||||
|
|
||||||
|
let dict = &state.dictionary;
|
||||||
|
|
||||||
|
let mut index = 0;
|
||||||
|
|
||||||
|
for access_index in 0..dict.len() {
|
||||||
|
let mut i = access_index;
|
||||||
if self.reverse_list {
|
if self.reverse_list {
|
||||||
dict.reverse()
|
i = dict.len() - access_index - 1;
|
||||||
} else {
|
|
||||||
range = range.iter().rev().map(|x| *x).collect::<Vec<usize>>();
|
|
||||||
}
|
}
|
||||||
|
let word = &dict[i];
|
||||||
for word in dict {
|
if word.group_id != group_id {
|
||||||
let i = range.pop().unwrap();
|
|
||||||
if !self.search.is_empty() {
|
|
||||||
if word.key.contains(&self.search) == false
|
|
||||||
&& word.value.contains(&self.search) == false
|
|
||||||
&& word.tags.contains(&self.search) == false
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if word.group_id != group_id {
|
if !self.search.is_empty()
|
||||||
|
&& !word.key.contains(&self.search)
|
||||||
|
&& !word.value.contains(&self.search)
|
||||||
|
&& !word.tags.contains(&self.search)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,12 +364,14 @@ impl DictionaryState {
|
|||||||
value: word.value.clone(),
|
value: word.value.clone(),
|
||||||
tags: word.tags.clone(),
|
tags: word.tags.clone(),
|
||||||
id: word.id,
|
id: word.id,
|
||||||
index: i
|
index: i,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
|
||||||
let lazy_line = lazy(word_line_data, move |data| {
|
let lazy_line = lazy(word_line_data, move |data| {
|
||||||
let index = data.index;
|
let index = data.index;
|
||||||
let mut line = Row::new().width(Length::Fill).align_y(Center);
|
let mut line = Row::new().width(Fill).align_y(Center);
|
||||||
line = line.push(
|
line = line.push(
|
||||||
checkbox(data.is_included)
|
checkbox(data.is_included)
|
||||||
.label("")
|
.label("")
|
||||||
@@ -360,7 +382,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Слово", &data.key)
|
text_input("Слово", &data.key)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetKey(index, string))
|
.on_input(move |string| SetKey(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -372,7 +394,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Перевод", &data.value)
|
text_input("Перевод", &data.value)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetValue(index, string))
|
.on_input(move |string| SetValue(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -385,7 +407,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Теги", &data.tags)
|
text_input("Теги", &data.tags)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetTags(index, string))
|
.on_input(move |string| SetTags(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -398,7 +420,7 @@ impl DictionaryState {
|
|||||||
let line_button = || {
|
let line_button = || {
|
||||||
let action = WordAction(index);
|
let action = WordAction(index);
|
||||||
|
|
||||||
if data.id == 0 {
|
if !data.id.is_valid() {
|
||||||
return button("-").on_press(action).style(|_x, _status| Style {
|
return button("-").on_press(action).style(|_x, _status| Style {
|
||||||
background: None,
|
background: None,
|
||||||
text_color: Color::BLACK,
|
text_color: Color::BLACK,
|
||||||
@@ -414,14 +436,12 @@ impl DictionaryState {
|
|||||||
line
|
line
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
col = col.push(lazy_line);
|
col = col.push(lazy_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Drawing {index} lines");
|
||||||
println!("Words rendering time: {:?}", time.elapsed());
|
println!("Words rendering time: {:?}", time.elapsed());
|
||||||
scrollable(col).height(Length::Fill).into()
|
scrollable(col).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
@@ -430,7 +450,7 @@ impl DictionaryState {
|
|||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text_input("Поиск", &self.search)
|
text_input("Поиск", &self.search)
|
||||||
.on_input(Search)
|
.on_input(Search)
|
||||||
.width(Length::Fill),
|
.width(Fill),
|
||||||
text!("Всего слов: {}", dict.len()),
|
text!("Всего слов: {}", dict.len()),
|
||||||
text!(
|
text!(
|
||||||
"Выбрано слов: {}",
|
"Выбрано слов: {}",
|
||||||
@@ -443,10 +463,10 @@ impl DictionaryState {
|
|||||||
toggler(self.reverse)
|
toggler(self.reverse)
|
||||||
.label("Обратный тест")
|
.label("Обратный тест")
|
||||||
.on_toggle(SetReverse),
|
.on_toggle(SetReverse),
|
||||||
button(text!("Тест").center().width(Length::Fill))
|
button(text!("Тест").center().width(Fill))
|
||||||
.style(cta_button)
|
.style(cta_button)
|
||||||
.on_press(Test)
|
.on_press(Test)
|
||||||
.width(Length::Fill),
|
.width(Fill),
|
||||||
]
|
]
|
||||||
.width(250)
|
.width(250)
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -454,7 +474,7 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
let mut col = Column::new().width(Length::Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
col = col.push(
|
col = col.push(
|
||||||
button("Сбросить")
|
button("Сбросить")
|
||||||
.on_press(ResetTags)
|
.on_press(ResetTags)
|
||||||
@@ -476,7 +496,7 @@ impl DictionaryState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
container(scrollable(col)).height(Length::Fill).into()
|
container(scrollable(col)).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_tags(&mut self) {
|
fn update_tags(&mut self) {
|
||||||
@@ -509,7 +529,7 @@ impl DictionaryState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_words_include(&mut self, group_id: u32) {
|
fn update_words_include(&mut self, group_id: crate::lang::Id) {
|
||||||
let include_tags = self
|
let include_tags = self
|
||||||
.tag_map
|
.tag_map
|
||||||
.iter()
|
.iter()
|
||||||
@@ -529,7 +549,9 @@ impl DictionaryState {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|word| (split_with_coma(word.tags.as_str()), word.group_id))
|
.map(|word| (split_with_coma(word.tags.as_str()), word.group_id))
|
||||||
.map(|(tags, word_group_id)| {
|
.map(|(tags, word_group_id)| {
|
||||||
tags.iter().all(|t| include_tags.contains(t)) && word_group_id == group_id
|
!tags.is_empty()
|
||||||
|
&& tags.iter().all(|t| include_tags.contains(t))
|
||||||
|
&& word_group_id == group_id
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -543,20 +565,18 @@ impl DictionaryState {
|
|||||||
let state = &self.state.lock().unwrap();
|
let state = &self.state.lock().unwrap();
|
||||||
let groups = &state.word_groups;
|
let groups = &state.word_groups;
|
||||||
|
|
||||||
let mut index = 0;
|
for (index, group) in groups.iter().enumerate() {
|
||||||
for group in groups {
|
|
||||||
row = row.push(
|
row = row.push(
|
||||||
button(text!("{}", group.name.clone()))
|
button(text!("{}", group.name.clone()))
|
||||||
.style(text)
|
.style(text)
|
||||||
.on_press(SelectGroup(index)),
|
.on_press(SelectGroup(index)),
|
||||||
);
|
);
|
||||||
index = index + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = state.word_groups[self.selected_group_index].clone();
|
let group = state.word_groups[self.selected_group_index].clone();
|
||||||
|
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
scrollable(row).width(Length::Fill).horizontal(),
|
scrollable(row).width(Fill).horizontal(),
|
||||||
row![
|
row![
|
||||||
button("⇳").on_press(ChangeDirection).style(jl_button),
|
button("⇳").on_press(ChangeDirection).style(jl_button),
|
||||||
text_input("Название группы слов", &group.name)
|
text_input("Название группы слов", &group.name)
|
||||||
@@ -564,12 +584,20 @@ impl DictionaryState {
|
|||||||
.width(250)
|
.width(250)
|
||||||
.on_submit(SaveGroup),
|
.on_submit(SaveGroup),
|
||||||
horizontal(),
|
horizontal(),
|
||||||
button("Удалить").style(danger).on_press(DeleteGroup),
|
self.group_delete_button(),
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING / 2.0)
|
.spacing(DEFAULT_SPACING / 2.0)
|
||||||
]
|
]
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn group_delete_button(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
|
if self.selected_group_index != 0 {
|
||||||
|
button("Удалить").style(danger).on_press(DeleteGroup).into()
|
||||||
|
} else {
|
||||||
|
space().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
||||||
@@ -583,7 +611,7 @@ pub fn app_data_dir() -> PathBuf {
|
|||||||
let mut dir = dirs::data_dir().unwrap();
|
let mut dir = dirs::data_dir().unwrap();
|
||||||
dir.push("jap_learn");
|
dir.push("jap_learn");
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
fs::create_dir(dir.clone()).unwrap();
|
fs::create_dir_all(dir.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
dir
|
dir
|
||||||
@@ -595,6 +623,6 @@ struct WordLineState{
|
|||||||
key: String,
|
key: String,
|
||||||
value: String,
|
value: String,
|
||||||
tags: String,
|
tags: String,
|
||||||
id: u32,
|
id: crate::lang::Id,
|
||||||
index: usize,
|
index: usize,
|
||||||
}
|
}
|
||||||
+37
-31
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::RootMessage;
|
||||||
use crate::dictionary::split_with_coma;
|
use crate::dictionary::split_with_coma;
|
||||||
use crate::dictionary_test::DictionaryQuizMessage::*;
|
use crate::dictionary_test::DictionaryQuizMessage::*;
|
||||||
use crate::lang::WordData;
|
use crate::lang::WordData;
|
||||||
@@ -5,12 +6,11 @@ use crate::navigation::Page::PreviousPage;
|
|||||||
use crate::navigation::*;
|
use crate::navigation::*;
|
||||||
use crate::quiz::Score;
|
use crate::quiz::Score;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::RootMessage;
|
use iced::Background::Color;
|
||||||
use iced::border::Radius;
|
use iced::border::Radius;
|
||||||
use iced::widget::container::Style;
|
use iced::widget::container::Style;
|
||||||
use iced::widget::{button, container, row, space, text, text_input, Row};
|
use iced::widget::{Row, button, container, row, space, text, text_input};
|
||||||
use iced::Background::Color;
|
use iced::{Border, Element, Fill, Task, Theme, alignment};
|
||||||
use iced::{alignment, Border, Element, Fill, Task, Theme};
|
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -35,34 +35,16 @@ pub enum DictionaryQuizMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
||||||
fn navigate(&self, message: &DictionaryQuizMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &DictionaryQuizMessage) -> Option<Page> {
|
||||||
match message {
|
match message {
|
||||||
Back => Some(PreviousPage),
|
Back => Some(PreviousPage),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DictionaryQuizState {
|
fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
||||||
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
|
||||||
DictionaryQuizState {
|
|
||||||
words,
|
|
||||||
current_set: Vec::new(),
|
|
||||||
answer: "".to_string(),
|
|
||||||
view: "---".to_string(),
|
|
||||||
correct: "".to_string(),
|
|
||||||
score: Default::default(),
|
|
||||||
is_help: false,
|
|
||||||
reverse,
|
|
||||||
laps: 0,
|
|
||||||
no_typing,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
AnswerChanged(c) => self.answer = c.clone(),
|
AnswerChanged(c) => self.answer = c.clone(),
|
||||||
@@ -72,7 +54,7 @@ impl DictionaryQuizState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
self.laps(),
|
self.laps(),
|
||||||
@@ -119,6 +101,24 @@ impl DictionaryQuizState {
|
|||||||
.center_x(Fill)
|
.center_x(Fill)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DictionaryQuizState {
|
||||||
|
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
||||||
|
DictionaryQuizState {
|
||||||
|
words,
|
||||||
|
current_set: Vec::new(),
|
||||||
|
answer: "".to_string(),
|
||||||
|
view: "---".to_string(),
|
||||||
|
correct: "".to_string(),
|
||||||
|
score: Default::default(),
|
||||||
|
is_help: false,
|
||||||
|
reverse,
|
||||||
|
laps: 0,
|
||||||
|
no_typing,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn submit(&mut self) {
|
fn submit(&mut self) {
|
||||||
if self.view == "---" {
|
if self.view == "---" {
|
||||||
self.show_next();
|
self.show_next();
|
||||||
@@ -149,7 +149,7 @@ impl DictionaryQuizState {
|
|||||||
if self.answer == self.correct
|
if self.answer == self.correct
|
||||||
|| split_with_coma(self.correct.as_str()).contains(&self.answer)
|
|| split_with_coma(self.correct.as_str()).contains(&self.answer)
|
||||||
{
|
{
|
||||||
if self.is_help == false {
|
if !self.is_help {
|
||||||
self.score.correct += 1;
|
self.score.correct += 1;
|
||||||
}
|
}
|
||||||
self.show_next()
|
self.show_next()
|
||||||
@@ -171,11 +171,17 @@ impl DictionaryQuizState {
|
|||||||
self.is_help = false;
|
self.is_help = false;
|
||||||
self.answer = String::new();
|
self.answer = String::new();
|
||||||
|
|
||||||
if self.current_set.is_empty() {
|
let next : WordData =
|
||||||
self.update_set();
|
match self.current_set.pop() {
|
||||||
|
Some(word) => {
|
||||||
|
word
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
self.update_set();
|
||||||
|
self.current_set.pop().expect("Empty set")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let next = self.current_set.pop().unwrap();
|
|
||||||
if self.reverse {
|
if self.reverse {
|
||||||
self.view = next.value.clone();
|
self.view = next.value.clone();
|
||||||
self.correct = next.key.clone();
|
self.correct = next.key.clone();
|
||||||
@@ -206,7 +212,7 @@ impl DictionaryQuizState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
|
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||||
if self.is_help && self.no_typing == false {
|
if self.is_help && !self.no_typing {
|
||||||
return button("Апелляция").style(jl_button).on_press(Appeal).into();
|
return button("Апелляция").style(jl_button).on_press(Appeal).into();
|
||||||
}
|
}
|
||||||
space().into()
|
space().into()
|
||||||
|
|||||||
+25
-25
@@ -18,17 +18,35 @@ pub struct HistoryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<HistoryMessage> for HistoryState {
|
impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||||
fn navigate(&self, message: &HistoryMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &HistoryMessage) -> Option<Page> {
|
||||||
match message {
|
match message {
|
||||||
Back => Some(Page::PreviousPage),
|
Back => Some(Page::PreviousPage),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
|
fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, HistoryMessage> {
|
||||||
|
back_overlay(
|
||||||
|
iced::widget::row![
|
||||||
|
horizontal().width(FillPortion(1)),
|
||||||
|
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
||||||
|
.height(Fill)
|
||||||
|
.width(FillPortion(5)),
|
||||||
|
horizontal().width(FillPortion(1))
|
||||||
|
]
|
||||||
|
.height(Fill)
|
||||||
|
.width(Fill)
|
||||||
|
.into(),
|
||||||
|
Back,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryState {
|
impl HistoryState {
|
||||||
pub fn new(id: u32, state: Arc<Mutex<AppState>>) -> Self {
|
pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self {
|
||||||
let state = state.lock().unwrap();
|
let state = state.lock().unwrap();
|
||||||
let history = get_history_of_set(id);
|
let history = get_history_of_set(id);
|
||||||
let words = history
|
let words = history
|
||||||
@@ -49,26 +67,6 @@ impl HistoryState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, HistoryMessage> {
|
|
||||||
back_overlay(
|
|
||||||
iced::widget::row![
|
|
||||||
horizontal().width(FillPortion(1)),
|
|
||||||
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
|
||||||
.height(Fill)
|
|
||||||
.width(FillPortion(5)),
|
|
||||||
horizontal().width(FillPortion(1))
|
|
||||||
]
|
|
||||||
.height(Fill)
|
|
||||||
.width(Fill)
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
||||||
let mut column = Column::new();
|
let mut column = Column::new();
|
||||||
for (item, index) in self.list.iter().zip(0..self.list.len()) {
|
for (item, index) in self.list.iter().zip(0..self.list.len()) {
|
||||||
@@ -85,11 +83,13 @@ impl HistoryState {
|
|||||||
.align_x(Center),
|
.align_x(Center),
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text!("{} ➞ {}", item.before, item.after),
|
text!("{} ➞ {}", item.before, item.after),
|
||||||
text!("{}", item.timestamp.with_timezone(&Local).format("%d.%m %H:%M"))
|
text!(
|
||||||
|
"{}",
|
||||||
|
item.timestamp.with_timezone(&Local).format("%d.%m %H:%M")
|
||||||
|
)
|
||||||
]
|
]
|
||||||
.spacing(5)
|
.spacing(5)
|
||||||
.align_x(Center)
|
.align_x(Center)
|
||||||
|
|
||||||
]
|
]
|
||||||
.spacing(5),
|
.spacing(5),
|
||||||
);
|
);
|
||||||
|
|||||||
+552
@@ -0,0 +1,552 @@
|
|||||||
|
use crate::data_provider::import::{get_words_of_group, load_groups, ImportData, ImportGroup};
|
||||||
|
use crate::data_provider::words::{add_group, add_words};
|
||||||
|
use crate::dictionary::app_data_dir;
|
||||||
|
use crate::import::ImportMessage::*;
|
||||||
|
use crate::lang::{WordData, WordGroup};
|
||||||
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
|
use crate::styling::*;
|
||||||
|
use crate::AppState;
|
||||||
|
use iced::widget::button::danger;
|
||||||
|
use iced::widget::container::success;
|
||||||
|
use iced::widget::{
|
||||||
|
button, checkbox, column, container, progress_bar, row, rule, text, text_input, Row,
|
||||||
|
};
|
||||||
|
use iced::widget::{scrollable, space};
|
||||||
|
use iced::{Element, Task};
|
||||||
|
use iced_core::Alignment::Center;
|
||||||
|
use iced_core::Length::Fill;
|
||||||
|
use iced_core::Padding;
|
||||||
|
use rfd::AsyncFileDialog;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use std::fs::{File, OpenOptions};
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tokio::task::spawn_blocking;
|
||||||
|
use zip::ZipArchive;
|
||||||
|
|
||||||
|
const DEFAULT_FIELDS: [&str; 6] = ["key", "value", "tags", "reading", "context", "description"];
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportState {
|
||||||
|
state: Arc<Mutex<AppState>>,
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
import_data: Option<ImportData>,
|
||||||
|
selected_index: usize,
|
||||||
|
selected_property: Option<String>,
|
||||||
|
custom_property_name: String,
|
||||||
|
skip_empty: bool,
|
||||||
|
separator: String,
|
||||||
|
progress: Option<Arc<Mutex<f32>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum ImportMessage {
|
||||||
|
Back,
|
||||||
|
SelectFile,
|
||||||
|
UpdateFile(PathBuf),
|
||||||
|
UpdateImport(ImportData),
|
||||||
|
NextGroup,
|
||||||
|
PreviousGroup,
|
||||||
|
OpenPropertyMapper(String),
|
||||||
|
EditCustomProperty(String),
|
||||||
|
SetupCustomProperty,
|
||||||
|
SetupDefaultProperty(String),
|
||||||
|
SetupDirect,
|
||||||
|
RemoveMapping(String),
|
||||||
|
SwitchSkipEmpty(bool),
|
||||||
|
EditSeparator(String),
|
||||||
|
StartImport,
|
||||||
|
NextProgress,
|
||||||
|
ImportFinished,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NavigatedPage<ImportMessage> for ImportState {
|
||||||
|
fn navigate(&mut self, message: &ImportMessage) -> Option<Page> {
|
||||||
|
if self.progress.is_some() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Back = message {
|
||||||
|
return Some(Page::PreviousPage);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn navigated(&mut self) {}
|
||||||
|
|
||||||
|
fn update(&mut self, message: ImportMessage) -> Task<RootMessage> {
|
||||||
|
match message {
|
||||||
|
Back => {}
|
||||||
|
UpdateFile(path) => {
|
||||||
|
self.path = Some(path);
|
||||||
|
self.import_data = None;
|
||||||
|
return self.load_package();
|
||||||
|
}
|
||||||
|
SelectFile => return Self::select_import_file(),
|
||||||
|
UpdateImport(import) => {
|
||||||
|
self.selected_index = 0;
|
||||||
|
self.import_data = Some(import);
|
||||||
|
}
|
||||||
|
NextGroup => {
|
||||||
|
self.selected_index += 1;
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
PreviousGroup => {
|
||||||
|
self.selected_index -= 1;
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
OpenPropertyMapper(prop) => self.selected_property = Some(prop),
|
||||||
|
EditCustomProperty(prop_name) => self.custom_property_name = prop_name,
|
||||||
|
SetupCustomProperty => {
|
||||||
|
self.setup_mapping(self.custom_property_name.clone());
|
||||||
|
}
|
||||||
|
SetupDefaultProperty(prop_name) => {
|
||||||
|
self.setup_mapping(prop_name);
|
||||||
|
}
|
||||||
|
SetupDirect => {
|
||||||
|
self.setup_mapping(self.selected_property.clone().unwrap());
|
||||||
|
}
|
||||||
|
RemoveMapping(pro_name) => {
|
||||||
|
self.remove_mapping(pro_name);
|
||||||
|
}
|
||||||
|
SwitchSkipEmpty(skip) => {
|
||||||
|
self.skip_empty = skip;
|
||||||
|
}
|
||||||
|
EditSeparator(separator) => {
|
||||||
|
self.separator = separator.clone();
|
||||||
|
}
|
||||||
|
StartImport => {
|
||||||
|
self.progress = Some(Arc::new(Mutex::new(0.0)));
|
||||||
|
return Task::batch([self.start_import(), self.next_progress()]);
|
||||||
|
}
|
||||||
|
NextProgress => {
|
||||||
|
if self.progress.is_none() {
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
|
return self.next_progress();
|
||||||
|
}
|
||||||
|
ImportFinished => {
|
||||||
|
self.progress = None;
|
||||||
|
let group = &mut self.import_data.as_mut().unwrap().0[self.selected_index];
|
||||||
|
group.imported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, ImportMessage> {
|
||||||
|
back_overlay(
|
||||||
|
{
|
||||||
|
if let Some(value) = &self.progress {
|
||||||
|
column![progress_bar(0f32..=1f32, *value.lock().unwrap()),]
|
||||||
|
.spacing(QUARTER_SPACING)
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
scrollable(
|
||||||
|
column![
|
||||||
|
row![
|
||||||
|
button("Выбрать файл").style(jl_button).on_press(SelectFile),
|
||||||
|
text!("{}", {
|
||||||
|
if let Some(path) = &self.path {
|
||||||
|
path.to_string_lossy().to_string()
|
||||||
|
} else {
|
||||||
|
"Файл не выбран".to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
.align_y(Center)
|
||||||
|
.spacing(DEFAULT_SPACING),
|
||||||
|
self.selected_group()
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING),
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportState {
|
||||||
|
fn selected_group(&self) -> Element<'_, ImportMessage> {
|
||||||
|
if let Some(data) = &self.import_data {
|
||||||
|
let group = &data.0[self.selected_index];
|
||||||
|
return column![
|
||||||
|
row![
|
||||||
|
self.back_button(),
|
||||||
|
space().width(Fill),
|
||||||
|
text!("{}", group.name.clone()),
|
||||||
|
space().width(Fill),
|
||||||
|
self.next_button()
|
||||||
|
]
|
||||||
|
.width(Fill),
|
||||||
|
text!("Количество карточек: {}", group.length),
|
||||||
|
self.property_mapper(group),
|
||||||
|
self.import_settings(),
|
||||||
|
self.import_button(group),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
space().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_button(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
if group.imported {
|
||||||
|
return container(text!("Группа слов успешно импортирована"))
|
||||||
|
.padding(HALF_SPACING)
|
||||||
|
.align_x(Center)
|
||||||
|
.style(success)
|
||||||
|
.width(Fill)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
button("Начать импорт")
|
||||||
|
.style(cta_button)
|
||||||
|
.on_press(StartImport)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_mapper(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
column![
|
||||||
|
self.property_list(group),
|
||||||
|
rule::horizontal(2),
|
||||||
|
self.property_selector()
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_list(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
let mut row = Row::new();
|
||||||
|
for prop in &group.fields {
|
||||||
|
let primary_button_name = (*prop).clone();
|
||||||
|
if let Some(mapped) = group.mapping.get(prop.clone().as_str()) {
|
||||||
|
row = row.push(
|
||||||
|
column![
|
||||||
|
button(text!("{}", primary_button_name)),
|
||||||
|
"↕",
|
||||||
|
button(text!("{}", mapped))
|
||||||
|
.style(danger)
|
||||||
|
.on_press(RemoveMapping(mapped.as_str().to_string())),
|
||||||
|
]
|
||||||
|
.align_x(Center),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
row = row.push(
|
||||||
|
button(text!("{}", primary_button_name))
|
||||||
|
.on_press(OpenPropertyMapper(prop.clone())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scrollable(row.spacing(HALF_SPACING).padding(Padding {
|
||||||
|
top: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
bottom: DEFAULT_SPACING,
|
||||||
|
left: 0.0,
|
||||||
|
}))
|
||||||
|
.horizontal()
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_selector(&self) -> Element<'_, ImportMessage> {
|
||||||
|
if self.selected_property.is_none() {
|
||||||
|
return space().into();
|
||||||
|
}
|
||||||
|
column![
|
||||||
|
self.available_properties(),
|
||||||
|
button("Добавить напрямую").on_press(SetupDirect),
|
||||||
|
row![
|
||||||
|
text_input("Пользовательское поле", &self.custom_property_name)
|
||||||
|
.on_input(EditCustomProperty),
|
||||||
|
button("Установить привязку").on_press(SetupCustomProperty)
|
||||||
|
]
|
||||||
|
.spacing(QUARTER_SPACING)
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn available_properties(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut row = Row::new();
|
||||||
|
|
||||||
|
for default in DEFAULT_FIELDS {
|
||||||
|
// if group.mapping.values().any(|name| name == default) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
row = row.push(
|
||||||
|
button(text!("{default}")).on_press(SetupDefaultProperty(default.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
row.spacing(HALF_SPACING).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_settings(&self) -> Element<'_, ImportMessage> {
|
||||||
|
column![
|
||||||
|
checkbox(self.skip_empty)
|
||||||
|
.label("Пропускать пустые строки")
|
||||||
|
.on_toggle(SwitchSkipEmpty),
|
||||||
|
column![
|
||||||
|
text!("Разделитель при множественном объединении"),
|
||||||
|
text_input("", &self.separator).on_input(EditSeparator)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn back_button(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut button = button("←").style(button::text);
|
||||||
|
if self.selected_index > 0 {
|
||||||
|
button = button.on_press(PreviousGroup);
|
||||||
|
}
|
||||||
|
button.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_button(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut button = button("→").style(button::text);
|
||||||
|
if self.selected_index < self.import_data.as_ref().unwrap().0.len() - 1 {
|
||||||
|
button = button.on_press(NextGroup);
|
||||||
|
}
|
||||||
|
button.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> ImportState {
|
||||||
|
ImportState {
|
||||||
|
state,
|
||||||
|
path: None,
|
||||||
|
import_data: None,
|
||||||
|
selected_index: 0,
|
||||||
|
selected_property: None,
|
||||||
|
custom_property_name: "".to_string(),
|
||||||
|
skip_empty: true,
|
||||||
|
separator: ", ".to_string(),
|
||||||
|
progress: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_import_file() -> Task<RootMessage> {
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
let file = AsyncFileDialog::new()
|
||||||
|
.add_filter("Anki", &["apkg"])
|
||||||
|
.pick_file()
|
||||||
|
.await;
|
||||||
|
if let Some(file) = file {
|
||||||
|
return Some(file.path().into());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
},
|
||||||
|
|result| {
|
||||||
|
if let Some(path) = result {
|
||||||
|
RootMessage::Import(UpdateFile(path))
|
||||||
|
} else {
|
||||||
|
RootMessage::None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_package(&self) -> Task<RootMessage> {
|
||||||
|
let path = self.path.clone().unwrap();
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
spawn_blocking(move || {
|
||||||
|
Self::extract_import_file(path)?;
|
||||||
|
let data = Self::read_import_file()?;
|
||||||
|
Ok(data)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
},
|
||||||
|
|result: Result<ImportData, ()>| {
|
||||||
|
if let Ok(import) = result {
|
||||||
|
RootMessage::Import(UpdateImport(import))
|
||||||
|
} else {
|
||||||
|
RootMessage::None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_import_file(path: PathBuf) -> Result<(), ()> {
|
||||||
|
let file = File::open(path).map_err(|_| ())?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let mut archive = ZipArchive::new(reader).map_err(|_| ())?;
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let mut temp_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&temp_file_path)
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
if let Ok(mut file) = archive.by_name("collection.anki21") {
|
||||||
|
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||||
|
Ok(())
|
||||||
|
} else if let Ok(mut file) = archive.by_name("collection.anki2") {
|
||||||
|
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn read_import_file() -> Result<ImportData, ()> {
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||||
|
let data = load_groups(&connection);
|
||||||
|
Ok(data)
|
||||||
|
}
|
||||||
|
fn setup_mapping(&mut self, property_name: String) {
|
||||||
|
let group = self.import_data.as_mut().unwrap();
|
||||||
|
let group = &mut group.0[self.selected_index];
|
||||||
|
group
|
||||||
|
.mapping
|
||||||
|
.insert(self.selected_property.clone().unwrap(), property_name);
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
fn remove_mapping(&mut self, property_name: String) {
|
||||||
|
let group = self.import_data.as_mut().unwrap();
|
||||||
|
let group = &mut group.0[self.selected_index];
|
||||||
|
let remove_key = group
|
||||||
|
.mapping
|
||||||
|
.keys()
|
||||||
|
.find(|key| group.mapping[*key] == property_name)
|
||||||
|
.unwrap();
|
||||||
|
group.mapping.remove(remove_key.clone().as_str());
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_import(&self) -> Task<RootMessage> {
|
||||||
|
let state = self.state.clone();
|
||||||
|
let separator = self.separator.clone();
|
||||||
|
let skip_empty = self.skip_empty;
|
||||||
|
let group = self.import_data.as_ref().unwrap().0[self.selected_index].clone();
|
||||||
|
let progress = self.progress.clone().unwrap();
|
||||||
|
println!("{}", group.name);
|
||||||
|
Task::perform(
|
||||||
|
async move {
|
||||||
|
spawn_blocking(move || {
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||||
|
let import_list = get_words_of_group(&connection, group.id);
|
||||||
|
let mut words_list = Vec::with_capacity(import_list.len());
|
||||||
|
|
||||||
|
let map_indices = Self::get_mapping_indices(&group);
|
||||||
|
let mut group_entity = WordGroup {
|
||||||
|
id: 0.into(),
|
||||||
|
name: group.name.clone(),
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let state = state.lock().unwrap();
|
||||||
|
add_group(&mut group_entity, &state.connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
let group_id = group_entity.id;
|
||||||
|
for import in import_list {
|
||||||
|
let mut word = WordData::new();
|
||||||
|
|
||||||
|
word.tags = import.tags.trim().replace(" ", ", ");
|
||||||
|
word.group_id = group_id;
|
||||||
|
for (dest, indices) in &map_indices {
|
||||||
|
let collected_string = Self::collect_strings(
|
||||||
|
&import.fields,
|
||||||
|
indices,
|
||||||
|
&separator,
|
||||||
|
skip_empty,
|
||||||
|
);
|
||||||
|
match dest.as_str() {
|
||||||
|
"key" => {
|
||||||
|
word.key = collected_string;
|
||||||
|
}
|
||||||
|
"value" => {
|
||||||
|
word.value = collected_string;
|
||||||
|
}
|
||||||
|
"tags" => {
|
||||||
|
word.tags = collected_string;
|
||||||
|
}
|
||||||
|
&_ => {
|
||||||
|
word.additional.insert((*dest).clone(), collected_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
words_list.push(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut state = state.lock().unwrap();
|
||||||
|
let connection = &mut state.connection;
|
||||||
|
let mut index = 0;
|
||||||
|
let total_len = words_list.len() as f32 / 1024.0;
|
||||||
|
for word in &mut words_list.chunks_mut(1024) {
|
||||||
|
add_words(word, connection);
|
||||||
|
index += 1;
|
||||||
|
let mut progress = progress.lock().unwrap();
|
||||||
|
*progress = index as f32 / total_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.dictionary.append(&mut words_list);
|
||||||
|
state.word_groups.push(group_entity);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
},
|
||||||
|
|_: Result<(), ()>| RootMessage::Import(ImportFinished),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_mapping_indices(group: &ImportGroup) -> Vec<(String, Vec<usize>)> {
|
||||||
|
let mut final_props = group.mapping.values().cloned().collect::<Vec<_>>();
|
||||||
|
final_props.sort();
|
||||||
|
final_props.dedup();
|
||||||
|
let mut result = final_props
|
||||||
|
.iter()
|
||||||
|
.map(|name| (name.clone(), Vec::<usize>::with_capacity(1)))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
for (key, endpoint) in &group.mapping {
|
||||||
|
let property_index = group.fields.iter().position(|f| f == key).expect("Unknown property");
|
||||||
|
let group_index = result
|
||||||
|
.iter()
|
||||||
|
.position(|(name, _)| name == endpoint)
|
||||||
|
.unwrap();
|
||||||
|
result[group_index].1.push(property_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_strings(
|
||||||
|
properties: &[String],
|
||||||
|
indices: &[usize],
|
||||||
|
separator: &str,
|
||||||
|
skip_empty: bool,
|
||||||
|
) -> String {
|
||||||
|
let mut working_words = Vec::with_capacity(indices.len());
|
||||||
|
for index in indices {
|
||||||
|
let str = &properties[*index];
|
||||||
|
if skip_empty && str.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
working_words.push(str.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
working_words.join(separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_progress(&self) -> Task<RootMessage> {
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||||
|
},
|
||||||
|
|_| RootMessage::Import(NextProgress),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+207
-121
@@ -1,18 +1,23 @@
|
|||||||
use crate::data_provider::card_stats::{
|
|
||||||
add_stat_list, delete_stat, load_stats_of_set, update_stat_score,
|
|
||||||
};
|
|
||||||
use crate::data_provider::history::{push_note, HistoryItem};
|
|
||||||
use crate::repetitions::CardSetSettings;
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
use crate::data_provider::card_stats::{delete_stat, load_stats_of_deck, update_stat_score};
|
||||||
|
use crate::data_provider::history::{HistoryItem, push_note};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use rand::distr::weighted::WeightedIndex;
|
|
||||||
use rand::distr::Distribution;
|
use rand::distr::Distribution;
|
||||||
|
use rand::distr::weighted::WeightedIndex;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
use rand::rng;
|
use rand::rng;
|
||||||
use rand::rngs::ThreadRng;
|
use rand::rngs::ThreadRng;
|
||||||
use serde::{Deserialize, Serialize};
|
use rayon::iter::IndexedParallelIterator;
|
||||||
use std::cmp::min;
|
use rayon::iter::IntoParallelRefIterator;
|
||||||
|
use rayon::iter::ParallelIterator;
|
||||||
|
use rhai::{Engine, Scope};
|
||||||
|
use rusqlite::ToSql;
|
||||||
|
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||||
|
use std::cmp::PartialEq;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::num::ParseIntError;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@@ -20,6 +25,55 @@ const MAX_HISTORY_LEN: usize = 20;
|
|||||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||||
const MAX_SCORE: u8 = 25;
|
const MAX_SCORE: u8 = 25;
|
||||||
const FADE_PER_DAY: f32 = 0.95;
|
const FADE_PER_DAY: f32 = 0.95;
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
|
||||||
|
pub struct Id(u32);
|
||||||
|
pub const INVALID_ID: Id = Id(0);
|
||||||
|
impl FromStr for Id {
|
||||||
|
type Err = ParseIntError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(Id(s.parse::<u32>()?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u32> for Id {
|
||||||
|
fn from(value: u32) -> Self {
|
||||||
|
Id(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<u32> for Id {
|
||||||
|
fn into(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Display for Id {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromSql for Id {
|
||||||
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
|
match value {
|
||||||
|
ValueRef::Integer(i) => Ok(Id(i as u32)),
|
||||||
|
_ => Err(FromSqlError::InvalidType),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToSql for Id {
|
||||||
|
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
|
||||||
|
Ok(ToSqlOutput::from(self.0 as i64))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Id {
|
||||||
|
pub(crate) fn is_valid(self) -> bool {
|
||||||
|
self.0 != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct KanaSet {
|
pub struct KanaSet {
|
||||||
name: String,
|
name: String,
|
||||||
@@ -27,13 +81,11 @@ pub struct KanaSet {
|
|||||||
pub(crate) dictionary: Vec<Vec<(String, String)>>,
|
pub(crate) dictionary: Vec<Vec<(String, String)>>,
|
||||||
pub(crate) include_map: [bool; 10],
|
pub(crate) include_map: [bool; 10],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum KanaType {
|
pub enum KanaType {
|
||||||
Hiragana,
|
Hiragana,
|
||||||
Katakana,
|
Katakana,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KanaSet {
|
impl KanaSet {
|
||||||
pub fn hiragana() -> Self {
|
pub fn hiragana() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -199,14 +251,6 @@ impl KanaSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pub fn next(&mut self) -> (String, String) {
|
|
||||||
let current_set = self.list();
|
|
||||||
|
|
||||||
let mut rand = rand::rng();
|
|
||||||
let index: u32 = rand.random();
|
|
||||||
current_set[index as usize % current_set.len()].clone()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
pub fn list(&self) -> Vec<(String, String)> {
|
pub fn list(&self) -> Vec<(String, String)> {
|
||||||
let mut current_set: Vec<(String, String)> = Vec::new();
|
let mut current_set: Vec<(String, String)> = Vec::new();
|
||||||
|
|
||||||
@@ -221,7 +265,6 @@ impl KanaSet {
|
|||||||
current_set
|
current_set
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for KanaSet {
|
impl Default for KanaSet {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
KanaSet::hiragana()
|
KanaSet::hiragana()
|
||||||
@@ -232,45 +275,40 @@ impl PartialEq<Self> for KanaSet {
|
|||||||
self.name == other.name
|
self.name == other.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct WordData {
|
pub struct WordData {
|
||||||
pub id: u32,
|
pub id: Id,
|
||||||
pub key: String,
|
pub key: String,
|
||||||
pub value: String,
|
pub value: String,
|
||||||
pub tags: String,
|
pub tags: String,
|
||||||
pub additional: HashMap<String, String>,
|
pub additional: HashMap<String, String>,
|
||||||
pub group_id: u32,
|
pub group_id: Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WordData {
|
impl WordData {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: 0,
|
id: INVALID_ID,
|
||||||
key: String::new(),
|
key: String::new(),
|
||||||
value: String::new(),
|
value: String::new(),
|
||||||
tags: String::new(),
|
tags: String::new(),
|
||||||
additional: Default::default(),
|
additional: Default::default(),
|
||||||
group_id: 1,
|
group_id: 1.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WordGroup {
|
pub struct WordGroup {
|
||||||
pub id: u32,
|
pub id: Id,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct CardStatistics {
|
pub struct CardStatistics {
|
||||||
pub id: u32,
|
pub id: Id,
|
||||||
pub word_id: u32,
|
pub word_id: Id,
|
||||||
pub set_id: u32,
|
pub set_id: Id,
|
||||||
pub last_open: DateTime<Utc>,
|
pub last_open: DateTime<Utc>,
|
||||||
pub score: u8,
|
pub score: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CardStatistics {
|
impl CardStatistics {
|
||||||
pub fn update(&mut self, status: WordOpenMode) {
|
pub fn update(&mut self, status: WordOpenMode) {
|
||||||
match status {
|
match status {
|
||||||
@@ -286,11 +324,7 @@ impl CardStatistics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.score < 1 {
|
self.score = self.score.clamp(1, MAX_SCORE);
|
||||||
self.score = 1
|
|
||||||
} else if self.score > MAX_SCORE {
|
|
||||||
self.score = MAX_SCORE
|
|
||||||
}
|
|
||||||
self.last_open = Utc::now();
|
self.last_open = Utc::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +335,6 @@ impl CardStatistics {
|
|||||||
(self.score as f32 * multiplier).max(1.0)
|
(self.score as f32 * multiplier).max(1.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum WordOpenMode {
|
pub enum WordOpenMode {
|
||||||
Easy,
|
Easy,
|
||||||
@@ -309,51 +342,29 @@ pub enum WordOpenMode {
|
|||||||
Hard,
|
Hard,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CardSet {
|
pub struct DeckData {
|
||||||
words: Vec<WordData>,
|
words: Vec<WordData>,
|
||||||
set: Vec<CardStatistics>,
|
set: Vec<CardStatistics>,
|
||||||
current_word_index: Option<usize>,
|
current_word_index: Option<usize>,
|
||||||
state: Arc<Mutex<AppState>>,
|
state: Arc<Mutex<AppState>>,
|
||||||
order_module: OrderModule,
|
order_module: OrderModule,
|
||||||
settings: CardSetSettings,
|
settings: DeckSettings,
|
||||||
}
|
}
|
||||||
|
impl DeckData {
|
||||||
impl CardSet {
|
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Self {
|
||||||
pub fn new(settings: &CardSetSettings, state: Arc<Mutex<AppState>>) -> Self {
|
|
||||||
let state_for = state.clone();
|
let state_for = state.clone();
|
||||||
let state_locked = state.lock().unwrap();
|
let state_locked = state.lock().unwrap();
|
||||||
|
|
||||||
let mut current_set = load_stats_of_set(&settings, &state_locked.connection);
|
let mut current_set = load_stats_of_deck(settings, &state_locked.connection);
|
||||||
let last_list = settings.get_word_list(&state_locked);
|
let last_list: Vec<_> = settings
|
||||||
let saved_ids = current_set.iter().map(|l| l.word_id).collect::<Vec<u32>>();
|
.get_word_list(&state_locked)
|
||||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
|
||||||
|
|
||||||
let new_stats: &mut Vec<CardStatistics> = &mut last_list
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|word| !saved_ids.contains(&word.id))
|
.map(|w| &state_locked.dictionary[*w])
|
||||||
.map(|word| CardStatistics {
|
.cloned()
|
||||||
id: 0,
|
|
||||||
word_id: word.id.clone(),
|
|
||||||
last_open: Utc::now(),
|
|
||||||
score: 1,
|
|
||||||
set_id: settings.id.clone(),
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<Id>>();
|
||||||
|
|
||||||
let time = Instant::now();
|
|
||||||
|
|
||||||
if !new_stats.is_empty() {
|
|
||||||
add_stat_list(new_stats, &state_locked.connection);
|
|
||||||
current_set.append(new_stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"Added {} stats: {}",
|
|
||||||
new_stats.len(),
|
|
||||||
time.elapsed().as_millis()
|
|
||||||
);
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
for stat in current_set.clone() {
|
for stat in current_set.clone() {
|
||||||
if !word_ids.contains(&stat.word_id) {
|
if !word_ids.contains(&stat.word_id) {
|
||||||
@@ -370,20 +381,19 @@ impl CardSet {
|
|||||||
current_word_index: None,
|
current_word_index: None,
|
||||||
state: state_for,
|
state: state_for,
|
||||||
order_module: match settings.open_mode {
|
order_module: match settings.open_mode {
|
||||||
SetOrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
OrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
||||||
SetOrderMode::TrainWorstFirst => {
|
OrderMode::TrainWorstFirst => {
|
||||||
OrderModule::WorstWordsSRS(WorstWordsSRSModule::new())
|
OrderModule::WorstWordsSRS(WorstWordsSRSModule::new())
|
||||||
}
|
}
|
||||||
SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
OrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||||
},
|
},
|
||||||
settings: settings.clone(),
|
settings: settings.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
||||||
let index = match self.order_module.clone() {
|
let index = match self.order_module.clone() {
|
||||||
OrderModule::SemiRandomSRS(mut module) => {
|
OrderModule::SemiRandomSRS(mut module) => {
|
||||||
if module.initialized == false {
|
if !module.initialized {
|
||||||
module.init(self)
|
module.init(self)
|
||||||
}
|
}
|
||||||
let index = module.next(self);
|
let index = module.next(self);
|
||||||
@@ -391,7 +401,7 @@ impl CardSet {
|
|||||||
index
|
index
|
||||||
}
|
}
|
||||||
OrderModule::RandomSRS(mut module) => {
|
OrderModule::RandomSRS(mut module) => {
|
||||||
if module.initialized == false {
|
if !module.initialized {
|
||||||
module.init(self)
|
module.init(self)
|
||||||
}
|
}
|
||||||
let index = module.next(self);
|
let index = module.next(self);
|
||||||
@@ -399,7 +409,7 @@ impl CardSet {
|
|||||||
index
|
index
|
||||||
}
|
}
|
||||||
OrderModule::WorstWordsSRS(mut module) => {
|
OrderModule::WorstWordsSRS(mut module) => {
|
||||||
if module.initialized == false {
|
if !module.initialized {
|
||||||
module.init(self)
|
module.init(self)
|
||||||
}
|
}
|
||||||
let index = module.next(self);
|
let index = module.next(self);
|
||||||
@@ -411,9 +421,8 @@ impl CardSet {
|
|||||||
self.current_word_index = Some(index);
|
self.current_word_index = Some(index);
|
||||||
(self.words[index].clone(), self.set[index].clone())
|
(self.words[index].clone(), self.set[index].clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(&mut self, status: WordOpenMode) {
|
pub fn open(&mut self, status: WordOpenMode) {
|
||||||
if let None = self.current_word_index {
|
if self.current_word_index.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let index = self.current_word_index.unwrap();
|
let index = self.current_word_index.unwrap();
|
||||||
@@ -443,44 +452,44 @@ impl CardSet {
|
|||||||
HistoryItem {
|
HistoryItem {
|
||||||
timestamp: Utc::now(),
|
timestamp: Utc::now(),
|
||||||
word_id: word.word_id,
|
word_id: word.word_id,
|
||||||
mode: WordOpenMode::Easy,
|
mode: status,
|
||||||
before: old_score,
|
before: old_score,
|
||||||
after: new_score,
|
after: new_score,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.set.len()
|
self.set.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Copy, Eq)]
|
#[derive(Clone, PartialEq, Copy, Eq)]
|
||||||
pub enum SetOrderMode {
|
pub enum OrderMode {
|
||||||
Default,
|
Default,
|
||||||
TrainWorstFirst,
|
TrainWorstFirst,
|
||||||
FullRandom,
|
FullRandom,
|
||||||
}
|
}
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq, Default)]
|
||||||
|
pub enum AppendMode {
|
||||||
|
Full,
|
||||||
|
#[default]
|
||||||
|
Manual,
|
||||||
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum OrderModule {
|
enum OrderModule {
|
||||||
SemiRandomSRS(SemiRandomSRSModule),
|
SemiRandomSRS(SemiRandomSRSModule),
|
||||||
RandomSRS(RandomSRSModule),
|
RandomSRS(RandomSRSModule),
|
||||||
WorstWordsSRS(WorstWordsSRSModule),
|
WorstWordsSRS(WorstWordsSRSModule),
|
||||||
}
|
}
|
||||||
|
|
||||||
trait SRSModule {
|
trait SRSModule {
|
||||||
fn next(&mut self, set: &mut CardSet) -> usize;
|
fn next(&mut self, set: &mut DeckData) -> usize;
|
||||||
fn open(&mut self, status: WordOpenMode, index: usize, updated_word: CardStatistics);
|
fn open(&mut self, status: WordOpenMode, index: usize, updated_word: CardStatistics);
|
||||||
fn init(&mut self, set: &mut CardSet);
|
fn init(&mut self, set: &mut DeckData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct RandomSRSModule {
|
struct RandomSRSModule {
|
||||||
basket: Vec<usize>,
|
basket: Vec<usize>,
|
||||||
initialized: bool,
|
initialized: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RandomSRSModule {
|
impl RandomSRSModule {
|
||||||
fn new() -> RandomSRSModule {
|
fn new() -> RandomSRSModule {
|
||||||
Self {
|
Self {
|
||||||
@@ -489,26 +498,26 @@ impl RandomSRSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SRSModule for RandomSRSModule {
|
impl SRSModule for RandomSRSModule {
|
||||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||||
if self.basket.is_empty() {
|
match self.basket.pop() {
|
||||||
|
Some(index) => index,
|
||||||
|
None => {
|
||||||
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
||||||
self.basket.shuffle(&mut rand::rng())
|
self.basket.shuffle(&mut rand::rng());
|
||||||
|
self.basket.pop().expect("empty basket")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.basket.pop().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
||||||
|
|
||||||
fn init(&mut self, set: &mut CardSet) {
|
fn init(&mut self, set: &mut DeckData) {
|
||||||
self.initialized = true;
|
self.initialized = true;
|
||||||
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
||||||
self.basket.shuffle(&mut rand::rng())
|
self.basket.shuffle(&mut rand::rng())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct SemiRandomSRSModule {
|
struct SemiRandomSRSModule {
|
||||||
history: Vec<usize>,
|
history: Vec<usize>,
|
||||||
@@ -516,7 +525,6 @@ struct SemiRandomSRSModule {
|
|||||||
generator: ThreadRng,
|
generator: ThreadRng,
|
||||||
initialized: bool,
|
initialized: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SemiRandomSRSModule {
|
impl SemiRandomSRSModule {
|
||||||
fn new() -> SemiRandomSRSModule {
|
fn new() -> SemiRandomSRSModule {
|
||||||
SemiRandomSRSModule {
|
SemiRandomSRSModule {
|
||||||
@@ -527,9 +535,8 @@ impl SemiRandomSRSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SRSModule for SemiRandomSRSModule {
|
impl SRSModule for SemiRandomSRSModule {
|
||||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||||
let index = self.last_weights.sample(&mut self.generator);
|
let index = self.last_weights.sample(&mut self.generator);
|
||||||
|
|
||||||
if self.history.contains(&index) {
|
if self.history.contains(&index) {
|
||||||
@@ -543,15 +550,13 @@ impl SRSModule for SemiRandomSRSModule {
|
|||||||
|
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(&mut self, _: WordOpenMode, index: usize, word: CardStatistics) {
|
fn open(&mut self, _: WordOpenMode, index: usize, word: CardStatistics) {
|
||||||
let new_weight = (100.0 / word.calculated_score()).powf(2.0);
|
let new_weight = (100.0 / word.calculated_score()).powf(2.0);
|
||||||
self.last_weights
|
self.last_weights
|
||||||
.update_weights(&[(index, &new_weight)])
|
.update_weights(&[(index, &new_weight)])
|
||||||
.unwrap();
|
.expect("update weights error");
|
||||||
}
|
}
|
||||||
|
fn init(&mut self, set: &mut DeckData) {
|
||||||
fn init(&mut self, set: &mut CardSet) {
|
|
||||||
self.initialized = true;
|
self.initialized = true;
|
||||||
let weights = set
|
let weights = set
|
||||||
.set
|
.set
|
||||||
@@ -561,16 +566,11 @@ impl SRSModule for SemiRandomSRSModule {
|
|||||||
self.last_weights = WeightedIndex::new(weights).unwrap();
|
self.last_weights = WeightedIndex::new(weights).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SemiRandomSRSModule {
|
impl SemiRandomSRSModule {
|
||||||
fn history_len(&self, set: &CardSet) -> usize {
|
fn history_len(&self, set: &DeckData) -> usize {
|
||||||
min(
|
((set.len() as f32 * MAX_HISTORY_LEN_PART) as usize).clamp(1, MAX_HISTORY_LEN)
|
||||||
MAX_HISTORY_LEN,
|
|
||||||
(set.len() as f32 * MAX_HISTORY_LEN_PART) as usize,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct WorstWordsSRSModule {
|
struct WorstWordsSRSModule {
|
||||||
initialized: bool,
|
initialized: bool,
|
||||||
@@ -580,29 +580,31 @@ struct WorstWordsSRSModule {
|
|||||||
queue: Vec<usize>,
|
queue: Vec<usize>,
|
||||||
rounds_count: u8,
|
rounds_count: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SRSModule for WorstWordsSRSModule {
|
impl SRSModule for WorstWordsSRSModule {
|
||||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||||
if self.rounds_remaining == 0 {
|
if self.rounds_remaining == 0 {
|
||||||
self.fill_pool(set);
|
self.fill_pool(set);
|
||||||
self.rounds_remaining = self.rounds_count;
|
self.rounds_remaining = self.rounds_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.queue.is_empty() {
|
match self.queue.pop() {
|
||||||
|
Some(index) => {
|
||||||
|
index
|
||||||
|
}
|
||||||
|
None => {
|
||||||
self.queue.append(&mut self.pool.clone());
|
self.queue.append(&mut self.pool.clone());
|
||||||
self.rounds_remaining -= 1;
|
self.rounds_remaining -= 1;
|
||||||
|
self.queue.pop().expect("empty queue")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.queue.pop().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
||||||
|
|
||||||
fn init(&mut self, _: &mut CardSet) {
|
fn init(&mut self, _: &mut DeckData) {
|
||||||
self.initialized = true;
|
self.initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorstWordsSRSModule {
|
impl WorstWordsSRSModule {
|
||||||
fn new() -> WorstWordsSRSModule {
|
fn new() -> WorstWordsSRSModule {
|
||||||
WorstWordsSRSModule {
|
WorstWordsSRSModule {
|
||||||
@@ -614,8 +616,7 @@ impl WorstWordsSRSModule {
|
|||||||
queue: vec![],
|
queue: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn fill_pool(&mut self, set: &DeckData) {
|
||||||
fn fill_pool(&mut self, set: &CardSet) {
|
|
||||||
let mut sorted = set
|
let mut sorted = set
|
||||||
.set
|
.set
|
||||||
.clone()
|
.clone()
|
||||||
@@ -631,3 +632,88 @@ impl WorstWordsSRSModule {
|
|||||||
self.pool = worst;
|
self.pool = worst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DeckSettings {
|
||||||
|
pub id: Id,
|
||||||
|
pub name: String,
|
||||||
|
pub forward: String,
|
||||||
|
pub backward: String,
|
||||||
|
pub filter: String,
|
||||||
|
pub count: Option<usize>,
|
||||||
|
pub worst_words_list: Option<Vec<WordData>>,
|
||||||
|
pub open_mode: OrderMode,
|
||||||
|
}
|
||||||
|
impl DeckSettings {
|
||||||
|
pub(crate) fn with_name(name: String) -> DeckSettings {
|
||||||
|
DeckSettings {
|
||||||
|
id: 0.into(),
|
||||||
|
name,
|
||||||
|
forward: "".to_string(),
|
||||||
|
backward: "".to_string(),
|
||||||
|
filter: "true".to_string(),
|
||||||
|
count: None,
|
||||||
|
worst_words_list: None,
|
||||||
|
open_mode: OrderMode::Default,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn check_filter(&self) -> bool {
|
||||||
|
let time = Instant::now();
|
||||||
|
let engine = Engine::new();
|
||||||
|
let ast = engine.compile(&self.filter);
|
||||||
|
println!("Compile time is {:?}", time.elapsed());
|
||||||
|
ast.is_ok()
|
||||||
|
}
|
||||||
|
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
|
||||||
|
let time = Instant::now();
|
||||||
|
let mut list = vec![];
|
||||||
|
let engine = Engine::new();
|
||||||
|
|
||||||
|
let ast = engine.compile(&self.filter);
|
||||||
|
if ast.is_err() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ast = ast.unwrap();
|
||||||
|
|
||||||
|
let groups = &state.word_groups;
|
||||||
|
|
||||||
|
list = state
|
||||||
|
.dictionary
|
||||||
|
.par_iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, word)| {
|
||||||
|
let mut more = rhai::Map::new();
|
||||||
|
for iced in &word.additional {
|
||||||
|
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
||||||
|
}
|
||||||
|
let mut scope = Scope::new();
|
||||||
|
scope
|
||||||
|
.push_constant("id", word.id.0)
|
||||||
|
.push_constant("key", word.key.clone())
|
||||||
|
.push_constant("value", word.value.clone())
|
||||||
|
.push_constant("tags", word.tags.clone())
|
||||||
|
.push_constant("more", more)
|
||||||
|
.push_constant(
|
||||||
|
"group",
|
||||||
|
groups
|
||||||
|
.iter()
|
||||||
|
.find(|g| g.id == word.group_id)
|
||||||
|
.cloned()
|
||||||
|
.unwrap()
|
||||||
|
.name,
|
||||||
|
);
|
||||||
|
|
||||||
|
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||||
|
result.is_ok() && result.unwrap()
|
||||||
|
})
|
||||||
|
.map(|(index, _)| index)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
println!("Collecting available words is {:?}", time.elapsed());
|
||||||
|
|
||||||
|
list
|
||||||
|
}
|
||||||
|
pub fn require_speech(&self) -> bool {
|
||||||
|
self.forward == "speech" || self.backward == "speech"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+55
-27
@@ -3,50 +3,47 @@ mod data_provider;
|
|||||||
mod dictionary;
|
mod dictionary;
|
||||||
mod dictionary_test;
|
mod dictionary_test;
|
||||||
mod history;
|
mod history;
|
||||||
|
pub mod import;
|
||||||
mod lang;
|
mod lang;
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
mod quiz;
|
mod quiz;
|
||||||
mod randomizer;
|
mod randomizer;
|
||||||
mod repetition;
|
mod repetition;
|
||||||
|
mod repetition_settings;
|
||||||
mod repetitions;
|
mod repetitions;
|
||||||
mod selector;
|
mod selector;
|
||||||
pub mod styling;
|
pub mod styling;
|
||||||
mod sync;
|
mod sync;
|
||||||
mod word;
|
mod word;
|
||||||
mod writing;
|
mod writing;
|
||||||
mod repetition_settings;
|
|
||||||
|
|
||||||
|
use crate::RootMessage::Keyboard;
|
||||||
use crate::data_provider::card_sets::load_sets;
|
use crate::data_provider::card_sets::load_sets;
|
||||||
use crate::data_provider::settings::get_setting;
|
use crate::data_provider::settings::get_setting;
|
||||||
use crate::data_provider::sqlite::default_connection;
|
use crate::data_provider::sqlite::default_connection;
|
||||||
use crate::data_provider::words::{load_word_groups, load_words};
|
use crate::data_provider::words::{load_word_groups, load_words};
|
||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{DeckSettings, Id, WordData, WordGroup};
|
||||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||||
use crate::quiz::*;
|
use crate::quiz::*;
|
||||||
use crate::repetitions::CardSetSettings;
|
|
||||||
use crate::RootMessage::Keyboard;
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use iced::{keyboard, Subscription, Theme};
|
use hashbrown::HashMap;
|
||||||
use iced::{window, Font};
|
use iced::{Font, window};
|
||||||
use iced_core::window::Position;
|
use iced::{Subscription, Theme, keyboard};
|
||||||
use iced_core::Size;
|
use iced_core::Size;
|
||||||
|
use iced_core::window::Position;
|
||||||
|
use mimalloc::MiMalloc;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::collections::HashMap;
|
#[cfg(target_os = "linux")]
|
||||||
use iced_core::window::settings::PlatformSpecific;
|
use iced_core::window::settings::PlatformSpecific;
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: MiMalloc = MiMalloc;
|
||||||
|
|
||||||
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||||
|
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
println!("Welcome to JapLearn");
|
println!("Welcome to JapLearn");
|
||||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).window(window::Settings{
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
||||||
position: Position::Centered,
|
.window(window_settings())
|
||||||
min_size: Some(Size::new(700.0_f32.into(), 700.0_f32.into())),
|
|
||||||
platform_specific: PlatformSpecific {
|
|
||||||
application_id: "JapLearn".to_string(),
|
|
||||||
override_redirect: false
|
|
||||||
},
|
|
||||||
.. Default::default()
|
|
||||||
})
|
|
||||||
.subscription(subscription)
|
.subscription(subscription)
|
||||||
.title("JapLearn")
|
.title("JapLearn")
|
||||||
.settings(iced::Settings {
|
.settings(iced::Settings {
|
||||||
@@ -59,29 +56,54 @@ fn main() -> iced::Result {
|
|||||||
.run()
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn window_settings() -> window::Settings {
|
||||||
|
let mut settings = window::Settings {
|
||||||
|
position: Position::Centered,
|
||||||
|
min_size: Some(Size::new(700.0_f32, 700.0_f32)),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
settings.platform_specific = PlatformSpecific {
|
||||||
|
application_id: "JapLearn".to_string(),
|
||||||
|
override_redirect: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
settings
|
||||||
|
}
|
||||||
|
|
||||||
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
||||||
keyboard::listen().map(|e| Keyboard(e))
|
keyboard::listen().map(Keyboard)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub dictionary: Vec<WordData>,
|
pub dictionary: Vec<WordData>,
|
||||||
pub card_sets: Vec<CardSetSettings>,
|
pub decks: Vec<DeckSettings>,
|
||||||
pub word_groups: Vec<WordGroup>,
|
pub word_groups: Vec<WordGroup>,
|
||||||
pub connection: Connection,
|
pub connection: Connection,
|
||||||
pub sync_data: AppSettings,
|
pub sync_data: AppSettings,
|
||||||
pub activity: HashMap<u32, Vec<(NaiveDate, u32)>>
|
pub activity: HashMap<Id, Vec<(NaiveDate, u32)>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
dictionary: vec![],
|
dictionary: vec![],
|
||||||
card_sets: vec![],
|
decks: vec![],
|
||||||
word_groups: vec![],
|
word_groups: vec![],
|
||||||
connection: default_connection(),
|
connection: default_connection(),
|
||||||
sync_data: AppSettings { key: None, auto_web_fetch: false },
|
sync_data: AppSettings {
|
||||||
|
key: None,
|
||||||
|
auto_web_fetch: false,
|
||||||
|
},
|
||||||
activity: Default::default(),
|
activity: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,13 +116,19 @@ fn fill_state(state: &mut AppState) {
|
|||||||
let setting = load_settings(&state.connection);
|
let setting = load_settings(&state.connection);
|
||||||
|
|
||||||
state.dictionary = list;
|
state.dictionary = list;
|
||||||
state.card_sets = sets;
|
state.decks = sets;
|
||||||
state.word_groups = groups;
|
state.word_groups = groups;
|
||||||
state.sync_data = setting
|
state.sync_data = setting
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_settings(connection: &Connection) -> AppSettings {
|
fn load_settings(connection: &Connection) -> AppSettings {
|
||||||
let key = get_setting("SYNC_KEY".to_string(), connection);
|
let key = get_setting("SYNC_KEY".to_string(), connection);
|
||||||
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection).unwrap_or("false".to_string()).parse::<bool>().unwrap();
|
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection)
|
||||||
AppSettings { key, auto_web_fetch: fetch }
|
.unwrap_or("false".to_string())
|
||||||
|
.parse::<bool>()
|
||||||
|
.unwrap();
|
||||||
|
AppSettings {
|
||||||
|
key,
|
||||||
|
auto_web_fetch: fetch,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-16
@@ -1,9 +1,13 @@
|
|||||||
use crate::data_provider::history::{get_history_of_set, history_dir};
|
use crate::data_provider::history::{get_history_of_set, history_dir};
|
||||||
use crate::data_provider::sqlite::{create_db, default_connection};
|
use crate::data_provider::sqlite::{create_db, default_connection};
|
||||||
use crate::data_provider::web_api::{get_local_version, get_web_version, load_data, set_local_version};
|
use crate::data_provider::web_api::{
|
||||||
|
get_local_version, get_web_version, load_data, set_local_version,
|
||||||
|
};
|
||||||
use crate::dictionary::{app_data_dir, DictionaryMessage, DictionaryState};
|
use crate::dictionary::{app_data_dir, DictionaryMessage, DictionaryState};
|
||||||
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
||||||
use crate::history::{HistoryMessage, HistoryState};
|
use crate::history::{HistoryMessage, HistoryState};
|
||||||
|
use crate::import::{ImportMessage, ImportState};
|
||||||
|
use crate::lang::Id;
|
||||||
use crate::message_navigation;
|
use crate::message_navigation;
|
||||||
use crate::navigation::Page::*;
|
use crate::navigation::Page::*;
|
||||||
use crate::navigation::RootMessage::{DataLoaded, Keyboard, UpdateData};
|
use crate::navigation::RootMessage::{DataLoaded, Keyboard, UpdateData};
|
||||||
@@ -19,12 +23,13 @@ use crate::sync::{SyncMessage, SyncState};
|
|||||||
use crate::view_navigation;
|
use crate::view_navigation;
|
||||||
use crate::word::{WordMessage, WordState};
|
use crate::word::{WordMessage, WordState};
|
||||||
use crate::writing::{WritingMessage, WritingState};
|
use crate::writing::{WritingMessage, WritingState};
|
||||||
use crate::{AppState, fill_state};
|
use crate::{fill_state, AppState};
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use hashbrown::HashMap;
|
||||||
use iced::keyboard::Event;
|
use iced::keyboard::Event;
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use std::collections::HashMap;
|
use rusqlite::Connection;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@@ -54,8 +59,9 @@ pub enum RootMessage {
|
|||||||
Sync(SyncMessage),
|
Sync(SyncMessage),
|
||||||
History(HistoryMessage),
|
History(HistoryMessage),
|
||||||
RepetitionSettings(RepetitionSettingsMessage),
|
RepetitionSettings(RepetitionSettingsMessage),
|
||||||
|
Import(ImportMessage),
|
||||||
Keyboard(Event),
|
Keyboard(Event),
|
||||||
DataLoaded(HashMap<u32, Vec<(NaiveDate, u32)>>),
|
DataLoaded(HashMap<Id, Vec<(NaiveDate, u32)>>),
|
||||||
None,
|
None,
|
||||||
UpdateData,
|
UpdateData,
|
||||||
}
|
}
|
||||||
@@ -73,7 +79,7 @@ pub enum Page {
|
|||||||
Sync(SyncState),
|
Sync(SyncState),
|
||||||
History(HistoryState),
|
History(HistoryState),
|
||||||
RepetitionSettings(RepetitionSettingsState),
|
RepetitionSettings(RepetitionSettingsState),
|
||||||
|
Import(ImportState),
|
||||||
PreviousPage,
|
PreviousPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,9 @@ impl ScreenState {
|
|||||||
final_task = Task::batch([
|
final_task = Task::batch([
|
||||||
reading_additional_task,
|
reading_additional_task,
|
||||||
Task::perform(Self::load_web_backup(key), |result| {
|
Task::perform(Self::load_web_backup(key), |result| {
|
||||||
if let Ok(update) = result && update {
|
if let Ok(update) = result
|
||||||
|
&& update
|
||||||
|
{
|
||||||
UpdateData
|
UpdateData
|
||||||
} else {
|
} else {
|
||||||
RootMessage::None
|
RootMessage::None
|
||||||
@@ -116,12 +124,15 @@ impl ScreenState {
|
|||||||
async fn load_additional_data() -> RootMessage {
|
async fn load_additional_data() -> RootMessage {
|
||||||
let directory = history_dir();
|
let directory = history_dir();
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
for file in directory.read_dir().unwrap() {
|
for file in directory.read_dir().unwrap().flatten() {
|
||||||
if let Ok(file) = file {
|
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
let history_file_name = file.file_name().into_string().unwrap();
|
let history_file_name = match file.file_name().into_string() {
|
||||||
let id = history_file_name[4..history_file_name.len() - 12]
|
Err(_) => continue,
|
||||||
.parse::<u32>()
|
Ok(v) => v,
|
||||||
|
};
|
||||||
|
|
||||||
|
let id: Id = history_file_name[4..history_file_name.len() - 12]
|
||||||
|
.parse::<Id>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let history = get_history_of_set(id);
|
let history = get_history_of_set(id);
|
||||||
@@ -133,13 +144,13 @@ impl ScreenState {
|
|||||||
}
|
}
|
||||||
map.insert(id, vec);
|
map.insert(id, vec);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DataLoaded(map)
|
DataLoaded(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_web_backup(string: String) -> Result<bool, Error> {
|
async fn load_web_backup(string: String) -> Result<bool, Error> {
|
||||||
let local = get_local_version().await;
|
let local = get_local_version().await;
|
||||||
let web = get_web_version(string.as_str()).await?;
|
let web = get_web_version(string.as_str()).await?;
|
||||||
|
println!("{} {}", local, web);
|
||||||
if web > local {
|
if web > local {
|
||||||
println!("Web version is newer than local version");
|
println!("Web version is newer than local version");
|
||||||
load_data(string, true).await;
|
load_data(string, true).await;
|
||||||
@@ -165,6 +176,9 @@ impl ScreenState {
|
|||||||
if let UpdateData = message {
|
if let UpdateData = message {
|
||||||
println!("Loading data");
|
println!("Loading data");
|
||||||
let mut state = self.app_state.lock().unwrap();
|
let mut state = self.app_state.lock().unwrap();
|
||||||
|
if cfg!(windows) {
|
||||||
|
state.connection = Connection::open_in_memory().unwrap();
|
||||||
|
}
|
||||||
let path = app_data_dir();
|
let path = app_data_dir();
|
||||||
let db_file = path.join("data.db");
|
let db_file = path.join("data.db");
|
||||||
let temp_db_file = path.join("data.db.tmp");
|
let temp_db_file = path.join("data.db.tmp");
|
||||||
@@ -190,7 +204,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!("Update took {:?}", time.elapsed());
|
println!("Update took {:?}", time.elapsed());
|
||||||
@@ -213,7 +228,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +249,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("View took {:?}", time.elapsed());
|
println!("View took {:?}", time.elapsed());
|
||||||
@@ -290,7 +307,10 @@ macro_rules! message_navigation {
|
|||||||
($msg:expr, $stack:expr, $state:expr) => {
|
($msg:expr, $stack:expr, $state:expr) => {
|
||||||
if let Some(new_page) = $state.navigate(&$msg) {
|
if let Some(new_page) = $state.navigate(&$msg) {
|
||||||
if let Page::PreviousPage = new_page {
|
if let Page::PreviousPage = new_page {
|
||||||
|
if $stack.len() > 1 {
|
||||||
$stack.pop();
|
$stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
return (Task::<RootMessage>::none(), true);
|
return (Task::<RootMessage>::none(), true);
|
||||||
} else {
|
} else {
|
||||||
$stack.push(new_page);
|
$stack.push(new_page);
|
||||||
@@ -318,8 +338,10 @@ macro_rules! state_navigate_handle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait NavigatedPage<T> {
|
pub trait NavigatedPage<T> {
|
||||||
fn navigate(&self, message: &T) -> Option<Page>;
|
fn navigate(&mut self, message: &T) -> Option<Page>;
|
||||||
fn navigated(&mut self);
|
fn navigated(&mut self);
|
||||||
|
fn update(&mut self, message: T) -> Task<RootMessage>;
|
||||||
|
fn view(&self) -> Element<'_, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait KeyPressedPage {
|
pub trait KeyPressedPage {
|
||||||
|
|||||||
+78
-74
@@ -5,7 +5,7 @@ use crate::quiz::QuizMessage::*;
|
|||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{RootMessage, USER_FONT};
|
use crate::{RootMessage, USER_FONT};
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{alignment, Element, Fill, Task};
|
use iced::{Element, Fill, Task, alignment};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -20,7 +20,7 @@ pub struct QuizState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<QuizMessage> for QuizState {
|
impl NavigatedPage<QuizMessage> for QuizState {
|
||||||
fn navigate(&self, message: &QuizMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &QuizMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else {
|
} else {
|
||||||
@@ -28,8 +28,83 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
|
|
||||||
|
fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||||
|
match message {
|
||||||
|
ContentChanged(content) => {
|
||||||
|
if content.contains("`") {
|
||||||
|
self.is_help = true;
|
||||||
|
self.score.fail += 1;
|
||||||
|
|
||||||
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
self.current_roman = content;
|
||||||
|
if self.correct_roman == self.current_roman {
|
||||||
|
if !self.is_help {
|
||||||
|
self.score.correct += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.is_help = false;
|
||||||
|
self.score.total += 1;
|
||||||
|
self.update_showed()
|
||||||
|
} else if self.current_roman.len() == self.correct_roman.len() {
|
||||||
|
self.score.total += 1;
|
||||||
|
self.score.fail += 1;
|
||||||
|
self.update_showed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Back => {},
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, QuizMessage> {
|
||||||
|
container(
|
||||||
|
iced::widget::column![
|
||||||
|
row![
|
||||||
|
text!("{}", self.kana.to_lowercase())
|
||||||
|
.size(54)
|
||||||
|
.font(USER_FONT),
|
||||||
|
text!(
|
||||||
|
"{}",
|
||||||
|
if self.is_help {
|
||||||
|
self.correct_roman.clone()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.align_y(alignment::Vertical::Center)
|
||||||
|
.spacing(20),
|
||||||
|
text_input("Романдзи", &self.current_roman)
|
||||||
|
.size(28)
|
||||||
|
.width(150)
|
||||||
|
.on_input(ContentChanged),
|
||||||
|
score_display(&self.score),
|
||||||
|
button("Закончить").style(jl_button).on_press(Back),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.align_x(alignment::Horizontal::Center),
|
||||||
|
)
|
||||||
|
.center_y(Fill)
|
||||||
|
.center_x(Fill)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn score_display<'a, T: 'a>(score: &Score) -> Element<'a, T> {
|
||||||
|
row![
|
||||||
|
text!("{}", score.total.to_string()).size(25),
|
||||||
|
text!("{}", score.correct.to_string())
|
||||||
|
.size(25)
|
||||||
|
.color(iced::Color::from_rgb8(60, 170, 60)),
|
||||||
|
text!("{}", score.fail.to_string())
|
||||||
|
.color(iced::Color::from_rgb8(255, 79, 0))
|
||||||
|
.size(25),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuizState {
|
impl QuizState {
|
||||||
@@ -57,35 +132,6 @@ impl Default for QuizState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl QuizState {
|
impl QuizState {
|
||||||
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
|
||||||
ContentChanged(content) => {
|
|
||||||
if content.contains("`") {
|
|
||||||
self.is_help = true;
|
|
||||||
self.score.fail += 1;
|
|
||||||
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
self.current_roman = content;
|
|
||||||
if self.correct_roman == self.current_roman {
|
|
||||||
if self.is_help == false {
|
|
||||||
self.score.correct += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.is_help = false;
|
|
||||||
self.score.total += 1;
|
|
||||||
self.update_showed()
|
|
||||||
} else if self.current_roman.len() == self.correct_roman.len() {
|
|
||||||
self.score.total += 1;
|
|
||||||
self.score.fail += 1;
|
|
||||||
self.update_showed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Back => todo!(),
|
|
||||||
}
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_showed(&mut self) {
|
fn update_showed(&mut self) {
|
||||||
self.current_roman = String::new();
|
self.current_roman = String::new();
|
||||||
let queue = &mut self.queue;
|
let queue = &mut self.queue;
|
||||||
@@ -102,48 +148,6 @@ impl QuizState {
|
|||||||
self.kana = pair.0;
|
self.kana = pair.0;
|
||||||
self.correct_roman = pair.1;
|
self.correct_roman = pair.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, QuizMessage> {
|
|
||||||
container(
|
|
||||||
iced::widget::column![
|
|
||||||
row![
|
|
||||||
text!("{}", self.kana.to_lowercase())
|
|
||||||
.size(54)
|
|
||||||
.font(USER_FONT),
|
|
||||||
text!(
|
|
||||||
"{}",
|
|
||||||
if self.is_help {
|
|
||||||
self.correct_roman.clone()
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]
|
|
||||||
.align_y(alignment::Vertical::Center)
|
|
||||||
.spacing(20),
|
|
||||||
text_input("Романдзи", &self.current_roman)
|
|
||||||
.size(28)
|
|
||||||
.width(150)
|
|
||||||
.on_input(ContentChanged),
|
|
||||||
row![
|
|
||||||
text!("{}", self.score.total.to_string()).size(25),
|
|
||||||
text!("{}", self.score.correct.to_string())
|
|
||||||
.size(25)
|
|
||||||
.color(iced::Color::from_rgb8(60, 170, 60)),
|
|
||||||
text!("{}", self.score.fail.to_string())
|
|
||||||
.color(iced::Color::from_rgb8(255, 79, 0))
|
|
||||||
.size(25),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING),
|
|
||||||
button("Закончить").style(jl_button).on_press(Back),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.align_x(alignment::Horizontal::Center),
|
|
||||||
)
|
|
||||||
.center_y(Fill)
|
|
||||||
.center_x(Fill)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum QuizMessage {
|
pub enum QuizMessage {
|
||||||
|
|||||||
+22
-24
@@ -1,9 +1,9 @@
|
|||||||
|
use crate::RootMessage;
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::randomizer::RandomizerMessage::{Back, Edit, Start};
|
use crate::randomizer::RandomizerMessage::{Back, Edit, Start};
|
||||||
use crate::styling::{back_overlay, jl_button, HALF_SPACING};
|
use crate::styling::{HALF_SPACING, back_overlay, jl_button};
|
||||||
use crate::RootMessage;
|
|
||||||
use iced::widget::{button, text_editor};
|
|
||||||
use iced::Task;
|
use iced::Task;
|
||||||
|
use iced::widget::{button, text_editor};
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -20,32 +20,15 @@ pub enum RandomizerMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||||
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &RandomizerMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
return Some(Page::PreviousPage);
|
return Some(Page::PreviousPage);
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RandomizerState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RandomizerState {
|
|
||||||
pub fn new() -> RandomizerState {
|
|
||||||
RandomizerState {
|
|
||||||
text: Default::default(),
|
|
||||||
list: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Edit(action) => {
|
Edit(action) => {
|
||||||
self.text.perform(action);
|
self.text.perform(action);
|
||||||
@@ -65,7 +48,7 @@ impl RandomizerState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text_editor(&self.text)
|
text_editor(&self.text)
|
||||||
@@ -81,3 +64,18 @@ impl RandomizerState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RandomizerState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RandomizerState {
|
||||||
|
pub fn new() -> RandomizerState {
|
||||||
|
RandomizerState {
|
||||||
|
text: Default::default(),
|
||||||
|
list: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+70
-65
@@ -1,8 +1,8 @@
|
|||||||
use crate::data_provider::voice::get_voice;
|
use crate::data_provider::voice::get_voice;
|
||||||
use crate::lang::{CardSet, CardStatistics, WordData, WordOpenMode};
|
use crate::lang::Id;
|
||||||
|
use crate::lang::{CardStatistics, DeckData, DeckSettings, WordData, WordOpenMode};
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page};
|
use crate::navigation::{KeyPressedPage, NavigatedPage, Page};
|
||||||
use crate::repetitions::CardSetSettings;
|
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
@@ -18,18 +18,18 @@ use tokio::task::spawn_blocking;
|
|||||||
|
|
||||||
pub struct RepetitionState {
|
pub struct RepetitionState {
|
||||||
state: Arc<Mutex<AppState>>,
|
state: Arc<Mutex<AppState>>,
|
||||||
pub settings: CardSetSettings,
|
pub settings: DeckSettings,
|
||||||
pub set: CardSet,
|
pub set: DeckData,
|
||||||
current_word: WordData,
|
current_word: WordData,
|
||||||
current_statistic: CardStatistics,
|
current_statistic: CardStatistics,
|
||||||
open: bool,
|
open: bool,
|
||||||
can_play: bool,
|
can_play: bool,
|
||||||
sink: Arc<MixerDeviceSink>,
|
sink: Arc<MixerDeviceSink>,
|
||||||
opened: HashSet<u32>,
|
opened: HashSet<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||||
fn navigate(&self, message: &RepetitionMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &RepetitionMessage) -> Option<Page> {
|
||||||
if let RepetitionMessage::Back = message {
|
if let RepetitionMessage::Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else {
|
} else {
|
||||||
@@ -37,32 +37,8 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionState {
|
|
||||||
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
|
||||||
let mut card_set = CardSet::new(&set, state.clone());
|
|
||||||
let (word, stat) = card_set.next();
|
|
||||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
|
||||||
|
|
||||||
RepetitionState {
|
|
||||||
state,
|
|
||||||
settings: set,
|
|
||||||
set: card_set,
|
|
||||||
current_word: word,
|
|
||||||
current_statistic: stat,
|
|
||||||
open: false,
|
|
||||||
can_play: true,
|
|
||||||
sink: Arc::new(sink_handle),
|
|
||||||
opened: HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionState {
|
|
||||||
pub fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
RepetitionMessage::Back => {}
|
RepetitionMessage::Back => {}
|
||||||
RepetitionMessage::Next => return self.next(),
|
RepetitionMessage::Next => return self.next(),
|
||||||
@@ -87,7 +63,59 @@ impl RepetitionState {
|
|||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||||
|
back_overlay(
|
||||||
|
column![
|
||||||
|
container(self.draw_forward())
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.align_y(alignment::Vertical::Center),
|
||||||
|
rule::horizontal(2),
|
||||||
|
container(self.draw_backward())
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.align_y(alignment::Vertical::Center),
|
||||||
|
container(self.answer_bar())
|
||||||
|
.width(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.height(80),
|
||||||
|
text!(
|
||||||
|
"Затронуто слов {}, {}%",
|
||||||
|
self.opened.len(),
|
||||||
|
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||||
|
)
|
||||||
|
]
|
||||||
|
.height(Fill)
|
||||||
|
.width(Fill)
|
||||||
|
.into(),
|
||||||
|
RepetitionMessage::Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionState {
|
||||||
|
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||||
|
let mut card_set = DeckData::new(&set, state.clone());
|
||||||
|
let (word, stat) = card_set.next();
|
||||||
|
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||||
|
|
||||||
|
RepetitionState {
|
||||||
|
state,
|
||||||
|
settings: set,
|
||||||
|
set: card_set,
|
||||||
|
current_word: word,
|
||||||
|
current_statistic: stat,
|
||||||
|
open: false,
|
||||||
|
can_play: true,
|
||||||
|
sink: Arc::new(sink_handle),
|
||||||
|
opened: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionState {
|
||||||
fn next(&mut self) -> Task<RootMessage> {
|
fn next(&mut self) -> Task<RootMessage> {
|
||||||
if self.open {
|
if self.open {
|
||||||
self.answer(WordOpenMode::None)
|
self.answer(WordOpenMode::None)
|
||||||
@@ -137,36 +165,6 @@ impl RepetitionState {
|
|||||||
state.activity.insert(id, vec![(now, 1)]);
|
state.activity.insert(id, vec![(now, 1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn view(&self) -> Element<'_, RepetitionMessage> {
|
|
||||||
back_overlay(
|
|
||||||
column![
|
|
||||||
container(self.draw_forward())
|
|
||||||
.width(Fill)
|
|
||||||
.height(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.align_y(alignment::Vertical::Center),
|
|
||||||
rule::horizontal(2),
|
|
||||||
container(self.draw_backward())
|
|
||||||
.width(Fill)
|
|
||||||
.height(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.align_y(alignment::Vertical::Center),
|
|
||||||
container(self.answer_bar())
|
|
||||||
.width(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.height(80),
|
|
||||||
text!(
|
|
||||||
"Затронуто слов {}, {}%",
|
|
||||||
self.opened.len(),
|
|
||||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
|
||||||
)
|
|
||||||
]
|
|
||||||
.height(Fill)
|
|
||||||
.width(Fill)
|
|
||||||
.into(),
|
|
||||||
RepetitionMessage::Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||||
self.draw_card_view(self.settings.forward.as_str())
|
self.draw_card_view(self.settings.forward.as_str())
|
||||||
@@ -197,6 +195,7 @@ impl RepetitionState {
|
|||||||
"speech" => self.draw_voice(),
|
"speech" => self.draw_voice(),
|
||||||
"reading" => self.draw_reading(word),
|
"reading" => self.draw_reading(word),
|
||||||
"context" => self.draw_context(word),
|
"context" => self.draw_context(word),
|
||||||
|
"description" => self.draw_description(word),
|
||||||
_ => space().into(),
|
_ => space().into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -272,6 +271,12 @@ impl RepetitionState {
|
|||||||
Some(context) => text!("{}", context).size(24).into(),
|
Some(context) => text!("{}", context).size(24).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
match word.additional.get("context") {
|
||||||
|
None => space().into(),
|
||||||
|
Some(context) => text!("{}", context).size(24).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyPressedPage for RepetitionState {
|
impl KeyPressedPage for RepetitionState {
|
||||||
@@ -285,8 +290,8 @@ impl KeyPressedPage for RepetitionState {
|
|||||||
text: _,
|
text: _,
|
||||||
repeat: _,
|
repeat: _,
|
||||||
} = message
|
} = message
|
||||||
|
&& let Code(code) = pk
|
||||||
{
|
{
|
||||||
if let Code(code) = pk {
|
|
||||||
return match code {
|
return match code {
|
||||||
keyboard::key::Code::Space => self.next(),
|
keyboard::key::Code::Space => self.next(),
|
||||||
keyboard::key::Code::Digit1 => self.answer(WordOpenMode::None),
|
keyboard::key::Code::Digit1 => self.answer(WordOpenMode::None),
|
||||||
@@ -296,7 +301,7 @@ impl KeyPressedPage for RepetitionState {
|
|||||||
_ => Task::none(),
|
_ => Task::none(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,7 +318,7 @@ pub enum RepetitionMessage {
|
|||||||
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
|
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
|
||||||
let data = get_voice(text.as_str()).await;
|
let data = get_voice(text.as_str()).await;
|
||||||
spawn_blocking(move || {
|
spawn_blocking(move || {
|
||||||
rodio::play(&sink.mixer(), data).unwrap().sleep_until_end();
|
rodio::play(sink.mixer(), data).unwrap().sleep_until_end();
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
+32
-22
@@ -1,23 +1,25 @@
|
|||||||
use crate::data_provider::card_sets::{delete_set, update_card_set};
|
use crate::AppState;
|
||||||
|
use crate::data_provider::card_sets::{delete_set, update_deck};
|
||||||
|
use crate::lang::DeckSettings;
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::repetition_settings::RepetitionSettingsMessage::*;
|
use crate::repetition_settings::RepetitionSettingsMessage::*;
|
||||||
use crate::repetitions::CardSetSettings;
|
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::AppState;
|
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use iced_core::Padding;
|
use iced_core::{color, Padding, Theme};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use iced::widget::text_input::Catalog;
|
||||||
|
|
||||||
pub struct RepetitionSettingsState {
|
pub struct RepetitionSettingsState {
|
||||||
set: CardSetSettings,
|
set: DeckSettings,
|
||||||
index: usize,
|
index: usize,
|
||||||
state: Arc<Mutex<AppState>>,
|
state: Arc<Mutex<AppState>>,
|
||||||
real_delete: bool,
|
real_delete: bool,
|
||||||
|
correct_filter: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepetitionSettingsState {
|
impl RepetitionSettingsState {
|
||||||
@@ -25,19 +27,22 @@ impl RepetitionSettingsState {
|
|||||||
let set;
|
let set;
|
||||||
{
|
{
|
||||||
let local_state = p1.lock().unwrap();
|
let local_state = p1.lock().unwrap();
|
||||||
set = local_state.card_sets[index].clone();
|
set = local_state.decks[index].clone();
|
||||||
}
|
}
|
||||||
|
let filter_state = set.check_filter();
|
||||||
|
|
||||||
RepetitionSettingsState {
|
RepetitionSettingsState {
|
||||||
index,
|
index,
|
||||||
set,
|
set,
|
||||||
state: p1,
|
state: p1,
|
||||||
real_delete: false,
|
real_delete: false,
|
||||||
|
correct_filter: filter_state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||||
fn navigate(&self, message: &RepetitionSettingsMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &RepetitionSettingsMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else {
|
} else {
|
||||||
@@ -45,18 +50,14 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionSettingsState {
|
|
||||||
pub fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
Save => {
|
Save => {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
update_card_set(&mut self.set, &state.connection);
|
update_deck(&mut self.set, &state.connection);
|
||||||
state.card_sets[self.index] = self.set.clone();
|
state.decks[self.index] = self.set.clone();
|
||||||
}
|
}
|
||||||
SetName(new) => {
|
SetName(new) => {
|
||||||
self.set.name = new;
|
self.set.name = new;
|
||||||
@@ -69,6 +70,7 @@ impl RepetitionSettingsState {
|
|||||||
}
|
}
|
||||||
SetFilter(new) => {
|
SetFilter(new) => {
|
||||||
self.set.filter = new;
|
self.set.filter = new;
|
||||||
|
self.correct_filter = self.set.check_filter();
|
||||||
}
|
}
|
||||||
TryFilter => {
|
TryFilter => {
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
@@ -76,24 +78,24 @@ impl RepetitionSettingsState {
|
|||||||
self.set.count = Some(count);
|
self.set.count = Some(count);
|
||||||
}
|
}
|
||||||
DeleteSet => {
|
DeleteSet => {
|
||||||
if self.real_delete == false {
|
if !self.real_delete {
|
||||||
self.real_delete = true;
|
self.real_delete = true;
|
||||||
return Task::future(async {
|
return Task::future(async {
|
||||||
tokio::time::sleep(Duration::from_millis(3000)).await;
|
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||||
return RootMessage::RepetitionSettings(RevertDeleteSet);
|
RootMessage::RepetitionSettings(RevertDeleteSet)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
delete_set(&self.set, &state.connection);
|
delete_set(&self.set, &state.connection);
|
||||||
state.card_sets.remove(self.index);
|
state.decks.remove(self.index);
|
||||||
return Task::done(RootMessage::RepetitionSettings(Back));
|
return Task::done(RootMessage::RepetitionSettings(Back));
|
||||||
},
|
}
|
||||||
RevertDeleteSet => self.real_delete = false,
|
RevertDeleteSet => self.real_delete = false,
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
scrollable(
|
scrollable(
|
||||||
@@ -115,7 +117,13 @@ impl RepetitionSettingsState {
|
|||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Фильтр"),
|
text!("Фильтр"),
|
||||||
text_input("", &self.set.filter).on_input(SetFilter),
|
text_input("", &self.set.filter).style(|x, status| {
|
||||||
|
let mut primary = Theme::default()(x, status);
|
||||||
|
if !self.correct_filter {
|
||||||
|
primary.border.color = color!(255, 255, 0);
|
||||||
|
}
|
||||||
|
primary
|
||||||
|
}).on_input(SetFilter),
|
||||||
button("Проверить фильтр")
|
button("Проверить фильтр")
|
||||||
.style(jl_button)
|
.style(jl_button)
|
||||||
.on_press(TryFilter),
|
.on_press(TryFilter),
|
||||||
@@ -150,8 +158,10 @@ impl RepetitionSettingsState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionSettingsMessage> {
|
impl RepetitionSettingsState {
|
||||||
|
fn count_view(&self, set: &DeckSettings) -> Element<'_, RepetitionSettingsMessage> {
|
||||||
if let Some(count) = set.count {
|
if let Some(count) = set.count {
|
||||||
return text!("Количество слов: {}", count).into();
|
return text!("Количество слов: {}", count).into();
|
||||||
}
|
}
|
||||||
|
|||||||
+385
-265
@@ -1,7 +1,7 @@
|
|||||||
use crate::data_provider::card_sets::{delete_set, update_card_set};
|
use crate::data_provider::card_sets::update_deck;
|
||||||
use crate::data_provider::card_stats::load_stats_of_set;
|
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
||||||
use crate::history::HistoryState;
|
use crate::history::HistoryState;
|
||||||
use crate::lang::{SetOrderMode, WordData};
|
use crate::lang::{AppendMode, CardStatistics, DeckSettings, Id, OrderMode};
|
||||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::repetition::RepetitionState;
|
use crate::repetition::RepetitionState;
|
||||||
@@ -9,141 +9,229 @@ use crate::repetition_settings::RepetitionSettingsState;
|
|||||||
use crate::repetitions::RepetitionsMessage::*;
|
use crate::repetitions::RepetitionsMessage::*;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use chrono::{Days, Local};
|
use chrono::{Days, Local, Utc};
|
||||||
use iced::widget::button::{danger, Status};
|
use hashbrown::{HashMap, HashSet};
|
||||||
pub use iced::widget::button::{Catalog, Style};
|
pub use iced::widget::button::{Catalog, Style};
|
||||||
use iced::widget::container::bordered_box;
|
use iced::widget::button::{Status, danger};
|
||||||
use iced::widget::tooltip::Position::Top;
|
use iced::widget::tooltip::Position::Top;
|
||||||
use iced::widget::{button, column, container, lazy, radio, row, scrollable, space, svg, text, text_input, tooltip, Column, Row};
|
use iced::widget::{
|
||||||
|
Column, Row, button, column, container, lazy, radio, row, scrollable, space, svg, text,
|
||||||
|
text_input, tooltip,
|
||||||
|
};
|
||||||
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
|
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
|
||||||
|
use iced_core::Padding;
|
||||||
use iced_core::border::Radius;
|
use iced_core::border::Radius;
|
||||||
use iced_core::svg::Handle;
|
use iced_core::svg::Handle;
|
||||||
use iced_core::Padding;
|
use std::ops::Deref;
|
||||||
use rhai::{Engine, Scope};
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RepetitionsState {
|
pub struct RepetitionsState {
|
||||||
selected_set: Option<usize>,
|
word_id_index_map: HashMap<Id, usize>,
|
||||||
correct_filters: Vec<bool>,
|
selected_deck_index: Option<usize>,
|
||||||
pub state: Arc<Mutex<AppState>>,
|
decks: Vec<DeckViewData>,
|
||||||
|
state: Arc<Mutex<AppState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
||||||
fn navigate(&self, message: &RepetitionsMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &RepetitionsMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else if let GoToHistory = message {
|
} else if let GoToHistory = message {
|
||||||
let card_set;
|
Some(History(HistoryState::new(
|
||||||
{
|
self.selected_deck().unwrap().id,
|
||||||
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].id;
|
self.state.clone(),
|
||||||
}
|
)))
|
||||||
Some(History(HistoryState::new(card_set, self.state.clone())))
|
|
||||||
} else if let GoToRepetition = message {
|
} else if let GoToRepetition = message {
|
||||||
let clone = self.state.clone();
|
let clone = self.state.clone();
|
||||||
let card_set;
|
|
||||||
|
let selected_set = self.selected_deck_mut().unwrap();
|
||||||
|
if selected_set.append_mode == AppendMode::Full {
|
||||||
|
Self::append_all_words(&mut clone.lock().unwrap(), selected_set);
|
||||||
|
selected_set.existing_words_indices = selected_set.available_words_indices.clone();
|
||||||
|
} else {
|
||||||
|
if selected_set
|
||||||
|
.available_words_indices
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.is_empty()
|
||||||
|
|| selected_set
|
||||||
|
.existing_words_indices
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.is_empty()
|
||||||
{
|
{
|
||||||
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].clone();
|
return None;
|
||||||
}
|
}
|
||||||
Some(Repetition(RepetitionState::new(card_set, clone)))
|
}
|
||||||
|
|
||||||
|
Some(Repetition(RepetitionState::new(
|
||||||
|
selected_set.general_settings.clone(),
|
||||||
|
clone,
|
||||||
|
)))
|
||||||
} else if let GoToSettings = message {
|
} else if let GoToSettings = message {
|
||||||
Some(RepetitionSettings(RepetitionSettingsState::new(
|
Some(RepetitionSettings(RepetitionSettingsState::new(
|
||||||
self.selected_set.unwrap(),
|
self.selected_deck().unwrap().index.unwrap(),
|
||||||
self.state.clone(),
|
self.state.clone(),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
self.selected_set = None;
|
let index = self.selected_deck_index.unwrap();
|
||||||
|
let state = self.state.lock().unwrap();
|
||||||
|
if let Some(global_deck) = state.decks.get(index) {
|
||||||
|
if global_deck.id != self.selected_deck().unwrap().id {
|
||||||
|
drop(state);
|
||||||
|
self.decks.remove(index);
|
||||||
|
self.clear_selection();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drop(state);
|
||||||
|
self.decks.remove(index);
|
||||||
|
self.clear_selection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||||
impl RepetitionsState {
|
|
||||||
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
|
||||||
let count = state.lock().unwrap().card_sets.len();
|
|
||||||
RepetitionsState {
|
|
||||||
selected_set: None,
|
|
||||||
correct_filters: vec![true; count],
|
|
||||||
state,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionsState {
|
|
||||||
pub fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
match message {
|
match message {
|
||||||
Next => {}
|
Next => {}
|
||||||
Back => {}
|
Back => {}
|
||||||
GoToRepetition => {}
|
GoToRepetition => {}
|
||||||
GoToHistory => {}
|
GoToHistory => {}
|
||||||
GoToSettings => {}
|
GoToSettings => {}
|
||||||
|
|
||||||
CreateSet => {
|
CreateSet => {
|
||||||
let index = state.card_sets.len() + 1;
|
let index = self.decks.len() + 1;
|
||||||
state
|
self.decks.push(DeckViewData {
|
||||||
.card_sets
|
general_settings: DeckSettings::with_name(format!("Колода #{}", index)),
|
||||||
.push(CardSetSettings::with_name(format!("Card set #{}", index)));
|
existing_words_indices: None,
|
||||||
self.correct_filters.push(true);
|
available_words_indices: None,
|
||||||
|
append_mode: Default::default(),
|
||||||
|
index: None,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
DeleteSet => {
|
DeleteSet => {
|
||||||
let set = state.card_sets.remove(self.selected_set.unwrap());
|
let index = self.selected_deck_index.unwrap();
|
||||||
self.correct_filters.remove(self.selected_set.unwrap());
|
self.clear_selection();
|
||||||
self.selected_set = None;
|
let deck = self.decks.remove(index);
|
||||||
delete_set(&set, &state.connection);
|
if deck.id.is_valid() {
|
||||||
|
let mut state = self.state.lock().unwrap();
|
||||||
|
state.decks.remove(index);
|
||||||
|
self.decks = self
|
||||||
|
.decks
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|mut deck| {
|
||||||
|
deck.index = state.decks.iter().position(|d| d.id == deck.id);
|
||||||
|
deck
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetName(value) => {
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.general_settings.name = value;
|
||||||
}
|
}
|
||||||
SelectSet(index) => {
|
SelectSet(index) => {
|
||||||
self.selected_set = Some(index);
|
self.select_deck(index);
|
||||||
let mut set = state.card_sets.get(index).unwrap().clone();
|
let deck = self.selected_deck().unwrap();
|
||||||
set.update_worst_words(&state);
|
if deck.existing_words_indices.is_none() {
|
||||||
state.card_sets[index] = set;
|
let state = self.state.lock().unwrap();
|
||||||
|
let added: Vec<_> = load_stats_of_deck(deck, &state.connection)
|
||||||
|
.iter()
|
||||||
|
.map(|c| self.word_id_index_map[&c.word_id])
|
||||||
|
.collect();
|
||||||
|
let total = deck.get_word_list(&state);
|
||||||
|
drop(state);
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.existing_words_indices = Some(added);
|
||||||
|
deck.available_words_indices = Some(total);
|
||||||
}
|
}
|
||||||
SetName(new) => {
|
|
||||||
state.card_sets[self.selected_set.unwrap()].name = new;
|
|
||||||
}
|
}
|
||||||
Save => {
|
Save => {
|
||||||
for i in 0..state.card_sets.len() {
|
let mut deck = self.selected_deck().unwrap().clone();
|
||||||
self.correct_filters[i] = state.card_sets[i].check_filter();
|
let mut state = self.state.lock().unwrap();
|
||||||
|
{
|
||||||
|
update_deck(&mut deck.general_settings, &state.connection);
|
||||||
|
if let Some(index) = deck.index {
|
||||||
|
state.decks[index] = deck.general_settings.clone();
|
||||||
|
} else {
|
||||||
|
state.decks.push(deck.general_settings.clone());
|
||||||
|
deck.index = Some(state.decks.len() - 1);
|
||||||
|
self.decks[self.selected_deck_index.unwrap()] = deck.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let set = &mut state.card_sets[self.selected_set.unwrap()].clone();
|
|
||||||
|
|
||||||
update_card_set(set, &state.connection);
|
|
||||||
|
|
||||||
state.card_sets[self.selected_set.unwrap()] = set.clone();
|
|
||||||
}
|
}
|
||||||
SetForward(new) => {
|
|
||||||
state.card_sets[self.selected_set.unwrap()].forward = new;
|
|
||||||
}
|
}
|
||||||
SetBackward(new) => {
|
SetForward(value) => {
|
||||||
state.card_sets[self.selected_set.unwrap()].backward = new;
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.general_settings.forward = value;
|
||||||
}
|
}
|
||||||
SetFilter(new) => {
|
SetBackward(value) => {
|
||||||
state.card_sets[self.selected_set.unwrap()].filter = new;
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.general_settings.backward = value;
|
||||||
|
}
|
||||||
|
SetFilter(value) => {
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.general_settings.filter = value;
|
||||||
}
|
}
|
||||||
TryFilter => {
|
TryFilter => {
|
||||||
let set = state.card_sets.get(self.selected_set.unwrap()).unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
let count = set.get_word_list(&state).len();
|
let deck = self.selected_deck().unwrap();
|
||||||
state.card_sets[self.selected_set.unwrap()].count = Some(count);
|
let count = deck.get_word_list(&state).len();
|
||||||
|
drop(state);
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.general_settings.count = Some(count);
|
||||||
}
|
}
|
||||||
SetOpenMode(mode) => {
|
SetOpenMode(mode) => {
|
||||||
state
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
.card_sets
|
deck.general_settings.open_mode = mode;
|
||||||
.get_mut(self.selected_set.unwrap())
|
}
|
||||||
|
SetAppendMode(mode) => {
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.append_mode = mode;
|
||||||
|
}
|
||||||
|
AppendWords(count) => {
|
||||||
|
let adding: Vec<usize>;
|
||||||
|
{
|
||||||
|
{
|
||||||
|
let deck = self.selected_deck().unwrap();
|
||||||
|
let existing_words_indices = deck.existing_words_indices.as_ref().unwrap();
|
||||||
|
let mut created_set = HashSet::with_capacity(existing_words_indices.len());
|
||||||
|
existing_words_indices.iter().for_each(|c| {
|
||||||
|
created_set.insert(c);
|
||||||
|
});
|
||||||
|
adding = deck
|
||||||
|
.available_words_indices
|
||||||
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.open_mode = mode;
|
.iter()
|
||||||
|
.filter(|c| !created_set.contains(c))
|
||||||
|
.take(count)
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
let deck = self.selected_deck_mut().unwrap();
|
||||||
|
deck.existing_words_indices
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.append(&mut adding.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let deck = self.selected_deck().unwrap();
|
||||||
|
let mut state = self.state.lock().unwrap();
|
||||||
|
Self::append_words(&mut state, &deck.general_settings, adding.into_iter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, RepetitionsMessage> {
|
fn view(&self) -> Element<'_, RepetitionsMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
row![
|
row![
|
||||||
column![
|
column![
|
||||||
scrollable(self.sets_list()).height(Fill),
|
scrollable(self.decks_list()).height(Fill),
|
||||||
button("Добавить")
|
button("Добавить")
|
||||||
.style(jl_button)
|
.style(jl_button)
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
@@ -151,7 +239,7 @@ impl RepetitionsState {
|
|||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.width(Length::FillPortion(1)),
|
.width(Length::FillPortion(1)),
|
||||||
self.selected_set_view(),
|
self.selected_deck_view(),
|
||||||
]
|
]
|
||||||
.align_y(Center)
|
.align_y(Center)
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -161,9 +249,55 @@ impl RepetitionsState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn launch_delete_button(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
impl RepetitionsState {
|
||||||
if set.id != 0 {
|
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
||||||
|
let state_ = state.lock().unwrap();
|
||||||
|
let mut map = HashMap::with_capacity(state_.dictionary.len());
|
||||||
|
|
||||||
|
state_
|
||||||
|
.dictionary
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(index, word)| {
|
||||||
|
map.insert(word.id, index);
|
||||||
|
});
|
||||||
|
|
||||||
|
let decks = Self::get_decks_from_state(&state_);
|
||||||
|
drop(state_);
|
||||||
|
RepetitionsState {
|
||||||
|
word_id_index_map: map,
|
||||||
|
selected_deck_index: None,
|
||||||
|
decks,
|
||||||
|
state,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_decks_from_state(state: &AppState) -> Vec<DeckViewData> {
|
||||||
|
state
|
||||||
|
.decks
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, deck)| DeckViewData {
|
||||||
|
general_settings: deck.clone(),
|
||||||
|
existing_words_indices: None,
|
||||||
|
available_words_indices: None,
|
||||||
|
append_mode: Default::default(),
|
||||||
|
index: Some(index),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionsState {
|
||||||
|
fn launch_delete_button(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||||
|
if deck.id.is_valid() {
|
||||||
|
if deck.append_mode == AppendMode::Manual
|
||||||
|
&& deck.existing_words_indices.as_ref().unwrap().is_empty()
|
||||||
|
{
|
||||||
|
return text!("Добавьте карточки или измените фильтр").into();
|
||||||
|
}
|
||||||
return row![
|
return row![
|
||||||
space().width(Fill),
|
space().width(Fill),
|
||||||
button(text!("Начать повторение").width(200).center())
|
button(text!("Начать повторение").width(200).center())
|
||||||
@@ -174,24 +308,15 @@ impl RepetitionsState {
|
|||||||
}
|
}
|
||||||
button("Удалить").style(danger).on_press(DeleteSet).into()
|
button("Удалить").style(danger).on_press(DeleteSet).into()
|
||||||
}
|
}
|
||||||
|
fn selected_deck_view(&self) -> Element<'_, RepetitionsMessage> {
|
||||||
fn selected_set_view(&self) -> Element<'_, RepetitionsMessage> {
|
if let Some(deck) = &self.selected_deck() {
|
||||||
if let Some(index) = self.selected_set {
|
|
||||||
let set;
|
|
||||||
{
|
|
||||||
let state = self.state.lock().unwrap();
|
|
||||||
if state.card_sets.len() <= index {
|
|
||||||
return space().width(Length::FillPortion(3)).into();
|
|
||||||
}
|
|
||||||
set = state.card_sets[index].clone();
|
|
||||||
}
|
|
||||||
return column![
|
return column![
|
||||||
scrollable(
|
scrollable(
|
||||||
column![
|
column![
|
||||||
column![
|
column![
|
||||||
text!("Название набора"),
|
text!("Название набора"),
|
||||||
row![
|
row![
|
||||||
text_input("", &set.name).on_input(SetName),
|
text_input("", &deck.name).on_input(SetName),
|
||||||
button(svg(Handle::from_memory(SETTINGS_ICON)))
|
button(svg(Handle::from_memory(SETTINGS_ICON)))
|
||||||
.width(43)
|
.width(43)
|
||||||
.on_press(GoToSettings),
|
.on_press(GoToSettings),
|
||||||
@@ -200,42 +325,58 @@ impl RepetitionsState {
|
|||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
{
|
{
|
||||||
if set.id == 0 {
|
if !deck.id.is_valid() {
|
||||||
column![
|
column![
|
||||||
column![
|
column![
|
||||||
text!("Передняя сторона"),
|
text!("Передняя сторона"),
|
||||||
text_input("", &set.forward).on_input(SetForward),
|
text_input("", &deck.forward).on_input(SetForward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Задняя сторона"),
|
text!("Задняя сторона"),
|
||||||
text_input("", &set.backward).on_input(SetBackward),
|
text_input("", &deck.backward).on_input(SetBackward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Фильтр"),
|
text!("Фильтр"),
|
||||||
text_input("", &set.filter).on_input(SetFilter),
|
text_input("", &deck.filter).on_input(SetFilter),
|
||||||
button("Проверить фильтр")
|
button("Проверить фильтр")
|
||||||
.style(jl_button)
|
.style(jl_button)
|
||||||
.on_press(TryFilter),
|
.on_press(TryFilter),
|
||||||
self.count_view(&set),
|
self.count_view(deck),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
} else {
|
} else {
|
||||||
self.filled_set_data_view(&set)
|
column![
|
||||||
}
|
self.filled_deck_data_view(deck),
|
||||||
},
|
self.word_append_panel(deck),
|
||||||
radio(
|
radio(
|
||||||
"Обычный режим",
|
"Обычный режим",
|
||||||
SetOrderMode::Default,
|
OrderMode::Default,
|
||||||
Some(set.open_mode),
|
Some(deck.open_mode),
|
||||||
|
SetOpenMode
|
||||||
|
),
|
||||||
|
radio(
|
||||||
|
"Начать с плохих слов",
|
||||||
|
OrderMode::TrainWorstFirst,
|
||||||
|
Some(deck.open_mode),
|
||||||
|
SetOpenMode
|
||||||
|
),
|
||||||
|
radio(
|
||||||
|
"Полностью случайно",
|
||||||
|
OrderMode::FullRandom,
|
||||||
|
Some(deck.open_mode),
|
||||||
SetOpenMode
|
SetOpenMode
|
||||||
),
|
),
|
||||||
self.words_words_view(&set),
|
|
||||||
button("История").style(jl_button).on_press(GoToHistory),
|
button("История").style(jl_button).on_press(GoToHistory),
|
||||||
]
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// self.words_words_view(&set),
|
||||||
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.padding(Padding {
|
.padding(Padding {
|
||||||
top: 0.0,
|
top: 0.0,
|
||||||
@@ -247,40 +388,36 @@ impl RepetitionsState {
|
|||||||
.height(Fill),
|
.height(Fill),
|
||||||
row![
|
row![
|
||||||
button("Сохранить").style(jl_button).on_press(Save),
|
button("Сохранить").style(jl_button).on_press(Save),
|
||||||
self.launch_delete_button(&set)
|
self.launch_delete_button(deck)
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING),
|
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.width(Length::FillPortion(3))
|
.align_y(Center),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.width(Length::FillPortion(2))
|
||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
space().width(Length::FillPortion(3)).into()
|
space().width(Length::FillPortion(2)).into()
|
||||||
}
|
}
|
||||||
|
fn filled_deck_data_view(&self, deck: &DeckSettings) -> Column<'_, RepetitionsMessage> {
|
||||||
fn filled_set_data_view(&self, set: &CardSetSettings) -> Column<'_, RepetitionsMessage> {
|
column![self.activity_bar(deck), self.count_comparator_view()]
|
||||||
column![self.activity_bar(set)].align_x(Center)
|
.align_x(Center)
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
fn activity_bar(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
fn activity_bar(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> {
|
||||||
const MAX_DAY_COUNT: f32 = 128.0;
|
const MAX_DAY_COUNT: f32 = 128.0;
|
||||||
|
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
let history = state.activity.get(&set.id);
|
let history = state.activity.get(&deck.id);
|
||||||
let mut counts: Vec<u32> = vec![0; 30 * 7];
|
let mut counts: Vec<u32> = vec![0; 30 * 7];
|
||||||
let now = Local::now().date_naive();
|
let now = Local::now().date_naive();
|
||||||
|
|
||||||
|
|
||||||
if let Some(history) = history {
|
if let Some(history) = history {
|
||||||
for (date, activity) in history {
|
for (date, activity) in history {
|
||||||
let distance = now - *date;
|
let distance = now - *date;
|
||||||
let index = counts.len() as i64 - distance.num_days() - 1;
|
let index = counts.len() as i64 - distance.num_days() - 1;
|
||||||
|
|
||||||
if index == 210 {
|
|
||||||
println!("invalid index")
|
|
||||||
}
|
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -299,8 +436,7 @@ impl RepetitionsState {
|
|||||||
})
|
})
|
||||||
.spacing(QUARTER_SPACING);
|
.spacing(QUARTER_SPACING);
|
||||||
|
|
||||||
|
let mut iter = counts.iter();
|
||||||
let mut iter = counts.into_iter();
|
|
||||||
for i in 0..30 {
|
for i in 0..30 {
|
||||||
let mut column = Column::new().spacing(QUARTER_SPACING);
|
let mut column = Column::new().spacing(QUARTER_SPACING);
|
||||||
|
|
||||||
@@ -308,13 +444,17 @@ impl RepetitionsState {
|
|||||||
let value = *iter.next().unwrap() as f32;
|
let value = *iter.next().unwrap() as f32;
|
||||||
let k = (value / MAX_DAY_COUNT).min(1.0) * 0.9 + 0.1;
|
let k = (value / MAX_DAY_COUNT).min(1.0) * 0.9 + 0.1;
|
||||||
|
|
||||||
let date = now.clone().checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1)).unwrap();
|
let date = (*now)
|
||||||
|
.checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
column = column.push(tooltip(
|
column = column.push(tooltip(
|
||||||
iced::widget::container(space().height(15).width(15)).style(
|
iced::widget::container(space().height(15).width(15)).style(
|
||||||
move |x: &Theme| container::Style {
|
move |x: &Theme| container::Style {
|
||||||
text_color: None,
|
text_color: None,
|
||||||
background: Some(Background::Color(x.palette().primary.scale_alpha(k))),
|
background: Some(Background::Color(
|
||||||
|
x.palette().primary.scale_alpha(k),
|
||||||
|
)),
|
||||||
border: Border {
|
border: Border {
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
width: 0.0,
|
width: 0.0,
|
||||||
@@ -331,67 +471,81 @@ impl RepetitionsState {
|
|||||||
|
|
||||||
row = row.push(column);
|
row = row.push(column);
|
||||||
}
|
}
|
||||||
scrollable(column!["Карта активности", row].spacing(QUARTER_SPACING).align_x(Center))
|
scrollable(
|
||||||
}).into()
|
column!["Карта активности", row]
|
||||||
|
.spacing(QUARTER_SPACING)
|
||||||
}
|
.align_x(Center),
|
||||||
|
|
||||||
fn words_words_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
|
||||||
column![
|
|
||||||
text!("Худшие слова"),
|
|
||||||
container(scrollable(self.worst_words_list(&set)).height(200)).style(bordered_box),
|
|
||||||
radio(
|
|
||||||
"Начать с плохих слов",
|
|
||||||
SetOrderMode::TrainWorstFirst,
|
|
||||||
Some(set.open_mode),
|
|
||||||
SetOpenMode
|
|
||||||
),
|
|
||||||
radio(
|
|
||||||
"Полностью случайно",
|
|
||||||
SetOrderMode::FullRandom,
|
|
||||||
Some(set.open_mode),
|
|
||||||
SetOpenMode
|
|
||||||
)
|
)
|
||||||
]
|
})
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
fn word_append_panel(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||||
fn worst_words_list(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
column![
|
||||||
let mut column = Column::new();
|
text!("Режим добавления карточек"),
|
||||||
|
row![
|
||||||
for word in set.worst_words_list.clone().unwrap() {
|
radio(
|
||||||
column = column.push(text!("{} | {}", &word.key, &word.value));
|
"Добавлять все доступные",
|
||||||
|
AppendMode::Full,
|
||||||
|
Some(deck.append_mode),
|
||||||
|
SetAppendMode
|
||||||
|
),
|
||||||
|
radio(
|
||||||
|
"Добавлять вручную",
|
||||||
|
AppendMode::Manual,
|
||||||
|
Some(deck.append_mode),
|
||||||
|
SetAppendMode
|
||||||
|
)
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING),
|
||||||
|
self.adder_panel(deck),
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
fn adder_panel(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||||
|
match deck.append_mode {
|
||||||
|
AppendMode::Full => space().into(),
|
||||||
|
AppendMode::Manual => row![
|
||||||
|
button("+5").on_press(AppendWords(5)),
|
||||||
|
button("+10").on_press(AppendWords(10)),
|
||||||
|
button("+15").on_press(AppendWords(15)),
|
||||||
|
button("+20").on_press(AppendWords(20))
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into(),
|
||||||
}
|
}
|
||||||
column.into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
fn count_comparator_view(&self) -> Element<'_, RepetitionsMessage> {
|
||||||
if let Some(count) = set.count {
|
let selected_deck = self.selected_deck().unwrap();
|
||||||
|
let now = selected_deck.existing_words_indices.as_ref().unwrap().len();
|
||||||
|
let available = selected_deck
|
||||||
|
.available_words_indices
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.len();
|
||||||
|
text!("{} слова добавлено из {}", now, available).into()
|
||||||
|
}
|
||||||
|
fn count_view(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> {
|
||||||
|
if let Some(count) = deck.count {
|
||||||
return text!("Количество слов: {}", count).into();
|
return text!("Количество слов: {}", count).into();
|
||||||
}
|
}
|
||||||
space().into()
|
space().into()
|
||||||
}
|
}
|
||||||
|
fn decks_list(&self) -> Column<'_, RepetitionsMessage> {
|
||||||
fn sets_list(&self) -> Column<'_, RepetitionsMessage> {
|
|
||||||
let mut column = Column::new();
|
let mut column = Column::new();
|
||||||
let mut i = 0;
|
|
||||||
let sets = &self.state.lock().unwrap().card_sets;
|
for (i, deck) in self.decks.iter().enumerate() {
|
||||||
for set in sets {
|
|
||||||
column = column.push(
|
column = column.push(
|
||||||
button(text!("{}", set.name.clone()))
|
button(text!("{}", &deck.name))
|
||||||
.on_press_with(move || SelectSet(i.clone()))
|
.on_press_with(move || SelectSet(i))
|
||||||
.style(move |_x: &Theme, status: Status| Style {
|
.style(move |_x: &Theme, status: Status| Style {
|
||||||
background: if status == Status::Hovered {
|
background: if status == Status::Hovered {
|
||||||
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
|
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
text_color: if self.correct_filters[i.clone()] {
|
text_color: _x.palette().primary,
|
||||||
_x.palette().primary
|
|
||||||
} else {
|
|
||||||
_x.palette().warning
|
|
||||||
},
|
|
||||||
border: Border {
|
border: Border {
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
width: 0.0,
|
width: 0.0,
|
||||||
@@ -401,13 +555,65 @@ impl RepetitionsState {
|
|||||||
snap: false,
|
snap: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
column
|
column
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RepetitionsState {
|
||||||
|
fn append_all_words(state: &mut AppState, deck: &DeckViewData) {
|
||||||
|
let existing = deck.existing_words_indices.as_ref().unwrap();
|
||||||
|
let mut created_set = HashSet::with_capacity(existing.len());
|
||||||
|
existing.iter().for_each(|c| {
|
||||||
|
created_set.insert(c);
|
||||||
|
});
|
||||||
|
let required = deck
|
||||||
|
.available_words_indices
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(|i| !created_set.contains(i))
|
||||||
|
.cloned();
|
||||||
|
Self::append_words(state, deck, required);
|
||||||
|
}
|
||||||
|
fn append_words(state: &mut AppState, deck: &DeckSettings, indices: impl Iterator<Item = usize>) {
|
||||||
|
let words = &state.dictionary;
|
||||||
|
let stats = &mut indices
|
||||||
|
.map(|i| {
|
||||||
|
let word = &words[i];
|
||||||
|
CardStatistics {
|
||||||
|
id: 0.into(),
|
||||||
|
word_id: word.id,
|
||||||
|
last_open: Utc::now(),
|
||||||
|
score: 1,
|
||||||
|
set_id: deck.id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if !stats.is_empty() {
|
||||||
|
add_stat_list(stats, &mut state.connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_deck(&mut self, index: usize) {
|
||||||
|
if self.decks.get(index).is_some() {
|
||||||
|
self.selected_deck_index = Some(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selected_deck(&self) -> Option<&DeckViewData> {
|
||||||
|
self.decks.get(self.selected_deck_index?)
|
||||||
|
}
|
||||||
|
fn selected_deck_mut(&mut self) -> Option<&mut DeckViewData> {
|
||||||
|
self.decks.get_mut(self.selected_deck_index?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_selection(&mut self) {
|
||||||
|
self.selected_deck_index = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum RepetitionsMessage {
|
pub enum RepetitionsMessage {
|
||||||
Next,
|
Next,
|
||||||
@@ -422,111 +628,25 @@ pub enum RepetitionsMessage {
|
|||||||
SetBackward(String),
|
SetBackward(String),
|
||||||
SetFilter(String),
|
SetFilter(String),
|
||||||
TryFilter,
|
TryFilter,
|
||||||
SetOpenMode(SetOrderMode),
|
SetOpenMode(OrderMode),
|
||||||
|
SetAppendMode(AppendMode),
|
||||||
GoToHistory,
|
GoToHistory,
|
||||||
GoToSettings,
|
GoToSettings,
|
||||||
|
AppendWords(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CardSetSettings {
|
struct DeckViewData {
|
||||||
pub id: u32,
|
general_settings: DeckSettings,
|
||||||
pub name: String,
|
existing_words_indices: Option<Vec<usize>>,
|
||||||
pub forward: String,
|
available_words_indices: Option<Vec<usize>>,
|
||||||
pub backward: String,
|
append_mode: AppendMode,
|
||||||
pub filter: String,
|
index: Option<usize>,
|
||||||
pub count: Option<usize>,
|
|
||||||
pub worst_words_list: Option<Vec<WordData>>,
|
|
||||||
pub open_mode: SetOrderMode,
|
|
||||||
}
|
}
|
||||||
|
impl Deref for DeckViewData {
|
||||||
|
type Target = DeckSettings;
|
||||||
|
|
||||||
impl CardSetSettings {
|
fn deref(&self) -> &Self::Target {
|
||||||
fn with_name(name: String) -> CardSetSettings {
|
&self.general_settings
|
||||||
CardSetSettings {
|
|
||||||
id: 0,
|
|
||||||
name,
|
|
||||||
forward: "".to_string(),
|
|
||||||
backward: "".to_string(),
|
|
||||||
filter: "true".to_string(),
|
|
||||||
count: None,
|
|
||||||
worst_words_list: None,
|
|
||||||
open_mode: SetOrderMode::Default,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_filter(&self) -> bool {
|
|
||||||
let engine = Engine::new();
|
|
||||||
let ast = engine.compile(&self.filter);
|
|
||||||
ast.is_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_word_list(&self, state: &AppState) -> Vec<WordData> {
|
|
||||||
let mut list = vec![];
|
|
||||||
let engine = Engine::new();
|
|
||||||
let ast = engine.compile(&self.filter);
|
|
||||||
if ast.is_err() {
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ast = ast.unwrap();
|
|
||||||
|
|
||||||
let groups = &state.word_groups;
|
|
||||||
|
|
||||||
for word in &state.dictionary {
|
|
||||||
let mut more = rhai::Map::new();
|
|
||||||
for iced in &word.additional {
|
|
||||||
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
|
||||||
}
|
|
||||||
let mut scope = Scope::new();
|
|
||||||
scope
|
|
||||||
.push_constant("key", word.key.clone())
|
|
||||||
.push_constant("value", word.value.clone())
|
|
||||||
.push_constant("tags", word.tags.clone())
|
|
||||||
.push_constant("more", more)
|
|
||||||
.push_constant(
|
|
||||||
"group",
|
|
||||||
groups
|
|
||||||
.iter()
|
|
||||||
.find(|g| g.id == word.group_id)
|
|
||||||
.cloned()
|
|
||||||
.unwrap()
|
|
||||||
.name,
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
|
||||||
if result.is_ok() && result.unwrap() {
|
|
||||||
list.push(word.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn require_speech(&self) -> bool {
|
|
||||||
self.forward == "speech" || self.backward == "speech"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_worst_words(&mut self, state: &AppState) {
|
|
||||||
if let Some(_) = self.worst_words_list {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let connection = &state.connection;
|
|
||||||
let mut stats = load_stats_of_set(self, connection);
|
|
||||||
stats.sort_by_key(|s| s.calculated_score() as i32);
|
|
||||||
let avg = stats.iter().map(|s| s.calculated_score()).sum::<f32>() / stats.len() as f32;
|
|
||||||
let avg = avg * 0.7;
|
|
||||||
let bad: Vec<WordData> = stats
|
|
||||||
.iter()
|
|
||||||
.take_while(|word| word.calculated_score() < avg)
|
|
||||||
.map(|stat| {
|
|
||||||
state.dictionary[state
|
|
||||||
.dictionary
|
|
||||||
.binary_search_by_key(&stat.word_id, |x| x.id)
|
|
||||||
.unwrap()]
|
|
||||||
.clone()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
self.worst_words_list = Some(bad.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-27
@@ -36,7 +36,7 @@ pub enum SelectorMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<SelectorMessage> for SelectorState {
|
impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||||
fn navigate(&self, message: &SelectorMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &SelectorMessage) -> Option<Page> {
|
||||||
if let SelectorMessage::Goto = message {
|
if let SelectorMessage::Goto = message {
|
||||||
return if self.is_writing {
|
return if self.is_writing {
|
||||||
let writing = WritingState::new(&self.set);
|
let writing = WritingState::new(&self.set);
|
||||||
@@ -62,19 +62,8 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl SelectorState {
|
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
|
||||||
Self {
|
|
||||||
set: Default::default(),
|
|
||||||
is_writing: false,
|
|
||||||
state,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
SelectorMessage::Change => match self.set.chars_type {
|
SelectorMessage::Change => match self.set.chars_type {
|
||||||
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
||||||
@@ -86,19 +75,7 @@ impl SelectorState {
|
|||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
fn view(&self) -> Element<'_, SelectorMessage> {
|
||||||
fn nav_style(theme: &Theme, status: Status) -> Style {
|
|
||||||
let mut basic = button::text(theme, status);
|
|
||||||
basic.background = if status == Status::Hovered {
|
|
||||||
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
basic.border.radius = BUTTON_RADIUS.into();
|
|
||||||
basic
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, SelectorMessage> {
|
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
row![
|
row![
|
||||||
@@ -132,6 +109,27 @@ impl SelectorState {
|
|||||||
.padding(10)
|
.padding(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SelectorState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||||
|
Self {
|
||||||
|
set: Default::default(),
|
||||||
|
is_writing: false,
|
||||||
|
state,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nav_style(theme: &Theme, status: Status) -> Style {
|
||||||
|
let mut basic = button::text(theme, status);
|
||||||
|
basic.background = if status == Status::Hovered {
|
||||||
|
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
basic.border.radius = BUTTON_RADIUS.into();
|
||||||
|
basic
|
||||||
|
}
|
||||||
|
|
||||||
fn rows_selector(&self) -> Element<'_, SelectorMessage> {
|
fn rows_selector(&self) -> Element<'_, SelectorMessage> {
|
||||||
let mut row = Row::new();
|
let mut row = Row::new();
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
use crate::repetitions::Style;
|
use crate::repetitions::Style;
|
||||||
|
use iced::Element;
|
||||||
use iced::border::Radius;
|
use iced::border::Radius;
|
||||||
use iced::widget::button::*;
|
use iced::widget::button::*;
|
||||||
use iced::widget::{button, container};
|
use iced::widget::{button, container};
|
||||||
use iced::Element;
|
|
||||||
use iced_core::alignment::Horizontal::Left;
|
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
|
use iced_core::alignment::Horizontal::Left;
|
||||||
use iced_core::{Border, Theme};
|
use iced_core::{Border, Theme};
|
||||||
|
|
||||||
pub const HALF_SPACING: f32 = DEFAULT_SPACING / 2.0;
|
pub const HALF_SPACING: f32 = DEFAULT_SPACING / 2.0;
|
||||||
|
|||||||
+29
-26
@@ -4,7 +4,7 @@ use crate::navigation::Page::PreviousPage;
|
|||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::sync::SyncMessage::*;
|
use crate::sync::SyncMessage::*;
|
||||||
use crate::{fill_state, AppState, RootMessage};
|
use crate::{AppState, RootMessage, fill_state};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::container::rounded_box;
|
use iced::widget::container::rounded_box;
|
||||||
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
|
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
|
||||||
@@ -12,7 +12,6 @@ use iced::{Center, Element, Fill, Font, Length, Task};
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum SyncMessage {
|
pub enum SyncMessage {
|
||||||
Back,
|
Back,
|
||||||
@@ -38,7 +37,7 @@ pub struct SyncState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<SyncMessage> for SyncState {
|
impl NavigatedPage<SyncMessage> for SyncState {
|
||||||
fn navigate(&self, message: &SyncMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &SyncMessage) -> Option<Page> {
|
||||||
if let Back = message
|
if let Back = message
|
||||||
&& !self.frozen
|
&& !self.frozen
|
||||||
{
|
{
|
||||||
@@ -49,23 +48,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {}
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl SyncState {
|
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
|
||||||
let auto_fetch;
|
|
||||||
{
|
|
||||||
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
|
||||||
}
|
|
||||||
Self {
|
|
||||||
auto_fetch,
|
|
||||||
state,
|
|
||||||
frozen: false,
|
|
||||||
progress: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
CopyKey => {
|
CopyKey => {
|
||||||
@@ -83,7 +66,7 @@ impl SyncState {
|
|||||||
}
|
}
|
||||||
KeyCopied => {}
|
KeyCopied => {}
|
||||||
IdReceived(new_id) => {
|
IdReceived(new_id) => {
|
||||||
if validate_id(&new_id) == false {
|
if !validate_id(&new_id) {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
@@ -136,7 +119,7 @@ impl SyncState {
|
|||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
state.sync_data = updated_state.sync_data;
|
state.sync_data = updated_state.sync_data;
|
||||||
state.connection = updated_state.connection;
|
state.connection = updated_state.connection;
|
||||||
state.card_sets = updated_state.card_sets;
|
state.decks = updated_state.decks;
|
||||||
state.dictionary = updated_state.dictionary;
|
state.dictionary = updated_state.dictionary;
|
||||||
state.word_groups = updated_state.word_groups;
|
state.word_groups = updated_state.word_groups;
|
||||||
}
|
}
|
||||||
@@ -146,19 +129,22 @@ impl SyncState {
|
|||||||
state.sync_data.key = None;
|
state.sync_data.key = None;
|
||||||
delete_settings("SYNC_KEY".to_string(), &state.connection);
|
delete_settings("SYNC_KEY".to_string(), &state.connection);
|
||||||
delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection);
|
delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection);
|
||||||
|
|
||||||
}
|
}
|
||||||
SwitchAutoSync => {
|
SwitchAutoSync => {
|
||||||
self.auto_fetch = !self.auto_fetch;
|
self.auto_fetch = !self.auto_fetch;
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
state.sync_data.auto_web_fetch = self.auto_fetch;
|
state.sync_data.auto_web_fetch = self.auto_fetch;
|
||||||
set_setting("AUTO_WEB_FETCH".to_string(), self.auto_fetch.to_string(), &state.connection);
|
set_setting(
|
||||||
|
"AUTO_WEB_FETCH".to_string(),
|
||||||
|
self.auto_fetch.to_string(),
|
||||||
|
&state.connection,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, SyncMessage> {
|
fn view(&self) -> Element<'_, SyncMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
row![space().width(Fill), self.sync_column(), space().width(Fill)]
|
row![space().width(Fill), self.sync_column(), space().width(Fill)]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -167,6 +153,21 @@ impl SyncState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
||||||
|
let auto_fetch;
|
||||||
|
{
|
||||||
|
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
auto_fetch,
|
||||||
|
state,
|
||||||
|
frozen: false,
|
||||||
|
progress: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn sync_column(&self) -> Element<'_, SyncMessage> {
|
fn sync_column(&self) -> Element<'_, SyncMessage> {
|
||||||
let network_view: Element<'_, SyncMessage> = if self.frozen {
|
let network_view: Element<'_, SyncMessage> = if self.frozen {
|
||||||
@@ -197,7 +198,9 @@ impl SyncState {
|
|||||||
button("↓ Скачать").style(jl_button).on_press(GetLast)
|
button("↓ Скачать").style(jl_button).on_press(GetLast)
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING),
|
.spacing(DEFAULT_SPACING),
|
||||||
toggler(self.auto_fetch).label("Автоматическая синхронизация").on_toggle(|_| SwitchAutoSync),
|
toggler(self.auto_fetch)
|
||||||
|
.label("Автоматическая синхронизация")
|
||||||
|
.on_toggle(|_| SwitchAutoSync),
|
||||||
container(network_view).width(Fill),
|
container(network_view).width(Fill),
|
||||||
button("Отключить синхронизацию")
|
button("Отключить синхронизацию")
|
||||||
.style(danger)
|
.style(danger)
|
||||||
|
|||||||
+23
-33
@@ -6,7 +6,7 @@ use crate::styling::*;
|
|||||||
use crate::word::WordMessage::*;
|
use crate::word::WordMessage::*;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
|
use iced::widget::{button, column, row, rule, scrollable, text, text_input};
|
||||||
use iced::{Element, Fill, Task};
|
use iced::{Element, Fill, Task};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ pub struct WordState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<WordMessage> for WordState {
|
impl NavigatedPage<WordMessage> for WordState {
|
||||||
fn navigate(&self, message: &WordMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &WordMessage) -> Option<Page> {
|
||||||
if let Back = message {
|
if let Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else {
|
} else {
|
||||||
@@ -26,18 +26,8 @@ impl NavigatedPage<WordMessage> for WordState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl WordState {
|
|
||||||
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
|
||||||
WordState { state, index, word }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WordState {
|
|
||||||
pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
Save => {
|
Save => {
|
||||||
@@ -59,11 +49,9 @@ impl WordState {
|
|||||||
SetValue(n) => {
|
SetValue(n) => {
|
||||||
self.word.value = n;
|
self.word.value = n;
|
||||||
}
|
}
|
||||||
SetAdditional(key, value) => match key.as_str() {
|
SetAdditional(key, value) => {
|
||||||
_ => {
|
|
||||||
self.word.additional.insert(key, value.clone());
|
self.word.additional.insert(key, value.clone());
|
||||||
}
|
}
|
||||||
},
|
|
||||||
AddAdditional(key) => {
|
AddAdditional(key) => {
|
||||||
self.word.additional.insert(key, "".to_string());
|
self.word.additional.insert(key, "".to_string());
|
||||||
}
|
}
|
||||||
@@ -74,7 +62,7 @@ impl WordState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, WordMessage> {
|
fn view(&self) -> Element<'_, WordMessage> {
|
||||||
let mut fast_add = row![];
|
let mut fast_add = row![];
|
||||||
if !self.word.additional.contains_key("reading") {
|
if !self.word.additional.contains_key("reading") {
|
||||||
fast_add = fast_add.push(
|
fast_add = fast_add.push(
|
||||||
@@ -137,38 +125,40 @@ impl WordState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WordState {
|
||||||
|
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
||||||
|
WordState { state, index, word }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WordState {
|
||||||
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||||
match value.0.as_str() {
|
match value.0.as_str() {
|
||||||
"reading" => self.reading_field(value),
|
"reading" => self.reading_field(value.1),
|
||||||
"description" => self.description_field(value),
|
"description" => self.description_field(value.1),
|
||||||
"context" => self.context_field(value),
|
"context" => self.context_field(value.1),
|
||||||
_ => space().into(),
|
_ => self.additional_field(value.1, value.0.clone(), value.0.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn reading_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "Чтение слова".to_string(), "reading".to_string())
|
self.additional_field(value, "Чтение слова".to_string(), "reading".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn description_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "Описание".to_string(), "description".to_string())
|
self.additional_field(value, "Описание".to_string(), "description".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn context_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn context_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "В контексте".to_string(), "context".to_string())
|
self.additional_field(value, "В контексте".to_string(), "context".to_string())
|
||||||
}
|
}
|
||||||
|
fn additional_field(&self, value: &str, name: String, id: String) -> Element<'_, WordMessage> {
|
||||||
fn additional_field(
|
|
||||||
&self,
|
|
||||||
value: (&String, &String),
|
|
||||||
name: String,
|
|
||||||
id: String,
|
|
||||||
) -> Element<'_, WordMessage> {
|
|
||||||
column![
|
column![
|
||||||
text!("{}", name),
|
text!("{}", name),
|
||||||
row![
|
row![
|
||||||
text_input(id.clone().as_str(), &value.1)
|
text_input(id.clone().as_str(), value)
|
||||||
.on_input({
|
.on_input({
|
||||||
let value = id.clone();
|
let value = id.clone();
|
||||||
move |string| SetAdditional(value.clone(), string)
|
move |string| SetAdditional(value.clone(), string)
|
||||||
|
|||||||
+53
-56
@@ -1,10 +1,10 @@
|
|||||||
|
use crate::RootMessage;
|
||||||
use crate::lang::KanaSet;
|
use crate::lang::KanaSet;
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::RootMessage;
|
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{alignment, Element, Fill, Task};
|
use iced::{Element, Fill, Task, alignment};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -19,7 +19,7 @@ pub struct WritingState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<WritingMessage> for WritingState {
|
impl NavigatedPage<WritingMessage> for WritingState {
|
||||||
fn navigate(&self, message: &WritingMessage) -> Option<Page> {
|
fn navigate(&mut self, message: &WritingMessage) -> Option<Page> {
|
||||||
if let WritingMessage::Back = message {
|
if let WritingMessage::Back = message {
|
||||||
Some(PreviousPage)
|
Some(PreviousPage)
|
||||||
} else {
|
} else {
|
||||||
@@ -27,65 +27,16 @@ impl NavigatedPage<WritingMessage> for WritingState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl WritingState {
|
|
||||||
pub(crate) fn new(set: &KanaSet) -> WritingState {
|
|
||||||
let mut list = set.list();
|
|
||||||
list.shuffle(&mut rand::rng());
|
|
||||||
WritingState {
|
|
||||||
kana: "".to_string(),
|
|
||||||
set: list.clone(),
|
|
||||||
original_set: list,
|
|
||||||
kana_total: "".to_string(),
|
|
||||||
roman_total: "".to_string(),
|
|
||||||
next_text: "Дальше".to_string(),
|
|
||||||
show_all: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WritingState {
|
|
||||||
pub fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
WritingMessage::Back => todo!(),
|
WritingMessage::Back => {},
|
||||||
WritingMessage::Next => self.next(),
|
WritingMessage::Next => self.next(),
|
||||||
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
fn view(&self) -> Element<'_, WritingMessage> {
|
||||||
fn next(&mut self) {
|
|
||||||
if self.set.is_empty() {
|
|
||||||
self.kana = "".to_string();
|
|
||||||
self.roman_total = "".to_string();
|
|
||||||
self.kana_total = "".to_string();
|
|
||||||
|
|
||||||
self.set = self.original_set.clone();
|
|
||||||
self.set.shuffle(&mut rand::rng());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.show_all {
|
|
||||||
if self.set.is_empty() == false && self.kana_total.is_empty() == false {
|
|
||||||
self.set.clear();
|
|
||||||
}
|
|
||||||
for pair in &self.set {
|
|
||||||
self.kana = "---".to_string();
|
|
||||||
self.roman_total += &*format!("{} ", &pair.1.clone()).to_string();
|
|
||||||
self.kana_total += &*format!("{} ", &pair.0).to_string();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let current = self.set.pop().unwrap();
|
|
||||||
self.kana_total += &*format!("{} ", ¤t.0).to_string();
|
|
||||||
self.roman_total += &*format!("{} ", ¤t.1.clone()).to_string();
|
|
||||||
self.kana = current.1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, WritingMessage> {
|
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
checkbox(self.show_all)
|
checkbox(self.show_all)
|
||||||
@@ -112,6 +63,52 @@ impl WritingState {
|
|||||||
.padding(10)
|
.padding(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WritingState {
|
||||||
|
pub(crate) fn new(set: &KanaSet) -> WritingState {
|
||||||
|
let mut list = set.list();
|
||||||
|
list.shuffle(&mut rand::rng());
|
||||||
|
WritingState {
|
||||||
|
kana: "".to_string(),
|
||||||
|
set: list.clone(),
|
||||||
|
original_set: list,
|
||||||
|
kana_total: "".to_string(),
|
||||||
|
roman_total: "".to_string(),
|
||||||
|
next_text: "Дальше".to_string(),
|
||||||
|
show_all: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WritingState {
|
||||||
|
fn next(&mut self) {
|
||||||
|
if self.set.is_empty() {
|
||||||
|
self.kana = "".to_string();
|
||||||
|
self.roman_total = "".to_string();
|
||||||
|
self.kana_total = "".to_string();
|
||||||
|
|
||||||
|
self.set = self.original_set.clone();
|
||||||
|
self.set.shuffle(&mut rand::rng());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.show_all {
|
||||||
|
if !self.set.is_empty() && !self.kana_total.is_empty() {
|
||||||
|
self.set.clear();
|
||||||
|
}
|
||||||
|
for pair in &self.set {
|
||||||
|
self.kana = "---".to_string();
|
||||||
|
self.roman_total += &*format!("{} ", pair.1.clone()).to_string();
|
||||||
|
self.kana_total += &*format!("{} ", pair.0).to_string();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let current = self.set.pop().unwrap();
|
||||||
|
self.kana_total += &*format!("{} ", current.0).to_string();
|
||||||
|
self.roman_total += &*format!("{} ", current.1.clone()).to_string();
|
||||||
|
self.kana = current.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn answers(&self) -> Element<'_, WritingMessage> {
|
fn answers(&self) -> Element<'_, WritingMessage> {
|
||||||
if self.set.is_empty() {
|
if self.set.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user