Add backend routine for browser rows

This commit is contained in:
RumovZ 2021-03-20 12:02:51 +01:00
parent 436269b701
commit c68a6131e0
2 changed files with 62 additions and 2 deletions

View File

@ -234,6 +234,7 @@ service SearchService {
rpc JoinSearchNodes(JoinSearchNodesIn) returns (String);
rpc ReplaceSearchNode(ReplaceSearchNodeIn) returns (String);
rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount);
rpc BrowserRowForCard(CardID) returns (BrowserRow);
}
service StatsService {
@ -1038,6 +1039,26 @@ message FindAndReplaceIn {
string field_name = 6;
}
message BrowserRow {
message Cell {
string text = 1;
bool is_rtl = 2;
}
enum Color {
COLOR_DEFAULT = 0;
COLOR_MARKED = 1;
COLOR_SUSPENDED = 2;
COLOR_FLAG_RED = 3;
COLOR_FLAG_ORANGE = 4;
COLOR_FLAG_GREEN = 5;
COLOR_FLAG_BLUE = 6;
}
repeated Cell cells = 1;
Color color = 2;
string font_name = 3;
uint32 font_size = 4;
}
message AfterNoteUpdatesIn {
repeated int64 nids = 1;
bool mark_notes_modified = 2;

View File

@ -13,8 +13,9 @@ use crate::{
config::SortKind,
prelude::*,
search::{
concatenate_searches, parse_search, replace_search_node, write_nodes, BoolSeparator, Node,
PropertyKind, RatingKind, SearchNode, SortMode, StateKind, TemplateKind,
browser, concatenate_searches, parse_search, replace_search_node, write_nodes,
BoolSeparator, Node, PropertyKind, RatingKind, SearchNode, SortMode, StateKind,
TemplateKind,
},
text::escape_anki_wildcards,
};
@ -89,6 +90,10 @@ impl SearchService for Backend {
.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 {
@ -264,3 +269,37 @@ 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,
}
}
}