deckconfig->deckoptions

This commit is contained in:
Damien Elmes 2021-04-25 18:40:02 +10:00
parent d6df6c0f89
commit b485b8cbb9
34 changed files with 51 additions and 51 deletions

View file

@ -3,7 +3,7 @@ load("//ts:copy.bzl", "copy_files_into_group")
_pages = [ _pages = [
"graphs", "graphs",
"congrats", "congrats",
"deckconfig", "deckoptions",
] ]
[copy_files_into_group( [copy_files_into_group(

View file

@ -32,7 +32,7 @@ class DeckOptionsDialog(QDialog):
self.web = AnkiWebView(title=self.TITLE) self.web = AnkiWebView(title=self.TITLE)
self.web.setVisible(False) self.web.setVisible(False)
self.web.load_ts_page("deckconfig") self.web.load_ts_page("deckoptions")
layout = QVBoxLayout() layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.web) layout.addWidget(self.web)
@ -40,7 +40,7 @@ class DeckOptionsDialog(QDialog):
deck_id = self.mw.col.decks.get_current_id() deck_id = self.mw.col.decks.get_current_id()
self.web.eval( self.web.eval(
f"""const $deckOptions = anki.deckConfig( f"""const $deckOptions = anki.deckOptions(
document.getElementById('main'), {deck_id});""" document.getElementById('main'), {deck_id});"""
) )
gui_hooks.deck_options_did_load(self) gui_hooks.deck_options_did_load(self)

View file

@ -4,9 +4,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
// import * as tr from "lib/i18n"; // import * as tr from "lib/i18n";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let components = state.addonComponents; let components = state.addonComponents;
</script> </script>

View file

@ -8,7 +8,7 @@ load("//ts:compile_sass.bzl", "compile_sass")
load("//ts:jest.bzl", "jest_test") load("//ts:jest.bzl", "jest_test")
compile_sass( compile_sass(
srcs = ["deckconfig-base.scss"], srcs = ["deckoptions-base.scss"],
group = "base_css", group = "base_css",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
@ -43,7 +43,7 @@ ts_library(
name = "index", name = "index",
srcs = ["index.ts"], srcs = ["index.ts"],
deps = [ deps = [
"DeckConfigPage", "DeckOptionsPage",
"lib", "lib",
"//ts/lib", "//ts/lib",
"@npm//@popperjs", "@npm//@popperjs",
@ -59,7 +59,7 @@ ts_library(
"steps.ts", "steps.ts",
"textInputModal.ts", "textInputModal.ts",
], ],
module_name = "deckconfig", module_name = "deckoptions",
deps = [ deps = [
"TextInputModal", "TextInputModal",
"//ts:image_module_support", "//ts:image_module_support",
@ -72,7 +72,7 @@ ts_library(
) )
esbuild( esbuild(
name = "deckconfig", name = "deckoptions",
srcs = [ srcs = [
"//ts:protobuf-shim.js", "//ts:protobuf-shim.js",
], ],
@ -87,7 +87,7 @@ esbuild(
external = [ external = [
"protobufjs/light", "protobufjs/light",
], ],
output_css = "deckconfig.css", output_css = "deckoptions.css",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"index", "index",
@ -100,7 +100,7 @@ esbuild(
] + svelte_names, ] + svelte_names,
) )
exports_files(["deckconfig.html"]) exports_files(["deckoptions.html"])
# Tests # Tests
################ ################

View file

@ -9,9 +9,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import LapseOptions from "./LapseOptions.svelte"; import LapseOptions from "./LapseOptions.svelte";
import GeneralOptions from "./GeneralOptions.svelte"; import GeneralOptions from "./GeneralOptions.svelte";
import Addons from "./Addons.svelte"; import Addons from "./Addons.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
</script> </script>
<style lang="scss"> <style lang="scss">

View file

@ -4,10 +4,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import type { DeckConfigState, ConfigListEntry } from "./lib"; import type { DeckOptionsState, ConfigListEntry } from "./lib";
import OptionsDropdown from "./OptionsDropdown.svelte"; import OptionsDropdown from "./OptionsDropdown.svelte";
export let state: DeckConfigState; export let state: DeckOptionsState;
let configList = state.configList; let configList = state.configList;
function configLabel(entry: ConfigListEntry): string { function configLabel(entry: ConfigListEntry): string {

View file

@ -5,9 +5,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts"> <script lang="ts">
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import SpinBox from "./SpinBox.svelte"; import SpinBox from "./SpinBox.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let config = state.currentConfig; let config = state.currentConfig;
let defaults = state.defaults; let defaults = state.defaults;
let parentLimits = state.parentLimits; let parentLimits = state.parentLimits;

View file

@ -5,13 +5,13 @@ 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 type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
import { onMount, onDestroy } from "svelte"; import { onMount, onDestroy } from "svelte";
import { registerShortcut } from "lib/shortcuts"; import { registerShortcut } from "lib/shortcuts";
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";
import HtmlAddon from "./HtmlAddon.svelte"; import HtmlAddon from "./HtmlAddon.svelte";
export let state: DeckConfigState; export let state: DeckOptionsState;
let addons = state.addonComponents; let addons = state.addonComponents;
export function auxData(): Writable<Record<string, unknown>> { export function auxData(): Writable<Record<string, unknown>> {

View file

@ -6,9 +6,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import SpinBox from "./SpinBox.svelte"; import SpinBox from "./SpinBox.svelte";
import CheckBox from "./CheckBox.svelte"; import CheckBox from "./CheckBox.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let config = state.currentConfig; let config = state.currentConfig;
let defaults = state.defaults; let defaults = state.defaults;
</script> </script>

View file

@ -8,9 +8,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import SpinBoxFloat from "./SpinBoxFloat.svelte"; import SpinBoxFloat from "./SpinBoxFloat.svelte";
import StepsInput from "./StepsInput.svelte"; import StepsInput from "./StepsInput.svelte";
import EnumSelector from "./EnumSelector.svelte"; import EnumSelector from "./EnumSelector.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let config = state.currentConfig; let config = state.currentConfig;
let defaults = state.defaults; let defaults = state.defaults;

View file

@ -9,9 +9,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import CheckBox from "./CheckBox.svelte"; import CheckBox from "./CheckBox.svelte";
import StepsInput from "./StepsInput.svelte"; import StepsInput from "./StepsInput.svelte";
import EnumSelector from "./EnumSelector.svelte"; import EnumSelector from "./EnumSelector.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let config = state.currentConfig; let config = state.currentConfig;
let defaults = state.defaults; let defaults = state.defaults;

View file

@ -5,9 +5,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts"> <script lang="ts">
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import { textInputModal } from "./textInputModal"; import { textInputModal } from "./textInputModal";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
function addConfig(): void { function addConfig(): void {
textInputModal({ textInputModal({

View file

@ -7,9 +7,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import SpinBox from "./SpinBox.svelte"; import SpinBox from "./SpinBox.svelte";
import SpinBoxFloat from "./SpinBoxFloat.svelte"; import SpinBoxFloat from "./SpinBoxFloat.svelte";
import CheckBox from "./CheckBox.svelte"; import CheckBox from "./CheckBox.svelte";
import type { DeckConfigState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckConfigState; export let state: DeckOptionsState;
let config = state.currentConfig; let config = state.currentConfig;
let defaults = state.defaults; let defaults = state.defaults;
</script> </script>

View file

@ -3,18 +3,18 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" id="viewport" content="width=device-width" /> <meta name="viewport" id="viewport" content="width=device-width" />
<link href="deckconfig-base.css" rel="stylesheet" /> <link href="deckoptions-base.css" rel="stylesheet" />
<link href="deckconfig.css" rel="stylesheet" /> <link href="deckoptions.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script> <script src="../js/vendor/protobuf.min.js"></script>
<script src="../js/vendor/bootstrap.bundle.min.js"></script> <script src="../js/vendor/bootstrap.bundle.min.js"></script>
<script src="deckconfig.js"></script> <script src="deckoptions.js"></script>
</head> </head>
<body> <body>
<div id="main"></div> <div id="main"></div>
<script> <script>
if (window.location.hash.startsWith("#test")) { if (window.location.hash.startsWith("#test")) {
anki.deckConfig(document.getElementById("main"), 1); anki.deckOptions(document.getElementById("main"), 1);
} }
</script> </script>
</body> </body>

View file

@ -1,22 +1,22 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { getDeckConfigInfo, DeckConfigState } from "./lib"; import { getDeckOptionsInfo, DeckOptionsState } from "./lib";
import { setupI18n, ModuleName } from "lib/i18n"; import { setupI18n, ModuleName } from "lib/i18n";
import { checkNightMode } from "lib/nightmode"; import { checkNightMode } from "lib/nightmode";
import DeckConfigPage from "./DeckConfigPage.svelte"; import DeckOptionsPage from "./DeckOptionsPage.svelte";
export async function deckConfig( export async function deckOptions(
target: HTMLDivElement, target: HTMLDivElement,
deckId: number deckId: number
): Promise<DeckConfigPage> { ): Promise<DeckOptionsPage> {
checkNightMode(); checkNightMode();
await setupI18n({ await setupI18n({
modules: [ModuleName.SCHEDULING, ModuleName.ACTIONS, ModuleName.DECK_CONFIG], modules: [ModuleName.SCHEDULING, ModuleName.ACTIONS, ModuleName.DECK_CONFIG],
}); });
const info = await getDeckConfigInfo(deckId); const info = await getDeckOptionsInfo(deckId);
const state = new DeckConfigState(deckId, info); const state = new DeckOptionsState(deckId, info);
return new DeckConfigPage({ return new DeckOptionsPage({
target, target,
props: { state }, props: { state },
}); });

View file

@ -6,7 +6,7 @@
*/ */
import * as pb from "lib/backend_proto"; import * as pb from "lib/backend_proto";
import { DeckConfigState } from "./lib"; import { DeckOptionsState } from "./lib";
import { get } from "svelte/store"; import { get } from "svelte/store";
const exampleData = { const exampleData = {
@ -92,8 +92,8 @@ const exampleData = {
}, },
}; };
function startingState(): DeckConfigState { function startingState(): DeckOptionsState {
return new DeckConfigState( return new DeckOptionsState(
123, 123,
pb.BackendProto.DeckConfigsForUpdate.fromObject(exampleData) pb.BackendProto.DeckConfigsForUpdate.fromObject(exampleData)
); );

View file

@ -12,7 +12,7 @@ import { isEqual, cloneDeep } from "lodash-es";
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent"; import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
export async function getDeckConfigInfo( export async function getDeckOptionsInfo(
deckId: number deckId: number
): Promise<pb.BackendProto.DeckConfigsForUpdate> { ): Promise<pb.BackendProto.DeckConfigsForUpdate> {
return pb.BackendProto.DeckConfigsForUpdate.decode( return pb.BackendProto.DeckConfigsForUpdate.decode(
@ -20,7 +20,7 @@ export async function getDeckConfigInfo(
); );
} }
export async function saveDeckConfig( export async function saveDeckOptions(
input: pb.BackendProto.UpdateDeckConfigsIn input: pb.BackendProto.UpdateDeckConfigsIn
): Promise<void> { ): Promise<void> {
const data: Uint8Array = pb.BackendProto.UpdateDeckConfigsIn.encode(input).finish(); const data: Uint8Array = pb.BackendProto.UpdateDeckConfigsIn.encode(input).finish();
@ -28,7 +28,7 @@ export async function saveDeckConfig(
return; return;
} }
export type DeckConfigId = number; export type DeckOptionsId = number;
export interface ConfigWithCount { export interface ConfigWithCount {
config: pb.BackendProto.DeckConfig; config: pb.BackendProto.DeckConfig;
@ -49,7 +49,7 @@ export interface ConfigListEntry {
} }
type ConfigInner = pb.BackendProto.DeckConfig.Config; type ConfigInner = pb.BackendProto.DeckConfig.Config;
export class DeckConfigState { export class DeckOptionsState {
readonly currentConfig: Writable<ConfigInner>; readonly currentConfig: Writable<ConfigInner>;
readonly currentAuxData: Writable<Record<string, unknown>>; readonly currentAuxData: Writable<Record<string, unknown>>;
readonly configList: Readable<ConfigListEntry[]>; readonly configList: Readable<ConfigListEntry[]>;
@ -63,8 +63,8 @@ export class DeckConfigState {
private selectedIdx: number; private selectedIdx: number;
private configListSetter!: (val: ConfigListEntry[]) => void; private configListSetter!: (val: ConfigListEntry[]) => void;
private parentLimitsSetter!: (val: ParentLimits) => void; private parentLimitsSetter!: (val: ParentLimits) => void;
private modifiedConfigs: Set<DeckConfigId> = new Set(); private modifiedConfigs: Set<DeckOptionsId> = new Set();
private removedConfigs: DeckConfigId[] = []; private removedConfigs: DeckOptionsId[] = [];
private schemaModified: boolean; private schemaModified: boolean;
constructor(targetDeckId: number, data: pb.BackendProto.DeckConfigsForUpdate) { constructor(targetDeckId: number, data: pb.BackendProto.DeckConfigsForUpdate) {
@ -195,7 +195,7 @@ export class DeckConfigState {
} }
async save(applyToChildren: boolean): Promise<void> { async save(applyToChildren: boolean): Promise<void> {
await saveDeckConfig(this.dataForSaving(applyToChildren)); await saveDeckOptions(this.dataForSaving(applyToChildren));
} }
private onCurrentConfigChanged(config: ConfigInner): void { private onCurrentConfigChanged(config: ConfigInner): void {

View file

@ -48,7 +48,7 @@ def jest_test(deps, name = "jest", protobuf = False):
deps = [ deps = [
name + "_lib", name + "_lib",
] + deps, ] + deps,
# the code shaking saves close to a second off the deckconfig/lib.test.ts test # the code shaking saves close to a second off the deckoptions/lib.test.ts test
minify = True, minify = True,
) )