Debian Codegraph @

frontend/src/reports/import/FileList.svelte

raw
1 <script lang="ts">
2 import type { Entry } from "../../entries";
3 import AccountInput from "../../entry-forms/AccountInput.svelte";
4 import { _ } from "../../i18n";
5 import type { ProcessedImportableFile } from ".";
6
7 interface Props {
8 files: ProcessedImportableFile[];
9 extract_cache: Map<string, Entry[]>;
10 file_accounts: Map<string, string>;
11 file_names: Map<string, string>;
12 selected: string | null;
13 remove: (name: string) => void;
14 move: (name: string, a: string, newName: string) => void;
15 extract: (name: string, importer: string) => void;
16 }
17
18 let {
19 files,
20 extract_cache = $bindable(),
21 file_accounts = $bindable(),
22 file_names = $bindable(),
23 selected = $bindable(),
24 remove,
25 move,
26 extract,
27 }: Props = $props();
28 </script>
29
30 {#each files as file}
31 <div class="header" title={file.name} class:selected={selected === file.name}>
32 <button
33 type="button"
34 class="unset"
35 onclick={() => {
36 selected = selected === file.name ? null : file.name;
37 }}
38 >
39 {file.basename}
40 </button>
41 <button
42 type="button"
43 class="round"
44 onclick={() => {
45 remove(file.name);
46 }}
47 title={_("Delete")}
48 tabindex={-1}
49 >
50 ×
51 </button>
52 </div>
53 {#each file.importers as info}
54 {@const file_importer_key = `${file.name}:${info.importer_name}`}
55 {@const account = file_accounts.get(file_importer_key) ?? info.account}
56 {@const new_name = file_names.get(file_importer_key) ?? info.newName}
57 <form
58 class="flex-row"
59 onsubmit={(event) => {
60 event.preventDefault();
61 move(file.name, account, new_name);
62 }}
63 >
64 <AccountInput
65 bind:value={
66 () => account,
67 (value: string) => {
68 file_accounts.set(file_importer_key, value);
69 }
70 }
71 required
72 />
73 <input
74 size={40}
75 bind:value={
76 () => new_name,
77 (value: string) => {
78 file_names.set(file_importer_key, value);
79 }
80 }
81 />
82 <button type="submit">
83 {_("Move")}
84 </button>
85 {#if info.importer_name}
86 {@const is_cached = extract_cache.has(file_importer_key)}
87 <button
88 type="button"
89 title="{_('Extract')} with importer {info.importer_name}"
90 onclick={() => {
91 extract(file.name, info.importer_name);
92 }}
93 >
94 {is_cached ? _("Continue") : _("Extract")}
95 </button>
96 {#if is_cached}
97 <button
98 type="button"
99 onclick={() => {
100 extract_cache.delete(file_importer_key);
101 }}
102 >
103 {_("Clear")}
104 </button>
105 {/if}
106 {info.importer_name}
107 {/if}
108 </form>
109 {/each}
110 {/each}
111
112 <style>
113 .header {
114 padding: 0.5rem;
115 margin: 0.5rem 0;
116 background-color: var(--summary-background);
117 }
118
119 .header button:first-child {
120 width: 90%;
121 }
122
123 .header button:nth-child(2) {
124 float: right;
125 }
126
127 .header.selected {
128 background-color: var(--summary-background-darker);
129 }
130 </style>