2018-10-23 12:42:36 +00:00
|
|
|
<template>
|
2020-01-28 18:15:42 +00:00
|
|
|
<div
|
2022-04-22 11:02:03 +00:00
|
|
|
class="py-10 flex-1 bg-white flex justify-center items-center"
|
2021-12-07 13:10:06 +00:00
|
|
|
:class="{
|
|
|
|
'pointer-events-none': loadingDatabase,
|
|
|
|
'window-drag': platform !== 'Windows',
|
|
|
|
}"
|
2020-01-28 18:15:42 +00:00
|
|
|
>
|
2022-04-28 18:57:10 +00:00
|
|
|
<WindowControls v-if="platform === 'Mac'" class="absolute top-6 left-5" />
|
2022-04-22 11:02:03 +00:00
|
|
|
<div
|
|
|
|
class="w-full w-600 shadow rounded-lg border relative"
|
|
|
|
style="height: 700px"
|
|
|
|
>
|
2022-04-28 12:37:07 +00:00
|
|
|
<!-- Welcome to Frappe Books -->
|
|
|
|
<div class="px-6 py-10">
|
|
|
|
<h1 class="text-2xl font-semibold select-none">
|
2022-02-14 05:15:26 +00:00
|
|
|
{{ t`Welcome to Frappe Books` }}
|
2020-01-28 08:20:01 +00:00
|
|
|
</h1>
|
2022-04-28 12:37:07 +00:00
|
|
|
<p class="text-gray-600 text-base select-none">
|
2020-01-28 08:20:01 +00:00
|
|
|
{{
|
2022-02-14 05:15:26 +00:00
|
|
|
t`Create a new file or select an existing one from your computer`
|
2020-01-28 08:20:01 +00:00
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-04-28 12:37:07 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<!-- New File (Blue Icon) -->
|
|
|
|
<div
|
|
|
|
@click="newDatabase"
|
|
|
|
class="
|
|
|
|
px-6
|
|
|
|
h-18
|
|
|
|
flex flex-row
|
|
|
|
items-center
|
|
|
|
cursor-pointer
|
|
|
|
gap-4
|
|
|
|
p-2
|
|
|
|
hover:bg-gray-100
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<div class="w-8 h-8 rounded-full bg-blue-500 relative flex-center">
|
|
|
|
<feather-icon name="plus" class="text-white w-5 h-5" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<p class="font-medium">
|
|
|
|
{{ t`New File` }}
|
|
|
|
</p>
|
|
|
|
<p class="text-sm text-gray-600">
|
|
|
|
{{ t`Create a new file and store it in your computer.` }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Existing File (Green Icon) -->
|
|
|
|
<div
|
|
|
|
@click="existingDatabase"
|
|
|
|
class="
|
|
|
|
px-6
|
|
|
|
h-18
|
|
|
|
flex flex-row
|
|
|
|
items-center
|
|
|
|
cursor-pointer
|
|
|
|
gap-4
|
|
|
|
p-2
|
|
|
|
hover:bg-gray-100
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<div class="w-8 h-8 rounded-full bg-green-500 relative flex-center">
|
|
|
|
<feather-icon name="upload" class="w-4 h-4 text-white" />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<p class="font-medium">
|
|
|
|
{{ t`Existing File` }}
|
|
|
|
</p>
|
|
|
|
<p class="text-sm text-gray-600">
|
|
|
|
{{ t`Load an existing .db file from your computer.` }}
|
|
|
|
</p>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
2019-10-13 12:03:01 +00:00
|
|
|
</div>
|
2022-04-28 12:37:07 +00:00
|
|
|
<hr />
|
2020-01-28 08:20:01 +00:00
|
|
|
|
2022-04-28 12:37:07 +00:00
|
|
|
<!-- File List -->
|
|
|
|
<div class="overflow-scroll" style="max-height: 340px">
|
|
|
|
<div
|
|
|
|
class="
|
|
|
|
h-18
|
|
|
|
px-6
|
|
|
|
flex
|
|
|
|
gap-4
|
|
|
|
items-center
|
|
|
|
hover:bg-gray-100
|
|
|
|
cursor-pointer
|
|
|
|
"
|
|
|
|
v-for="(file, i) in files"
|
|
|
|
:key="file.dbPath"
|
|
|
|
@click="selectFile(file)"
|
|
|
|
>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div
|
2021-11-11 18:53:10 +00:00
|
|
|
class="
|
2022-04-28 12:37:07 +00:00
|
|
|
w-8
|
|
|
|
h-8
|
|
|
|
rounded-full
|
2021-11-11 18:53:10 +00:00
|
|
|
flex
|
2022-04-28 12:37:07 +00:00
|
|
|
justify-center
|
2021-11-11 18:53:10 +00:00
|
|
|
items-center
|
2022-04-28 12:37:07 +00:00
|
|
|
bg-gray-200
|
|
|
|
text-gray-500
|
|
|
|
font-semibold
|
|
|
|
text-base
|
2021-11-11 18:53:10 +00:00
|
|
|
"
|
2020-01-28 08:20:01 +00:00
|
|
|
>
|
2022-04-28 12:37:07 +00:00
|
|
|
{{ i + 1 }}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<p class="font-medium">
|
|
|
|
{{ file.companyName }}
|
|
|
|
</p>
|
|
|
|
<p class="text-sm text-gray-600">
|
2022-04-22 11:02:03 +00:00
|
|
|
{{ file.modified }}
|
2022-04-28 12:37:07 +00:00
|
|
|
</p>
|
2019-10-13 12:03:01 +00:00
|
|
|
</div>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-28 12:37:07 +00:00
|
|
|
<hr v-if="files?.length" />
|
|
|
|
|
|
|
|
<!-- Language Selector -->
|
2022-04-22 11:02:03 +00:00
|
|
|
<div
|
|
|
|
class="w-full flex justify-end absolute px-6 py-6"
|
|
|
|
style="top: 100%; transform: translateY(-100%)"
|
|
|
|
>
|
|
|
|
<LanguageSelector class="w-40" />
|
|
|
|
</div>
|
2022-02-17 07:46:36 +00:00
|
|
|
</div>
|
2018-10-23 12:42:36 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2021-11-29 09:45:23 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
2022-03-30 10:57:45 +00:00
|
|
|
import fs from 'fs';
|
2022-04-22 11:02:03 +00:00
|
|
|
import { cloneDeep } from 'lodash';
|
2022-03-30 10:57:45 +00:00
|
|
|
import { DateTime } from 'luxon';
|
2022-04-20 06:38:47 +00:00
|
|
|
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
|
2022-04-28 18:57:10 +00:00
|
|
|
import WindowControls from 'src/components/WindowControls.vue';
|
2022-04-21 13:08:36 +00:00
|
|
|
import { fyo } from 'src/initFyo';
|
2022-04-22 11:02:03 +00:00
|
|
|
import { getSavePath } from 'src/utils/ipcCalls';
|
2022-04-21 13:08:36 +00:00
|
|
|
import { IPC_ACTIONS } from 'utils/messages';
|
2018-10-23 12:42:36 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DatabaseSelector',
|
2022-04-22 11:02:03 +00:00
|
|
|
emits: ['file-selected'],
|
2020-01-28 08:20:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2020-01-28 18:15:42 +00:00
|
|
|
loadingDatabase: false,
|
|
|
|
fileSelectedFrom: null,
|
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();
|
2022-04-28 12:37:07 +00:00
|
|
|
window.ds = this;
|
2021-11-11 18:53:10 +00:00
|
|
|
},
|
2018-10-23 12:42:36 +00:00
|
|
|
methods: {
|
2021-11-11 18:53:10 +00:00
|
|
|
setFiles() {
|
2022-04-28 12:37:07 +00:00
|
|
|
const files = cloneDeep(fyo.config.get('files', []));
|
|
|
|
this.files = files.filter(({ dbPath }) => fs.existsSync(dbPath));
|
2022-04-22 11:02:03 +00:00
|
|
|
|
|
|
|
for (const file of this.files) {
|
2022-04-28 12:37:07 +00:00
|
|
|
const stats = fs.statSync(file.dbPath);
|
2022-04-22 11:02:03 +00:00
|
|
|
file.modified = DateTime.fromJSDate(stats.mtime).toRelative();
|
|
|
|
}
|
2021-11-11 18:53:10 +00:00
|
|
|
},
|
2019-10-26 14:46:04 +00:00
|
|
|
async newDatabase() {
|
2020-01-28 18:15:42 +00:00
|
|
|
this.fileSelectedFrom = 'New File';
|
2022-04-22 11:02:03 +00:00
|
|
|
const { filePath, canceled } = await getSavePath('books', 'db');
|
|
|
|
if (canceled || !filePath) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.connectToDatabase(filePath, true);
|
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-12-07 13:10:06 +00:00
|
|
|
const filePath = (
|
|
|
|
await ipcRenderer.invoke(IPC_ACTIONS.GET_OPEN_FILEPATH, {
|
2022-02-09 07:17:54 +00:00
|
|
|
title: this.t`Select file`,
|
2021-12-07 13:10:06 +00:00
|
|
|
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;
|
2022-04-28 12:37:07 +00:00
|
|
|
await this.connectToDatabase(file.dbPath);
|
2020-01-28 18:15:42 +00:00
|
|
|
},
|
2022-04-22 11:02:03 +00:00
|
|
|
async connectToDatabase(filePath, isNew) {
|
2021-11-09 10:38:25 +00:00
|
|
|
if (!filePath) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-22 11:02:03 +00:00
|
|
|
|
|
|
|
if (isNew) {
|
|
|
|
this.$emit('file-selected', filePath, isNew);
|
2022-01-24 09:04:37 +00:00
|
|
|
return;
|
2021-11-05 19:41:39 +00:00
|
|
|
}
|
2022-04-22 11:02:03 +00:00
|
|
|
|
|
|
|
this.$emit('file-selected', filePath, !!isNew);
|
2021-11-11 18:53:10 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-28 18:57:10 +00:00
|
|
|
components: { LanguageSelector, WindowControls },
|
2018-10-23 12:42:36 +00:00
|
|
|
};
|
2019-10-13 12:03:01 +00:00
|
|
|
</script>
|