Custom fields repo into AppState
This commit is contained in:
1 parent
be64b1da2d
commit
f61f93717c
6 files changed
+20
-3
No files matched your search
@@ -2,5 +2,5 @@ create table custom_fields
|
|||||||
(
|
(
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
name text not null,
|
name text not null,
|
||||||
custom_fields text not null
|
identifier text not null
|
||||||
);
|
);
|
||||||
@@ -17,6 +17,7 @@ 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::custom_fields::CustomFieldRepository;
|
||||||
|
|
||||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ pub struct AppState {
|
|||||||
pub decks: DeckRepository,
|
pub decks: DeckRepository,
|
||||||
pub word_groups: WordGroupRepository,
|
pub word_groups: WordGroupRepository,
|
||||||
pub card_states: CardStateRepository,
|
pub card_states: CardStateRepository,
|
||||||
|
pub custom_fields: CustomFieldRepository,
|
||||||
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,
|
||||||
@@ -85,6 +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()),
|
||||||
|
custom_fields: CustomFieldRepository::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,
|
||||||
@@ -104,6 +107,7 @@ pub fn fill_state(state: &mut AppState) {
|
|||||||
state.decks.write().start().unwrap();
|
state.decks.write().start().unwrap();
|
||||||
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.sync_data = Arc::new(RwLock::new(setting))
|
state.sync_data = Arc::new(RwLock::new(setting))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,12 +196,23 @@ impl CardState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct CustomField {
|
pub struct CustomField {
|
||||||
pub id: Id,
|
pub id: Id,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EntityData for CustomField {
|
||||||
|
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,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use rusqlite::{Error, Params, Row};
|
|||||||
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
|
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
|
||||||
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
|
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
|
||||||
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
|
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct CustomFieldsQuerySet;
|
pub struct CustomFieldsQuerySet;
|
||||||
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
||||||
fn load() -> &'static str {
|
fn load() -> &'static str {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ impl TableAccessQuerySet<HistoryNote> for HistoryQuerySet {
|
|||||||
(
|
(
|
||||||
entity.deck_id,
|
entity.deck_id,
|
||||||
entity.word_id,
|
entity.word_id,
|
||||||
entity.timestamp,
|
entity.timestamp.timestamp(),
|
||||||
entity.answer,
|
entity.answer,
|
||||||
entity.before,
|
entity.before,
|
||||||
entity.after,
|
entity.after,
|
||||||
@@ -60,7 +60,7 @@ impl TableAccessQuerySet<HistoryNote> for HistoryQuerySet {
|
|||||||
(
|
(
|
||||||
entity.deck_id,
|
entity.deck_id,
|
||||||
entity.word_id,
|
entity.word_id,
|
||||||
entity.timestamp,
|
entity.timestamp.timestamp(),
|
||||||
entity.answer,
|
entity.answer,
|
||||||
entity.before,
|
entity.before,
|
||||||
entity.after,
|
entity.after,
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ fn make_history(conn: &Connection) -> Result<(), rusqlite::Error> {
|
|||||||
fn make_custom_fields(conn: &Connection) -> Result<(), rusqlite::Error> {
|
fn make_custom_fields(conn: &Connection) -> Result<(), rusqlite::Error> {
|
||||||
let query = include_str!("../../sql/custom_fields.sql");
|
let query = include_str!("../../sql/custom_fields.sql");
|
||||||
conn.execute(query, ())?;
|
conn.execute(query, ())?;
|
||||||
|
conn.execute("insert into custom_fields (name, identifier) values (\"Чтение\", \"reading\"), (\"Описание\", \"description\"), (\"Пример использования\", \"context\")", ())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user