2
0
mirror of https://github.com/frappe/books.git synced 2024-11-13 00:46:28 +00:00

Code to handle onloadFilters for reports

This commit is contained in:
Suraj Shetty 2018-07-14 20:27:31 +05:30
parent bd9521cec4
commit a69b73e47c
2 changed files with 67 additions and 55 deletions

View File

@ -4,40 +4,49 @@
v-for="docfield in filters" v-for="docfield in filters"
:key="docfield.fieldname" :key="docfield.fieldname"
:docfield="docfield" :docfield="docfield"
:value="$data[docfield.fieldname]" :value="$data.filterValues[docfield.fieldname]"
@change="updateValue(docfield.fieldname, $event)"/> @change="updateValue(docfield.fieldname, $event)"/>
</div> </div>
</template> </template>
<script> <script>
import FrappeControl from 'frappejs/ui/components/controls/FrappeControl' import FrappeControl from 'frappejs/ui/components/controls/FrappeControl';
export default { export default {
props: ['filters'], props: ['filters', 'filterDefaults'],
data () { data() {
const filterValues = {}; const filterValues = {};
for (let filter of this.filters) { for (let filter of this.filters) {
filterValues[filter.fieldname] = ''; filterValues[filter.fieldname] =
this.filterDefaults[filter.fieldname] || null;
}
return { filterValues };
},
created() {
const hasOnloadFilters = Object.values(this.filterValues).filter(
value => value !== null
).length;
if (hasOnloadFilters) {
this.$emit('change', this.filterValues);
} }
return {filterValues};
}, },
provide() { provide() {
return { return {
dynamicLinkTarget: (reference) => { dynamicLinkTarget: reference => {
return this.filterValues[reference] return this.filterValues[reference];
} }
}; };
}, },
methods: { methods: {
updateValue(fieldname, value) { updateValue(fieldname, value) {
this.filterValues[fieldname] = value; this.filterValues[fieldname] = value;
this.$emit('change', this.filterValues) this.$emit('change', this.filterValues);
} }
}, },
components: { components: {
FrappeControl FrappeControl
} }
} };
</script> </script>
<style> <style>
</style> </style>

View File

@ -2,43 +2,46 @@
<div> <div>
<div class="p-4"> <div class="p-4">
<h4 class="pb-2">{{ reportConfig.title }}</h4> <h4 class="pb-2">{{ reportConfig.title }}</h4>
<report-filters v-if="reportConfig.filterFields.length" :filters="reportConfig.filterFields" @change="getReportData"></report-filters> <report-filters v-if="reportConfig.filterFields.length" :filters="reportConfig.filterFields" :filterDefaults="filters" @change="getReportData"></report-filters>
<div class="pt-2" ref="datatable" v-once></div> <div class="pt-2" ref="datatable" v-once></div>
</div> </div>
<not-found v-if="!reportConfig" /> <not-found v-if="!reportConfig" />
</div> </div>
</template> </template>
<script> <script>
import DataTable from 'frappe-datatable' import DataTable from 'frappe-datatable';
import frappe from 'frappejs' import frappe from 'frappejs';
import ReportFilters from './ReportFilters' import ReportFilters from './ReportFilters';
import utils from 'frappejs/client/ui/utils' import utils from 'frappejs/client/ui/utils';
export default { export default {
props: ['reportName', 'reportConfig'], name: 'Report',
props: ['reportName', 'reportConfig', 'filters'],
computed: { computed: {
reportColumns() { reportColumns() {
return utils.convertFieldsToDatatableColumns(this.reportConfig.getColumns()) return utils.convertFieldsToDatatableColumns(
this.reportConfig.getColumns()
);
} }
}, },
methods: { methods: {
getReportData(filters) { getReportData(filters) {
frappe.methods[this.reportConfig.method](filters).then(data => { frappe.methods[this.reportConfig.method](filters).then(data => {
if (this.datatable) { if (this.datatable) {
this.datatable.refresh(data || []) this.datatable.refresh(data || []);
} else { } else {
this.datatable = new DataTable(this.$refs.datatable, { this.datatable = new DataTable(this.$refs.datatable, {
columns: this.reportColumns, columns: this.reportColumns,
data: data || [], data: data || []
}); });
} }
}) });
} }
}, },
components: { components: {
ReportFilters, ReportFilters
} }
} };
</script> </script>
<style> <style>
</style> </style>