mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Refactor search/browser.rs to browser_rows.rs
This commit is contained in:
parent
a5be72742c
commit
7425aa6b58
7 changed files with 59 additions and 43 deletions
|
@ -103,6 +103,7 @@ enum ServiceIndex {
|
||||||
SERVICE_INDEX_I18N = 12;
|
SERVICE_INDEX_I18N = 12;
|
||||||
SERVICE_INDEX_COLLECTION = 13;
|
SERVICE_INDEX_COLLECTION = 13;
|
||||||
SERVICE_INDEX_CARDS = 14;
|
SERVICE_INDEX_CARDS = 14;
|
||||||
|
SERVICE_INDEX_BROWSER_ROWS = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
service SchedulingService {
|
service SchedulingService {
|
||||||
|
@ -234,7 +235,6 @@ service SearchService {
|
||||||
rpc JoinSearchNodes(JoinSearchNodesIn) returns (String);
|
rpc JoinSearchNodes(JoinSearchNodesIn) returns (String);
|
||||||
rpc ReplaceSearchNode(ReplaceSearchNodeIn) returns (String);
|
rpc ReplaceSearchNode(ReplaceSearchNodeIn) returns (String);
|
||||||
rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount);
|
rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount);
|
||||||
rpc BrowserRowForCard(CardID) returns (BrowserRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service StatsService {
|
service StatsService {
|
||||||
|
@ -277,6 +277,10 @@ service CardsService {
|
||||||
rpc SetFlag(SetFlagIn) returns (OpChanges);
|
rpc SetFlag(SetFlagIn) returns (OpChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
service BrowserRowsService {
|
||||||
|
rpc BrowserRowForCard(CardID) returns (BrowserRow);
|
||||||
|
}
|
||||||
|
|
||||||
// Protobuf stored in .anki2 files
|
// Protobuf stored in .anki2 files
|
||||||
// These should be moved to a separate file in the future
|
// These should be moved to a separate file in the future
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
46
rslib/src/backend/browser_rows.rs
Normal file
46
rslib/src/backend/browser_rows.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::Backend;
|
||||||
|
use crate::{backend_proto as pb, browser_rows, prelude::*};
|
||||||
|
pub(super) use pb::browserrows_service::Service as BrowserRowsService;
|
||||||
|
|
||||||
|
impl BrowserRowsService for Backend {
|
||||||
|
fn browser_row_for_card(&self, input: pb::CardId) -> Result<pb::BrowserRow> {
|
||||||
|
self.with_col(|col| col.browser_row_for_card(input.cid.into()).map(Into::into))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<browser_rows::Row> for pb::BrowserRow {
|
||||||
|
fn from(row: browser_rows::Row) -> Self {
|
||||||
|
pb::BrowserRow {
|
||||||
|
cells: row.cells.into_iter().map(Into::into).collect(),
|
||||||
|
color: row.color.into(),
|
||||||
|
font_name: row.font.name,
|
||||||
|
font_size: row.font.size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<browser_rows::Cell> for pb::browser_row::Cell {
|
||||||
|
fn from(cell: browser_rows::Cell) -> Self {
|
||||||
|
pb::browser_row::Cell {
|
||||||
|
text: cell.text,
|
||||||
|
is_rtl: cell.is_rtl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<browser_rows::RowColor> for i32 {
|
||||||
|
fn from(color: browser_rows::RowColor) -> Self {
|
||||||
|
match color {
|
||||||
|
browser_rows::RowColor::Default => pb::browser_row::Color::Default as i32,
|
||||||
|
browser_rows::RowColor::Marked => pb::browser_row::Color::Marked as i32,
|
||||||
|
browser_rows::RowColor::Suspended => pb::browser_row::Color::Suspended as i32,
|
||||||
|
browser_rows::RowColor::FlagRed => pb::browser_row::Color::FlagRed as i32,
|
||||||
|
browser_rows::RowColor::FlagOrange => pb::browser_row::Color::FlagOrange as i32,
|
||||||
|
browser_rows::RowColor::FlagGreen => pb::browser_row::Color::FlagGreen as i32,
|
||||||
|
browser_rows::RowColor::FlagBlue => pb::browser_row::Color::FlagBlue as i32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
mod adding;
|
mod adding;
|
||||||
|
mod browser_rows;
|
||||||
mod card;
|
mod card;
|
||||||
mod cardrendering;
|
mod cardrendering;
|
||||||
mod collection;
|
mod collection;
|
||||||
|
@ -24,6 +25,7 @@ mod sync;
|
||||||
mod tags;
|
mod tags;
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
|
browser_rows::BrowserRowsService,
|
||||||
card::CardsService,
|
card::CardsService,
|
||||||
cardrendering::CardRenderingService,
|
cardrendering::CardRenderingService,
|
||||||
collection::CollectionService,
|
collection::CollectionService,
|
||||||
|
@ -137,6 +139,9 @@ impl Backend {
|
||||||
pb::ServiceIndex::I18n => I18nService::run_method(self, method, input),
|
pb::ServiceIndex::I18n => I18nService::run_method(self, method, input),
|
||||||
pb::ServiceIndex::Collection => CollectionService::run_method(self, method, input),
|
pb::ServiceIndex::Collection => CollectionService::run_method(self, method, input),
|
||||||
pb::ServiceIndex::Cards => CardsService::run_method(self, method, input),
|
pb::ServiceIndex::Cards => CardsService::run_method(self, method, input),
|
||||||
|
pb::ServiceIndex::BrowserRows => {
|
||||||
|
BrowserRowsService::run_method(self, method, input)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
let backend_err = anki_error_to_proto_error(err, &self.i18n);
|
let backend_err = anki_error_to_proto_error(err, &self.i18n);
|
||||||
|
|
|
@ -13,9 +13,8 @@ use crate::{
|
||||||
config::SortKind,
|
config::SortKind,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
search::{
|
search::{
|
||||||
browser, concatenate_searches, parse_search, replace_search_node, write_nodes,
|
concatenate_searches, parse_search, replace_search_node, write_nodes, BoolSeparator, Node,
|
||||||
BoolSeparator, Node, PropertyKind, RatingKind, SearchNode, SortMode, StateKind,
|
PropertyKind, RatingKind, SearchNode, SortMode, StateKind, TemplateKind,
|
||||||
TemplateKind,
|
|
||||||
},
|
},
|
||||||
text::escape_anki_wildcards,
|
text::escape_anki_wildcards,
|
||||||
};
|
};
|
||||||
|
@ -90,10 +89,6 @@ impl SearchService for Backend {
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn browser_row_for_card(&self, input: pb::CardId) -> Result<pb::BrowserRow> {
|
|
||||||
self.with_col(|col| col.browser_row_for_card(input.cid.into()).map(Into::into))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<pb::SearchNode> for Node {
|
impl TryFrom<pb::SearchNode> for Node {
|
||||||
|
@ -269,37 +264,3 @@ impl From<Option<SortOrderProto>> for SortMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<browser::Row> for pb::BrowserRow {
|
|
||||||
fn from(row: browser::Row) -> Self {
|
|
||||||
pb::BrowserRow {
|
|
||||||
cells: row.cells.into_iter().map(Into::into).collect(),
|
|
||||||
color: row.color.into(),
|
|
||||||
font_name: row.font.name,
|
|
||||||
font_size: row.font.size,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<browser::Cell> for pb::browser_row::Cell {
|
|
||||||
fn from(cell: browser::Cell) -> Self {
|
|
||||||
pb::browser_row::Cell {
|
|
||||||
text: cell.text,
|
|
||||||
is_rtl: cell.is_rtl,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<browser::RowColor> for i32 {
|
|
||||||
fn from(color: browser::RowColor) -> Self {
|
|
||||||
match color {
|
|
||||||
browser::RowColor::Default => pb::browser_row::Color::Default as i32,
|
|
||||||
browser::RowColor::Marked => pb::browser_row::Color::Marked as i32,
|
|
||||||
browser::RowColor::Suspended => pb::browser_row::Color::Suspended as i32,
|
|
||||||
browser::RowColor::FlagRed => pb::browser_row::Color::FlagRed as i32,
|
|
||||||
browser::RowColor::FlagOrange => pb::browser_row::Color::FlagOrange as i32,
|
|
||||||
browser::RowColor::FlagGreen => pb::browser_row::Color::FlagGreen as i32,
|
|
||||||
browser::RowColor::FlagBlue => pb::browser_row::Color::FlagBlue as i32,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
pub mod adding;
|
pub mod adding;
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
mod backend_proto;
|
mod backend_proto;
|
||||||
|
pub mod browser_rows;
|
||||||
pub mod card;
|
pub mod card;
|
||||||
pub mod cloze;
|
pub mod cloze;
|
||||||
pub mod collection;
|
pub mod collection;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
pub mod browser;
|
|
||||||
mod cards;
|
mod cards;
|
||||||
mod notes;
|
mod notes;
|
||||||
mod parser;
|
mod parser;
|
||||||
|
|
Loading…
Reference in a new issue