2
0
mirror of https://github.com/frappe/books.git synced 2025-01-27 00:58:35 +00:00
books/src/pages/Report.vue

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

132 lines
3.3 KiB
Vue
Raw Normal View History

2019-10-14 03:26:20 +05:30
<template>
<div class="flex flex-col w-full h-full">
<PageHeader :title="title">
<DropdownWithActions
2022-05-18 12:34:33 +05:30
v-for="group of groupedActions"
:icon="false"
:key="group.label"
:type="group.type"
:actions="group.actions"
class="text-xs"
>
2022-05-18 12:34:33 +05:30
{{ group.group }}
</DropdownWithActions>
2019-10-14 03:26:20 +05:30
</PageHeader>
<!-- Filters -->
<div v-if="report" class="grid grid-cols-5 gap-4 p-4 border-b">
<FormControl
v-for="field in report.filters"
2022-09-18 19:37:26 +05:30
:border="true"
size="small"
:show-label="field.fieldtype === 'Check'"
:key="field.fieldname + '-filter'"
:df="field"
:value="report.get(field.fieldname)"
:read-only="loading"
@change="async (value) => await report.set(field.fieldname, value)"
/>
</div>
<!-- Report Body -->
<ListReport v-if="report" :report="report" class="" />
2019-10-14 03:26:20 +05:30
</div>
</template>
<script>
import { computed } from '@vue/reactivity';
import { t } from 'fyo';
import { reports } from 'reports';
2022-04-22 16:32:03 +05:30
import FormControl from 'src/components/Controls/FormControl.vue';
2022-05-18 12:34:33 +05:30
import DropdownWithActions from 'src/components/DropdownWithActions.vue';
import PageHeader from 'src/components/PageHeader.vue';
import ListReport from 'src/components/Report/ListReport.vue';
import { fyo } from 'src/initFyo';
2022-06-19 01:47:19 +05:30
import { docsPathMap } from 'src/utils/misc';
import { docsPath } from 'src/utils/ui';
import { defineComponent } from 'vue';
2019-10-14 03:26:20 +05:30
export default defineComponent({
props: {
2022-05-18 12:34:33 +05:30
reportClassName: String,
2022-05-27 12:45:07 +05:30
defaultFilters: {
type: String,
default: '{}',
},
2019-10-14 03:26:20 +05:30
},
data() {
return {
loading: false,
report: null,
2019-10-14 03:26:20 +05:30
};
},
provide() {
return {
report: computed(() => this.report),
};
},
2022-05-18 12:34:33 +05:30
components: { PageHeader, FormControl, ListReport, DropdownWithActions },
async activated() {
2022-06-19 01:47:19 +05:30
docsPath.value = docsPathMap[this.reportClassName] ?? docsPathMap.Reports;
await this.setReportData();
2022-05-27 12:45:07 +05:30
const filters = JSON.parse(this.defaultFilters);
const filterKeys = Object.keys(filters);
for (const key of filterKeys) {
await this.report.set(key, filters[key]);
}
if (filterKeys.length) {
2022-06-14 14:40:46 +05:30
await this.report.updateData();
2022-05-27 12:45:07 +05:30
}
if (fyo.store.isDevelopment) {
window.rep = this;
}
2019-10-14 03:26:20 +05:30
},
2022-06-19 01:47:19 +05:30
deactivated() {
docsPath.value = '';
},
computed: {
title() {
2022-05-18 12:34:33 +05:30
return reports[this.reportClassName]?.title ?? t`Report`;
},
groupedActions() {
const actions = this.report?.getActions() ?? [];
const actionsMap = actions.reduce((acc, ac) => {
if (!ac.group) {
ac.group = 'none';
}
acc[ac.group] ??= {
group: ac.group,
label: ac.label ?? '',
type: ac.type,
actions: [],
};
acc[ac.group].actions.push(ac);
return acc;
}, {});
return Object.values(actionsMap);
},
},
methods: {
async setReportData() {
2022-05-18 12:34:33 +05:30
const Report = reports[this.reportClassName];
if (this.report === null) {
this.report = new Report(fyo);
await this.report.initialize();
2022-03-18 13:29:48 +05:30
}
2022-04-27 17:32:43 +05:30
if (!this.report.reportData.length) {
await this.report.setReportData();
} else if (this.report.shouldRefresh) {
await this.report.setReportData(undefined, true);
}
},
},
});
2019-10-14 03:26:20 +05:30
</script>