Anki/rslib/src/backend/stats.rs
RumovZ 3672b0fe73
Switch CardInfoDialog to ts page (#1414)
* Only collect card stats on the backend ...

... instead of rendering an HTML string using askama.

* Add ts page Card Info

* Update test for new `col.card_stats()`

* Remove obsolete CardStats code

* Use new ts page in `CardInfoDialog`

* Align start and end instead of left and right

Curiously, `text-align: start` does not work for `th` tags if assigned
via classes.

* Adopt ts refactorings after rebase

#1405 and #1409

* Clean up `ts/card-info/BUILD.bazel`

* Port card info logic from Rust to TS

* Move repeated field to the top

https://github.com/ankitects/anki/pull/1414#discussion_r725402730

* Convert pseudo classes to interfaces

* CardInfoPage -> CardInfo

* Make revlog in card info optional

* Add legacy support for old card stats

* Check for undefined instead of falsy

* Make Revlog separate component

* drop askama dependency (dae)

* Fix nightmode for legacy card stats
2021-10-14 19:22:47 +10:00

37 lines
1.5 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use super::Backend;
pub(super) use crate::backend_proto::stats_service::Service as StatsService;
use crate::{backend_proto as pb, prelude::*, revlog::RevlogReviewKind};
impl StatsService for Backend {
fn card_stats(&self, input: pb::CardId) -> Result<pb::CardStatsResponse> {
self.with_col(|col| col.card_stats(input.into()))
}
fn graphs(&self, input: pb::GraphsRequest) -> Result<pb::GraphsResponse> {
self.with_col(|col| col.graph_data_for_search(&input.search, input.days))
}
fn get_graph_preferences(&self, _input: pb::Empty) -> Result<pb::GraphPreferences> {
self.with_col(|col| Ok(col.get_graph_preferences()))
}
fn set_graph_preferences(&self, input: pb::GraphPreferences) -> Result<pb::Empty> {
self.with_col(|col| col.set_graph_preferences(input))
.map(Into::into)
}
}
impl From<RevlogReviewKind> for i32 {
fn from(kind: RevlogReviewKind) -> Self {
(match kind {
RevlogReviewKind::Learning => pb::revlog_entry::ReviewKind::Learning,
RevlogReviewKind::Review => pb::revlog_entry::ReviewKind::Review,
RevlogReviewKind::Relearning => pb::revlog_entry::ReviewKind::Relearning,
RevlogReviewKind::Filtered => pb::revlog_entry::ReviewKind::Filtered,
RevlogReviewKind::Manual => pb::revlog_entry::ReviewKind::Manual,
}) as i32
}
}