favour readability over brevity in filter conversion
This commit is contained in:
parent
8b877f0a08
commit
5f70d718b8
@ -279,40 +279,51 @@ impl From<pb::DeckConfigId> for DeckConfID {
|
|||||||
|
|
||||||
impl From<pb::FilterToSearchIn> for Node<'_> {
|
impl From<pb::FilterToSearchIn> for Node<'_> {
|
||||||
fn from(msg: pb::FilterToSearchIn) -> Self {
|
fn from(msg: pb::FilterToSearchIn) -> Self {
|
||||||
use pb::filter_to_search_in::Filter as F;
|
use pb::filter_to_search_in::Filter;
|
||||||
use pb::filter_to_search_in::NamedFilter as NF;
|
use pb::filter_to_search_in::NamedFilter;
|
||||||
use Node as N;
|
match msg
|
||||||
use SearchNode as SN;
|
.filter
|
||||||
match msg.filter.unwrap_or(F::Name(NF::WholeCollection as i32)) {
|
.unwrap_or(Filter::Name(NamedFilter::WholeCollection as i32))
|
||||||
F::Name(name) => match NF::from_i32(name).unwrap_or(NF::WholeCollection) {
|
{
|
||||||
NF::WholeCollection => N::Search(SN::WholeCollection),
|
Filter::Name(name) => {
|
||||||
NF::CurrentDeck => N::Search(SN::Deck("current".into())),
|
match NamedFilter::from_i32(name).unwrap_or(NamedFilter::WholeCollection) {
|
||||||
NF::AddedToday => N::Search(SN::AddedInDays(1)),
|
NamedFilter::WholeCollection => Node::Search(SearchNode::WholeCollection),
|
||||||
NF::StudiedToday => N::Search(SN::Rated {
|
NamedFilter::CurrentDeck => Node::Search(SearchNode::Deck("current".into())),
|
||||||
days: 1,
|
NamedFilter::AddedToday => Node::Search(SearchNode::AddedInDays(1)),
|
||||||
ease: None,
|
NamedFilter::StudiedToday => Node::Search(SearchNode::Rated {
|
||||||
}),
|
days: 1,
|
||||||
NF::AgainToday => N::Search(SN::Rated {
|
ease: None,
|
||||||
days: 1,
|
}),
|
||||||
ease: Some(1),
|
NamedFilter::AgainToday => Node::Search(SearchNode::Rated {
|
||||||
}),
|
days: 1,
|
||||||
NF::New => N::Search(SN::State(StateKind::New)),
|
ease: Some(1),
|
||||||
NF::Learn => N::Search(SN::State(StateKind::Learning)),
|
}),
|
||||||
NF::Review => N::Search(SN::State(StateKind::Review)),
|
NamedFilter::New => Node::Search(SearchNode::State(StateKind::New)),
|
||||||
NF::Due => N::Search(SN::State(StateKind::Due)),
|
NamedFilter::Learn => Node::Search(SearchNode::State(StateKind::Learning)),
|
||||||
NF::Suspended => N::Search(SN::State(StateKind::Suspended)),
|
NamedFilter::Review => Node::Search(SearchNode::State(StateKind::Review)),
|
||||||
NF::Buried => N::Search(SN::State(StateKind::Buried)),
|
NamedFilter::Due => Node::Search(SearchNode::State(StateKind::Due)),
|
||||||
NF::RedFlag => N::Search(SN::Flag(1)),
|
NamedFilter::Suspended => Node::Search(SearchNode::State(StateKind::Suspended)),
|
||||||
NF::OrangeFlag => N::Search(SN::Flag(2)),
|
NamedFilter::Buried => Node::Search(SearchNode::State(StateKind::Buried)),
|
||||||
NF::GreenFlag => N::Search(SN::Flag(3)),
|
NamedFilter::RedFlag => Node::Search(SearchNode::Flag(1)),
|
||||||
NF::BlueFlag => N::Search(SN::Flag(4)),
|
NamedFilter::OrangeFlag => Node::Search(SearchNode::Flag(2)),
|
||||||
NF::NoFlag => N::Search(SN::Flag(0)),
|
NamedFilter::GreenFlag => Node::Search(SearchNode::Flag(3)),
|
||||||
NF::AnyFlag => N::Not(Box::new(N::Search(SN::Flag(0)))),
|
NamedFilter::BlueFlag => Node::Search(SearchNode::Flag(4)),
|
||||||
},
|
NamedFilter::NoFlag => Node::Search(SearchNode::Flag(0)),
|
||||||
F::Tag(s) => N::Search(SN::Tag(escape_anki_wildcards(&s).into_owned().into())),
|
NamedFilter::AnyFlag => Node::Not(Box::new(Node::Search(SearchNode::Flag(0)))),
|
||||||
F::Deck(s) => N::Search(SN::Deck(escape_anki_wildcards(&s).into_owned().into())),
|
}
|
||||||
F::Note(s) => N::Search(SN::NoteType(escape_anki_wildcards(&s).into_owned().into())),
|
}
|
||||||
F::Template(u) => N::Search(SN::CardTemplate(TemplateKind::Ordinal(u as u16))),
|
Filter::Tag(s) => Node::Search(SearchNode::Tag(
|
||||||
|
escape_anki_wildcards(&s).into_owned().into(),
|
||||||
|
)),
|
||||||
|
Filter::Deck(s) => Node::Search(SearchNode::Deck(
|
||||||
|
escape_anki_wildcards(&s).into_owned().into(),
|
||||||
|
)),
|
||||||
|
Filter::Note(s) => Node::Search(SearchNode::NoteType(
|
||||||
|
escape_anki_wildcards(&s).into_owned().into(),
|
||||||
|
)),
|
||||||
|
Filter::Template(u) => {
|
||||||
|
Node::Search(SearchNode::CardTemplate(TemplateKind::Ordinal(u as u16)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user