2018-10-23 12:42:36 +00:00
|
|
|
<template>
|
2020-01-28 18:15:42 +00:00
|
|
|
<div
|
|
|
|
class="py-10 flex-1 bg-white window-drag"
|
|
|
|
:class="{ 'pointer-events-none': loadingDatabase }"
|
|
|
|
>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div class="w-full">
|
|
|
|
<div class="px-12">
|
|
|
|
<h1 class="text-2xl font-semibold">
|
|
|
|
{{ _('Welcome to Frappe Books') }}
|
|
|
|
</h1>
|
|
|
|
<p class="text-gray-600 text-base" v-if="!showFiles">
|
|
|
|
{{
|
|
|
|
_('Create a new file or select an existing one from your computer')
|
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
<p class="text-gray-600 text-base" v-if="showFiles">
|
|
|
|
{{ _('Select a file to load the company transactions') }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="px-12 mt-10 window-no-drag" v-if="!showFiles">
|
|
|
|
<div class="flex">
|
|
|
|
<div
|
|
|
|
@click="newDatabase"
|
2021-11-11 18:53:10 +00:00
|
|
|
class="
|
|
|
|
w-1/2
|
|
|
|
border
|
|
|
|
rounded-xl
|
|
|
|
flex flex-col
|
|
|
|
items-center
|
|
|
|
py-8
|
|
|
|
px-5
|
|
|
|
cursor-pointer
|
|
|
|
hover:shadow
|
|
|
|
"
|
2020-01-28 08:20:01 +00:00
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="w-14 h-14 rounded-full bg-blue-200 relative flex-center"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="w-12 h-12 absolute rounded-full bg-blue-500 flex-center"
|
|
|
|
>
|
|
|
|
<feather-icon name="plus" class="text-white w-5 h-5" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-28 18:15:42 +00:00
|
|
|
<div class="mt-5 font-medium">
|
|
|
|
<template
|
|
|
|
v-if="loadingDatabase && fileSelectedFrom === 'New File'"
|
|
|
|
>
|
|
|
|
{{ _('Loading...') }}
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ _('New File') }}
|
|
|
|
</template>
|
|
|
|
</div>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div class="mt-2 text-sm text-gray-600 text-center">
|
|
|
|
{{ _('Create a new file and store it in your computer.') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
@click="existingDatabase"
|
2021-11-11 18:53:10 +00:00
|
|
|
class="
|
|
|
|
ml-6
|
|
|
|
w-1/2
|
|
|
|
border
|
|
|
|
rounded-xl
|
|
|
|
flex flex-col
|
|
|
|
items-center
|
|
|
|
py-8
|
|
|
|
px-5
|
|
|
|
cursor-pointer
|
|
|
|
hover:shadow
|
|
|
|
"
|
2020-01-28 08:20:01 +00:00
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="w-14 h-14 rounded-full bg-green-200 relative flex-center"
|
|
|
|
>
|
|
|
|
<div class="w-12 h-12 rounded-full bg-green-500 flex-center">
|
|
|
|
<feather-icon name="upload" class="w-4 h-4 text-white" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-28 18:15:42 +00:00
|
|
|
<div class="mt-5 font-medium">
|
|
|
|
<template
|
|
|
|
v-if="loadingDatabase && fileSelectedFrom === 'Existing File'"
|
|
|
|
>
|
|
|
|
{{ _('Loading...') }}
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ _('Existing File') }}
|
|
|
|
</template>
|
|
|
|
</div>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div class="mt-2 text-sm text-gray-600 text-center">
|
|
|
|
{{ _('Load an existing .db file from your computer.') }}
|
|
|
|
</div>
|
2019-10-13 12:03:01 +00:00
|
|
|
</div>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
2020-01-28 08:20:01 +00:00
|
|
|
<a
|
|
|
|
v-if="files.length > 0"
|
|
|
|
class="text-brand text-sm mt-4 inline-block cursor-pointer"
|
|
|
|
@click="showFiles = true"
|
|
|
|
>
|
|
|
|
Select from existing files
|
|
|
|
</a>
|
2019-10-13 12:03:01 +00:00
|
|
|
</div>
|
2020-01-28 08:20:01 +00:00
|
|
|
|
|
|
|
<div v-if="showFiles">
|
|
|
|
<div class="px-12 mt-6">
|
|
|
|
<div
|
2021-11-11 18:53:10 +00:00
|
|
|
class="
|
|
|
|
py-2
|
|
|
|
px-4
|
|
|
|
text-sm
|
|
|
|
flex
|
|
|
|
justify-between
|
|
|
|
items-center
|
|
|
|
hover:bg-gray-100
|
|
|
|
cursor-pointer
|
|
|
|
border-b
|
|
|
|
"
|
2020-01-28 08:20:01 +00:00
|
|
|
:class="{ 'border-t': i === 0 }"
|
|
|
|
v-for="(file, i) in files"
|
|
|
|
:key="file.filePath"
|
2020-01-28 18:15:42 +00:00
|
|
|
@click="selectFile(file)"
|
2020-01-28 08:20:01 +00:00
|
|
|
>
|
|
|
|
<div class="flex items-baseline">
|
|
|
|
<span>
|
2020-01-28 18:15:42 +00:00
|
|
|
<template v-if="loadingDatabase && fileSelectedFrom === file">
|
|
|
|
{{ _('Loading...') }}
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ file.companyName }}
|
|
|
|
</template>
|
2020-01-28 08:20:01 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="text-gray-700">
|
|
|
|
{{ getFileLastModified(file.filePath) }}
|
|
|
|
</div>
|
2019-10-13 12:03:01 +00:00
|
|
|
</div>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div class="px-12 mt-4">
|
|
|
|
<a
|
|
|
|
class="text-brand text-sm cursor-pointer"
|
|
|
|
@click="showFiles = false"
|
|
|
|
>
|
|
|
|
Select file manually
|
|
|
|
</a>
|
2019-12-16 11:34:22 +00:00
|
|
|
</div>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2020-01-28 08:20:01 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import config from '@/config';
|
|
|
|
import { DateTime } from 'luxon';
|
2021-11-29 09:45:23 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
|
|
|
import { IPC_ACTIONS } from '../messages';
|
2020-01-28 08:20:01 +00:00
|
|
|
|
2021-11-29 09:45:23 +00:00
|
|
|
import { createNewDatabase, connectToLocalDatabase } from '@/initialization';
|
2018-10-23 12:42:36 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DatabaseSelector',
|
2020-01-28 08:20:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-01-28 18:15:42 +00:00
|
|
|
loadingDatabase: false,
|
|
|
|
fileSelectedFrom: null,
|
2020-01-28 08:20:01 +00:00
|
|
|
showFiles: false,
|
2021-11-11 18:53:10 +00:00
|
|
|
files: [],
|
2020-01-28 08:20:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-11-11 18:53:10 +00:00
|
|
|
this.setFiles();
|
2020-01-28 08:20:01 +00:00
|
|
|
this.showFiles = this.files.length > 0;
|
|
|
|
},
|
2021-11-11 18:53:10 +00:00
|
|
|
watch: {
|
|
|
|
showFiles() {
|
|
|
|
this.setFiles();
|
|
|
|
},
|
|
|
|
},
|
2018-10-23 12:42:36 +00:00
|
|
|
methods: {
|
2021-11-11 18:53:10 +00:00
|
|
|
setFiles() {
|
|
|
|
this.files = config
|
|
|
|
.get('files', [])
|
|
|
|
.filter(({ filePath }) => fs.existsSync(filePath));
|
|
|
|
},
|
2019-10-26 14:46:04 +00:00
|
|
|
async newDatabase() {
|
2020-01-28 18:15:42 +00:00
|
|
|
this.fileSelectedFrom = 'New File';
|
2019-10-26 14:46:04 +00:00
|
|
|
let filePath = await createNewDatabase();
|
2020-01-01 08:11:57 +00:00
|
|
|
this.connectToDatabase(filePath);
|
2018-10-23 12:42:36 +00:00
|
|
|
},
|
2019-10-26 14:46:04 +00:00
|
|
|
async existingDatabase() {
|
2020-01-28 18:15:42 +00:00
|
|
|
this.fileSelectedFrom = 'Existing File';
|
2021-11-29 09:45:23 +00:00
|
|
|
const filePath = (await ipcRenderer.invoke(IPC_ACTIONS.GET_OPEN_FILEPATH, {
|
|
|
|
title: this._('Select file'),
|
|
|
|
properties: ['openFile'],
|
|
|
|
filters: [{ name: 'SQLite DB File', extensions: ['db'] }],
|
|
|
|
}))?.filePaths?.[0];
|
2020-01-01 08:11:57 +00:00
|
|
|
this.connectToDatabase(filePath);
|
|
|
|
},
|
2020-01-28 18:15:42 +00:00
|
|
|
async selectFile(file) {
|
|
|
|
this.fileSelectedFrom = file;
|
|
|
|
await this.connectToDatabase(file.filePath);
|
|
|
|
},
|
2020-01-01 08:11:57 +00:00
|
|
|
async connectToDatabase(filePath) {
|
2021-11-09 10:38:25 +00:00
|
|
|
if (!filePath) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 18:15:42 +00:00
|
|
|
this.loadingDatabase = true;
|
2021-11-05 19:41:39 +00:00
|
|
|
const connectionSuccess = await connectToLocalDatabase(filePath);
|
2020-01-28 18:15:42 +00:00
|
|
|
this.loadingDatabase = false;
|
2021-11-11 18:53:10 +00:00
|
|
|
|
|
|
|
if (connectionSuccess) {
|
2021-11-05 19:41:39 +00:00
|
|
|
this.$emit('database-connect');
|
|
|
|
} else {
|
2021-11-11 18:53:10 +00:00
|
|
|
alert(
|
|
|
|
frappe._('Please select an existing database or create a new one.')
|
|
|
|
);
|
2021-11-05 19:41:39 +00:00
|
|
|
}
|
2020-01-28 08:20:01 +00:00
|
|
|
},
|
|
|
|
getFileLastModified(filePath) {
|
|
|
|
let stats = fs.statSync(filePath);
|
|
|
|
return DateTime.fromJSDate(stats.mtime).toRelative();
|
2021-11-11 18:53:10 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-23 12:42:36 +00:00
|
|
|
};
|
2019-10-13 12:03:01 +00:00
|
|
|
</script>
|