2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00

Desk, DatabaseSelector and SetupWizard

This commit is contained in:
Faris Ansari 2018-10-23 18:12:36 +05:30
parent e7984bcfce
commit 082bb526b6
6 changed files with 142 additions and 57 deletions

View File

@ -1,53 +1,57 @@
<template> <template>
<div id="app"> <div id="app">
<div class="row no-gutters" v-if="showDesk"> <desk v-if="showDesk" />
<sidebar class="col-2" /> <database-selector v-if="showDatabaseSelector" @file="connectToDBFile" />
<div class="page-container col-10 bg-light"> <setup-wizard v-if="showSetupWizard" />
<router-view />
</div>
</div>
<setup-wizard v-else/>
</div> </div>
</template> </template>
<script> <script>
import Sidebar from './components/Sidebar';
import frappe from 'frappejs'; import frappe from 'frappejs';
import Vue from 'vue'; import Desk from './pages/Desk';
import Observable from 'frappejs/utils/observable';
import Desk from 'frappejs/ui/components/Desk';
import sidebarConfig from './sidebarConfig';
import SetupWizard from './pages/SetupWizard/SetupWizard'; import SetupWizard from './pages/SetupWizard/SetupWizard';
import DatabaseSelector from './pages/DatabaseSelector';
export default { export default {
name: 'App', name: 'App',
data() { data() {
return { return {
showDesk: JSON.parse(localStorage.showDesk), showDatabaseSelector: false,
sidebarConfig showDesk: false,
showSetupWizard: false
} }
}, },
components: { components: {
Desk,
SetupWizard, SetupWizard,
Sidebar DatabaseSelector,
}, },
async created() { mounted() {
if (!localStorage.dbPath) {
this.showDatabaseSelector = true;
} else {
frappe.events.trigger('connect-database', localStorage.dbPath);
}
frappe.events.on('show-setup-wizard', () => { frappe.events.on('show-setup-wizard', () => {
this.showSetupWizard = true;
this.showDesk = false; this.showDesk = false;
}) this.showDatabaseSelector = false;
});
frappe.events.on('show-desk', () => { frappe.events.on('show-desk', () => {
this.showDesk = true; this.showDesk = true;
this.$router.push('/tree/Account'); this.showSetupWizard = false;
}); this.showDatabaseSelector = false;
})
},
methods: {
connectToDBFile(filePath) {
frappe.events.trigger('DatabaseSelector:file-selected', filePath);
}
} }
} }
</script> </script>
<style lang="scss"> <style lang="scss">
@import "styles/index.scss"; @import "styles/index.scss";
.page-container {
height: 100vh;
overflow: auto;
overflow-x: hidden;
}
</style> </style>

View File

