From 82196753ecb64a297fd54a86d673a9fea178214b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 20 May 2022 17:13:46 +1000 Subject: [PATCH] Rework display of available cards in custom study In v3, it's more informative to show the count of child decks separately, since increasing the limit of the current deck does not increase the limits of child decks. When we rework the decks list in the future, a tooltip will hopefully provide an easier way for users to see where cards are available, and where limits are being applied. Closes #1868 --- ftl/core/custom-study.ftl | 7 +++-- proto/anki/scheduler.proto | 3 +++ qt/aqt/customstudy.py | 22 +++++++++++++--- qt/aqt/main.py | 1 + rslib/src/scheduler/filtered/custom_study.rs | 27 ++++++++++++++++++-- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ftl/core/custom-study.ftl b/ftl/core/custom-study.ftl index 06b61ff30..fd46d72c2 100644 --- a/ftl/core/custom-study.ftl +++ b/ftl/core/custom-study.ftl @@ -24,8 +24,11 @@ custom-study-select = Select custom-study-select-tags-to-exclude = Select tags to exclude: custom-study-selective-study = Selective Study custom-study-study-by-card-state-or-tag = Study by card state or tag -custom-study-available-new-cards = Available new cards: { $count } -custom-study-available-review-cards = Available review cards: { $count } +custom-study-available-new-cards-2 = Available new cards: { $countString } +custom-study-available-review-cards-2 = Available review cards: { $countString } +custom-study-available-child-count = ({ $count } in subdecks) ## DEPRECATED - you do not need to translate these. +custom-study-available-new-cards = Available new cards: { $count } +custom-study-available-review-cards = Available review cards: { $count } diff --git a/proto/anki/scheduler.proto b/proto/anki/scheduler.proto index c8bbf419f..c133664ac 100644 --- a/proto/anki/scheduler.proto +++ b/proto/anki/scheduler.proto @@ -291,4 +291,7 @@ message CustomStudyDefaultsResponse { uint32 extend_review = 3; uint32 available_new = 4; uint32 available_review = 5; + // in v3, counts for children are provided separately + uint32 available_new_in_children = 6; + uint32 available_review_in_children = 7; } diff --git a/qt/aqt/customstudy.py b/qt/aqt/customstudy.py index 1c43ca69d..b6c359c82 100644 --- a/qt/aqt/customstudy.py +++ b/qt/aqt/customstudy.py @@ -1,6 +1,8 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +from __future__ import annotations + from typing import Tuple import aqt @@ -75,6 +77,12 @@ class CustomStudy(QDialog): qconnect(f.radioPreview.clicked, lambda: self.onRadioChange(RADIO_PREVIEW)) qconnect(f.radioCram.clicked, lambda: self.onRadioChange(RADIO_CRAM)) + def count_with_children(self, parent: int, children: int) -> str: + if children: + return f"{parent} {tr.custom_study_available_child_count(children)}" + else: + return str(parent) + def onRadioChange(self, idx: int) -> None: form = self.form min_spinner_value = 1 @@ -86,15 +94,21 @@ class CustomStudy(QDialog): ok = tr.custom_study_ok() if idx == RADIO_NEW: - title_text = tr.custom_study_available_new_cards( - count=self.defaults.available_new + title_text = tr.custom_study_available_new_cards_2( + count_string=self.count_with_children( + self.defaults.available_new, + self.defaults.available_new_in_children, + ), ) text_before_spinner = tr.custom_study_increase_todays_new_card_limit_by() current_spinner_value = self.defaults.extend_new min_spinner_value = -DYN_MAX_SIZE elif idx == RADIO_REV: - title_text = tr.custom_study_available_review_cards( - count=self.defaults.available_review + title_text = tr.custom_study_available_review_cards_2( + count_string=self.count_with_children( + self.defaults.available_review, + self.defaults.available_review_in_children, + ), ) text_before_spinner = tr.custom_study_increase_todays_review_limit_by() current_spinner_value = self.defaults.extend_review diff --git a/qt/aqt/main.py b/qt/aqt/main.py index b611e25f5..501e456b0 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -1,5 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + from __future__ import annotations import enum diff --git a/rslib/src/scheduler/filtered/custom_study.rs b/rslib/src/scheduler/filtered/custom_study.rs index e6090a311..73f368a6b 100644 --- a/rslib/src/scheduler/filtered/custom_study.rs +++ b/rslib/src/scheduler/filtered/custom_study.rs @@ -34,8 +34,29 @@ impl Collection { .deck_tree(Some(TimestampSecs::now()))? .get_deck(deck_id) .ok_or(AnkiError::NotFound)?; - let available_new = subtree.sum(|node| node.new_uncapped); - let available_review = subtree.sum(|node| node.review_uncapped); + let v3 = self.get_config_bool(BoolKey::Sched2021); + let available_new_including_children = subtree.sum(|node| node.new_uncapped); + let available_review_including_children = subtree.sum(|node| node.review_uncapped); + let ( + available_new, + available_new_in_children, + available_review, + available_review_in_children, + ) = if v3 { + ( + subtree.new_uncapped, + available_new_including_children - subtree.new_uncapped, + subtree.review_uncapped, + available_review_including_children - subtree.review_uncapped, + ) + } else { + ( + available_new_including_children, + 0, + available_review_including_children, + 0, + ) + }; // tags let include_tags: HashSet = self.get_config_default( DeckConfigKey::CustomStudyIncludeTags @@ -67,6 +88,8 @@ impl Collection { extend_review, available_new, available_review, + available_new_in_children, + available_review_in_children, }) } }