2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 10:16:22 +00:00
books/src/pages/GetStarted.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

228 lines
6.6 KiB
Vue
Raw Normal View History

<template>
2019-12-23 12:51:04 +00:00
<div class="flex flex-col overflow-y-hidden">
2022-08-30 10:38:31 +00:00
<PageHeader :title="t`Set Up Your Workspace`" />
2022-10-11 20:20:15 +00:00
<div class="flex-1 overflow-y-auto overflow-x-hidden custom-scroll">
<div
v-for="section in sections"
:key="section.label"
class="p-4 border-b"
>
<h2 class="font-medium">{{ section.label }}</h2>
<div class="flex mt-4 gap-4">
<div
v-for="item in section.items"
:key="item.label"
class="w-full md:w-1/3 sm:w-1/2"
>
<div
class="flex flex-col justify-between h-40 p-4 border rounded-lg"
@mouseenter="() => (activeCard = item.key)"
@mouseleave="() => (activeCard = null)"
>
<div>
<component
:is="getIconComponent(item)"
v-show="activeCard !== item.key && !isCompleted(item)"
class="mb-4"
/>
<Icon
v-show="isCompleted(item)"
name="green-check"
size="24"
class="w-5 h-5 mb-4"
/>
<h3 class="font-medium">{{ item.label }}</h3>
<p class="mt-2 text-sm text-gray-800">
{{ item.description }}
</p>
</div>
<div
v-show="activeCard === item.key && !isCompleted(item)"
class="flex mt-2 overflow-hidden"
>
<Button
v-if="item.action"
class="leading-tight"
type="primary"
2021-12-02 13:10:46 +00:00
@click="handleAction(item)"
>
<span class="text-base text-white">
2022-08-30 10:38:31 +00:00
{{ item.actionLabel || t`Set Up` }}
</span>
</Button>
<Button
v-if="item.documentation"
class="leading-tight"
:class="{ 'ms-4': item.action }"
2021-12-02 13:10:46 +00:00
@click="handleDocumentation(item)"
>
<span class="text-base">
{{ t`Documentation` }}
</span>
</Button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
2023-06-14 04:35:27 +00:00
import Button from 'src/components/Button.vue';
import Icon from 'src/components/Icon.vue';
import PageHeader from 'src/components/PageHeader.vue';
import { fyo } from 'src/initFyo';
2022-04-25 10:37:25 +00:00
import { getGetStartedConfig } from 'src/utils/getStartedConfig';
2022-06-17 08:50:04 +00:00
import { openLink } from 'src/utils/ipcCalls';
import { h } from 'vue';
export default {
name: 'GetStarted',
components: {
PageHeader,
Button,
2021-12-02 13:10:46 +00:00
Icon,
},
data() {
return {
2021-12-02 13:10:46 +00:00
activeCard: null,
2022-04-25 10:37:25 +00:00
sections: [],
};
},
2022-04-25 10:37:25 +00:00
mounted() {
this.sections = getGetStartedConfig();
},
async activated() {
await fyo.doc.getDoc('GetStarted');
this.checkForCompletedTasks();
},
methods: {
2021-12-02 13:10:46 +00:00
async handleDocumentation({ key, documentation }) {
if (documentation) {
2022-06-17 08:50:04 +00:00
openLink(documentation);
2021-12-02 13:10:46 +00:00
}
switch (key) {
case 'Opening Balances':
await this.updateChecks({ openingBalanceChecked: true });
2021-12-02 13:10:46 +00:00
break;
}
},
async handleAction({ key, action }) {
if (action) {
action();
this.activeCard = null;
}
switch (key) {
2023-03-02 09:08:33 +00:00
case 'Print':
await this.updateChecks({ printSetup: true });
break;
2021-12-02 13:10:46 +00:00
case 'General':
await this.updateChecks({ companySetup: true });
2021-12-02 13:10:46 +00:00
break;
case 'System':
await this.updateChecks({ systemSetup: true });
2021-12-02 13:10:46 +00:00
break;
case 'Review Accounts':
await this.updateChecks({ chartOfAccountsReviewed: true });
2021-12-02 13:10:46 +00:00
break;
case 'Add Taxes':
await this.updateChecks({ taxesAdded: true });
2021-12-02 13:10:46 +00:00
break;
}
},
async checkIsOnboardingComplete() {
2022-04-25 10:37:25 +00:00
if (fyo.singles.GetStarted.onboardingComplete) {
2021-12-02 13:10:46 +00:00
return true;
}
const doc = await fyo.doc.getDoc('GetStarted');
2022-04-25 10:37:25 +00:00
const onboardingComplete = fyo.schemaMap.GetStarted.fields
2021-12-02 13:10:46 +00:00
.filter(({ fieldname }) => fieldname !== 'onboardingComplete')
.map(({ fieldname }) => doc.get(fieldname))
.every(Boolean);
if (onboardingComplete) {
await this.updateChecks({ onboardingComplete });
const systemSettings = await fyo.doc.getDoc('SystemSettings');
await systemSettings.set('hideGetStarted', true);
await systemSettings.sync();
2021-12-02 13:10:46 +00:00
}
return onboardingComplete;
},
async checkForCompletedTasks() {
let toUpdate = {};
2021-12-02 13:10:46 +00:00
if (await this.checkIsOnboardingComplete()) {
return;
}
if (!fyo.singles.GetStarted.salesItemCreated) {
const count = await fyo.db.count('Item', { filters: { for: 'Sales' } });
toUpdate.salesItemCreated = count > 0;
}
if (!fyo.singles.GetStarted.purchaseItemCreated) {
const count = await fyo.db.count('Item', {
filters: { for: 'Purchases' },
});
toUpdate.purchaseItemCreated = count > 0;
}
2022-04-25 10:37:25 +00:00
if (!fyo.singles.GetStarted.invoiceCreated) {
const count = await fyo.db.count('SalesInvoice');
toUpdate.invoiceCreated = count > 0;
}
2022-04-25 10:37:25 +00:00
if (!fyo.singles.GetStarted.customerCreated) {
const count = await fyo.db.count('Party', {
filters: { role: 'Customer' },
});
toUpdate.customerCreated = count > 0;
}
2022-04-25 10:37:25 +00:00
if (!fyo.singles.GetStarted.billCreated) {
const count = await fyo.db.count('SalesInvoice');
toUpdate.billCreated = count > 0;
}
2022-04-25 10:37:25 +00:00
if (!fyo.singles.GetStarted.supplierCreated) {
const count = await fyo.db.count('Party', {
filters: { role: 'Supplier' },
});
toUpdate.supplierCreated = count > 0;
}
await this.updateChecks(toUpdate);
},
async updateChecks(toUpdate) {
await fyo.singles.GetStarted.setAndSync(toUpdate);
await fyo.doc.getDoc('GetStarted');
},
isCompleted(item) {
return fyo.singles.GetStarted.get(item.fieldname) || false;
},
getIconComponent(item) {
let completed = fyo.singles.GetStarted[item.fieldname] || false;
let name = completed ? 'green-check' : item.icon;
let size = completed ? '24' : '18';
return {
name,
render() {
return h(Icon, {
...Object.assign(
{
name,
2021-12-02 13:10:46 +00:00
size,
},
this.$attrs
2021-12-02 13:10:46 +00:00
),
});
2021-12-02 13:10:46 +00:00
},
};
2021-12-02 13:10:46 +00:00
},
},
};
</script>