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
@ -903,8 +903,7 @@ message DeckConfigForUpdate {
|
||||
message CurrentDeck {
|
||||
string name = 1;
|
||||
int64 config_id = 2;
|
||||
uint32 parent_new_limit = 3;
|
||||
uint32 parent_review_limit = 4;
|
||||
repeated int64 parent_config_ids = 3;
|
||||
}
|
||||
|
||||
repeated ConfigWithExtra all_config = 1;
|
||||
|
@ -49,20 +49,14 @@ impl Collection {
|
||||
fn get_current_deck_for_update(&mut self, deck: DeckId) -> Result<CurrentDeck> {
|
||||
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 {
|
||||
name: deck.name.clone(),
|
||||
name: deck.human_name(),
|
||||
config_id: deck.normal()?.config_id,
|
||||
parent_new_limit,
|
||||
parent_review_limit,
|
||||
parent_config_ids: self
|
||||
.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 {
|
||||
height: 2.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="outer">
|
||||
<div class="inner">
|
||||
<!-- 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>
|
||||
<div>
|
||||
<div>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</div>
|
||||
|
||||
<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 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">
|
||||
import ConfigSelector from "./ConfigSelector.svelte";
|
||||
import ConfigEditor from "./ConfigEditor.svelte";
|
||||
import * as tr from "anki/i18n";
|
||||
import type { DeckConfigState } from "./lib";
|
||||
|
||||
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="inner">
|
||||
<div><b>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</b></div>
|
||||
|
||||
<ConfigSelector {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;
|
||||
let config = state.currentConfig;
|
||||
let defaults = state.defaults;
|
||||
let parentLimits = state.parentLimits;
|
||||
|
||||
const newOrderChoices = [
|
||||
tr.schedulingShowNewCardsInOrderAdded(),
|
||||
@ -33,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
$config.graduatingIntervalGood > $config.graduatingIntervalEasy;
|
||||
|
||||
// fixme: change impl; support warning messages
|
||||
$: newCardsGreaterThanParent = $config.newPerDay > state.currentDeck.parentNewLimit;
|
||||
$: newCardsGreaterThanParent = $config.newPerDay > $parentLimits.newCards;
|
||||
</script>
|
||||
|
||||
<div>
|
||||
|
@ -26,6 +26,11 @@ export interface ConfigWithCount {
|
||||
useCount: number;
|
||||
}
|
||||
|
||||
export interface ParentLimits {
|
||||
newCards: number;
|
||||
reviews: number;
|
||||
}
|
||||
|
||||
/// Info for showing the top selector
|
||||
export interface ConfigListEntry {
|
||||
idx: number;
|
||||
@ -38,12 +43,14 @@ type ConfigInner = pb.BackendProto.DeckConfig.Config;
|
||||
export class DeckConfigState {
|
||||
readonly currentConfig: Writable<ConfigInner>;
|
||||
readonly configList: Readable<ConfigListEntry[]>;
|
||||
readonly parentLimits: Readable<ParentLimits>;
|
||||
readonly currentDeck: pb.BackendProto.DeckConfigForUpdate.CurrentDeck;
|
||||
readonly defaults: ConfigInner;
|
||||
|
||||
private configs: ConfigWithCount[];
|
||||
private selectedIdx: number;
|
||||
private configListSetter?: (val: ConfigListEntry[]) => void;
|
||||
private parentLimitsSetter?: (val: ParentLimits) => void;
|
||||
private removedConfigs: DeckConfigId[] = [];
|
||||
|
||||
constructor(data: pb.BackendProto.DeckConfigForUpdate) {
|
||||
@ -64,7 +71,11 @@ export class DeckConfigState {
|
||||
this.currentConfig = writable(this.getCurrentConfig());
|
||||
this.configList = readable(this.getConfigList(), (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 {
|
||||
this.currentConfig.set(this.getCurrentConfig());
|
||||
this.parentLimitsSetter?.(this.getParentLimits());
|
||||
}
|
||||
|
||||
private updateConfigList(): void {
|
||||
@ -170,4 +182,24 @@ export class DeckConfigState {
|
||||
);
|
||||
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 New Issue
Block a user