mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 13:26:56 -05:00
fix parent limit handling
We can't calculate it on the backend, as adjusting a config may alter the parent limit. Also fix hidden deck name and missing separator.
This commit is contained in:
parent
f869148d5e
commit
8cf8c901fe
6 changed files with 63 additions and 28 deletions
|
|
@ -903,8 +903,7 @@ message DeckConfigForUpdate {
|
||||||
message CurrentDeck {
|
message CurrentDeck {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
int64 config_id = 2;
|
int64 config_id = 2;
|
||||||
uint32 parent_new_limit = 3;
|
repeated int64 parent_config_ids = 3;
|
||||||
uint32 parent_review_limit = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repeated ConfigWithExtra all_config = 1;
|
repeated ConfigWithExtra all_config = 1;
|
||||||
|
|
|
||||||
|
|
@ -49,20 +49,14 @@ impl Collection {
|
||||||
fn get_current_deck_for_update(&mut self, deck: DeckId) -> Result<CurrentDeck> {
|
fn get_current_deck_for_update(&mut self, deck: DeckId) -> Result<CurrentDeck> {
|
||||||
let deck = self.get_deck(deck)?.ok_or(AnkiError::NotFound)?;
|
let deck = self.get_deck(deck)?.ok_or(AnkiError::NotFound)?;
|
||||||
|
|
||||||
let mut parent_new_limit = u32::MAX;
|
|
||||||
let mut parent_review_limit = u32::MAX;
|
|
||||||
for config_id in self.parent_config_ids(&deck)? {
|
|
||||||
if let Some(config) = self.storage.get_deck_config(config_id)? {
|
|
||||||
parent_new_limit = parent_new_limit.min(config.inner.new_per_day);
|
|
||||||
parent_review_limit = parent_review_limit.min(config.inner.reviews_per_day);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(CurrentDeck {
|
Ok(CurrentDeck {
|
||||||
name: deck.name.clone(),
|
name: deck.human_name(),
|
||||||
config_id: deck.normal()?.config_id,
|
config_id: deck.normal()?.config_id,
|
||||||
parent_new_limit,
|
parent_config_ids: self
|
||||||
parent_review_limit,
|
.parent_config_ids(&deck)?
|
||||||
|
.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,19 +46,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
padding-right: 0.5em;
|
padding-right: 0.5em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.padding {
|
||||||
|
height: 2.5em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="outer">
|
<div class="outer">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<!-- svelte-ignore a11y-no-onchange -->
|
<div>
|
||||||
<select class="form-select" on:change={myblur}>
|
<div>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</div>
|
||||||
{#each $configList as entry}
|
|
||||||
<option value={entry.idx} selected={entry.current}>
|
|
||||||
{configLabel(entry)}
|
|
||||||
</option>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<OptionsDropdown {state} />
|
<!-- svelte-ignore a11y-no-onchange -->
|
||||||
|
<select class="form-select" on:change={myblur}>
|
||||||
|
{#each $configList as entry}
|
||||||
|
<option value={entry.idx} selected={entry.current}>
|
||||||
|
{configLabel(entry)}
|
||||||
|
</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<OptionsDropdown {state} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="padding">
|
||||||
|
<!-- make sure subsequent content doesn't flow under us -->
|
||||||
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import ConfigSelector from "./ConfigSelector.svelte";
|
import ConfigSelector from "./ConfigSelector.svelte";
|
||||||
import ConfigEditor from "./ConfigEditor.svelte";
|
import ConfigEditor from "./ConfigEditor.svelte";
|
||||||
import * as tr from "anki/i18n";
|
|
||||||
import type { DeckConfigState } from "./lib";
|
import type { DeckConfigState } from "./lib";
|
||||||
|
|
||||||
export let state: DeckConfigState;
|
export let state: DeckConfigState;
|
||||||
|
|
@ -32,8 +31,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
<div class="outer">
|
<div class="outer">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div><b>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</b></div>
|
|
||||||
|
|
||||||
<ConfigSelector {state} />
|
<ConfigSelector {state} />
|
||||||
|
|
||||||
<ConfigEditor {state} />
|
<ConfigEditor {state} />
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let state: DeckConfigState;
|
export let state: DeckConfigState;
|
||||||
let config = state.currentConfig;
|
let config = state.currentConfig;
|
||||||
let defaults = state.defaults;
|
let defaults = state.defaults;
|
||||||
|
let parentLimits = state.parentLimits;
|
||||||
|
|
||||||
const newOrderChoices = [
|
const newOrderChoices = [
|
||||||
tr.schedulingShowNewCardsInOrderAdded(),
|
tr.schedulingShowNewCardsInOrderAdded(),
|
||||||
|
|
@ -33,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
$config.graduatingIntervalGood > $config.graduatingIntervalEasy;
|
$config.graduatingIntervalGood > $config.graduatingIntervalEasy;
|
||||||
|
|
||||||
// fixme: change impl; support warning messages
|
// fixme: change impl; support warning messages
|
||||||
$: newCardsGreaterThanParent = $config.newPerDay > state.currentDeck.parentNewLimit;
|
$: newCardsGreaterThanParent = $config.newPerDay > $parentLimits.newCards;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ export interface ConfigWithCount {
|
||||||
useCount: number;
|
useCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ParentLimits {
|
||||||
|
newCards: number;
|
||||||
|
reviews: number;
|
||||||
|
}
|
||||||
|
|
||||||
/// Info for showing the top selector
|
/// Info for showing the top selector
|
||||||
export interface ConfigListEntry {
|
export interface ConfigListEntry {
|
||||||
idx: number;
|
idx: number;
|
||||||
|
|
@ -38,12 +43,14 @@ type ConfigInner = pb.BackendProto.DeckConfig.Config;
|
||||||
export class DeckConfigState {
|
export class DeckConfigState {
|
||||||
readonly currentConfig: Writable<ConfigInner>;
|
readonly currentConfig: Writable<ConfigInner>;
|
||||||
readonly configList: Readable<ConfigListEntry[]>;
|
readonly configList: Readable<ConfigListEntry[]>;
|
||||||
|
readonly parentLimits: Readable<ParentLimits>;
|
||||||
readonly currentDeck: pb.BackendProto.DeckConfigForUpdate.CurrentDeck;
|
readonly currentDeck: pb.BackendProto.DeckConfigForUpdate.CurrentDeck;
|
||||||
readonly defaults: ConfigInner;
|
readonly defaults: ConfigInner;
|
||||||
|
|
||||||
private configs: ConfigWithCount[];
|
private configs: ConfigWithCount[];
|
||||||
private selectedIdx: number;
|
private selectedIdx: number;
|
||||||
private configListSetter?: (val: ConfigListEntry[]) => void;
|
private configListSetter?: (val: ConfigListEntry[]) => void;
|
||||||
|
private parentLimitsSetter?: (val: ParentLimits) => void;
|
||||||
private removedConfigs: DeckConfigId[] = [];
|
private removedConfigs: DeckConfigId[] = [];
|
||||||
|
|
||||||
constructor(data: pb.BackendProto.DeckConfigForUpdate) {
|
constructor(data: pb.BackendProto.DeckConfigForUpdate) {
|
||||||
|
|
@ -64,7 +71,11 @@ export class DeckConfigState {
|
||||||
this.currentConfig = writable(this.getCurrentConfig());
|
this.currentConfig = writable(this.getCurrentConfig());
|
||||||
this.configList = readable(this.getConfigList(), (set) => {
|
this.configList = readable(this.getConfigList(), (set) => {
|
||||||
this.configListSetter = set;
|
this.configListSetter = set;
|
||||||
return undefined;
|
return;
|
||||||
|
});
|
||||||
|
this.parentLimits = readable(this.getParentLimits(), (set) => {
|
||||||
|
this.parentLimitsSetter = set;
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,6 +155,7 @@ export class DeckConfigState {
|
||||||
|
|
||||||
private updateCurrentConfig(): void {
|
private updateCurrentConfig(): void {
|
||||||
this.currentConfig.set(this.getCurrentConfig());
|
this.currentConfig.set(this.getCurrentConfig());
|
||||||
|
this.parentLimitsSetter?.(this.getParentLimits());
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateConfigList(): void {
|
private updateConfigList(): void {
|
||||||
|
|
@ -170,4 +182,24 @@ export class DeckConfigState {
|
||||||
);
|
);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getParentLimits(): ParentLimits {
|
||||||
|
const parentConfigs = this.configs.filter((c) =>
|
||||||
|
this.currentDeck.parentConfigIds.includes(c.config.id)
|
||||||
|
);
|
||||||
|
const newCards = parentConfigs.reduce(
|
||||||
|
(previous, current) =>
|
||||||
|
Math.min(previous, current.config.config?.newPerDay ?? 0),
|
||||||
|
2 ** 31
|
||||||
|
);
|
||||||
|
const reviews = parentConfigs.reduce(
|
||||||
|
(previous, current) =>
|
||||||
|
Math.min(previous, current.config.config?.reviewsPerDay ?? 0),
|
||||||
|
2 ** 31
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
newCards,
|
||||||
|
reviews,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue