support passing in a native notetype object to render_uncommitted_card()

This commit is contained in:
Damien Elmes 2021-05-25 16:58:06 +10:00
parent f4defc2e81
commit 02c7f7989e
3 changed files with 27 additions and 1 deletions

View file

@ -238,7 +238,7 @@ class TemplateRenderContext:
def _partially_render(self) -> PartiallyRenderedCard: def _partially_render(self) -> PartiallyRenderedCard:
if self._template: if self._template:
# card layout screen # card layout screen
out = self._col._backend.render_uncommitted_card( out = self._col._backend.render_uncommitted_card_legacy(
note=self._note._to_backend_note(), note=self._note._to_backend_note(),
card_ord=self._card.ord, card_ord=self._card.ord,
template=to_json_bytes(self._template), template=to_json_bytes(self._template),

View file

@ -221,6 +221,8 @@ service CardRenderingService {
rpc GetEmptyCards(Empty) returns (EmptyCardsReport); rpc GetEmptyCards(Empty) returns (EmptyCardsReport);
rpc RenderExistingCard(RenderExistingCardIn) returns (RenderCardOut); rpc RenderExistingCard(RenderExistingCardIn) returns (RenderCardOut);
rpc RenderUncommittedCard(RenderUncommittedCardIn) returns (RenderCardOut); rpc RenderUncommittedCard(RenderUncommittedCardIn) returns (RenderCardOut);
rpc RenderUncommittedCardLegacy(RenderUncommittedCardLegacyIn)
returns (RenderCardOut);
rpc StripAVTags(String) returns (String); rpc StripAVTags(String) returns (String);
rpc RenderMarkdown(RenderMarkdownIn) returns (String); rpc RenderMarkdown(RenderMarkdownIn) returns (String);
} }
@ -686,6 +688,13 @@ message RenderExistingCardIn {
} }
message RenderUncommittedCardIn { message RenderUncommittedCardIn {
Note note = 1;
uint32 card_ord = 2;
Notetype.Template template = 3;
bool fill_empty = 4;
}
message RenderUncommittedCardLegacyIn {
Note note = 1; Note note = 1;
uint32 card_ord = 2; uint32 card_ord = 2;
bytes template = 3; bytes template = 3;

View file

@ -98,6 +98,23 @@ impl CardRenderingService for Backend {
fn render_uncommitted_card( fn render_uncommitted_card(
&self, &self,
input: pb::RenderUncommittedCardIn, input: pb::RenderUncommittedCardIn,
) -> Result<pb::RenderCardOut> {
let template = input.template.ok_or(AnkiError::NotFound)?.into();
let mut note = input
.note
.ok_or_else(|| AnkiError::invalid_input("missing note"))?
.into();
let ord = input.card_ord as u16;
let fill_empty = input.fill_empty;
self.with_col(|col| {
col.render_uncommitted_card(&mut note, &template, ord, fill_empty)
.map(Into::into)
})
}
fn render_uncommitted_card_legacy(
&self,
input: pb::RenderUncommittedCardLegacyIn,
) -> Result<pb::RenderCardOut> { ) -> Result<pb::RenderCardOut> {
let schema11: CardTemplateSchema11 = serde_json::from_slice(&input.template)?; let schema11: CardTemplateSchema11 = serde_json::from_slice(&input.template)?;
let template = schema11.into(); let template = schema11.into();