2018-10-23 12:42:36 +00:00
|
|
|
<template>
|
2020-01-28 08:20:01 +00:00
|
|
|
<div class="py-10 flex-1 bg-white window-drag">
|
|
|
|
<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"
|
|
|
|
class="w-1/2 border rounded-xl flex flex-col items-center py-8 px-5 cursor-pointer hover:shadow"
|
|
|
|
>
|
|
|
|
<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>
|
|
|
|
<div class="mt-5 font-medium">{{ _('New File') }}</div>
|
|
|
|
<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"
|
|
|
|
class="ml-6 w-1/2 border rounded-xl flex flex-col items-center py-8 px-5 cursor-pointer hover:shadow"
|
|
|
|
>
|
|
|
|
<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>
|
|
|
|
<div class="mt-5 font-medium">{{ _('Existing File') }}</div>
|
|
|
|
<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
|
|
|
|
class="py-2 px-4 text-sm flex justify-between items-center hover:bg-gray-100 cursor-pointer border-b"
|
|
|
|
:class="{ 'border-t': i === 0 }"
|
|
|
|
v-for="(file, i) in files"
|
|
|
|
:key="file.filePath"
|
|
|
|
@click="connectToDatabase(file.filePath)"
|
|
|
|
>
|
|
|
|
<div class="flex items-baseline">
|
|
|
|
<span>
|
|
|
|
{{ file.companyName }}
|
|
|
|
</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';
|
|
|
|
|
2020-01-01 08:11:57 +00:00
|
|
|
import {
|
|
|
|
createNewDatabase,
|
|
|
|
loadExistingDatabase,
|
|
|
|
connectToLocalDatabase
|
|
|
|
} from '@/utils';
|
2018-10-23 12:42:36 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DatabaseSelector',
|
2020-01-28 08:20:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showFiles: false,
|
|
|
|
files: []
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.files = config.get('files', []);
|
|
|
|
this.showFiles = this.files.length > 0;
|
|
|
|
},
|
2018-10-23 12:42:36 +00:00
|
|
|
methods: {
|
2019-10-26 14:46:04 +00:00
|
|
|
async newDatabase() {
|
|
|
|
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() {
|
|
|
|
let filePath = await loadExistingDatabase();
|
2020-01-01 08:11:57 +00:00
|
|
|
this.connectToDatabase(filePath);
|
|
|
|
},
|
|
|
|
async connectToDatabase(filePath) {
|
|
|
|
await connectToLocalDatabase(filePath);
|
|
|
|
this.$emit('database-connect');
|
2020-01-28 08:20:01 +00:00
|
|
|
},
|
|
|
|
getFileLastModified(filePath) {
|
|
|
|
let stats = fs.statSync(filePath);
|
|
|
|
return DateTime.fromJSDate(stats.mtime).toRelative();
|
2018-10-23 12:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-10-13 12:03:01 +00:00
|
|
|
</script>
|