diff --git a/src/lib/crud/cruds/BankAccountsCrud.ts b/src/lib/crud/cruds/BankAccountsCrud.ts index 5c9ba10..f350718 100644 --- a/src/lib/crud/cruds/BankAccountsCrud.ts +++ b/src/lib/crud/cruds/BankAccountsCrud.ts @@ -5,10 +5,10 @@ import { List, TextField, UrlAction, + type RequestParameters, + type CrudOperation, + type StateProcessorInput, } from "@orbitale/svelte-admin"; -import type {RequestParameters} from "@orbitale/svelte-admin/dist/request"; -import type {CrudOperation} from "@orbitale/svelte-admin/dist/Crud/Operations"; -import type {StateProcessorInput} from "@orbitale/svelte-admin/dist/State/Processor"; import {createBankAccount, getBankAccountById, getBankAccounts, updateBankAccount} from "$lib/db/bank_accounts"; import type BankAccount from "$lib/entities/BankAccount"; @@ -21,7 +21,8 @@ const baseFields = [ new TextField('currency', 'Currency'), ]; -export default new CrudDefinition('bank-accounts', { +export default new CrudDefinition({ + name: 'bank-accounts', defaultOperationName: "list", label: {plural: "BankAccounts", singular: "BankAccount"}, // minStateLoadingTimeMs: 0, @@ -34,7 +35,7 @@ export default new CrudDefinition('bank-accounts', { new Edit(baseFields), ], - stateProvider: new CallbackStateProvider(async (operation: CrudBankAccount, requestParameters: RequestParameters) => { + stateProvider: new CallbackStateProvider(async (operation: CrudOperation, requestParameters: RequestParameters) => { if (typeof window === 'undefined') { // SSR, can't call Tauri API then. return Promise.resolve([]); @@ -45,7 +46,7 @@ export default new CrudDefinition('bank-accounts', { } if (operation.name === 'view' || operation.name === 'edit') { - return getBankAccountById(requestParameters.id); + return getBankAccountById(Number(requestParameters.id)); } return Promise.resolve(null); @@ -57,10 +58,12 @@ export default new CrudDefinition('bank-accounts', { } if (operation.name === 'edit') { - data.id = parseInt(requestParameters.id, 10); + data.id = Number(requestParameters.id); + await updateBankAccount(data); success('Success!'); await goto('/crud/bank-accounts/list'); + return; } }) diff --git a/src/lib/crud/cruds/OperationCrud.ts b/src/lib/crud/cruds/OperationCrud.ts index 58395d9..b2d7684 100644 --- a/src/lib/crud/cruds/OperationCrud.ts +++ b/src/lib/crud/cruds/OperationCrud.ts @@ -1,21 +1,26 @@ import { CallbackStateProcessor, - CallbackStateProvider, CheckboxField, - CrudDefinition, DateField, + CallbackStateProvider, + CheckboxField, + CrudDefinition, + DateField, List, NumberField, PaginatedResults, TextField, UrlAction, - View + View, + type RequestParameters, + type CrudOperation, + type ListOperationOptions, + KeyValueObjectField } from "@orbitale/svelte-admin"; -import type {CrudOperation} from "@orbitale/svelte-admin/dist/Crud/Operations"; -import type {RequestParameters} from "@orbitale/svelte-admin/dist/request"; import {getOperationById, getOperations, getOperationsCount} from "$lib/db/operations"; import type Operation from "$lib/entities/Operation"; -export default new CrudDefinition('operations', { +export default new CrudDefinition({ + name: 'operations', defaultOperationName: "list", label: {plural: "Operations", singular: "Operation"}, // minStateLoadingTimeMs: 0, @@ -49,7 +54,7 @@ export default new CrudDefinition('operations', { new NumberField('amount', 'Montant'), new NumberField('hash', 'Hash'), new TextField('state', 'State'), - new TextField('bank_account', 'Bank account'), + new KeyValueObjectField('bank_account', 'Bank account', 'name'), new TextField('tags', 'Tags'), new CheckboxField('ignored_from_charts', 'Is ignored from charts'), ]), @@ -62,13 +67,14 @@ export default new CrudDefinition('operations', { } if (operation.name === 'list') { - const results = await getOperations(requestParameters.page||1); + const options: ListOperationOptions = operation.options; + const results = await getOperations(Number(requestParameters.page)||1); const numberOfItems = await getOperationsCount(null); - return Promise.resolve(new PaginatedResults(requestParameters.page, numberOfItems / operation.options.pagination.itemsPerPage, numberOfItems, results)); + return Promise.resolve(new PaginatedResults(Number(requestParameters.page), numberOfItems / Number(options.pagination?.itemsPerPage||10), numberOfItems, results)); } if (operation.name === 'view' || operation.name === 'edit') { - return getOperationById(requestParameters.id); + return getOperationById(Number(requestParameters.id)); } return Promise.resolve(null); diff --git a/src/lib/crud/cruds/TagRulesCrud.ts b/src/lib/crud/cruds/TagRulesCrud.ts index 2ce88ab..b499514 100644 --- a/src/lib/crud/cruds/TagRulesCrud.ts +++ b/src/lib/crud/cruds/TagRulesCrud.ts @@ -21,7 +21,8 @@ const baseFields = [ new ToggleField('is_regex', 'Regex'), ]; -export default new CrudDefinition('tag-rules', { +export default new CrudDefinition({ + name: 'tag-rules', defaultOperationName: "list", label: {plural: "TagRules", singular: "TagRule"}, // minStateLoadingTimeMs: 0, @@ -39,7 +40,7 @@ export default new CrudDefinition('tag-rules', { new Edit(baseFields), ], - stateProvider: new CallbackStateProvider(async (operation: CrudTagRule, requestParameters: RequestParameters) => { + stateProvider: new CallbackStateProvider(async (operation: CrudOperation, requestParameters: RequestParameters) => { if (typeof window === 'undefined') { // SSR, can't call Tauri API then. return Promise.resolve([]); @@ -61,7 +62,7 @@ export default new CrudDefinition('tag-rules', { data.id = parseInt(requestParameters.id || 0, 10); // TODO FIXME : remove this and use proper entity injection! data.is_regex = !!data.is_regex; - data.tags = data.tags.replace(/[^0-9,]/, '').split(',').map(i => parseInt(i, 10)); + data.tags = data.tags.replace(/[^0-9,]/, '').split(',').map((i: string) => parseInt(i, 10)); const tag_rule = TagRule.fromJson(data); if (operation.name === 'new') { diff --git a/src/lib/crud/cruds/TagsCrud.ts b/src/lib/crud/cruds/TagsCrud.ts index 2976c32..759576f 100644 --- a/src/lib/crud/cruds/TagsCrud.ts +++ b/src/lib/crud/cruds/TagsCrud.ts @@ -3,7 +3,7 @@ import { CallbackStateProvider, CrudDefinition, Edit, List, New, - TextField, ToggleField, + TextField, UrlAction, } from "@orbitale/svelte-admin"; import type {RequestParameters} from "@orbitale/svelte-admin/dist/request"; @@ -19,7 +19,8 @@ const baseFields = [ new TextField('name', 'Name'), ]; -export default new CrudDefinition('tags', { +export default new CrudDefinition({ + name: 'tags', defaultOperationName: "list", label: {plural: "Tags", singular: "Tag"}, // minStateLoadingTimeMs: 0, @@ -37,7 +38,7 @@ export default new CrudDefinition('tags', { new Edit(baseFields), ], - stateProvider: new CallbackStateProvider(async (operation: CrudTag, requestParameters: RequestParameters) => { + stateProvider: new CallbackStateProvider(async (operation: CrudOperation, requestParameters: RequestParameters) => { if (typeof window === 'undefined') { // SSR, can't call Tauri API then. return Promise.resolve([]); diff --git a/src/lib/crud/cruds/TriageCrud.ts b/src/lib/crud/cruds/TriageCrud.ts index c216f8a..6ce4255 100644 --- a/src/lib/crud/cruds/TriageCrud.ts +++ b/src/lib/crud/cruds/TriageCrud.ts @@ -1,7 +1,10 @@ import { CallbackStateProcessor, CallbackStateProvider, - CrudDefinition, DateField, Delete, Edit, + CrudDefinition, + DateField, + Delete, + Edit, List, NumberField, PaginatedResults, @@ -23,7 +26,8 @@ import type Operation from "$lib/entities/Operation"; import {success} from "$lib/utils/message"; import {goto} from "$app/navigation"; -export default new CrudDefinition('triage', { +export default new CrudDefinition({ + name: 'triage', defaultOperationName: "list", label: {plural: "Triaged operations", singular: "Triaged operation"}, // minStateLoadingTimeMs: 0, diff --git a/src/lib/entities/Operation.ts b/src/lib/entities/Operation.ts index f2493bd..c7d7a41 100644 --- a/src/lib/entities/Operation.ts +++ b/src/lib/entities/Operation.ts @@ -12,7 +12,7 @@ export enum OperationState { pending_triage = 'pending_triage' } -export var operations_filters = [ +export const operations_filters = [ new ConfigFilter('details', 'Details', FilterType.text), new ConfigFilter('operation_date', 'Date', FilterType.date), new ConfigFilter('amount_in_cents', 'Amount', FilterType.number), @@ -69,7 +69,7 @@ export default class Operation implements Entity { } get date() { - let date = new Date(this.operation_date.toString()); + const date = new Date(this.operation_date.toString()); return date.toLocaleDateString(); } @@ -103,7 +103,7 @@ export default class Operation implements Entity { } const parsedDate = Date.parse( - matches.groups.year + '-' + matches.groups.month + '-' + matches.groups.day + 'T00:00:00.000Z' + matches.groups?.year + '-' + matches.groups?.month + '-' + matches.groups?.day + 'T00:00:00.000Z' ); if (isNaN(parsedDate)) { throw new Error(