expose scheduler js option in deck config

This commit is contained in:
Damien Elmes 2021-06-24 14:38:10 +10:00
parent 943f2b0287
commit 0b697f5161
10 changed files with 71 additions and 0 deletions

View File

@ -173,6 +173,8 @@ deck-config-interval-modifier-tooltip =
deck-config-hard-interval-tooltip = The multiplier applied to a review interval when answering `Hard`.
deck-config-new-interval-tooltip = The multiplier applied to a review interval when answering `Again`.
deck-config-minimum-interval-tooltip = The minimum interval given to a review card after answering `Again`.
deck-config-custom-scheduling = Custom scheduling
deck-config-custom-scheduling-tooltip = Affects the entire collection. Use at your own risk!
## Adding/renaming

View File

@ -965,6 +965,8 @@ message DeckConfigsForUpdate {
bool schema_modified = 4;
bool v3_scheduler = 5;
bool have_addons = 6;
// only applies to v3 scheduler
string card_state_customizer = 7;
}
message UpdateDeckConfigsRequest {
@ -974,6 +976,7 @@ message UpdateDeckConfigsRequest {
repeated DeckConfig configs = 2;
repeated int64 removed_config_ids = 3;
bool apply_to_children = 4;
string card_state_customizer = 5;
}
message SetTagCollapsedRequest {
@ -1470,6 +1473,7 @@ message Config {
SET_DUE_BROWSER = 0;
SET_DUE_REVIEWER = 1;
DEFAULT_SEARCH_TEXT = 2;
CARD_STATE_CUSTOMIZER = 3;
}
Key key = 1;
}

View File

@ -43,6 +43,7 @@ impl From<StringKeyProto> for StringKey {
StringKeyProto::SetDueBrowser => StringKey::SetDueBrowser,
StringKeyProto::SetDueReviewer => StringKey::SetDueReviewer,
StringKeyProto::DefaultSearchText => StringKey::DefaultSearchText,
StringKeyProto::CardStateCustomizer => StringKey::CardStateCustomizer,
}
}
}

View File

@ -88,6 +88,7 @@ impl From<pb::UpdateDeckConfigsRequest> for UpdateDeckConfigsRequest {
configs: c.configs.into_iter().map(Into::into).collect(),
removed_config_ids: c.removed_config_ids.into_iter().map(Into::into).collect(),
apply_to_children: c.apply_to_children,
card_state_customizer: c.card_state_customizer,
}
}
}

View File

@ -11,6 +11,7 @@ pub enum StringKey {
SetDueBrowser,
SetDueReviewer,
DefaultSearchText,
CardStateCustomizer,
}
impl Collection {

View File

@ -11,6 +11,7 @@ use std::{
use crate::{
backend_proto as pb,
backend_proto::deck_configs_for_update::{ConfigWithExtra, CurrentDeck},
config::StringKey,
prelude::*,
};
@ -21,6 +22,7 @@ pub struct UpdateDeckConfigsRequest {
pub configs: Vec<DeckConfig>,
pub removed_config_ids: Vec<DeckConfigId>,
pub apply_to_children: bool,
pub card_state_customizer: String,
}
impl Collection {
@ -39,6 +41,7 @@ impl Collection {
.schema_changed_since_sync(),
v3_scheduler: self.get_config_bool(BoolKey::Sched2021),
have_addons: false,
card_state_customizer: self.get_config_string(StringKey::CardStateCustomizer),
})
}
@ -178,6 +181,8 @@ impl Collection {
}
}
self.set_config_string_inner(StringKey::CardStateCustomizer, &input.card_state_customizer)?;
Ok(())
}
}
@ -199,6 +204,9 @@ mod test {
col.add_note(&mut note, DeckId(1))?;
}
// add the key so it doesn't trigger a change below
col.set_config_string_inner(StringKey::CardStateCustomizer, "")?;
// pretend we're in sync
let stamps = col.storage.get_collection_timestamps()?;
col.storage.set_last_sync(stamps.schema_change)?;
@ -228,6 +236,7 @@ mod test {
.collect(),
removed_config_ids: vec![],
apply_to_children: false,
card_state_customizer: "".to_string(),
};
assert!(!col.update_deck_configs(input.clone())?.changes.had_change());

View File

@ -9,12 +9,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import SpinBoxRow from "./SpinBoxRow.svelte";
import SpinBoxFloatRow from "./SpinBoxFloatRow.svelte";
import type { DeckOptionsState } from "./lib";
import CardStateCustomizer from "./CardStateCustomizer.svelte";
export let state: DeckOptionsState;
export let api: Record<string, never>;
let config = state.currentConfig;
let defaults = state.defaults;
let cardStateCustomizer = state.cardStateCustomizer;
</script>
<TitledContainer title={tr.deckConfigAdvancedTitle()} {api}>
@ -88,4 +90,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{tr.schedulingNewInterval()}
</SpinBoxFloatRow>
</Item>
{#if state.v3Scheduler}
<Item>
<CardStateCustomizer bind:value={$cardStateCustomizer} />
</Item>
{/if}
</TitledContainer>

View File

@ -0,0 +1,37 @@
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import * as tr from "lib/i18n";
import TooltipLabel from "./TooltipLabel.svelte";
import RevertButton from "./RevertButton.svelte";
import Row from "./Row.svelte";
import Col from "./Col.svelte";
export let value: string;
</script>
<Row>
<Col>
<div class="text">
<TooltipLabel markdownTooltip={tr.deckConfigCustomSchedulingTooltip()}>
{tr.deckConfigCustomScheduling()}:</TooltipLabel
>
<RevertButton bind:value defaultValue="" />
</div>
</Col>
</Row>
<textarea bind:value />
<style>
.text {
min-height: 2em;
}
textarea {
width: 100%;
height: 10em;
font-family: monospace;
}
</style>

View File

@ -44,3 +44,8 @@ $tooltip-max-width: 300px;
color: #ffaaaa;
}
}
textarea {
color: var(--text-fg);
background-color: var(--frame-bg);
}

View File

@ -55,6 +55,7 @@ export class DeckOptionsState {
readonly currentAuxData: Writable<Record<string, unknown>>;
readonly configList: Readable<ConfigListEntry[]>;
readonly parentLimits: Readable<ParentLimits>;
readonly cardStateCustomizer: Writable<string>;
readonly currentDeck: pb.BackendProto.DeckConfigsForUpdate.CurrentDeck;
readonly defaults: ConfigInner;
readonly addonComponents: Writable<DynamicSvelteComponent[]>;
@ -88,6 +89,7 @@ export class DeckOptionsState {
);
this.v3Scheduler = data.v3Scheduler;
this.haveAddons = data.haveAddons;
this.cardStateCustomizer = writable(data.cardStateCustomizer);
// decrement the use count of the starting item, as we'll apply +1 to currently
// selected one at display time
@ -210,6 +212,7 @@ export class DeckOptionsState {
removedConfigIds: this.removedConfigs,
configs,
applyToChildren,
cardStateCustomizer: get(this.cardStateCustomizer),
});
}