Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4903725aa |
No files matched your search
Generated
+10
-10
@@ -2230,7 +2230,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"zip",
|
"zip",
|
||||||
"zstd 0.14.1",
|
"zstd 0.14.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4922,9 +4922,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.53.2"
|
version = "1.53.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e95f91fcc7a621e8b030f6aa23c71fe9838ae2fb4d8118b75602a328f5144044"
|
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -6485,11 +6485,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.14.1"
|
version = "0.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4a9ecd0608fac4196ed58e1f337e9a72680fcc9ee449b8bcde6acea680b46f0"
|
checksum = "bf06bd8162af0734b344780deb55b42a2429ae430870d13fcc12f238e880fe6e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zstd-safe 8.1.0",
|
"zstd-safe 8.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6503,18 +6503,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd-safe"
|
name = "zstd-safe"
|
||||||
version = "8.1.0"
|
version = "8.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bdd44c6a7284e91f3717755b24315a302edd9153a01f753c3cba3d765e8eafac"
|
checksum = "ae42c0555055784c70058d19ba8e275528e8a99a706684868ace5da4e716a4ab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zstd-sys",
|
"zstd-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd-sys"
|
name = "zstd-sys"
|
||||||
version = "2.1.1+zstd.1.5.7"
|
version = "2.1.0+zstd.1.5.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aeec9eaf2dffbbd09201e23bd0ffcbaa33bb8e9266a10734fd7ed90a85eca078"
|
checksum = "0ef0a8027ec3ee71300ab3bcbcd0393f434aa72b91ca6d635a39941deae8eea0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
|
|||||||
+2
-2
@@ -15,9 +15,9 @@ rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
|||||||
reqwest = { version = "0.13.5", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0.13.5", features = ["json", "stream", "multipart"] }
|
||||||
rodio = "0.22.2"
|
rodio = "0.22.2"
|
||||||
sha2 = "0.11.0"
|
sha2 = "0.11.0"
|
||||||
tokio = { version = "1.53.2", 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.14.1"
|
zstd = "0.14.0"
|
||||||
zip = "8.6.0"
|
zip = "8.6.0"
|
||||||
rfd = "0.17.2"
|
rfd = "0.17.2"
|
||||||
mimalloc = "0.1.52"
|
mimalloc = "0.1.52"
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
create table exams(
|
|
||||||
id integer primary key,
|
|
||||||
timestamp integer,
|
|
||||||
deck_id integer not null references decks on delete cascade
|
|
||||||
);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
create table exam_entries
|
|
||||||
(
|
|
||||||
id integer primary key,
|
|
||||||
exam_id integer not null references exams on delete cascade,
|
|
||||||
word_id integer not null references words on delete cascade,
|
|
||||||
status integer default null
|
|
||||||
);
|
|
||||||
+1
-7
@@ -18,7 +18,6 @@ use log::info;
|
|||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::data_provider::exam::{ExamEntryRepository, ExamRepository};
|
|
||||||
|
|
||||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||||
|
|
||||||
@@ -71,8 +70,6 @@ pub struct AppState {
|
|||||||
pub connection: Arc<Mutex<SqliteConnection>>,
|
pub connection: Arc<Mutex<SqliteConnection>>,
|
||||||
pub sync_data: Arc<RwLock<AppSettings>>,
|
pub sync_data: Arc<RwLock<AppSettings>>,
|
||||||
pub history: HistoryRepository,
|
pub history: HistoryRepository,
|
||||||
pub exam: ExamRepository,
|
|
||||||
pub exam_entries: ExamEntryRepository
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppState {
|
impl Default for AppState {
|
||||||
@@ -90,9 +87,7 @@ impl AppState {
|
|||||||
word_groups: WordGroupRepository::new(connection.clone()),
|
word_groups: WordGroupRepository::new(connection.clone()),
|
||||||
card_states: CardStateRepository::new(connection.clone()),
|
card_states: CardStateRepository::new(connection.clone()),
|
||||||
history: HistoryRepository::new(connection.clone()),
|
history: HistoryRepository::new(connection.clone()),
|
||||||
exam: ExamRepository::new(connection.clone()),
|
|
||||||
custom_fields: CustomFieldRepository::new(connection.clone()),
|
custom_fields: CustomFieldRepository::new(connection.clone()),
|
||||||
exam_entries: ExamEntryRepository::new(connection.clone()),
|
|
||||||
sync_data: Arc::new(RwLock::new(AppSettings {
|
sync_data: Arc::new(RwLock::new(AppSettings {
|
||||||
key: None,
|
key: None,
|
||||||
auto_web_fetch: false,
|
auto_web_fetch: false,
|
||||||
@@ -113,8 +108,7 @@ pub fn fill_state(state: &mut AppState) {
|
|||||||
state.history.write().start().unwrap();
|
state.history.write().start().unwrap();
|
||||||
state.card_states.write().start().unwrap();
|
state.card_states.write().start().unwrap();
|
||||||
state.custom_fields.write().start().unwrap();
|
state.custom_fields.write().start().unwrap();
|
||||||
state.exam.write().start().unwrap();
|
|
||||||
state.exam_entries.write().start().unwrap();
|
|
||||||
state.sync_data = Arc::new(RwLock::new(setting))
|
state.sync_data = Arc::new(RwLock::new(setting))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -172,7 +172,7 @@ impl DeckData {
|
|||||||
let query = dictionary.query_par(Arc::new(move |word| {
|
let query = dictionary.query_par(Arc::new(move |word| {
|
||||||
let mut more = rhai::Map::new();
|
let mut more = rhai::Map::new();
|
||||||
for kv in &word.additional {
|
for kv in &word.additional {
|
||||||
more.insert(fields[kv.0].clone().into(), kv.1.clone().into());
|
more.insert(fields[&kv.0].clone().into(), kv.1.clone().into());
|
||||||
}
|
}
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
let group_name = groups[groups
|
let group_name = groups[groups
|
||||||
|
|||||||
+1
-35
@@ -146,7 +146,7 @@ impl DeckSettings {
|
|||||||
ast.is_ok()
|
ast.is_ok()
|
||||||
}
|
}
|
||||||
pub fn require_speech(&self) -> bool {
|
pub fn require_speech(&self) -> bool {
|
||||||
self.forward.contains("speech") || self.backward.contains("speech")
|
self.forward == "speech" || self.backward == "speech"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,40 +216,6 @@ impl EntityData for CustomField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Exam {
|
|
||||||
pub id: Id,
|
|
||||||
pub timestamp: DateTime<Utc>,
|
|
||||||
pub deck_id: Id,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EntityData for Exam {
|
|
||||||
fn id(&self) -> Id {
|
|
||||||
self.id
|
|
||||||
}
|
|
||||||
fn set_id(&mut self, id: Id) {
|
|
||||||
self.id = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ExamEntry{
|
|
||||||
pub id: Id,
|
|
||||||
pub exam_id: Id,
|
|
||||||
pub word_id: Id,
|
|
||||||
pub status: Option<bool>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EntityData for ExamEntry {
|
|
||||||
fn id(&self) -> Id {
|
|
||||||
self.id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_id(&mut self, id: Id) {
|
|
||||||
self.id = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EntityHandle<E> {
|
pub struct EntityHandle<E> {
|
||||||
pub(crate) id: Id,
|
pub(crate) id: Id,
|
||||||
index: u32,
|
index: u32,
|
||||||
|
|||||||
@@ -1,22 +1,15 @@
|
|||||||
|
use crate::data::Id;
|
||||||
use crate::data::entities::CardState;
|
use crate::data::entities::CardState;
|
||||||
use crate::data::repositories::{DataRepository, DataRepositoryInner, Query};
|
use crate::data::repositories::{DataRepository, DataRepositoryInner, Query};
|
||||||
use crate::data::Id;
|
|
||||||
use crate::data_access_methods;
|
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use fsrs::MemoryState;
|
use fsrs::MemoryState;
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
data_access_methods!(
|
pub type CardStateRepository = DataRepository<CardState, CardStateDbLayer>;
|
||||||
CardStateDbLayer,
|
pub type CardStateRepositoryInner = DataRepositoryInner<CardState, CardStateDbLayer>;
|
||||||
CardStateRepository,
|
pub type CardStateDbLayer = SqliteDbLayer<CardState, CardStatesQuerySet>;
|
||||||
CardStateRepositoryInner,
|
|
||||||
CardState,
|
|
||||||
CardStatesQuerySet,
|
|
||||||
CardStateQuery
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CardStatesQuerySet;
|
pub struct CardStatesQuerySet;
|
||||||
impl TableAccessQuerySet<CardState> for CardStatesQuerySet {
|
impl TableAccessQuerySet<CardState> for CardStatesQuerySet {
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ use crate::data::entities::CustomField;
|
|||||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
use crate::data_access_methods;
|
|
||||||
|
|
||||||
data_access_methods!(CustomFieldDbLayer, CustomFieldRepository, CustomFieldRepositoryInner, CustomField, CustomFieldsQuerySet, CustomFieldQuery);
|
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
|
||||||
|
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
|
||||||
|
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CustomFieldsQuerySet;
|
pub struct CustomFieldsQuerySet;
|
||||||
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
use crate::data::entities::{Exam, ExamEntry};
|
|
||||||
use crate::data::repositories::*;
|
|
||||||
use crate::data_access_methods;
|
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
|
||||||
use rusqlite::{Error, Params, Row};
|
|
||||||
|
|
||||||
data_access_methods!(
|
|
||||||
ExamDataLayer,
|
|
||||||
ExamRepository,
|
|
||||||
ExamRepositoryInner,
|
|
||||||
Exam,
|
|
||||||
ExamQuerySet,
|
|
||||||
ExamQuery
|
|
||||||
);
|
|
||||||
|
|
||||||
data_access_methods!(
|
|
||||||
ExamEntryLayer,
|
|
||||||
ExamEntryRepository,
|
|
||||||
ExamEntryRepositoryInner,
|
|
||||||
ExamEntry,
|
|
||||||
ExamEntryQuerySet,
|
|
||||||
ExamEntryQuery
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ExamQuerySet;
|
|
||||||
|
|
||||||
impl TableAccessQuerySet<Exam> for ExamQuerySet {
|
|
||||||
fn load() -> &'static str {
|
|
||||||
"SELECT id, timestamp, deck_id FROM exams"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save() -> &'static str {
|
|
||||||
"UPDATE exams set deck_id = $1, timestamp = $2 WHERE id = $3"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add() -> &'static str {
|
|
||||||
"INSERT INTO exams (timestamp, deck_id) values ($1, $2)"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"exams"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_sql(row: &Row) -> Result<Exam, Error> {
|
|
||||||
Ok(Exam {
|
|
||||||
id: row.get(0)?,
|
|
||||||
timestamp: row.get(1)?,
|
|
||||||
deck_id: row.get(2)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert_params(entity: &Exam) -> impl Params {
|
|
||||||
(entity.timestamp.timestamp(), entity.deck_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_params(entity: &Exam) -> impl Params {
|
|
||||||
(entity.timestamp.timestamp(), entity.deck_id, entity.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ExamEntryQuerySet;
|
|
||||||
|
|
||||||
impl TableAccessQuerySet<ExamEntry> for ExamEntryQuerySet {
|
|
||||||
fn load() -> &'static str {
|
|
||||||
"SELECT id, exam_id, word_id, status FROM exam_entries"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save() -> &'static str {
|
|
||||||
"UPDATE exam_entries set status = $1 WHERE id = $2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add() -> &'static str {
|
|
||||||
"INSERT into exam_entries (exam_id, word_id, status) VALUES ($1, $2, $3)"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"exam_entries"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_sql(row: &Row) -> Result<ExamEntry, Error> {
|
|
||||||
Ok(ExamEntry {
|
|
||||||
id: row.get(0)?,
|
|
||||||
exam_id: row.get(1)?,
|
|
||||||
word_id: row.get(2)?,
|
|
||||||
status: row.get(3)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert_params(entity: &ExamEntry) -> impl Params {
|
|
||||||
(entity.exam_id, entity.word_id, entity.status)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_params(entity: &ExamEntry) -> impl Params {
|
|
||||||
(entity.status, entity.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,9 +4,10 @@ use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
|||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use rusqlite::types::{FromSql, FromSqlResult, ToSqlOutput, ValueRef};
|
use rusqlite::types::{FromSql, FromSqlResult, ToSqlOutput, ValueRef};
|
||||||
use rusqlite::{Error, Params, Row, ToSql};
|
use rusqlite::{Error, Params, Row, ToSql};
|
||||||
use crate::data_access_methods;
|
|
||||||
|
|
||||||
data_access_methods!(HistoryDataLayer, HistoryRepository, HistoryRepositoryInner, HistoryNote, HistoryQuerySet, HistoryQuery);
|
pub type HistoryRepository = DataRepository<HistoryNote, HistoryDataLayer>;
|
||||||
|
pub type HistoryRepositoryInner = DataRepositoryInner<HistoryNote, HistoryDataLayer>;
|
||||||
|
pub type HistoryDataLayer = SqliteDbLayer<HistoryNote, HistoryQuerySet>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HistoryQuerySet;
|
pub struct HistoryQuerySet;
|
||||||
|
|||||||
@@ -93,9 +93,7 @@ fn load_old_schema(connection: &Connection) -> Result<ImportData, NotificationDa
|
|||||||
}
|
}
|
||||||
Err(IncorrectAnkiFile)
|
Err(IncorrectAnkiFile)
|
||||||
}
|
}
|
||||||
fn load_new_schema(_: &Connection) -> Result<ImportData, NotificationData> {
|
|
||||||
Err(IncorrectAnkiFile)
|
|
||||||
}
|
|
||||||
pub fn get_words_of_group(
|
pub fn get_words_of_group(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
group_id: u64,
|
group_id: u64,
|
||||||
@@ -119,3 +117,23 @@ pub fn get_words_of_group(
|
|||||||
.filter_map(|x| x.ok())
|
.filter_map(|x| x.ok())
|
||||||
.collect::<Vec<ImportNote>>())
|
.collect::<Vec<ImportNote>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_new_schema(connection: &Connection) -> Result<ImportData, NotificationData> {
|
||||||
|
return Err(IncorrectAnkiFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DeckHeader {
|
||||||
|
pub id: u64,
|
||||||
|
pub name: String,
|
||||||
|
pub count: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_decks(connection: &Connection) -> Result<Vec<DeckHeader>, NotificationData> {
|
||||||
|
let mut stmt = connection
|
||||||
|
.prepare("select id, name from decks")
|
||||||
|
.unwrap();
|
||||||
|
Ok(stmt.query_map([], |row| Ok(DeckHeader{
|
||||||
|
id: row.get::<usize, i64>(0)? as u64,
|
||||||
|
name: row.get(1)?
|
||||||
|
})).unwrap().filter_map(|x| x.ok()).collect::<Vec<DeckHeader>>())
|
||||||
|
}
|
||||||
@@ -19,7 +19,6 @@ pub(crate) mod voice;
|
|||||||
pub(crate) mod web_api;
|
pub(crate) mod web_api;
|
||||||
pub mod word_groups;
|
pub mod word_groups;
|
||||||
pub(crate) mod words;
|
pub(crate) mod words;
|
||||||
pub(crate) mod exam;
|
|
||||||
|
|
||||||
pub trait TableAccessQuerySet<T> {
|
pub trait TableAccessQuerySet<T> {
|
||||||
fn load() -> &'static str;
|
fn load() -> &'static str;
|
||||||
@@ -191,12 +190,3 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> BatchedDbLayer<T> for SqliteDbLay
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! data_access_methods {
|
|
||||||
($layer:ident, $repo:ident, $repoinner:ident, $data:ty, $queryset:ty, $query:ident) => {
|
|
||||||
pub type $repo = DataRepository<$data, $layer>;
|
|
||||||
pub type $repoinner = DataRepositoryInner<$data, $layer>;
|
|
||||||
pub type $layer = SqliteDbLayer<$data, $queryset>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -24,8 +24,6 @@ fn create_tables(conn: &Connection) {
|
|||||||
make_card_stats(conn).expect("Failed to init table");
|
make_card_stats(conn).expect("Failed to init table");
|
||||||
make_history(conn).expect("Failed to init table");
|
make_history(conn).expect("Failed to init table");
|
||||||
make_custom_fields(conn).expect("Failed to init table");
|
make_custom_fields(conn).expect("Failed to init table");
|
||||||
make_exams(conn).expect("Failed to init table");
|
|
||||||
make_exam_entry(conn).expect("Failed to init table");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_settings(conn: &Connection) -> Result<(), rusqlite::Error> {
|
fn make_settings(conn: &Connection) -> Result<(), rusqlite::Error> {
|
||||||
@@ -70,18 +68,6 @@ fn make_custom_fields(conn: &Connection) -> Result<(), rusqlite::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_exams(conn: &Connection) -> Result<(), rusqlite::Error> {
|
|
||||||
let query = include_str!("../../sql/exam.sql");
|
|
||||||
conn.execute(query, ())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_exam_entry(conn: &Connection) -> Result<(), rusqlite::Error> {
|
|
||||||
let query = include_str!("../../sql/exam_entry.sql");
|
|
||||||
conn.execute(query, ())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn default_connection() -> Connection {
|
pub fn default_connection() -> Connection {
|
||||||
let db_file = db_path();
|
let db_file = db_path();
|
||||||
let connection = Connection::open(db_file).expect("Failed to open database");
|
let connection = Connection::open(db_file).expect("Failed to open database");
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
use crate::fs::*;
|
use crate::fs::*;
|
||||||
use crate::notification::NotificationData::{
|
use crate::notification::NotificationData::{CompressError, OpenFileError, PermissionDenied, WebApiUnavailable};
|
||||||
CompressError, OpenFileError, PermissionDenied, WebApiUnavailable,
|
|
||||||
};
|
|
||||||
use crate::notification::{MaybeError, NotificationData};
|
use crate::notification::{MaybeError, NotificationData};
|
||||||
use log::{debug, info};
|
use log::info;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::time::Instant;
|
use tokio::fs::{remove_file, File, OpenOptions};
|
||||||
use tokio::fs::{File, OpenOptions, remove_file};
|
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
||||||
|
|
||||||
@@ -38,13 +35,10 @@ pub async fn send_data(id: String) -> MaybeError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compress(data: Vec<u8>) -> Result<Vec<u8>, NotificationData> {
|
fn compress(data: Vec<u8>) -> Result<Vec<u8>, NotificationData> {
|
||||||
let time = Instant::now();
|
|
||||||
let mut encoder =
|
let mut encoder =
|
||||||
Encoder::new(Vec::new(), 17).map_err(|_| CompressError)?;
|
Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).map_err(|_| CompressError)?;
|
||||||
io::copy(&mut &data[..], &mut encoder).map_err(|_| PermissionDenied)?;
|
io::copy(&mut &data[..], &mut encoder).map_err(|_| PermissionDenied)?;
|
||||||
let result = encoder.finish().map_err(|_| CompressError);
|
encoder.finish().map_err(|_| CompressError)
|
||||||
debug!("Compress time: {:?}", time.elapsed());
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load_data(id: String, temp: bool) -> MaybeError {
|
pub async fn load_data(id: String, temp: bool) -> MaybeError {
|
||||||
@@ -55,7 +49,7 @@ pub async fn load_data(id: String, temp: bool) -> MaybeError {
|
|||||||
.get(&id_url)
|
.get(&id_url)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| WebApiUnavailable)?
|
.map_err(|_| WebApiUnavailable)?
|
||||||
.bytes()
|
.bytes()
|
||||||
.await
|
.await
|
||||||
.map_err(|_| WebApiUnavailable)?
|
.map_err(|_| WebApiUnavailable)?
|
||||||
@@ -80,12 +74,8 @@ pub async fn load_data(id: String, temp: bool) -> MaybeError {
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| WebApiUnavailable)?;
|
.map_err(|_| WebApiUnavailable)?;
|
||||||
set_local_version(version.parse::<u32>().unwrap_or_default()).await?;
|
set_local_version(version.parse::<u32>().unwrap_or_default()).await?;
|
||||||
if db_wal().exists() {
|
|
||||||
remove_file(db_wal()).await.map_err(|_| OpenFileError)?;
|
remove_file(db_wal()).await.map_err(|_| OpenFileError)?;
|
||||||
}
|
remove_file(db_wal()).await.map_err(|_| OpenFileError)?;
|
||||||
if db_shm().exists() {
|
|
||||||
remove_file(db_shm()).await.map_err(|_| OpenFileError)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ use crate::data::entities::WordGroup;
|
|||||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
use crate::data_access_methods;
|
|
||||||
|
|
||||||
data_access_methods!(WordGroupDataLayer, WordGroupRepository, WordGroupRepositoryInner, WordGroup, WordGroupQuerySet, WordGroupQuery);
|
pub type WordGroupRepository = DataRepository<WordGroup, WordGroupDataLayer>;
|
||||||
|
pub type WordGroupRepositoryInner = DataRepositoryInner<WordGroup, WordGroupDataLayer>;
|
||||||
|
pub type WordGroupDataLayer = SqliteDbLayer<WordGroup, WordGroupQuerySet>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WordGroupQuerySet;
|
pub struct WordGroupQuerySet;
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
|||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use litemap::LiteMap;
|
use litemap::LiteMap;
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
use crate::data_access_methods;
|
|
||||||
|
|
||||||
data_access_methods!(WordDataLayer, WordRepository, WordRepositoryInner, WordData, WordQuerySet, WordQuery);
|
|
||||||
|
|
||||||
|
pub type WordRepository = DataRepository<WordData, WordDataLayer>;
|
||||||
|
pub type WordRepositoryInner = DataRepositoryInner<WordData, WordDataLayer>;
|
||||||
|
pub type WordDataLayer = SqliteDbLayer<WordData, WordQuerySet>;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WordQuerySet;
|
pub struct WordQuerySet;
|
||||||
impl TableAccessQuerySet<WordData> for WordQuerySet {
|
impl TableAccessQuerySet<WordData> for WordQuerySet {
|
||||||
|
|||||||
+4
-17
@@ -1,4 +1,4 @@
|
|||||||
use crate::app::{fill_state, AppState};
|
use crate::app::{AppState, fill_state};
|
||||||
use crate::data_provider::sqlite::create_db;
|
use crate::data_provider::sqlite::create_db;
|
||||||
use crate::data_provider::web_api::{
|
use crate::data_provider::web_api::{
|
||||||
get_local_version, get_web_version, load_data, set_local_version,
|
get_local_version, get_web_version, load_data, set_local_version,
|
||||||
@@ -12,7 +12,6 @@ use crate::notification::{
|
|||||||
};
|
};
|
||||||
use crate::pages::dictionary::{DictionaryMessage, DictionaryState};
|
use crate::pages::dictionary::{DictionaryMessage, DictionaryState};
|
||||||
use crate::pages::dictionary_quiz::{DictionaryQuizMessage, DictionaryQuizState};
|
use crate::pages::dictionary_quiz::{DictionaryQuizMessage, DictionaryQuizState};
|
||||||
use crate::pages::exams::{ExamsMessage, ExamsState};
|
|
||||||
use crate::pages::history::{HistoryMessage, HistoryState};
|
use crate::pages::history::{HistoryMessage, HistoryState};
|
||||||
use crate::pages::import::{ImportMessage, ImportState};
|
use crate::pages::import::{ImportMessage, ImportState};
|
||||||
use crate::pages::quiz::{QuizMessage, QuizState};
|
use crate::pages::quiz::{QuizMessage, QuizState};
|
||||||
@@ -33,7 +32,6 @@ use iced::{Element, Task};
|
|||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use crate::pages::exam::{ExamMessage, ExamState};
|
|
||||||
|
|
||||||
impl Default for ScreenState {
|
impl Default for ScreenState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -61,8 +59,6 @@ pub enum RootMessage {
|
|||||||
History(HistoryMessage),
|
History(HistoryMessage),
|
||||||
RepetitionSettings(RepetitionSettingsMessage),
|
RepetitionSettings(RepetitionSettingsMessage),
|
||||||
Import(ImportMessage),
|
Import(ImportMessage),
|
||||||
Exams(ExamsMessage),
|
|
||||||
Exam(ExamMessage),
|
|
||||||
Keyboard(Event),
|
Keyboard(Event),
|
||||||
PushNotification(NotificationRequest),
|
PushNotification(NotificationRequest),
|
||||||
Notification(NotificationMessage),
|
Notification(NotificationMessage),
|
||||||
@@ -84,8 +80,6 @@ pub enum Page {
|
|||||||
History(HistoryState),
|
History(HistoryState),
|
||||||
RepetitionSettings(RepetitionSettingsState),
|
RepetitionSettings(RepetitionSettingsState),
|
||||||
Import(ImportState),
|
Import(ImportState),
|
||||||
Exams(ExamsState),
|
|
||||||
Exam(ExamState),
|
|
||||||
PreviousPage,
|
PreviousPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,9 +182,7 @@ impl ScreenState {
|
|||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings,
|
RepetitionSettings,
|
||||||
Import,
|
Import
|
||||||
Exams,
|
|
||||||
Exam
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
debug!("Update took {:?}", time.elapsed());
|
debug!("Update took {:?}", time.elapsed());
|
||||||
@@ -213,9 +205,7 @@ impl ScreenState {
|
|||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings,
|
RepetitionSettings,
|
||||||
Import,
|
Import
|
||||||
Exams,
|
|
||||||
Exam
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +225,7 @@ impl ScreenState {
|
|||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings,
|
RepetitionSettings,
|
||||||
Import,
|
Import
|
||||||
Exams,
|
|
||||||
Exam
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let notifications = self.notification_manager.draw().map(Notification);
|
let notifications = self.notification_manager.draw().map(Notification);
|
||||||
@@ -251,7 +239,6 @@ impl ScreenState {
|
|||||||
return match page {
|
return match page {
|
||||||
Repetition(page) => page.press(&message),
|
Repetition(page) => page.press(&message),
|
||||||
Dictionary(page) => page.press(&message),
|
Dictionary(page) => page.press(&message),
|
||||||
Exam(page) => page.press(&message),
|
|
||||||
_ => Task::none(),
|
_ => Task::none(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -148,7 +148,7 @@ impl NotificationManager {
|
|||||||
text!("Неподдерживаемый формат файла .apkg")
|
text!("Неподдерживаемый формат файла .apkg")
|
||||||
}
|
}
|
||||||
NotificationData::OpenFileError => {
|
NotificationData::OpenFileError => {
|
||||||
text!("Ошибка открытия файла")
|
text!("Ошибка открытия файла пакета")
|
||||||
}
|
}
|
||||||
NotificationData::VoiceVoxUnavailable => {
|
NotificationData::VoiceVoxUnavailable => {
|
||||||
text!("Не получается подключиться к VoiceVox")
|
text!("Не получается подключиться к VoiceVox")
|
||||||
|
|||||||
@@ -11,5 +11,3 @@ pub mod selector;
|
|||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod word;
|
pub mod word;
|
||||||
pub mod writing;
|
pub mod writing;
|
||||||
pub mod exams;
|
|
||||||
pub mod exam;
|
|
||||||
@@ -152,7 +152,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
}
|
}
|
||||||
ExtendedEdit(i) => {
|
ExtendedEdit(i) => {
|
||||||
self.word_editor = Some(self.editor_for_word(i));
|
self.word_editor = Some(self.editor_for_word(i));
|
||||||
if let Some((_, _, index)) = self.selected_cell {
|
if let Some((_, _, index)) = self.selected_cell.clone() {
|
||||||
self.selected_cell = Some((i, TotalLine, index))
|
self.selected_cell = Some((i, TotalLine, index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,9 +500,9 @@ impl DictionaryState {
|
|||||||
|
|
||||||
let word_line_data = WordLineState {
|
let word_line_data = WordLineState {
|
||||||
is_included: self.included.contains(word_handle),
|
is_included: self.included.contains(word_handle),
|
||||||
key: word.key.clone(),
|
key: word.key.clone().into(),
|
||||||
value: word.value.clone(),
|
value: word.value.clone().into(),
|
||||||
tags: word.tags.clone(),
|
tags: word.tags.clone().into(),
|
||||||
handle: *word_handle,
|
handle: *word_handle,
|
||||||
selection,
|
selection,
|
||||||
number: i,
|
number: i,
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ use crate::pages::dictionary_quiz::DictionaryQuizMessage::*;
|
|||||||
use crate::pages::quiz::Score;
|
use crate::pages::quiz::Score;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{jl_button, jl_text_input};
|
use crate::{jl_button, jl_text_input};
|
||||||
|
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::{container, row, space, text, Row};
|
use iced::widget::{Row, 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;
|
||||||
|
|
||||||
pub struct DictionaryQuizState {
|
pub struct DictionaryQuizState {
|
||||||
|
|||||||
@@ -1,253 +0,0 @@
|
|||||||
use crate::app::AppState;
|
|
||||||
use crate::data::entities::{CustomField, DeckSettings, EntityHandle, ExamEntry, WordData};
|
|
||||||
use crate::data::repositories::Repository;
|
|
||||||
use crate::data::Id;
|
|
||||||
use crate::navigation::Page::PreviousPage;
|
|
||||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
|
||||||
use crate::pages::exam::ExamMessage::*;
|
|
||||||
use crate::pages::repetition::play_sound;
|
|
||||||
use crate::styling::*;
|
|
||||||
use crate::{push_error, push_error_task};
|
|
||||||
use iced::widget::space::horizontal;
|
|
||||||
use iced::widget::{button, column, container, progress_bar, row, text, tooltip};
|
|
||||||
use iced::{Element, Task};
|
|
||||||
use iced_core::keyboard::key::Physical::Code;
|
|
||||||
use iced_core::keyboard::Event;
|
|
||||||
use iced_core::widget::text::Style;
|
|
||||||
use iced_core::Alignment::Center;
|
|
||||||
use iced_core::Length::Fill;
|
|
||||||
use iced_core::{keyboard, Theme};
|
|
||||||
use rand::prelude::SliceRandom;
|
|
||||||
use rand::rng;
|
|
||||||
use rodio::MixerDeviceSink;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub struct ExamState {
|
|
||||||
id: Id,
|
|
||||||
state: AppState,
|
|
||||||
entries: Vec<ExamEntry>,
|
|
||||||
total_count: u32,
|
|
||||||
open: bool,
|
|
||||||
custom_fields_cache: Vec<CustomField>,
|
|
||||||
current_word: WordData,
|
|
||||||
current_exam_entry_handle: EntityHandle<ExamEntry>,
|
|
||||||
deck: DeckSettings,
|
|
||||||
can_play: bool,
|
|
||||||
sink: Arc<Option<MixerDeviceSink>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum ExamMessage {
|
|
||||||
Back,
|
|
||||||
Open,
|
|
||||||
Answer(bool),
|
|
||||||
Play,
|
|
||||||
PlayFinished,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NavigatedPage<ExamMessage> for ExamState {
|
|
||||||
fn navigate(&mut self, message: &ExamMessage) -> Option<Page> {
|
|
||||||
if let Back = message {
|
|
||||||
return Some(PreviousPage);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn navigated(&mut self) {}
|
|
||||||
|
|
||||||
fn update(&mut self, message: ExamMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
|
||||||
Back => {}
|
|
||||||
Open => {
|
|
||||||
if self.open {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.open = true;
|
|
||||||
}
|
|
||||||
Answer(answer) => {
|
|
||||||
if !self.open {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
let id = self.current_exam_entry_handle.id;
|
|
||||||
let mut repo = self.state.exam_entries.write();
|
|
||||||
repo.set(
|
|
||||||
&mut self.current_exam_entry_handle,
|
|
||||||
ExamEntry {
|
|
||||||
id,
|
|
||||||
exam_id: self.id,
|
|
||||||
word_id: self.current_word.id,
|
|
||||||
status: Some(answer),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if let Err(err) = repo.save(&mut self.current_exam_entry_handle) {
|
|
||||||
return push_error_task!(err);
|
|
||||||
}
|
|
||||||
drop(repo);
|
|
||||||
self.open = false;
|
|
||||||
return self.next();
|
|
||||||
}
|
|
||||||
Play => {
|
|
||||||
if !self.can_play {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.can_play = false;
|
|
||||||
let value = self.current_word.key.clone();
|
|
||||||
if self.deck.require_speech() {
|
|
||||||
return Task::perform(play_sound(self.sink.clone(), value), |r| match r {
|
|
||||||
Ok(_) => RootMessage::Exam(PlayFinished),
|
|
||||||
Err(err) => push_error!(err),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayFinished => {
|
|
||||||
self.can_play = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, ExamMessage> {
|
|
||||||
back_overlay(
|
|
||||||
column![
|
|
||||||
column![
|
|
||||||
progress_bar(
|
|
||||||
0.0..=(self.total_count as f32),
|
|
||||||
(self.total_count - self.entries.len() as u32) as f32
|
|
||||||
),
|
|
||||||
row![
|
|
||||||
text!("Решено: {}", self.total_count - self.entries.len() as u32),
|
|
||||||
horizontal().width(Fill),
|
|
||||||
text!("Осталось: {}", self.entries.len())
|
|
||||||
],
|
|
||||||
],
|
|
||||||
crate::widgets::card_display::word_display(
|
|
||||||
&self.deck,
|
|
||||||
&self.current_word,
|
|
||||||
self.open,
|
|
||||||
Play,
|
|
||||||
self.custom_fields_cache.as_slice()
|
|
||||||
),
|
|
||||||
container(self.answer_bar())
|
|
||||||
.width(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.height(80),
|
|
||||||
]
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExamState {
|
|
||||||
fn answer_bar(&self) -> Element<'_, ExamMessage> {
|
|
||||||
if !self.open {
|
|
||||||
return text!("Нажмите Пробел для открытия карточки")
|
|
||||||
.style(|theme: &Theme| Style {
|
|
||||||
color: Some(theme.palette().text.scale_alpha(0.3)),
|
|
||||||
})
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
row![
|
|
||||||
tooltip(
|
|
||||||
button("Не знаю").on_press(Answer(false)),
|
|
||||||
"Клавиша 1",
|
|
||||||
tooltip::Position::Top
|
|
||||||
),
|
|
||||||
tooltip(
|
|
||||||
button("Знаю").on_press(Answer(true)),
|
|
||||||
"Клавиша 2",
|
|
||||||
tooltip::Position::Top
|
|
||||||
),
|
|
||||||
]
|
|
||||||
.spacing(QUARTER_SPACING)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExamState {
|
|
||||||
pub fn new(exam_id: Id, deck: DeckSettings, state: &AppState) -> Self {
|
|
||||||
let custom_fields_cache = state.custom_fields.read().iter().cloned().collect();
|
|
||||||
let sink_handle = if deck.require_speech() {
|
|
||||||
rodio::DeviceSinkBuilder::open_default_sink().ok()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut entries: Vec<_> = state
|
|
||||||
.exam_entries
|
|
||||||
.read()
|
|
||||||
.iter()
|
|
||||||
.filter(|e| e.exam_id == exam_id)
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
let total_count = entries.len() as u32;
|
|
||||||
entries.retain(|e| e.status.is_none());
|
|
||||||
entries.shuffle(&mut rng());
|
|
||||||
let word = state
|
|
||||||
.dictionary
|
|
||||||
.read()
|
|
||||||
.get_static(EntityHandle::from_id(entries.last().unwrap().word_id))
|
|
||||||
.unwrap();
|
|
||||||
Self {
|
|
||||||
id: exam_id,
|
|
||||||
state: state.clone(),
|
|
||||||
current_word: word,
|
|
||||||
current_exam_entry_handle: EntityHandle::from_id(entries.last().unwrap().id),
|
|
||||||
entries,
|
|
||||||
total_count,
|
|
||||||
open: false,
|
|
||||||
custom_fields_cache,
|
|
||||||
deck,
|
|
||||||
can_play: true,
|
|
||||||
sink: Arc::new(sink_handle),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next(&mut self) -> Task<RootMessage> {
|
|
||||||
self.entries.pop().unwrap();
|
|
||||||
if self.entries.is_empty() {
|
|
||||||
return Task::done(RootMessage::Exam(Back));
|
|
||||||
}
|
|
||||||
|
|
||||||
let entry = self.entries.last().unwrap();
|
|
||||||
let handle: EntityHandle<ExamEntry> = EntityHandle::from_id(entry.id);
|
|
||||||
let word = self
|
|
||||||
.state
|
|
||||||
.dictionary
|
|
||||||
.read()
|
|
||||||
.get_static(EntityHandle::from_id(entry.word_id))
|
|
||||||
.unwrap();
|
|
||||||
self.current_word = word;
|
|
||||||
self.current_exam_entry_handle = handle;
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyPressedPage for ExamState {
|
|
||||||
fn press(&mut self, message: &Event) -> Task<RootMessage> {
|
|
||||||
if let Event::KeyPressed {
|
|
||||||
key: _,
|
|
||||||
modified_key: _,
|
|
||||||
physical_key: pk,
|
|
||||||
location: _,
|
|
||||||
modifiers: _,
|
|
||||||
text: _,
|
|
||||||
repeat: _,
|
|
||||||
} = message
|
|
||||||
&& let Code(code) = pk
|
|
||||||
{
|
|
||||||
return match code {
|
|
||||||
keyboard::key::Code::Space => Task::done(RootMessage::Exam(Open)),
|
|
||||||
keyboard::key::Code::Digit1 => Task::done(RootMessage::Exam(Answer(false))),
|
|
||||||
keyboard::key::Code::Digit2 => Task::done(RootMessage::Exam(Answer(true))),
|
|
||||||
_ => Task::none(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,440 +0,0 @@
|
|||||||
use crate::app::AppState;
|
|
||||||
use crate::data::entities::{DeckSettings, EntityHandle, Exam, ExamEntry, WordData};
|
|
||||||
use crate::data::repositories::{BatchedRepository, Repository};
|
|
||||||
use crate::data::Id;
|
|
||||||
use crate::navigation::Page::PreviousPage;
|
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
|
||||||
use crate::notification::MaybeError;
|
|
||||||
use crate::pages::exam::ExamState;
|
|
||||||
use crate::pages::exams::ExamsMessage::*;
|
|
||||||
use crate::pages::repetitions::Style;
|
|
||||||
use crate::push_error;
|
|
||||||
use crate::styling::{
|
|
||||||
back_overlay, cta_button, BUTTON_RADIUS, DEFAULT_SPACING, HALF_SPACING, QUARTER_SPACING,
|
|
||||||
};
|
|
||||||
use crate::{jl_button, push_error_task};
|
|
||||||
use chrono::{Local, Utc};
|
|
||||||
use iced::widget::button::Status;
|
|
||||||
use iced::widget::container::bordered_box;
|
|
||||||
use iced::widget::space::horizontal;
|
|
||||||
use iced::widget::{
|
|
||||||
button, center_x, column, container, row, rule, scrollable, space, text, tooltip,
|
|
||||||
Column,
|
|
||||||
};
|
|
||||||
use iced::{Element, Task};
|
|
||||||
use iced_core::Alignment::*;
|
|
||||||
use iced_core::Length::{Fill, FillPortion};
|
|
||||||
use iced_core::{Background, Border, Color, Shadow, Theme};
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub struct ExamsState {
|
|
||||||
state: AppState,
|
|
||||||
deck_id: EntityHandle<DeckSettings>,
|
|
||||||
deck: DeckSettings,
|
|
||||||
selected_exam_id: Option<EntityHandle<Exam>>,
|
|
||||||
exams: BTreeMap<EntityHandle<Exam>, ExamExtended>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
|
||||||
pub enum ExamsMessage {
|
|
||||||
Back,
|
|
||||||
SelectExam(EntityHandle<Exam>),
|
|
||||||
CreateExam,
|
|
||||||
GotoExam,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NavigatedPage<ExamsMessage> for ExamsState {
|
|
||||||
fn navigate(&mut self, message: &ExamsMessage) -> Option<Page> {
|
|
||||||
if let Back = message {
|
|
||||||
return Some(PreviousPage);
|
|
||||||
}
|
|
||||||
if let Some(selected_exam_id) = self.selected_exam_id
|
|
||||||
&& GotoExam == *message
|
|
||||||
{
|
|
||||||
return Some(Page::Exam(ExamState::new(
|
|
||||||
selected_exam_id.id,
|
|
||||||
self.deck.clone(),
|
|
||||||
&self.state,
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
|
||||||
self.exams = Self::get_exams_list(&self.state, self.deck_id.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, message: ExamsMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
|
||||||
Back => {}
|
|
||||||
GotoExam => {}
|
|
||||||
SelectExam(id) => {
|
|
||||||
self.selected_exam_id = Some(id);
|
|
||||||
}
|
|
||||||
CreateExam => {
|
|
||||||
let exam = Exam {
|
|
||||||
id: Default::default(),
|
|
||||||
timestamp: Utc::now(),
|
|
||||||
deck_id: self.deck_id.id,
|
|
||||||
};
|
|
||||||
let mut exam_repo = self.state.exam.write();
|
|
||||||
let handle = exam_repo.create_now(exam);
|
|
||||||
if let Ok(handle) = handle {
|
|
||||||
drop(exam_repo);
|
|
||||||
if let Err(err) = self.append_exam_entries(handle) {
|
|
||||||
return push_error_task!(err);
|
|
||||||
}
|
|
||||||
self.exams = Self::get_exams_list(&self.state, self.deck_id.id);
|
|
||||||
self.selected_exam_id = Some(handle);
|
|
||||||
} else {
|
|
||||||
return push_error_task!(handle.err().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, ExamsMessage> {
|
|
||||||
back_overlay(
|
|
||||||
column![
|
|
||||||
text(format!("Экзамены для колоды {}", self.deck.name)),
|
|
||||||
row![
|
|
||||||
column![
|
|
||||||
scrollable(self.exams_list()).height(Fill),
|
|
||||||
jl_button!("Добавить").width(Fill).on_press(CreateExam),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.width(FillPortion(1)),
|
|
||||||
self.selected_exam_view(),
|
|
||||||
].spacing(DEFAULT_SPACING)
|
|
||||||
]
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExamsState {
|
|
||||||
pub fn new(deck_id: EntityHandle<DeckSettings>, state: AppState) -> Self {
|
|
||||||
let deck = state.decks.read().get_static(deck_id).unwrap();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
exams: Self::get_exams_list(&state, deck_id.id),
|
|
||||||
state,
|
|
||||||
deck_id,
|
|
||||||
deck,
|
|
||||||
selected_exam_id: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn selected_exam(&self) -> Option<&ExamExtended> {
|
|
||||||
self.exams.get(&self.selected_exam_id?)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn append_exam_entries(&mut self, handle: EntityHandle<Exam>) -> MaybeError {
|
|
||||||
let deck_id = self.deck_id.id;
|
|
||||||
let words: Vec<_> = self
|
|
||||||
.state
|
|
||||||
.card_states
|
|
||||||
.read()
|
|
||||||
.iter()
|
|
||||||
.filter(|state| state.deck_id == deck_id)
|
|
||||||
.map(|state| state.word_id)
|
|
||||||
.collect();
|
|
||||||
let mut entries = words
|
|
||||||
.iter()
|
|
||||||
.map(|word_id| ExamEntry {
|
|
||||||
id: Default::default(),
|
|
||||||
exam_id: handle.id,
|
|
||||||
word_id: *word_id,
|
|
||||||
status: None,
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
self.state
|
|
||||||
.exam_entries
|
|
||||||
.write()
|
|
||||||
.create_now_many(entries.as_mut_slice())?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_exams_list(state: &AppState, deck_id: Id) -> BTreeMap<EntityHandle<Exam>, ExamExtended> {
|
|
||||||
let mut query = state
|
|
||||||
.exam
|
|
||||||
.read()
|
|
||||||
.query(Arc::new(move |exam| exam.deck_id == deck_id));
|
|
||||||
let handles: Vec<_> = query.handles().collect();
|
|
||||||
query
|
|
||||||
.iter(&state.exam.read())
|
|
||||||
.cloned()
|
|
||||||
.zip(handles)
|
|
||||||
.map(|(e, h)| (h, ExamExtended::from(e, state)))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExamsState {
|
|
||||||
pub fn exams_list(&self) -> Column<'_, ExamsMessage> {
|
|
||||||
let mut column = Column::new();
|
|
||||||
|
|
||||||
for (handle, deck) in self.exams.iter() {
|
|
||||||
column = column.push(
|
|
||||||
jl_button!(text!(
|
|
||||||
"{}",
|
|
||||||
&deck
|
|
||||||
.timestamp
|
|
||||||
.with_timezone(&Local)
|
|
||||||
.format("%d/%m/%Y %H:%M")
|
|
||||||
))
|
|
||||||
.on_press_with(move || SelectExam(*handle))
|
|
||||||
.style(move |_x: &Theme, status: Status| Style {
|
|
||||||
background: if status == Status::Hovered {
|
|
||||||
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
text_color: if deck.finished() {
|
|
||||||
_x.palette().success
|
|
||||||
} else {
|
|
||||||
_x.palette().primary
|
|
||||||
},
|
|
||||||
border: Border {
|
|
||||||
color: Default::default(),
|
|
||||||
width: 0.0,
|
|
||||||
radius: BUTTON_RADIUS.into(),
|
|
||||||
},
|
|
||||||
shadow: Shadow::default(),
|
|
||||||
snap: false,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
column
|
|
||||||
}
|
|
||||||
pub fn selected_exam_view(&self) -> Element<'_, ExamsMessage> {
|
|
||||||
if let Some(exam) = self.selected_exam() {
|
|
||||||
return column![
|
|
||||||
center_x(text!(
|
|
||||||
"Экзамен от {}",
|
|
||||||
exam.timestamp
|
|
||||||
.with_timezone(&Local)
|
|
||||||
.format("%d/%m/%Y %H:%M")
|
|
||||||
)),
|
|
||||||
row![text!("{} карточек", exam.total), Self::exam_bar(exam)]
|
|
||||||
.height(30)
|
|
||||||
.align_y(Center)
|
|
||||||
.width(Fill)
|
|
||||||
.spacing(HALF_SPACING),
|
|
||||||
rule::horizontal(2),
|
|
||||||
self.exam_variable_view(exam),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.width(FillPortion(2))
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
space().width(FillPortion(3)).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exam_bar(exam: &ExamExtended) -> Element<'_, ExamsMessage> {
|
|
||||||
let total = 1000.0;
|
|
||||||
let answered = (exam.answered as f64 / exam.total as f64 * total).round();
|
|
||||||
let unknown = (exam.unknown as f64 / exam.total as f64 * total).round();
|
|
||||||
let remaining = (exam.remaining() as f64 / exam.total as f64 * total).round();
|
|
||||||
let mut row = row![];
|
|
||||||
if answered > 0.0 {
|
|
||||||
row = row.push(tooltip(
|
|
||||||
container(space())
|
|
||||||
.height(Fill)
|
|
||||||
.width(FillPortion(answered as u16))
|
|
||||||
.style(|theme: &Theme| container::Style {
|
|
||||||
background: Some(Background::Color(theme.palette().success)),
|
|
||||||
text_color: Default::default(),
|
|
||||||
border: Default::default(),
|
|
||||||
shadow: Default::default(),
|
|
||||||
snap: false,
|
|
||||||
}),
|
|
||||||
text!("Правильно: {}% ({})", answered / 10.0, exam.answered),
|
|
||||||
tooltip::Position::Bottom,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if unknown > 0.0 {
|
|
||||||
row = row.push(tooltip(
|
|
||||||
container(space())
|
|
||||||
.height(Fill)
|
|
||||||
.width(FillPortion(unknown as u16))
|
|
||||||
.style(|theme: &Theme| container::Style {
|
|
||||||
background: Some(Background::Color(theme.palette().danger)),
|
|
||||||
text_color: Default::default(),
|
|
||||||
border: Default::default(),
|
|
||||||
shadow: Default::default(),
|
|
||||||
snap: false,
|
|
||||||
}),
|
|
||||||
text!("Не получилось: {}% ({})", unknown / 10.0, exam.unknown),
|
|
||||||
tooltip::Position::Bottom,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if remaining > 0.0 {
|
|
||||||
row = row.push(tooltip(
|
|
||||||
container(space())
|
|
||||||
.height(Fill)
|
|
||||||
.width(FillPortion(remaining as u16))
|
|
||||||
.style(|theme: &Theme| container::Style {
|
|
||||||
background: Some(Background::Color(theme.palette().primary)),
|
|
||||||
text_color: Default::default(),
|
|
||||||
border: Default::default(),
|
|
||||||
shadow: Default::default(),
|
|
||||||
snap: false,
|
|
||||||
}),
|
|
||||||
text!("Осталось {}% ({})", remaining / 10.0, exam.remaining()),
|
|
||||||
tooltip::Position::Bottom,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
row.width(Fill).height(Fill).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exam_variable_view(&self, exam: &ExamExtended) -> Element<'_, ExamsMessage> {
|
|
||||||
if exam.finished() {
|
|
||||||
self.exam_finished_view(exam)
|
|
||||||
} else {
|
|
||||||
self.exam_ongoing_view(exam)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exam_finished_view(&self, exam: &ExamExtended) -> Element<'_, ExamsMessage> {
|
|
||||||
let result = (exam.answered as f64 / exam.total as f64 * 1000.0).round() / 10.0;
|
|
||||||
let words_repo = self.state.dictionary.read();
|
|
||||||
column![
|
|
||||||
center_x(text!("Итоговый результат: {}%", result).size(28)),
|
|
||||||
row![
|
|
||||||
Self::words_list(
|
|
||||||
"Правильно",
|
|
||||||
exam.answered_list
|
|
||||||
.iter()
|
|
||||||
.map(|handle| words_repo.get_ref_static(*handle).unwrap())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.as_slice()
|
|
||||||
)
|
|
||||||
.width(Fill),
|
|
||||||
Self::words_list(
|
|
||||||
"Не получилось",
|
|
||||||
exam.unknows_list
|
|
||||||
.iter()
|
|
||||||
.map(|handle| words_repo.get_ref_static(*handle).unwrap())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.as_slice()
|
|
||||||
)
|
|
||||||
.width(Fill)
|
|
||||||
]
|
|
||||||
.width(Fill)
|
|
||||||
.spacing(QUARTER_SPACING)
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn exam_ongoing_view(&self, _: &ExamExtended) -> Element<'_, ExamsMessage> {
|
|
||||||
center_x(
|
|
||||||
button("Продолжить экзамен")
|
|
||||||
.style(cta_button)
|
|
||||||
.on_press(GotoExam),
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn words_list<'a>(name: &str, words: &[&WordData]) -> Column<'a, ExamsMessage> {
|
|
||||||
let mut column = column![];
|
|
||||||
for word in words {
|
|
||||||
let container = container(
|
|
||||||
column![text!("{}", word.key), text!("{}", word.value)].padding(QUARTER_SPACING),
|
|
||||||
)
|
|
||||||
.width(Fill)
|
|
||||||
.style(bordered_box);
|
|
||||||
column = column.push(container);
|
|
||||||
}
|
|
||||||
column![
|
|
||||||
text!("{}", name),
|
|
||||||
scrollable(row![
|
|
||||||
column.spacing(QUARTER_SPACING),
|
|
||||||
horizontal().width(DEFAULT_SPACING)
|
|
||||||
])
|
|
||||||
]
|
|
||||||
.align_x(Center)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExamExtended {
|
|
||||||
exam: Exam,
|
|
||||||
total: u32,
|
|
||||||
answered: u32,
|
|
||||||
unknown: u32,
|
|
||||||
answered_list: Vec<EntityHandle<WordData>>,
|
|
||||||
unknows_list: Vec<EntityHandle<WordData>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExamExtended {
|
|
||||||
fn from(exam: Exam, state: &AppState) -> Self {
|
|
||||||
let entries = state.exam_entries.read();
|
|
||||||
let mut total = 0;
|
|
||||||
let mut answered = 0;
|
|
||||||
let mut unknown = 0;
|
|
||||||
let mut answered_list = Vec::with_capacity(128);
|
|
||||||
let mut unknows_list = Vec::with_capacity(128);
|
|
||||||
entries
|
|
||||||
.iter()
|
|
||||||
.filter(|e| e.exam_id == exam.id)
|
|
||||||
.for_each(|e| {
|
|
||||||
total += 1;
|
|
||||||
match e.status {
|
|
||||||
None => {}
|
|
||||||
Some(s) => {
|
|
||||||
if s {
|
|
||||||
answered += 1;
|
|
||||||
answered_list.push(EntityHandle::from_id(e.word_id));
|
|
||||||
} else {
|
|
||||||
unknown += 1;
|
|
||||||
unknows_list.push(EntityHandle::from_id(e.word_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self {
|
|
||||||
exam,
|
|
||||||
total,
|
|
||||||
answered,
|
|
||||||
unknown,
|
|
||||||
answered_list,
|
|
||||||
unknows_list,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn solved(&self) -> u32 {
|
|
||||||
self.answered + self.unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finished(&self) -> bool {
|
|
||||||
self.solved() == self.total
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remaining(&self) -> u32 {
|
|
||||||
self.total - self.solved()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for ExamExtended {
|
|
||||||
type Target = Exam;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.exam
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DerefMut for ExamExtended {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.exam
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,7 @@ impl HistoryState {
|
|||||||
let history_repo = &mut state.history.write();
|
let history_repo = &mut state.history.write();
|
||||||
history_repo.init().expect("TODO: panic message");
|
history_repo.init().expect("TODO: panic message");
|
||||||
let mut history = history_repo.query(Arc::new(move |h| h.deck_id == id));
|
let mut history = history_repo.query(Arc::new(move |h| h.deck_id == id));
|
||||||
let mut words: Vec<_> = history
|
let words = history
|
||||||
.iter(history_repo)
|
.iter(history_repo)
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
let handle = dict.handle_by_id(item.word_id);
|
let handle = dict.handle_by_id(item.word_id);
|
||||||
@@ -64,7 +64,6 @@ impl HistoryState {
|
|||||||
(word, item.clone())
|
(word, item.clone())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
words.reverse();
|
|
||||||
Self { list: words }
|
Self { list: words }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ use crate::{jl_text_input, push_error};
|
|||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::container::success;
|
use iced::widget::container::success;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
Row, button, checkbox, column, container, progress_bar, row, rule, text,
|
Row, button, checkbox, column, container, progress_bar, row, rule, text, text_input,
|
||||||
};
|
};
|
||||||
use iced::widget::{scrollable, space};
|
use iced::widget::{scrollable, space};
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
|
|||||||
+88
-13
@@ -1,22 +1,22 @@
|
|||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
use crate::core::deck::DeckData;
|
use crate::core::deck::DeckData;
|
||||||
use crate::core::srs::WordOpenMode;
|
use crate::core::srs::WordOpenMode;
|
||||||
use crate::data::entities::{CardState, CustomField, WordData};
|
|
||||||
use crate::data::repositories::Repository;
|
|
||||||
use crate::data::Id;
|
use crate::data::Id;
|
||||||
|
use crate::data::entities::{CardState, WordData};
|
||||||
|
use crate::data::repositories::Repository;
|
||||||
use crate::data_provider::voice::get_voice;
|
use crate::data_provider::voice::get_voice;
|
||||||
|
use crate::jl_button;
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
||||||
use crate::notification::{MaybeError, NotificationData};
|
use crate::notification::{MaybeError, NotificationData};
|
||||||
use crate::pages::repetition::RepetitionMessage::Play;
|
|
||||||
use crate::pages::repetitions::DeckRunData;
|
use crate::pages::repetitions::DeckRunData;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{push_error, push_error_task};
|
use crate::{push_error, push_error_task};
|
||||||
use iced::alignment::Horizontal::Center;
|
use iced::alignment::Horizontal::Center;
|
||||||
use iced::keyboard::key::Physical::Code;
|
use iced::keyboard::key::Physical::Code;
|
||||||
use iced::widget::text::Style;
|
use iced::widget::text::Style;
|
||||||
use iced::widget::{button, column, container, row, text, tooltip};
|
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
|
||||||
use iced::{keyboard, Element, Fill, Task, Theme};
|
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
||||||
use rodio::MixerDeviceSink;
|
use rodio::MixerDeviceSink;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -32,7 +32,6 @@ pub struct RepetitionState {
|
|||||||
can_play: bool,
|
can_play: bool,
|
||||||
sink: Arc<Option<MixerDeviceSink>>,
|
sink: Arc<Option<MixerDeviceSink>>,
|
||||||
opened: HashSet<Id>,
|
opened: HashSet<Id>,
|
||||||
custom_fields_cache: Vec<CustomField>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||||
@@ -50,7 +49,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
RepetitionMessage::Back => {}
|
RepetitionMessage::Back => {}
|
||||||
RepetitionMessage::Next => return self.next(),
|
RepetitionMessage::Next => return self.next(),
|
||||||
RepetitionMessage::Answer(m) => return self.answer(m),
|
RepetitionMessage::Answer(m) => return self.answer(m),
|
||||||
Play => {
|
RepetitionMessage::Play => {
|
||||||
if !self.can_play {
|
if !self.can_play {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
@@ -74,7 +73,17 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
fn view(&self) -> Element<'_, RepetitionMessage> {
|
fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
column![
|
column![
|
||||||
crate::widgets::card_display::word_display(&self.settings.general_settings, &self.current_word, self.open, Play, self.custom_fields_cache.as_slice()),
|
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())
|
container(self.answer_bar())
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.align_x(Center)
|
.align_x(Center)
|
||||||
@@ -83,7 +92,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
"Затронуто слов {}, {}%",
|
"Затронуто слов {}, {}%",
|
||||||
self.opened.len(),
|
self.opened.len(),
|
||||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||||
),
|
)
|
||||||
]
|
]
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
@@ -108,8 +117,6 @@ impl RepetitionState {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let custom_fields_cache = state.custom_fields.read().iter().cloned().collect();
|
|
||||||
|
|
||||||
Ok(RepetitionState {
|
Ok(RepetitionState {
|
||||||
state,
|
state,
|
||||||
settings: set,
|
settings: set,
|
||||||
@@ -120,7 +127,6 @@ impl RepetitionState {
|
|||||||
can_play: true,
|
can_play: true,
|
||||||
sink: Arc::new(sink_handle),
|
sink: Arc::new(sink_handle),
|
||||||
opened: HashSet::new(),
|
opened: HashSet::new(),
|
||||||
custom_fields_cache,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,6 +169,43 @@ impl RepetitionState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||||
|
self.draw_card_view(self.settings.forward.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_backward(&self) -> Element<'_, RepetitionMessage> {
|
||||||
|
if !self.open {
|
||||||
|
return container(text!("?").size(72))
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
|
.align_y(alignment::Vertical::Center)
|
||||||
|
.align_x(Center)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.draw_card_view(self.settings.backward.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_card_view(&self, properties: &str) -> Element<'_, RepetitionMessage> {
|
||||||
|
let word = &self.current_word;
|
||||||
|
|
||||||
|
let mut col = Column::new();
|
||||||
|
|
||||||
|
for view_type in properties.split(" ") {
|
||||||
|
col = col.push(match view_type {
|
||||||
|
"key" => self.draw_key(word),
|
||||||
|
"value" => self.draw_value(word),
|
||||||
|
"speech" => self.draw_voice(),
|
||||||
|
"reading" => self.draw_reading(word),
|
||||||
|
"context" => self.draw_context(word),
|
||||||
|
"description" => self.draw_description(word),
|
||||||
|
_ => space().into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
col.spacing(DEFAULT_SPACING).align_x(Center).into()
|
||||||
|
}
|
||||||
|
|
||||||
fn answer_bar(&self) -> Element<'_, RepetitionMessage> {
|
fn answer_bar(&self) -> Element<'_, RepetitionMessage> {
|
||||||
if !self.open {
|
if !self.open {
|
||||||
return text!("Нажмите Пробел для открытия карточки")
|
return text!("Нажмите Пробел для открытия карточки")
|
||||||
@@ -204,6 +247,38 @@ impl RepetitionState {
|
|||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_key(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
text!("{}", word.key).size(36).into()
|
||||||
|
}
|
||||||
|
fn draw_value(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
text!("{}", word.value).size(24).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_voice(&self) -> Element<'_, RepetitionMessage> {
|
||||||
|
jl_button!("Воспроизвести")
|
||||||
|
.on_press(RepetitionMessage::Play)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_reading(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
match word.additional.get(&Id(1)) {
|
||||||
|
None => space().into(),
|
||||||
|
Some(reading) => text!("{}", reading).size(24).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn draw_context(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
match word.additional.get(&Id(3)) {
|
||||||
|
None => space().into(),
|
||||||
|
Some(context) => text!("{}", context).center().size(24).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
match word.additional.get(&Id(2)) {
|
||||||
|
None => space().into(),
|
||||||
|
Some(context) => text!("{}", context).center().size(24).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyPressedPage for RepetitionState {
|
impl KeyPressedPage for RepetitionState {
|
||||||
@@ -242,7 +317,7 @@ pub enum RepetitionMessage {
|
|||||||
PlayFinished,
|
PlayFinished,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) -> MaybeError {
|
async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) -> MaybeError {
|
||||||
let data = get_voice(text.as_str()).await?;
|
let data = get_voice(text.as_str()).await?;
|
||||||
spawn_blocking(move || {
|
spawn_blocking(move || {
|
||||||
if let Some(sink) = sink.as_ref()
|
if let Some(sink) = sink.as_ref()
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ use crate::{push_error, push_error_task};
|
|||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
use iced::widget::text_input::Catalog;
|
use iced::widget::text_input::Catalog;
|
||||||
use iced::widget::{button, column, row, scrollable, space, text};
|
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::{color, Padding, Theme};
|
use iced_core::{Padding, Theme, color};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ use crate::core::deck::DeckData;
|
|||||||
use crate::core::srs::{AppendMode, OrderMode};
|
use crate::core::srs::{AppendMode, OrderMode};
|
||||||
use crate::data::entities::{CardState, DeckSettings, EntityHandle, WordData};
|
use crate::data::entities::{CardState, DeckSettings, EntityHandle, WordData};
|
||||||
use crate::data::repositories::{BatchedRepository, Repository};
|
use crate::data::repositories::{BatchedRepository, Repository};
|
||||||
use crate::navigation::Page::{Exams, History, PreviousPage, Repetition, RepetitionSettings};
|
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::notification::MaybeError;
|
use crate::notification::MaybeError;
|
||||||
use crate::pages::exams::ExamsState;
|
|
||||||
use crate::pages::history::HistoryState;
|
use crate::pages::history::HistoryState;
|
||||||
use crate::pages::repetition::RepetitionState;
|
use crate::pages::repetition::RepetitionState;
|
||||||
use crate::pages::repetition_settings::RepetitionSettingsState;
|
use crate::pages::repetition_settings::RepetitionSettingsState;
|
||||||
@@ -17,16 +16,17 @@ use crate::styling::*;
|
|||||||
use crate::{jl_button, jl_text_input};
|
use crate::{jl_button, jl_text_input};
|
||||||
use chrono::{Days, Local, Utc};
|
use chrono::{Days, Local, Utc};
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
use iced::widget::button::{danger, Status};
|
|
||||||
pub use iced::widget::button::{Catalog, Style};
|
pub use iced::widget::button::{Catalog, Style};
|
||||||
|
use iced::widget::button::{Status, danger};
|
||||||
use iced::widget::tooltip::Position::Top;
|
use iced::widget::tooltip::Position::Top;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
button, column, container, lazy, radio, row, scrollable, space, svg, text, tooltip, Column, Row,
|
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::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -74,9 +74,9 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
self.selected_deck_handle.unwrap(),
|
self.selected_deck_handle.unwrap(),
|
||||||
self.state.clone(),
|
self.state.clone(),
|
||||||
)))
|
)))
|
||||||
} else if let GoToExams = message {
|
} else {
|
||||||
Some(Exams(ExamsState::new(self.selected_deck_handle.unwrap(), self.state.clone())))
|
None
|
||||||
} else { None }
|
}
|
||||||
}
|
}
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
if let Some(index) = self.selected_deck_handle {
|
if let Some(index) = self.selected_deck_handle {
|
||||||
@@ -219,7 +219,6 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
return push_error_task!(err);
|
return push_error_task!(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GoToExams => {}
|
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
@@ -356,10 +355,7 @@ impl RepetitionsState {
|
|||||||
Some(deck.open_mode),
|
Some(deck.open_mode),
|
||||||
SetOpenMode
|
SetOpenMode
|
||||||
),
|
),
|
||||||
row![
|
|
||||||
jl_button!("История").on_press(GoToHistory),
|
jl_button!("История").on_press(GoToHistory),
|
||||||
jl_button!("Экзамены").on_press(GoToExams),
|
|
||||||
].spacing(DEFAULT_SPACING),
|
|
||||||
]
|
]
|
||||||
.spacing(HALF_SPACING)
|
.spacing(HALF_SPACING)
|
||||||
}
|
}
|
||||||
@@ -634,7 +630,6 @@ pub enum RepetitionsMessage {
|
|||||||
SetOpenMode(OrderMode),
|
SetOpenMode(OrderMode),
|
||||||
SetAppendMode(AppendMode),
|
SetAppendMode(AppendMode),
|
||||||
GoToHistory,
|
GoToHistory,
|
||||||
GoToExams,
|
|
||||||
GoToSettings,
|
GoToSettings,
|
||||||
AppendWords(usize),
|
AppendWords(usize),
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -107,7 +107,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
return Task::batch([
|
return Task::batch([
|
||||||
Task::future(async {
|
Task::future(async {
|
||||||
tokio::time::sleep(Duration::from_millis(3000)).await;
|
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||||
RootMessage::Sync(ResetRealLoad)
|
return RootMessage::Sync(ResetRealLoad);
|
||||||
}),
|
}),
|
||||||
Task::done(RootMessage::PushNotification(NotificationRequest::Warning(LocalVersionChanged)))
|
Task::done(RootMessage::PushNotification(NotificationRequest::Warning(LocalVersionChanged)))
|
||||||
]);
|
]);
|
||||||
@@ -115,16 +115,12 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
|
|
||||||
self.real_load = false;
|
self.real_load = false;
|
||||||
let id = self.state.sync_data.read().key.clone().unwrap();
|
let id = self.state.sync_data.read().key.clone().unwrap();
|
||||||
self.state.connection.lock().finish();
|
|
||||||
let tasks = Task::batch([
|
let tasks = Task::batch([
|
||||||
Task::perform(
|
Task::perform(
|
||||||
async { tokio::time::sleep(Duration::from_millis(200)).await },
|
async { tokio::time::sleep(Duration::from_millis(200)).await },
|
||||||
|_| RootMessage::Sync(NextAnimation),
|
|_| RootMessage::Sync(NextAnimation),
|
||||||
),
|
),
|
||||||
Task::perform(load_data(id, false), |load_result| match load_result {
|
Task::perform(load_data(id, false), |_| RootMessage::Sync(NetworkFinished)),
|
||||||
Ok(_) => RootMessage::Sync(NetworkFinished),
|
|
||||||
Err(error) => push_error!(error)
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return tasks;
|
return tasks;
|
||||||
@@ -222,8 +218,6 @@ impl SyncState {
|
|||||||
self.state.decks.write().reload()?;
|
self.state.decks.write().reload()?;
|
||||||
self.state.dictionary.write().reload()?;
|
self.state.dictionary.write().reload()?;
|
||||||
self.state.history.write().reload()?;
|
self.state.history.write().reload()?;
|
||||||
self.state.exam.write().reload()?;
|
|
||||||
self.state.exam_entries.write().reload()?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -138,7 +138,9 @@ impl<Message: std::clone::Clone> WordEditor<Message> {
|
|||||||
impl<Message: std::clone::Clone> WordEditor<Message> {
|
impl<Message: std::clone::Clone> WordEditor<Message> {
|
||||||
fn get_view_for_more(&self, value: (&Id, &String)) -> Element<'_, WordMessage> {
|
fn get_view_for_more(&self, value: (&Id, &String)) -> Element<'_, WordMessage> {
|
||||||
let field = self.fields.iter().find(|f| f.id == *value.0).unwrap();
|
let field = self.fields.iter().find(|f| f.id == *value.0).unwrap();
|
||||||
self.additional_field(value.1, field.name.as_str(), *value.0)
|
match value.0 {
|
||||||
|
_ => self.additional_field(value.1, field.name.as_str(), value.0.clone()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn additional_field(&self, value: &str, name: &str, id: Id) -> Element<'_, WordMessage> {
|
fn additional_field(&self, value: &str, name: &str, id: Id) -> Element<'_, WordMessage> {
|
||||||
|
|||||||
+17
-1
@@ -1,5 +1,5 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mod_tests {
|
mod data_access {
|
||||||
use crate::data::Id;
|
use crate::data::Id;
|
||||||
use crate::data::entities::{EntityData, EntityHandle};
|
use crate::data::entities::{EntityData, EntityHandle};
|
||||||
use crate::data::repositories::fast_position_of;
|
use crate::data::repositories::fast_position_of;
|
||||||
@@ -121,3 +121,19 @@ mod mod_tests {
|
|||||||
assert_eq!(entity.index(), 0)
|
assert_eq!(entity.index(), 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod anki_import{
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use crate::data_provider::import::load_decks;
|
||||||
|
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn decks(){
|
||||||
|
let file_name = Path::new("import");
|
||||||
|
let connection = Connection::open(file_name).unwrap();
|
||||||
|
let decks = load_decks(&connection).unwrap();
|
||||||
|
assert_eq!(decks.len(), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
use crate::data::entities::{CustomField, DeckSettings, WordData};
|
|
||||||
use crate::data::Id;
|
|
||||||
use crate::styling::HALF_SPACING;
|
|
||||||
use iced::widget::{button, center, column, rule, text};
|
|
||||||
use iced_core::Alignment::Center;
|
|
||||||
use iced_core::Length::Fill;
|
|
||||||
|
|
||||||
pub fn word_display<'a, T: 'a + Clone>(
|
|
||||||
deck: &DeckSettings,
|
|
||||||
word: &WordData,
|
|
||||||
open: bool,
|
|
||||||
speech_action: T,
|
|
||||||
fields_set: &[CustomField],
|
|
||||||
) -> iced::Element<'a, T> {
|
|
||||||
column![
|
|
||||||
forward_side(deck, word, speech_action.clone(), fields_set),
|
|
||||||
rule::horizontal(2),
|
|
||||||
backward_side(deck, word, speech_action, fields_set, open)
|
|
||||||
]
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn forward_side<'a, T: 'a + Clone>(
|
|
||||||
deck: &DeckSettings,
|
|
||||||
word: &WordData,
|
|
||||||
speech_action: T,
|
|
||||||
fields_set: &[CustomField],
|
|
||||||
) -> iced::Element<'a, T> {
|
|
||||||
center(property_draw(
|
|
||||||
deck.forward.as_str(),
|
|
||||||
word,
|
|
||||||
speech_action,
|
|
||||||
fields_set,
|
|
||||||
))
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn backward_side<'a, T: 'a + Clone>(
|
|
||||||
deck: &DeckSettings,
|
|
||||||
word: &WordData,
|
|
||||||
speech_action: T,
|
|
||||||
fields_set: &[CustomField],
|
|
||||||
open: bool,
|
|
||||||
) -> iced::Element<'a, T> {
|
|
||||||
if open {
|
|
||||||
return center(property_draw(
|
|
||||||
deck.backward.as_str(),
|
|
||||||
word,
|
|
||||||
speech_action,
|
|
||||||
fields_set,
|
|
||||||
))
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
center(text!("?").size(72)).width(Fill).height(Fill).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn property_draw<'a, T: 'a + Clone>(
|
|
||||||
formula: &str,
|
|
||||||
word: &WordData,
|
|
||||||
speech_action: T,
|
|
||||||
fields_set: &[CustomField],
|
|
||||||
) -> iced::Element<'a, T> {
|
|
||||||
let mut column = column![];
|
|
||||||
let parts = formula.split(" ");
|
|
||||||
println!("{:?}", formula);
|
|
||||||
for part in parts {
|
|
||||||
println!("displaying {}", part);
|
|
||||||
match part {
|
|
||||||
"key" => column = column.push(text!("{}", word.key).align_x(Center).size(48)),
|
|
||||||
"value" => column = column.push(text!("{}", word.value).align_x(Center).size(28)),
|
|
||||||
"tags" => column = column.push(text!("{}", word.tags).align_x(Center).size(28)),
|
|
||||||
"speech" => {
|
|
||||||
column = column.push(button("Воспроизвести").on_press(speech_action.clone()))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
if part == "reading"
|
|
||||||
&& let Some(reading) = word.additional.get(&Id(1))
|
|
||||||
{
|
|
||||||
column = column.push(text!("{}", reading).align_x(Center).size(24));
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if part == "description"
|
|
||||||
&& let Some(description) = word.additional.get(&Id(2))
|
|
||||||
{
|
|
||||||
column = column.push(text!("{}", description).align_x(Center).size(20));
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if part == "context"
|
|
||||||
&& let Some(context) = word.additional.get(&Id(3))
|
|
||||||
{
|
|
||||||
column = column.push(text!("{}", context).align_x(Center).size(24));
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
let field_id = fields_set.iter().find(|f| f.identifier == part);
|
|
||||||
if let Some(id) = field_id
|
|
||||||
&& let Some(custom) = word.additional.get(&id.id)
|
|
||||||
{
|
|
||||||
column = column.push(text!("{}", custom).align_x(Center).size(24))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
column.align_x(Center).spacing(HALF_SPACING).into()
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
use iced_core::widget::{tree, Operation, Tree};
|
use iced::widget::MouseArea;
|
||||||
|
use iced_core::widget::{Operation, Tree, tree};
|
||||||
use iced_core::{
|
use iced_core::{
|
||||||
layout, mouse, overlay, renderer, touch, Clipboard, Element, Event, Layout, Length, Point,
|
Clipboard, Element, Event, Layout, Length, Point, Rectangle, Shell, Size, Vector, Widget,
|
||||||
Rectangle, Shell, Size, Vector, Widget,
|
layout, mouse, overlay, renderer, touch,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn hard_mouse_area<'a, Message, Theme, Renderer>(
|
pub fn hard_mouse_area<'a, Message, Theme, Renderer>(
|
||||||
@@ -160,42 +161,6 @@ where
|
|||||||
Renderer: renderer::Renderer,
|
Renderer: renderer::Renderer,
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
{
|
{
|
||||||
fn size(&self) -> Size<Length> {
|
|
||||||
self.content.as_widget().size()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout(
|
|
||||||
&mut self,
|
|
||||||
tree: &mut Tree,
|
|
||||||
renderer: &Renderer,
|
|
||||||
limits: &layout::Limits,
|
|
||||||
) -> layout::Node {
|
|
||||||
self.content
|
|
||||||
.as_widget_mut()
|
|
||||||
.layout(&mut tree.children[0], renderer, limits)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(
|
|
||||||
&self,
|
|
||||||
tree: &Tree,
|
|
||||||
renderer: &mut Renderer,
|
|
||||||
theme: &Theme,
|
|
||||||
renderer_style: &renderer::Style,
|
|
||||||
layout: Layout<'_>,
|
|
||||||
cursor: mouse::Cursor,
|
|
||||||
viewport: &Rectangle,
|
|
||||||
) {
|
|
||||||
self.content.as_widget().draw(
|
|
||||||
&tree.children[0],
|
|
||||||
renderer,
|
|
||||||
theme,
|
|
||||||
renderer_style,
|
|
||||||
layout,
|
|
||||||
cursor,
|
|
||||||
viewport,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tag(&self) -> tree::Tag {
|
fn tag(&self) -> tree::Tag {
|
||||||
tree::Tag::of::<State>()
|
tree::Tag::of::<State>()
|
||||||
}
|
}
|
||||||
@@ -212,6 +177,21 @@ where
|
|||||||
tree.diff_children(std::slice::from_ref(&self.content));
|
tree.diff_children(std::slice::from_ref(&self.content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn size(&self) -> Size<Length> {
|
||||||
|
self.content.as_widget().size()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout(
|
||||||
|
&mut self,
|
||||||
|
tree: &mut Tree,
|
||||||
|
renderer: &Renderer,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
) -> layout::Node {
|
||||||
|
self.content
|
||||||
|
.as_widget_mut()
|
||||||
|
.layout(&mut tree.children[0], renderer, limits)
|
||||||
|
}
|
||||||
|
|
||||||
fn operate(
|
fn operate(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut Tree,
|
tree: &mut Tree,
|
||||||
@@ -251,7 +231,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.on_enter.is_none()
|
if self.on_enter.is_none()
|
||||||
&& let Event::Mouse(mouse::Event::CursorEntered) = event
|
&& let Event::Mouse(mouse::Event::CursorEntered { .. }) = event
|
||||||
{
|
{
|
||||||
self.content.as_widget_mut().update(
|
self.content.as_widget_mut().update(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
@@ -265,7 +245,7 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.on_exit.is_none()
|
if self.on_exit.is_none()
|
||||||
&& let Event::Mouse(mouse::Event::CursorLeft) = event
|
&& let Event::Mouse(mouse::Event::CursorLeft { .. }) = event
|
||||||
{
|
{
|
||||||
self.content.as_widget_mut().update(
|
self.content.as_widget_mut().update(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
@@ -310,6 +290,27 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(
|
||||||
|
&self,
|
||||||
|
tree: &Tree,
|
||||||
|
renderer: &mut Renderer,
|
||||||
|
theme: &Theme,
|
||||||
|
renderer_style: &renderer::Style,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor: mouse::Cursor,
|
||||||
|
viewport: &Rectangle,
|
||||||
|
) {
|
||||||
|
self.content.as_widget().draw(
|
||||||
|
&tree.children[0],
|
||||||
|
renderer,
|
||||||
|
theme,
|
||||||
|
renderer_style,
|
||||||
|
layout,
|
||||||
|
cursor,
|
||||||
|
viewport,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn overlay<'b>(
|
fn overlay<'b>(
|
||||||
&'b mut self,
|
&'b mut self,
|
||||||
tree: &'b mut Tree,
|
tree: &'b mut Tree,
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
pub mod hard_mouse_area;
|
pub mod hard_mouse_area;
|
||||||
pub mod card_display;
|
|
||||||
Reference in new issue
Block a user