2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

Sidebar Title

- set as companyName
- open DatabaseSelector on click
This commit is contained in:
Faris Ansari 2018-07-15 17:11:27 +05:30
parent 4b86558527
commit e170ab5655
2 changed files with 110 additions and 38 deletions

View File

@ -0,0 +1,50 @@
<template>
<form-layout
:fields="[docfield]"
:doc="doc"
/>
</template>
<script>
import frappe from 'frappejs';
// import SQLite from 'frappejs/backends/sqlite';
import FormLayout from 'frappejs/ui/components/Form/FormLayout';
import Observable from 'frappejs/utils/observable';
export default {
name: 'DatabaseSelector',
components: {
FormLayout
},
data() {
return {
docfield: {
fieldtype: 'File',
label: 'Select File',
fieldname: 'file',
filetypes: ['.db']
},
value: null,
invalid: false
}
},
created() {
this.doc = new Observable();
},
methods: {
handleChange(fileList) {
const value = fileList[0].name;
this.value = value;
},
async changeDatabase() {
if (frappe.db) {
frappe.db.close();
}
const dbPath = this.value;
frappe.db = new SQLite({ dbPath });
await frappe.db.connect();
await frappe.db.migrate();
}
}
}
</script>

View File

@ -1,6 +1,27 @@
const { _ } = require('frappejs/utils'); import frappe from 'frappejs';
import { _ } from 'frappejs/utils';
import DatabaseSelector from './components/DatabaseSelector';
export default [ export default {
async getTitle() {
const accountingSettings = await frappe.getSingle('AccountingSettings');
return accountingSettings.companyName;
},
onTitleClick(vm) {
vm.$modal.show({
component: DatabaseSelector,
modalProps: {
title: _('Change Database File'),
primaryAction: {
label: _('Submit'),
handler: (vm) => {
vm.changeDatabase();
}
}
}
});
},
groups: [
{ {
items: [ items: [
{ {
@ -39,4 +60,5 @@ export default [
} }
] ]
} }
]; ]
};