move filtered deck labels to backend
- use strum to generate an iterator for the protobuf enum so we don't forget to add new labels if extending in the future - no add-ons appear to be using dynOrderLabels(), so it has been removed @RumovZ perhaps a similar approach might work for listing the available browser columns as well?
This commit is contained in:
parent
f55fe6e518
commit
e73359510d
@ -124,18 +124,3 @@ def newCardSchedulingLabels(
|
|||||||
1: tr.scheduling_show_new_cards_after_reviews(),
|
1: tr.scheduling_show_new_cards_after_reviews(),
|
||||||
2: tr.scheduling_show_new_cards_before_reviews(),
|
2: tr.scheduling_show_new_cards_before_reviews(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def dynOrderLabels(col: Optional[anki.collection.Collection]) -> Dict[int, Any]:
|
|
||||||
tr = _tr(col)
|
|
||||||
return {
|
|
||||||
0: tr.decks_oldest_seen_first(),
|
|
||||||
1: tr.decks_random(),
|
|
||||||
2: tr.decks_increasing_intervals(),
|
|
||||||
3: tr.decks_decreasing_intervals(),
|
|
||||||
4: tr.decks_most_lapses(),
|
|
||||||
5: tr.decks_order_added(),
|
|
||||||
6: tr.decks_order_due(),
|
|
||||||
7: tr.decks_latest_added_first(),
|
|
||||||
8: tr.decks_relative_overdueness(),
|
|
||||||
}
|
|
||||||
|
@ -581,11 +581,11 @@ class DeckManager:
|
|||||||
def nameMap(self) -> Dict[str, DeckDict]:
|
def nameMap(self) -> Dict[str, DeckDict]:
|
||||||
return {d["name"]: d for d in self.all()}
|
return {d["name"]: d for d in self.all()}
|
||||||
|
|
||||||
# Dynamic decks
|
# Filtered decks
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def new_filtered(self, name: str) -> DeckId:
|
def new_filtered(self, name: str) -> DeckId:
|
||||||
"Return a new dynamic deck and set it as the current deck."
|
"For new code, prefer col.sched.get_or_create_filtered_deck()."
|
||||||
did = self.id(name, type=DEFAULT_DECK_CONF_ID)
|
did = self.id(name, type=DEFAULT_DECK_CONF_ID)
|
||||||
self.select(did)
|
self.select(did)
|
||||||
return did
|
return did
|
||||||
|
@ -105,6 +105,9 @@ select id from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? l
|
|||||||
) -> OpChangesWithId:
|
) -> OpChangesWithId:
|
||||||
return self.col._backend.add_or_update_filtered_deck(deck)
|
return self.col._backend.add_or_update_filtered_deck(deck)
|
||||||
|
|
||||||
|
def filtered_deck_order_labels(self) -> Sequence[str]:
|
||||||
|
return self.col._backend.filtered_deck_order_labels()
|
||||||
|
|
||||||
# Suspending & burying
|
# Suspending & burying
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -67,13 +67,13 @@ class FilteredDeckConfigDialog(QDialog):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def _initial_dialog_setup(self) -> None:
|
def _initial_dialog_setup(self) -> None:
|
||||||
import anki.consts as cs
|
|
||||||
|
|
||||||
self.form = aqt.forms.filtered_deck.Ui_Dialog()
|
self.form = aqt.forms.filtered_deck.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
|
|
||||||
self.form.order.addItems(list(cs.dynOrderLabels(self.mw.col).values()))
|
order_labels = self.col.sched.filtered_deck_order_labels()
|
||||||
self.form.order_2.addItems(list(cs.dynOrderLabels(self.mw.col).values()))
|
|
||||||
|
self.form.order.addItems(order_labels)
|
||||||
|
self.form.order_2.addItems(order_labels)
|
||||||
|
|
||||||
qconnect(self.form.resched.stateChanged, self._onReschedToggled)
|
qconnect(self.form.resched.stateChanged, self._onReschedToggled)
|
||||||
|
|
||||||
|
@ -150,6 +150,7 @@ service DecksService {
|
|||||||
rpc RenameDeck(RenameDeckIn) returns (OpChanges);
|
rpc RenameDeck(RenameDeckIn) returns (OpChanges);
|
||||||
rpc GetOrCreateFilteredDeck(DeckId) returns (FilteredDeckForUpdate);
|
rpc GetOrCreateFilteredDeck(DeckId) returns (FilteredDeckForUpdate);
|
||||||
rpc AddOrUpdateFilteredDeck(FilteredDeckForUpdate) returns (OpChangesWithId);
|
rpc AddOrUpdateFilteredDeck(FilteredDeckForUpdate) returns (OpChangesWithId);
|
||||||
|
rpc FilteredDeckOrderLabels(Empty) returns (StringList);
|
||||||
}
|
}
|
||||||
|
|
||||||
service NotesService {
|
service NotesService {
|
||||||
|
@ -89,6 +89,10 @@ pub fn write_backend_proto_rs() {
|
|||||||
config
|
config
|
||||||
.out_dir(&out_dir)
|
.out_dir(&out_dir)
|
||||||
.service_generator(service_generator())
|
.service_generator(service_generator())
|
||||||
|
.type_attribute(
|
||||||
|
"FilteredDeck.SearchTerm.Order",
|
||||||
|
"#[derive(strum::EnumIter)]",
|
||||||
|
)
|
||||||
.compile_protos(&[&backend_proto], &[&proto_dir, &out_dir])
|
.compile_protos(&[&backend_proto], &[&proto_dir, &out_dir])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use super::Backend;
|
use super::Backend;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{self as pb},
|
backend_proto::{self as pb},
|
||||||
decks::{Deck, DeckId, DeckSchema11},
|
decks::{Deck, DeckId, DeckSchema11, FilteredSearchOrder},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::filtered::FilteredDeckForUpdate,
|
scheduler::filtered::FilteredDeckForUpdate,
|
||||||
};
|
};
|
||||||
@ -153,6 +153,10 @@ impl DecksService for Backend {
|
|||||||
.map(|out| out.map(i64::from))
|
.map(|out| out.map(i64::from))
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn filtered_deck_order_labels(&self, _input: pb::Empty) -> Result<pb::StringList> {
|
||||||
|
Ok(FilteredSearchOrder::labels(&self.tr).into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<pb::DeckId> for DeckId {
|
impl From<pb::DeckId> for DeckId {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// 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
|
||||||
|
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
pub use crate::backend_proto::{
|
pub use crate::backend_proto::{
|
||||||
deck_kind::Kind as DeckKind, Deck as DeckProto, DeckCommon, DeckKind as DeckKindProto,
|
deck_kind::Kind as DeckKind, Deck as DeckProto, DeckCommon, DeckKind as DeckKindProto,
|
||||||
FilteredDeck, NormalDeck,
|
FilteredDeck, NormalDeck,
|
||||||
@ -41,3 +43,24 @@ impl Deck {
|
|||||||
matches!(self.kind, DeckKind::Filtered(_))
|
matches!(self.kind, DeckKind::Filtered(_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FilteredSearchOrder {
|
||||||
|
pub fn labels(tr: &I18n) -> Vec<String> {
|
||||||
|
FilteredSearchOrder::iter().map(|v| v.label(tr)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn label(self, tr: &I18n) -> String {
|
||||||
|
match self {
|
||||||
|
FilteredSearchOrder::OldestReviewedFirst => tr.decks_oldest_seen_first(),
|
||||||
|
FilteredSearchOrder::Random => tr.decks_random(),
|
||||||
|
FilteredSearchOrder::IntervalsAscending => tr.decks_increasing_intervals(),
|
||||||
|
FilteredSearchOrder::IntervalsDescending => tr.decks_decreasing_intervals(),
|
||||||
|
FilteredSearchOrder::Lapses => tr.decks_most_lapses(),
|
||||||
|
FilteredSearchOrder::Added => tr.decks_order_added(),
|
||||||
|
FilteredSearchOrder::Due => tr.decks_order_due(),
|
||||||
|
FilteredSearchOrder::ReverseAdded => tr.decks_latest_added_first(),
|
||||||
|
FilteredSearchOrder::DuePriority => tr.decks_relative_overdueness(),
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user