From 3ca0cf23f1461489222760b88ee23c5786f4c9ac Mon Sep 17 00:00:00 2001 From: Sirttas Date: Mon, 18 May 2026 21:19:01 +0200 Subject: [PATCH] edit ledger --- src/generated/mammon/api.ts | 309 +++++++++++++++++++++++++++---- src/ledger/CreateLedgerModal.vue | 82 ++++++-- src/ledger/LedgerLabel.vue | 4 +- src/ledger/ledger.ts | 63 +++++-- src/pages/ledger/ListLedgers.vue | 19 +- 5 files changed, 402 insertions(+), 75 deletions(-) diff --git a/src/generated/mammon/api.ts b/src/generated/mammon/api.ts index a7fdb04..ec314c8 100644 --- a/src/generated/mammon/api.ts +++ b/src/generated/mammon/api.ts @@ -23,29 +23,60 @@ import type { RequestArgs } from './base'; // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base'; -export interface CombiningLedgerDto extends LedgerDto { +export interface CombiningLedgerResponse extends LedgerResponse { 'ledgerId': number; 'name': string; 'memberLedgerIds': Array; + 'type'?: CombiningLedgerResponseTypeEnum; } -export interface CreateCombiningLedgerCommand { + +export const CombiningLedgerResponseTypeEnum = { + Combining: 'COMBINING', +} as const; + +export type CombiningLedgerResponseTypeEnum = typeof CombiningLedgerResponseTypeEnum[keyof typeof CombiningLedgerResponseTypeEnum]; + +export interface CreateCombiningLedgerRequest { 'name': string; 'memberLedgerIds': Array; } -export interface CreateMainLedgerCommand { +export interface CreateMainLedgerRequest { 'name': string; } /** * @type FindAll200ResponseInner */ -export type FindAll200ResponseInner = CombiningLedgerDto | MainLedgerDto; +export type FindAll200ResponseInner = CombiningLedgerResponse | MainLedgerResponse; -export interface LedgerDto { - 'type': string; +export interface LedgerResponse { + 'type'?: LedgerResponseTypeEnum; } -export interface MainLedgerDto extends LedgerDto { + +export const LedgerResponseTypeEnum = { + Main: 'MAIN', + Combining: 'COMBINING', +} as const; + +export type LedgerResponseTypeEnum = typeof LedgerResponseTypeEnum[keyof typeof LedgerResponseTypeEnum]; + +export interface MainLedgerResponse extends LedgerResponse { 'ledgerId': number; 'name': string; + 'type'?: MainLedgerResponseTypeEnum; +} + +export const MainLedgerResponseTypeEnum = { + Main: 'MAIN', +} as const; + +export type MainLedgerResponseTypeEnum = typeof MainLedgerResponseTypeEnum[keyof typeof MainLedgerResponseTypeEnum]; + +export interface UpdateCombiningLedgerRequest { + 'name': string; + 'memberLedgerIds': Array; +} +export interface UpdateMainLedgerRequest { + 'name': string; } /** @@ -55,13 +86,13 @@ export const LedgerControllerApiAxiosParamCreator = function (configuration?: Co return { /** * - * @param {CreateCombiningLedgerCommand} createCombiningLedgerCommand + * @param {CreateCombiningLedgerRequest} createCombiningLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - createCombiningLedger: async (createCombiningLedgerCommand: CreateCombiningLedgerCommand, options: RawAxiosRequestConfig = {}): Promise => { - // verify required parameter 'createCombiningLedgerCommand' is not null or undefined - assertParamExists('createCombiningLedger', 'createCombiningLedgerCommand', createCombiningLedgerCommand) + createCombiningLedger: async (createCombiningLedgerRequest: CreateCombiningLedgerRequest, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'createCombiningLedgerRequest' is not null or undefined + assertParamExists('createCombiningLedger', 'createCombiningLedgerRequest', createCombiningLedgerRequest) const localVarPath = `/ledgers/combining`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -80,7 +111,7 @@ export const LedgerControllerApiAxiosParamCreator = function (configuration?: Co setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(createCombiningLedgerCommand, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(createCombiningLedgerRequest, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -89,13 +120,13 @@ export const LedgerControllerApiAxiosParamCreator = function (configuration?: Co }, /** * - * @param {CreateMainLedgerCommand} createMainLedgerCommand + * @param {CreateMainLedgerRequest} createMainLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - createMainLedger: async (createMainLedgerCommand: CreateMainLedgerCommand, options: RawAxiosRequestConfig = {}): Promise => { - // verify required parameter 'createMainLedgerCommand' is not null or undefined - assertParamExists('createMainLedger', 'createMainLedgerCommand', createMainLedgerCommand) + createMainLedger: async (createMainLedgerRequest: CreateMainLedgerRequest, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'createMainLedgerRequest' is not null or undefined + assertParamExists('createMainLedger', 'createMainLedgerRequest', createMainLedgerRequest) const localVarPath = `/ledgers/main`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -114,7 +145,7 @@ export const LedgerControllerApiAxiosParamCreator = function (configuration?: Co setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(createMainLedgerCommand, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(createMainLedgerRequest, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -145,6 +176,115 @@ export const LedgerControllerApiAxiosParamCreator = function (configuration?: Co let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {number} ledgerId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + findById: async (ledgerId: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'ledgerId' is not null or undefined + assertParamExists('findById', 'ledgerId', ledgerId) + const localVarPath = `/ledgers/{ledgerId}` + .replace('{ledgerId}', encodeURIComponent(String(ledgerId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter['Accept'] = '*/*'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {number} ledgerId + * @param {UpdateCombiningLedgerRequest} updateCombiningLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updateCombiningLedger: async (ledgerId: number, updateCombiningLedgerRequest: UpdateCombiningLedgerRequest, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'ledgerId' is not null or undefined + assertParamExists('updateCombiningLedger', 'ledgerId', ledgerId) + // verify required parameter 'updateCombiningLedgerRequest' is not null or undefined + assertParamExists('updateCombiningLedger', 'updateCombiningLedgerRequest', updateCombiningLedgerRequest) + const localVarPath = `/ledgers/combining/{ledgerId}` + .replace('{ledgerId}', encodeURIComponent(String(ledgerId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter['Content-Type'] = 'application/json'; + localVarHeaderParameter['Accept'] = '*/*'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(updateCombiningLedgerRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {number} ledgerId + * @param {UpdateMainLedgerRequest} updateMainLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updateMainLedger: async (ledgerId: number, updateMainLedgerRequest: UpdateMainLedgerRequest, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'ledgerId' is not null or undefined + assertParamExists('updateMainLedger', 'ledgerId', ledgerId) + // verify required parameter 'updateMainLedgerRequest' is not null or undefined + assertParamExists('updateMainLedger', 'updateMainLedgerRequest', updateMainLedgerRequest) + const localVarPath = `/ledgers/main/{ledgerId}` + .replace('{ledgerId}', encodeURIComponent(String(ledgerId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter['Content-Type'] = 'application/json'; + localVarHeaderParameter['Accept'] = '*/*'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(updateMainLedgerRequest, localVarRequestOptions, configuration) + return { url: toPathString(localVarUrlObj), options: localVarRequestOptions, @@ -161,24 +301,24 @@ export const LedgerControllerApiFp = function(configuration?: Configuration) { return { /** * - * @param {CreateCombiningLedgerCommand} createCombiningLedgerCommand + * @param {CreateCombiningLedgerRequest} createCombiningLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async createCombiningLedger(createCombiningLedgerCommand: CreateCombiningLedgerCommand, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.createCombiningLedger(createCombiningLedgerCommand, options); + async createCombiningLedger(createCombiningLedgerRequest: CreateCombiningLedgerRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createCombiningLedger(createCombiningLedgerRequest, options); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.createCombiningLedger']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, /** * - * @param {CreateMainLedgerCommand} createMainLedgerCommand + * @param {CreateMainLedgerRequest} createMainLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async createMainLedger(createMainLedgerCommand: CreateMainLedgerCommand, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.createMainLedger(createMainLedgerCommand, options); + async createMainLedger(createMainLedgerRequest: CreateMainLedgerRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createMainLedger(createMainLedgerRequest, options); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.createMainLedger']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); @@ -194,6 +334,44 @@ export const LedgerControllerApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.findAll']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * + * @param {number} ledgerId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async findById(ledgerId: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.findById(ledgerId, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.findById']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @param {number} ledgerId + * @param {UpdateCombiningLedgerRequest} updateCombiningLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updateCombiningLedger(ledgerId: number, updateCombiningLedgerRequest: UpdateCombiningLedgerRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updateCombiningLedger(ledgerId, updateCombiningLedgerRequest, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.updateCombiningLedger']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @param {number} ledgerId + * @param {UpdateMainLedgerRequest} updateMainLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updateMainLedger(ledgerId: number, updateMainLedgerRequest: UpdateMainLedgerRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updateMainLedger(ledgerId, updateMainLedgerRequest, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['LedgerControllerApi.updateMainLedger']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, } }; @@ -205,21 +383,21 @@ export const LedgerControllerApiFactory = function (configuration?: Configuratio return { /** * - * @param {CreateCombiningLedgerCommand} createCombiningLedgerCommand + * @param {CreateCombiningLedgerRequest} createCombiningLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - createCombiningLedger(createCombiningLedgerCommand: CreateCombiningLedgerCommand, options?: RawAxiosRequestConfig): AxiosPromise { - return localVarFp.createCombiningLedger(createCombiningLedgerCommand, options).then((request) => request(axios, basePath)); + createCombiningLedger(createCombiningLedgerRequest: CreateCombiningLedgerRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.createCombiningLedger(createCombiningLedgerRequest, options).then((request) => request(axios, basePath)); }, /** * - * @param {CreateMainLedgerCommand} createMainLedgerCommand + * @param {CreateMainLedgerRequest} createMainLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - createMainLedger(createMainLedgerCommand: CreateMainLedgerCommand, options?: RawAxiosRequestConfig): AxiosPromise { - return localVarFp.createMainLedger(createMainLedgerCommand, options).then((request) => request(axios, basePath)); + createMainLedger(createMainLedgerRequest: CreateMainLedgerRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.createMainLedger(createMainLedgerRequest, options).then((request) => request(axios, basePath)); }, /** * @@ -229,6 +407,35 @@ export const LedgerControllerApiFactory = function (configuration?: Configuratio findAll(options?: RawAxiosRequestConfig): AxiosPromise> { return localVarFp.findAll(options).then((request) => request(axios, basePath)); }, + /** + * + * @param {number} ledgerId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + findById(ledgerId: number, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.findById(ledgerId, options).then((request) => request(axios, basePath)); + }, + /** + * + * @param {number} ledgerId + * @param {UpdateCombiningLedgerRequest} updateCombiningLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updateCombiningLedger(ledgerId: number, updateCombiningLedgerRequest: UpdateCombiningLedgerRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.updateCombiningLedger(ledgerId, updateCombiningLedgerRequest, options).then((request) => request(axios, basePath)); + }, + /** + * + * @param {number} ledgerId + * @param {UpdateMainLedgerRequest} updateMainLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updateMainLedger(ledgerId: number, updateMainLedgerRequest: UpdateMainLedgerRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.updateMainLedger(ledgerId, updateMainLedgerRequest, options).then((request) => request(axios, basePath)); + }, }; }; @@ -238,22 +445,22 @@ export const LedgerControllerApiFactory = function (configuration?: Configuratio export class LedgerControllerApi extends BaseAPI { /** * - * @param {CreateCombiningLedgerCommand} createCombiningLedgerCommand + * @param {CreateCombiningLedgerRequest} createCombiningLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - public createCombiningLedger(createCombiningLedgerCommand: CreateCombiningLedgerCommand, options?: RawAxiosRequestConfig) { - return LedgerControllerApiFp(this.configuration).createCombiningLedger(createCombiningLedgerCommand, options).then((request) => request(this.axios, this.basePath)); + public createCombiningLedger(createCombiningLedgerRequest: CreateCombiningLedgerRequest, options?: RawAxiosRequestConfig) { + return LedgerControllerApiFp(this.configuration).createCombiningLedger(createCombiningLedgerRequest, options).then((request) => request(this.axios, this.basePath)); } /** * - * @param {CreateMainLedgerCommand} createMainLedgerCommand + * @param {CreateMainLedgerRequest} createMainLedgerRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - public createMainLedger(createMainLedgerCommand: CreateMainLedgerCommand, options?: RawAxiosRequestConfig) { - return LedgerControllerApiFp(this.configuration).createMainLedger(createMainLedgerCommand, options).then((request) => request(this.axios, this.basePath)); + public createMainLedger(createMainLedgerRequest: CreateMainLedgerRequest, options?: RawAxiosRequestConfig) { + return LedgerControllerApiFp(this.configuration).createMainLedger(createMainLedgerRequest, options).then((request) => request(this.axios, this.basePath)); } /** @@ -264,6 +471,38 @@ export class LedgerControllerApi extends BaseAPI { public findAll(options?: RawAxiosRequestConfig) { return LedgerControllerApiFp(this.configuration).findAll(options).then((request) => request(this.axios, this.basePath)); } + + /** + * + * @param {number} ledgerId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + public findById(ledgerId: number, options?: RawAxiosRequestConfig) { + return LedgerControllerApiFp(this.configuration).findById(ledgerId, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @param {number} ledgerId + * @param {UpdateCombiningLedgerRequest} updateCombiningLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + public updateCombiningLedger(ledgerId: number, updateCombiningLedgerRequest: UpdateCombiningLedgerRequest, options?: RawAxiosRequestConfig) { + return LedgerControllerApiFp(this.configuration).updateCombiningLedger(ledgerId, updateCombiningLedgerRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @param {number} ledgerId + * @param {UpdateMainLedgerRequest} updateMainLedgerRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + public updateMainLedger(ledgerId: number, updateMainLedgerRequest: UpdateMainLedgerRequest, options?: RawAxiosRequestConfig) { + return LedgerControllerApiFp(this.configuration).updateMainLedger(ledgerId, updateMainLedgerRequest, options).then((request) => request(this.axios, this.basePath)); + } } diff --git a/src/ledger/CreateLedgerModal.vue b/src/ledger/CreateLedgerModal.vue index e8bdf2e..87e4979 100644 --- a/src/ledger/CreateLedgerModal.vue +++ b/src/ledger/CreateLedgerModal.vue @@ -2,23 +2,32 @@ import {computed, ref} from "vue"; import {storeToRefs} from "pinia"; -import {COMBINING_LEDGER, Ledger, LedgerType, MAIN_LEDGER, useLedgersStore} from "./ledger"; +import {isCombining, Ledger, LedgerType, LedgerTypes, useLedgersStore} from "./ledger"; import {Modal} from "@/components"; import LedgerLabel from "./LedgerLabel.vue"; import {PlusIcon, TrashIcon} from '@heroicons/vue/24/outline'; +interface Props { + ledgerId?: number; +} + +const props = withDefaults(defineProps(), { + ledgerId: 0 +}); + const ledgersStore = useLedgersStore(); const {ledgers} = storeToRefs(ledgersStore); -const {createMain, createCombining} = ledgersStore; +const {findById, findAllById, createMain, createCombining, updateMain, updateCombining} = ledgersStore; const modalOpen = ref(false); -const type = ref(MAIN_LEDGER); +const type = ref(LedgerTypes.Main); const name = ref(""); const members = ref([]); const selectedLedger = ref(); const availableLedgers = computed(() => ledgers.value.filter(l => !members.value.includes(l))); + const addMember = () => { if (selectedLedger.value && !members.value.includes(selectedLedger.value)) { members.value = [...members.value, selectedLedger.value]; @@ -27,21 +36,54 @@ const addMember = () => { } const open = () => { - type.value = MAIN_LEDGER; - name.value = ""; - members.value = []; + const ledger = isCreating.value ? undefined : findById(props.ledgerId); + + if (ledger) { + type.value = ledger.type; + name.value = ledger.name; + members.value = isCombining(ledger) ? findAllById(ledger.memberLedgerIds) : []; + } else { + type.value = LedgerTypes.Main; + name.value = ""; + members.value = []; + } modalOpen.value = true; } -const canCreate = computed(() => name.value.trim().length > 0); +const canSave = computed(() => name.value.trim().length > 0); +const isCreating = computed(() => props.ledgerId === 0) +const title = computed(() => { + if (isCreating.value) { + return `Creating ${type.value === LedgerTypes.Main ? 'Main' : 'Combining'} Ledger` + } + return `Updating ${name.value}` +}) const create = () => { - if (!canCreate.value) { - return; - } else if (type.value === MAIN_LEDGER) { - createMain({ name: name.value }) + if (type.value === LedgerTypes.Main) { + createMain({name: name.value}) } else { - createCombining({ name: name.value, memberLedgerIds: members.value.map(l => l.ledgerId) }) + createCombining({name: name.value, memberLedgerIds: members.value.map(l => l.ledgerId)}) + } +} + +const update = () => { + if (type.value === LedgerTypes.Main) { + updateMain(props.ledgerId, {name: name.value}) + } else { + updateCombining(props.ledgerId, {name: name.value, memberLedgerIds: members.value.map(l => l.ledgerId)}) + } +} + +const save = () => { + if (!canSave.value) { + return; + } + + if (isCreating.value) { + create(); + } else { + update(); } modalOpen.value = false; } @@ -51,24 +93,26 @@ defineExpose({ open });