2018-06-27 14:38:27 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div class="p-4">
|
|
|
|
<h4 class="pb-2">{{ reportConfig.title }}</h4>
|
2018-09-07 10:08:15 +00:00
|
|
|
<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>
|
2018-07-14 14:57:31 +00:00
|
|
|
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 {
|
2018-07-14 14:57:31 +00:00
|
|
|
name: 'Report',
|
|
|
|
props: ['reportName', 'reportConfig', 'filters'],
|
|
|
|
computed: {
|
2018-09-07 10:08:15 +00:00
|
|
|
filtersExists() {
|
|
|
|
return (this.reportConfig.filterFields || []).length;
|
2018-07-14 14:57:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-09-06 08:34:45 +00:00
|
|
|
async getReportData(filters) {
|
|
|
|
let data = await frappe.call({
|
|
|
|
method: this.reportConfig.method,
|
|
|
|
args: filters
|
2018-07-14 14:57:31 +00:00
|
|
|
});
|
2018-09-06 08:34:45 +00:00
|
|
|
|
|
|
|
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);
|
2018-09-06 08:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!rows) {
|
|
|
|
rows = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!columns) {
|
2018-10-25 20:58:08 +00:00
|
|
|
columns = this.getColumns();
|
2018-09-06 08:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 10:53:18 +00:00
|
|
|
for(let column of columns) {
|
|
|
|
column.editable = false;
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:34:45 +00:00
|
|
|
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
|
|
|
}
|
2018-07-14 14:57:31 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ReportFilters
|
|
|
|
}
|
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
</style>
|