Add back support for custom mountpoint in card stats
The move to separate .html files broke our legacy card stats routine.
Related: d1d71ffdbb
This commit is contained in:
parent
24ab8ac423
commit
a9769813ba
@ -853,6 +853,12 @@ class Collection(DeprecatedNamesMixin):
|
|||||||
return CollectionStats(self)
|
return CollectionStats(self)
|
||||||
|
|
||||||
def card_stats_data(self, card_id: CardId) -> stats_pb2.CardStatsResponse:
|
def card_stats_data(self, card_id: CardId) -> stats_pb2.CardStatsResponse:
|
||||||
|
"""Returns the data required to show card stats.
|
||||||
|
|
||||||
|
If you wish to display the stats in a HTML table like Anki does,
|
||||||
|
you can use the .js file directly - see this add-on for an example:
|
||||||
|
https://ankiweb.net/shared/info/2179254157
|
||||||
|
"""
|
||||||
return self._backend.card_stats(card_id)
|
return self._backend.card_stats(card_id)
|
||||||
|
|
||||||
def studied_today(self) -> str:
|
def studied_today(self) -> str:
|
||||||
|
@ -39,7 +39,7 @@ def _legacy_card_stats(
|
|||||||
if ({1 if _legacy_nightmode else 0}) {{
|
if ({1 if _legacy_nightmode else 0}) {{
|
||||||
document.documentElement.className = "night-mode";
|
document.documentElement.className = "night-mode";
|
||||||
}}
|
}}
|
||||||
const {varName} = anki.cardInfo(document.getElementById('{random_id}'));
|
const {varName} = anki.setupCardInfo(document.getElementById('{random_id}'));
|
||||||
{varName}.then((c) => c.$set({{ cardId: {card_id}, includeRevlog: {str(include_revlog).lower()} }}));
|
{varName}.then((c) => c.$set({{ cardId: {card_id}, includeRevlog: {str(include_revlog).lower()} }}));
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
|
@ -63,6 +63,7 @@ class CardInfoDialog(QDialog):
|
|||||||
layout.addWidget(buttons)
|
layout.addWidget(buttons)
|
||||||
qconnect(buttons.rejected, self.reject)
|
qconnect(buttons.rejected, self.reject)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
self.web.eval("anki.cardInfoPromise = anki.setupCardInfo(document.body);")
|
||||||
self.update_card(card_id)
|
self.update_card(card_id)
|
||||||
|
|
||||||
def update_card(self, card_id: CardId | None) -> None:
|
def update_card(self, card_id: CardId | None) -> None:
|
||||||
|
@ -11,17 +11,17 @@ const i18n = setupI18n({
|
|||||||
modules: [ModuleName.CARD_STATS, ModuleName.SCHEDULING, ModuleName.STATISTICS],
|
modules: [ModuleName.CARD_STATS, ModuleName.SCHEDULING, ModuleName.STATISTICS],
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function setupCardInfo(): Promise<CardInfo> {
|
export async function setupCardInfo(target: HTMLElement): Promise<CardInfo> {
|
||||||
checkNightMode();
|
checkNightMode();
|
||||||
await i18n;
|
await i18n;
|
||||||
|
|
||||||
return new CardInfo({ target: document.body, props: { includeRevlog: true } });
|
return new CardInfo({ target, props: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cardInfoPromise = setupCardInfo();
|
|
||||||
|
|
||||||
if (window.location.hash.startsWith("#test")) {
|
if (window.location.hash.startsWith("#test")) {
|
||||||
// use #testXXXX where XXXX is card ID to test
|
// use #testXXXX where XXXX is card ID to test
|
||||||
const cardId = parseInt(window.location.hash.substr("#test".length), 10);
|
const cardId = parseInt(window.location.hash.substr("#test".length), 10);
|
||||||
cardInfoPromise.then((cardInfo: CardInfo): void => cardInfo.$set({ cardId }));
|
setupCardInfo(document.body).then((cardInfo: CardInfo): void =>
|
||||||
|
cardInfo.$set({ cardId }),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user