Allow configuring frontend plugins
This commit is contained in:
parent
81bce8e677
commit
94255ffb9d
@ -39,6 +39,7 @@ INSERT INTO metadata VALUES(1,'version','3');
|
||||
INSERT INTO metadata VALUES(2,'eofy_date','2025-06-30');
|
||||
INSERT INTO metadata VALUES(3,'reporting_commodity','$');
|
||||
INSERT INTO metadata VALUES(4,'amount_dps','2');
|
||||
INSERT INTO metadata VALUES(5,'plugins','');
|
||||
CREATE TABLE postings (
|
||||
id INTEGER NOT NULL,
|
||||
transaction_id INTEGER,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
DrCr: Web-based double-entry bookkeeping framework
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@ -39,6 +39,7 @@ export const db = reactive({
|
||||
eofy_date: null! as string,
|
||||
reporting_commodity: null! as string,
|
||||
dps: null! as number,
|
||||
plugins: null! as string[],
|
||||
},
|
||||
|
||||
init: async function(filename: string | null): Promise<void> {
|
||||
@ -77,6 +78,7 @@ export const db = reactive({
|
||||
this.metadata.eofy_date = metadataObject.eofy_date;
|
||||
this.metadata.reporting_commodity = metadataObject.reporting_commodity;
|
||||
this.metadata.dps = parseInt(metadataObject.amount_dps);
|
||||
this.metadata.plugins = metadataObject.plugins.length > 0 ? metadataObject.plugins.split(';') : [];
|
||||
}
|
||||
},
|
||||
|
||||
@ -114,6 +116,10 @@ export async function createNewDatabase(filename: string, eofy_date: string, rep
|
||||
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
|
||||
['amount_dps', dps.toString()] // Manually call .toString() to format as int, otherwise sqlx formats as float
|
||||
);
|
||||
await transaction.execute(
|
||||
`INSERT INTO metadata (key, value) VALUES (?, ?)`,
|
||||
['plugins', '']
|
||||
);
|
||||
|
||||
await transaction.commit();
|
||||
}
|
||||
|
41
src/main.ts
41
src/main.ts
@ -1,5 +1,5 @@
|
||||
/*
|
||||
DrCr: Web-based double-entry bookkeeping framework
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@ -20,16 +20,26 @@ import { invoke } from '@tauri-apps/api/core';
|
||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
|
||||
import { createApp } from 'vue';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { RouteRecordRaw, createRouter, createWebHistory } from 'vue-router';
|
||||
|
||||
import App from './App.vue';
|
||||
|
||||
import { db } from './db.ts';
|
||||
import { handleCriticalError } from './error.ts';
|
||||
import austax from './plugins/austax/plugin.ts';
|
||||
|
||||
async function initApp() {
|
||||
// Init state
|
||||
const dbFilename: string = await invoke('get_open_filename');
|
||||
if (dbFilename !== null) {
|
||||
try {
|
||||
await db.init(dbFilename); // Ensure all metadata cached before loading Vue
|
||||
} catch (err) {
|
||||
handleCriticalError(err);
|
||||
}
|
||||
}
|
||||
|
||||
// Init router
|
||||
const routes = [
|
||||
let routes: RouteRecordRaw[] = [
|
||||
{ path: '/', name: 'index', component: () => import('./pages/HomeView.vue') },
|
||||
{ path: '/balance-assertions', name: 'balance-assertions', component: () => import('./pages/BalanceAssertionsView.vue') },
|
||||
{ path: '/balance-assertions/edit/:id', name: 'balance-assertions-edit', component: () => import('./pages/EditBalanceAssertionView.vue') },
|
||||
@ -46,29 +56,18 @@ async function initApp() {
|
||||
{ path: '/statement-lines/import', name: 'import-statement', component: () => import('./pages/ImportStatementView.vue') },
|
||||
{ path: '/transactions/:account', name: 'transactions', component: () => import('./pages/TransactionsView.vue') },
|
||||
{ path: '/trial-balance', name: 'trial-balance', component: () => import('./reports/TrialBalanceReport.vue') },
|
||||
// TODO: Generate this list dynamically
|
||||
{ path: '/austax/cgt-adjustments', name: 'cgt-adjustments', component: () => import('./plugins/austax/CGTAdjustmentsView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/edit/:id', name: 'cgt-adjustments-edit', component: () => import('./plugins/austax/EditCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/new', name: 'cgt-adjustments-new', component: () => import('./plugins/austax/NewCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/multinew', name: 'cgt-adjustments-multinew', component: () => import('./plugins/austax/MultiNewCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-assets', name: 'cgt-assets', component: () => import('./plugins/austax/CGTAssetsView.vue') },
|
||||
{ path: '/austax/tax-summary', name: 'tax-summary', component: () => import('./plugins/austax/TaxSummaryReport.vue') },
|
||||
];
|
||||
|
||||
// Init plugin routes
|
||||
if (db.metadata.plugins.indexOf('austax') >= 0) {
|
||||
routes.push(...austax.getRoutes());
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
});
|
||||
|
||||
// Init state
|
||||
const dbFilename: string = await invoke('get_open_filename');
|
||||
if (dbFilename !== null) {
|
||||
try {
|
||||
await db.init(dbFilename); // Ensure all metadata cached before loading Vue
|
||||
} catch (err) {
|
||||
handleCriticalError(err);
|
||||
}
|
||||
}
|
||||
|
||||
// Create Vue app
|
||||
createApp(App).use(router).mount('#app');
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
DrCr: Web-based double-entry bookkeeping framework
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@ -17,7 +17,7 @@
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-3 divide-x divide-gray-200">
|
||||
<div :class="{'grid divide-x divide-gray-200': true, 'grid-cols-2': db.metadata.plugins.indexOf('austax') < 0, 'grid-cols-3': db.metadata.plugins.indexOf('austax') >= 0}">
|
||||
<div class="pr-4">
|
||||
<h2 class="font-medium text-gray-700 mb-2">Data sources</h2>
|
||||
<ul class="list-disc ml-6">
|
||||
@ -26,8 +26,7 @@
|
||||
<li><RouterLink :to="{ name: 'balance-assertions' }" class="text-gray-900 hover:text-blue-700 hover:underline">Balance assertions</RouterLink></li>
|
||||
<li><RouterLink :to="{ name: 'chart-of-accounts' }" class="text-gray-900 hover:text-blue-700 hover:underline">Chart of accounts</RouterLink></li>
|
||||
<!-- Plugin reports -->
|
||||
<!-- TODO: Generate this list dynamically -->
|
||||
<li><RouterLink :to="{ name: 'cgt-adjustments' }" class="text-gray-900 hover:text-blue-700 hover:underline">CGT adjustments</RouterLink></li>
|
||||
<component :is="austax.getDataSourcesLinks()" v-if="db.metadata.plugins.indexOf('austax') >= 0"></component>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="px-4">
|
||||
@ -37,15 +36,21 @@
|
||||
<li><RouterLink :to="{ name: 'trial-balance' }" class="text-gray-900 hover:text-blue-700 hover:underline">Trial balance</RouterLink></li>
|
||||
<li><RouterLink :to="{ name: 'balance-sheet' }" class="text-gray-900 hover:text-blue-700 hover:underline">Balance sheet</RouterLink></li>
|
||||
<li><RouterLink :to="{ name: 'income-statement' }" class="text-gray-900 hover:text-blue-700 hover:underline">Income statement</RouterLink></li>
|
||||
<!-- Plugin reports -->
|
||||
<component :is="austax.getGeneralReportsLinks()" v-if="db.metadata.plugins.indexOf('austax') >= 0"></component>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="pl-4">
|
||||
<div class="pl-4" v-if="db.metadata.plugins.indexOf('austax') >= 0">
|
||||
<h2 class="font-medium text-gray-700 mb-2">Advanced reports</h2>
|
||||
<ul class="list-disc ml-6">
|
||||
<!-- TODO: Generate this list dynamically -->
|
||||
<li><RouterLink :to="{ name: 'cgt-assets' }" class="text-gray-900 hover:text-blue-700 hover:underline">CGT assets</RouterLink></li>
|
||||
<li><RouterLink :to="{ name: 'tax-summary' }" class="text-gray-900 hover:text-blue-700 hover:underline">Tax summary</RouterLink></li>
|
||||
<!-- Plugin reports -->
|
||||
<component :is="austax.getAdvancedReportsLinks()" v-if="db.metadata.plugins.indexOf('austax') >= 0"></component>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { db } from '../db.ts';
|
||||
import austax from '../plugins/austax/plugin.ts';
|
||||
</script>
|
||||
|
28
src/plugin.ts
Normal file
28
src/plugin.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component } from 'vue';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
export interface Plugin {
|
||||
getAccountKinds: () => Promise<[string, string][]>,
|
||||
getAdvancedReportsLinks: () => Component,
|
||||
getDataSourcesLinks: () => Component,
|
||||
getGeneralReportsLinks: () => Component,
|
||||
getRoutes: () => RouteRecordRaw[],
|
||||
}
|
22
src/plugins/austax/AdvancedReportsLinks.vue
Normal file
22
src/plugins/austax/AdvancedReportsLinks.vue
Normal file
@ -0,0 +1,22 @@
|
||||
<!--
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<template>
|
||||
<li><RouterLink :to="{ name: 'cgt-assets' }" class="text-gray-900 hover:text-blue-700 hover:underline">CGT assets</RouterLink></li>
|
||||
<li><RouterLink :to="{ name: 'tax-summary' }" class="text-gray-900 hover:text-blue-700 hover:underline">Tax summary</RouterLink></li>
|
||||
</template>
|
21
src/plugins/austax/DataSourcesLinks.vue
Normal file
21
src/plugins/austax/DataSourcesLinks.vue
Normal file
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<template>
|
||||
<li><RouterLink :to="{ name: 'cgt-adjustments' }" class="text-gray-900 hover:text-blue-700 hover:underline">CGT adjustments</RouterLink></li>
|
||||
</template>
|
20
src/plugins/austax/GeneralReportsLinks.vue
Normal file
20
src/plugins/austax/GeneralReportsLinks.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<!--
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<template>
|
||||
</template>
|
40
src/plugins/austax/plugin.ts
Normal file
40
src/plugins/austax/plugin.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { getAccountKinds } from './account_kinds.ts';
|
||||
import DataSourcesLinks from './DataSourcesLinks.vue';
|
||||
import GeneralReportsLinks from './GeneralReportsLinks.vue';
|
||||
import AdvancedReportsLinks from './AdvancedReportsLinks.vue';
|
||||
import { Plugin } from '../../plugin.ts';
|
||||
|
||||
export default {
|
||||
'getAccountKinds': getAccountKinds,
|
||||
|
||||
getDataSourcesLinks: () => DataSourcesLinks,
|
||||
getGeneralReportsLinks: () => GeneralReportsLinks,
|
||||
getAdvancedReportsLinks: () => AdvancedReportsLinks,
|
||||
|
||||
getRoutes: () => [
|
||||
{ path: '/austax/cgt-adjustments', name: 'cgt-adjustments', component: () => import('./CGTAdjustmentsView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/edit/:id', name: 'cgt-adjustments-edit', component: () => import('./EditCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/new', name: 'cgt-adjustments-new', component: () => import('./NewCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-adjustments/multinew', name: 'cgt-adjustments-multinew', component: () => import('./MultiNewCGTAdjustmentView.vue') },
|
||||
{ path: '/austax/cgt-assets', name: 'cgt-assets', component: () => import('./CGTAssetsView.vue') },
|
||||
{ path: '/austax/tax-summary', name: 'tax-summary', component: () => import('./TaxSummaryReport.vue') },
|
||||
],
|
||||
} as Plugin;
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
DrCr: Web-based double-entry bookkeeping framework
|
||||
Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
|
||||
DrCr: Double-entry bookkeeping framework
|
||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
@ -16,7 +16,8 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as austax from './plugins/austax/account_kinds.ts';
|
||||
import { db } from './db.ts';
|
||||
import austax from './plugins/austax/plugin.ts';
|
||||
|
||||
export const drcrAccountKinds: [string, string][] = [
|
||||
['drcr.asset', 'Asset'],
|
||||
@ -29,8 +30,10 @@ export const drcrAccountKinds: [string, string][] = [
|
||||
export async function getAccountKinds() {
|
||||
const accountKinds = [...drcrAccountKinds];
|
||||
|
||||
// FIXME: Make this customisable
|
||||
// Add plugin account kinds
|
||||
if (db.metadata.plugins.indexOf('austax') >= 0) {
|
||||
accountKinds.push(...await austax.getAccountKinds());
|
||||
}
|
||||
|
||||
return accountKinds;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user