2
0
mirror of https://github.com/frappe/books.git synced 2024-09-21 03:39:02 +00:00
books/ui/pages/Report/index.vue

76 lines
1.7 KiB
Vue
Raw Normal View History

2018-06-27 14:38:27 +00:00
<template>
<div>
<div class="p-4">
<h4 class="pb-2">{{ reportConfig.title }}</h4>
<report-filters v-if="filtersExists" :filters="reportConfig.filterFields" :filterDefaults="filters" @change="getReportData"></report-filters>
2018-06-27 14:38:27 +00:00
<div class="pt-2" ref="datatable" v-once></div>
</div>
<not-found v-if="!reportConfig" />
</div>
</template>
<script>
import DataTable from 'frappe-datatable';
import frappe from 'frappejs';
import ReportFilters from './ReportFilters';
import utils from 'frappejs/client/ui/utils';
2018-06-27 14:38:27 +00:00
export default {
name: 'Report',
props: ['reportName', 'reportConfig', 'filters'],
computed: {
filtersExists() {
return (this.reportConfig.filterFields || []).length;
}
},
methods: {
async getReportData(filters) {
let data = await frappe.call({
method: this.reportConfig.method,
args: filters
});
let rows, columns;
if (data.rows) {
rows = data.rows;
} else {
rows = data;
}
if (data.columns) {
2018-10-25 20:58:08 +00:00
columns = this.getColumns(data);
}
if (!rows) {
rows = [];
}
if (!columns) {
2018-10-25 20:58:08 +00:00
columns = this.getColumns();
}
for(let column of columns) {
column.editable = false;
}
if (this.datatable) {
this.datatable.refresh(rows, columns);
} else {
this.datatable = new DataTable(this.$refs.datatable, {
columns: columns,
data: rows
});
}
2018-10-25 20:58:08 +00:00
},
getColumns(data) {
const columns = this.reportConfig.getColumns(data);
return utils.convertFieldsToDatatableColumns(columns);
2018-06-27 14:38:27 +00:00
}
},
components: {
ReportFilters
}
};
2018-06-27 14:38:27 +00:00
</script>
<style>
</style>