@ -24,17 +24,26 @@ import Toasted from 'vue-toasted';
frappe.registerModels(models); frappe.registerModels(models);
frappe.fetch = window.fetch.bind(); frappe.fetch = window.fetch.bind();
const electronSettings = getSettings(); frappe.events.on('connect-database', async (filepath) => {
if (!electronSettings.dbPath) { await connectToLocalDatabase(filepath);
localStorage.showDesk = false; frappe.events.trigger('show-desk');
} else { });
await connectToLocalDatabase();
localStorage.showDesk = true;
}
frappe.events.on('SetupWizard:setup-complete', async ({ setupWizardValues }) => { frappe.events.on('DatabaseSelector:file-selected', async (filepath) => {
await connectToLocalDatabase(filepath);
localStorage.dbPath = filepath;
const accountingSettings = await frappe.getSingle('AccountingSettings');
if (!accountingSettings.companyName) {
frappe.events.trigger('show-setup-wizard');
} else {
frappe.events.trigger('show-desk');
}
});
frappe.events.on('SetupWizard:setup-complete', async (setupWizardValues) => {
const { const {
file,
companyName, companyName,
country, country,
name, name,
@ -44,11 +53,6 @@ import Toasted from 'vue-toasted';
fiscalYearEnd fiscalYearEnd
} = setupWizardValues; } = setupWizardValues;
// db init
const dbPath = path.join(file[0].path, 'frappe-accounting.db');
await saveSettings({ dbPath });
await connectToLocalDatabase();
const doc = await frappe.getSingle('AccountingSettings'); const doc = await frappe.getSingle('AccountingSettings');
await doc.set({ await doc.set({
companyName, companyName,
@ -66,10 +70,9 @@ import Toasted from 'vue-toasted';
frappe.events.trigger('show-desk'); frappe.events.trigger('show-desk');
}); });
async function connectToLocalDatabase() { async function connectToLocalDatabase(filepath) {
const electronSettings = getSettings();
frappe.login('Administrator'); frappe.login('Administrator');
frappe.db = new SQLite({ dbPath: electronSettings.dbPath }); frappe.db = new SQLite({ dbPath: filepath });
await frappe.db.connect(); await frappe.db.connect();
await frappe.db.migrate(); await frappe.db.migrate();
frappe.getSingle('SystemSettings'); frappe.getSingle('SystemSettings');

View File

@ -0,0 +1,69 @@
<template>
<div class="row">
<div class="col-8 mx-auto p-5">
<div class="row">
<div class="col-6">
<clickable-card
@click="newDatabase"
:title="_('New Database')"
:description="_('Create a new database file and store it in your computer.')"
/>
</div>
<div class="col-6">
<clickable-card
@click="existingDatabase"
:title="_('Existing Database')"
:description="_('Load an existing .db file from your computer.')"
/>
</div>
</div>
</div>
</div>
</template>
<script>
import ClickableCard from '../components/ClickableCard';
const { remote } = require('electron');
const { dialog } = remote;
const currentWindow = remote.getCurrentWindow();
export default {
name: 'DatabaseSelector',
components: {
ClickableCard
},
methods: {
newDatabase() {
dialog.showSaveDialog(
currentWindow,
{
title: 'Select folder',
defaultPath: 'frappe-accounting.db'
},
(filePath) => {
if (filePath) {
if (!filePath.endsWith('.db')) {
filePath = filePath + '.db';
}
this.$emit('file', filePath);
}
}
);
},
existingDatabase() {
dialog.showOpenDialog(
currentWindow,
{
title: 'Select file',
properties: ['openFile'],
filters: [{ name: 'SQLite DB File', extensions: ['db'] }]
},
(files) => {
if (files && files[0]) {
this.$emit('file', files[0]);
}
}
);
}
}
};
</script>

24
src/pages/Desk.vue Normal file
View File

@ -0,0 +1,24 @@
<template>
<div class="row no-gutters">
<sidebar class="col-2" />
<div class="page-container col-10 bg-light">
<router-view />
</div>
</div>
</template>
<script>
import Sidebar from '../components/Sidebar';
export default {
name: 'Desk',
components: {
Sidebar
}
}
</script>
<style>
.page-container {
height: 100vh;
overflow: auto;
overflow-x: hidden;
}
</style>

View File

@ -55,7 +55,7 @@ export default {
methods: { methods: {
async submit() { async submit() {
try { try {
frappe.events.trigger('SetupWizard:setup-complete', { setupWizardValues: this.doc }); frappe.events.trigger('SetupWizard:setup-complete', this.doc);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -3,14 +3,6 @@ const countryList = Object.keys(require('../../../fixtures/countryInfo.json')).s
export default { export default {
fields: [ fields: [
{
fieldname: 'file',
label: 'File',
fieldtype: 'File',
required: 1,
directory: 1
},
{ {
fieldname: 'country', fieldname: 'country',
label: 'Country', label: 'Country',
@ -66,13 +58,6 @@ export default {
layout: { layout: {
paginated: true, paginated: true,
sections: [ sections: [
process.env.ELECTRON === 'true' ? {
title: 'Select File location',
columns: [
{ fields: ['file'] }
]
} : null,
{ {
title: 'Select Country', title: 'Select Country',
columns: [ columns: [