Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deck config prototype work in progress
Still in the early stages, and not hooked up yet.
- Loading branch information
Showing
32 changed files
with
1,133 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
load("//ts:copy.bzl", "copy_files_into_group") | ||
|
||
copy_files_into_group( | ||
name = "graphs_page", | ||
srcs = [ | ||
"graphs-base.css", | ||
"graphs.css", | ||
"graphs.html", | ||
"graphs.js", | ||
], | ||
package = "//ts/graphs", | ||
) | ||
_pages = [ | ||
"graphs", | ||
"congrats", | ||
"deckconfig", | ||
] | ||
|
||
copy_files_into_group( | ||
name = "congrats_page", | ||
[copy_files_into_group( | ||
name = name + "_page", | ||
srcs = [ | ||
"congrats-base.css", | ||
"congrats.css", | ||
"congrats.html", | ||
"congrats.js", | ||
name + "-base.css", | ||
name + ".css", | ||
name + ".html", | ||
name + ".js", | ||
], | ||
package = "//ts/congrats", | ||
) | ||
package = "//ts/" + name, | ||
) for name in _pages] | ||
|
||
filegroup( | ||
name = "pages", | ||
srcs = [ | ||
"congrats_page", | ||
"graphs_page", | ||
], | ||
srcs = [name + "_page" for name in _pages], | ||
visibility = ["//qt:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright: Ankitects Pty Ltd and contributors | ||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html | ||
|
||
use std::collections::{HashMap, HashSet}; | ||
|
||
use pb::deck_config_for_update::{ConfigWithExtra, CurrentDeck}; | ||
|
||
use crate::{backend_proto as pb, prelude::*}; | ||
|
||
impl Collection { | ||
/// Information required for the deck options screen. | ||
pub fn get_deck_config_for_update(&mut self, deck: DeckId) -> Result<pb::DeckConfigForUpdate> { | ||
Ok(pb::DeckConfigForUpdate { | ||
all_config: self.get_deck_config_with_extra_for_update()?, | ||
current_deck: Some(self.get_current_deck_for_update(deck)?), | ||
defaults: Some(DeckConf::default().into()), | ||
}) | ||
} | ||
} | ||
|
||
impl Collection { | ||
fn get_deck_config_with_extra_for_update(&self) -> Result<Vec<ConfigWithExtra>> { | ||
// grab the config and sort it | ||
let mut config = self.storage.all_deck_config()?; | ||
config.sort_unstable_by(|a, b| a.name.cmp(&b.name)); | ||
|
||
// combine with use counts | ||
let counts = self.get_deck_config_use_counts()?; | ||
Ok(config | ||
.into_iter() | ||
.map(|config| ConfigWithExtra { | ||
use_count: counts.get(&config.id).cloned().unwrap_or_default() as u32, | ||
config: Some(config.into()), | ||
}) | ||
.collect()) | ||
} | ||
|
||
fn get_deck_config_use_counts(&self) -> Result<HashMap<DeckConfId, usize>> { | ||
let mut counts = HashMap::new(); | ||
for deck in self.storage.get_all_decks()? { | ||
if let Ok(normal) = deck.normal() { | ||
*counts.entry(DeckConfId(normal.config_id)).or_default() += 1; | ||
} | ||
} | ||
|
||
Ok(counts) | ||
} | ||
|
||
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(), | ||
config_id: deck.normal()?.config_id, | ||
parent_new_limit, | ||
parent_review_limit, | ||
}) | ||
} | ||
|
||
/// Deck configs used by parent decks. | ||
fn parent_config_ids(&self, deck: &Deck) -> Result<HashSet<DeckConfId>> { | ||
Ok(self | ||
.storage | ||
.parent_decks(deck)? | ||
.iter() | ||
.filter_map(|deck| { | ||
deck.normal() | ||
.ok() | ||
.map(|normal| DeckConfId(normal.config_id)) | ||
}) | ||
.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
load("@npm//@bazel/typescript:index.bzl", "ts_library") | ||
load("//ts:prettier.bzl", "prettier_test") | ||
load("//ts:eslint.bzl", "eslint_test") | ||
load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte", "svelte_check") | ||
load("//ts:esbuild.bzl", "esbuild") | ||
load("//ts:vendor.bzl", "copy_bootstrap_icons") | ||
load("//ts:compile_sass.bzl", "compile_sass") | ||
|
||
compile_sass( | ||
srcs = ["deckconfig-base.scss"], | ||
group = "base_css", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//ts/bootstrap:scss", | ||
"//ts/sass:base_lib", | ||
"//ts/sass:scrollbar_lib", | ||
], | ||
) | ||
|
||
svelte_files = glob(["*.svelte"]) | ||
|
||
svelte_names = [f.replace(".svelte", "") for f in svelte_files] | ||
|
||
compile_svelte( | ||
name = "svelte", | ||
srcs = svelte_files, | ||
) | ||
|
||
copy_bootstrap_icons( | ||
name = "bootstrap-icons", | ||
icons = [ | ||
"arrow-counterclockwise.svg", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "index", | ||
srcs = ["index.ts"], | ||
deps = [ | ||
"DeckConfigPage", | ||
"lib", | ||
"//ts/lib", | ||
"@npm//svelte2tsx", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "lib", | ||
srcs = [ | ||
"icons.ts", | ||
"lib.ts", | ||
"steps.ts", | ||
], | ||
module_name = "deckconfig", | ||
deps = [ | ||
"//ts:image_module_support", | ||
"//ts/lib", | ||
"//ts/lib:backend_proto", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "deckconfig", | ||
srcs = [ | ||
"//ts:protobuf-shim.js", | ||
], | ||
args = [ | ||
"--global-name=anki", | ||
"--inject:$(location //ts:protobuf-shim.js)", | ||
"--resolve-extensions=.mjs,.js", | ||
"--log-level=warning", | ||
"--loader:.svg=text", | ||
], | ||
entry_point = "index.ts", | ||
external = [ | ||
"protobufjs/light", | ||
], | ||
output_css = True, | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"index", | ||
"//ts/lib", | ||
"//ts/lib:backend_proto", | ||
":bootstrap-icons", | ||
"@npm//bootstrap", | ||
":base_css", | ||
] + svelte_names, | ||
) | ||
|
||
exports_files(["deckconfig.html"]) | ||
|
||
# Tests | ||
################ | ||
|
||
prettier_test( | ||
name = "format_check", | ||
srcs = glob([ | ||
"*.ts", | ||
"*.svelte", | ||
]), | ||
) | ||
|
||
eslint_test( | ||
name = "eslint", | ||
srcs = glob([ | ||
"*.ts", | ||
]), | ||
) | ||
|
||
svelte_check( | ||
name = "svelte_check", | ||
srcs = glob([ | ||
"*.ts", | ||
"*.svelte", | ||
]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
Copyright: Ankitects Pty Ltd and contributors | ||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html | ||
--> | ||
<script lang="ts"> | ||
import ConfigEntry from "./ConfigEntry.svelte"; | ||
export let label: string; | ||
export let subLabel: string; | ||
export let value: boolean; | ||
export let defaultValue: boolean; | ||
</script> | ||
|
||
<style> | ||
</style> | ||
|
||
<ConfigEntry {label} bind:value {defaultValue}> | ||
<label> <input type="checkbox" bind:checked={value} /> {subLabel} </label> | ||
</ConfigEntry> |
Oops, something went wrong.