2018-06-27 14:38:27 +00:00
|
|
|
<template>
|
2019-07-17 10:02:49 +00:00
|
|
|
<div>
|
|
|
|
<div class="p-4">
|
|
|
|
<h4 class="pb-2">{{ reportConfig.title }}</h4>
|
|
|
|
<div class="row pb-4">
|
|
|
|
<report-filters
|
|
|
|
:class="linksExists ? 'col-10' : 'col-12'"
|
|
|
|
v-if="filtersExists"
|
|
|
|
:filters="reportConfig.filterFields"
|
|
|
|
:filterDefaults="filters"
|
|
|
|
@change="getReportData"
|
|
|
|
></report-filters>
|
|
|
|
<report-links class="col-2" v-if="linksExists" :links="links"></report-links>
|
|
|
|
</div>
|
|
|
|
<div class="pt-2" ref="datatable" v-once></div>
|
2018-06-27 14:38:27 +00:00
|
|
|
</div>
|
2019-07-17 10:02:49 +00:00
|
|
|
<not-found v-if="!reportConfig" />
|
|
|
|
</div>
|
2018-06-27 14:38:27 +00:00
|
|
|
</template>
|
|
|
|
<script>
|
2018-07-14 14:57:31 +00:00
|
|
|
import DataTable from 'frappe-datatable';
|
|
|
|
import frappe from 'frappejs';
|
|
|
|
import ReportFilters from './ReportFilters';
|
2019-07-17 10:02:49 +00:00
|
|
|
import ReportLinks from './ReportLinks';
|
2018-07-14 14:57:31 +00:00
|
|
|
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;
|
2019-07-17 10:02:49 +00:00
|
|
|
},
|
|
|
|
linksExists() {
|
|
|
|
return (this.reportConfig.linkFields || []).length;
|
2018-07-14 14:57:31 +00:00
|
|
|
}
|
|
|
|
},
|
2019-07-17 10:02:49 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
links: []
|
|
|
|
};
|
|
|
|
},
|
|
|
|
async created() {
|
|
|
|
this.setLinks();
|
|
|
|
// this.doc.on('change', this.setLinks);
|
|
|
|
},
|
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({
|
2019-07-17 10:02:49 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-17 10:02:49 +00:00
|
|
|
for (let column of columns) {
|
|
|
|
column.editable = false;
|
2018-09-20 10:53:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
2019-07-17 10:02:49 +00:00
|
|
|
return [rows, columns];
|
|
|
|
},
|
|
|
|
setLinks() {
|
|
|
|
if (this.linksExists) {
|
|
|
|
let links = [];
|
|
|
|
for (let link of this.reportConfig.linkFields) {
|
|
|
|
links.push({
|
|
|
|
label: link.label,
|
|
|
|
handler: () => {
|
|
|
|
link.action(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.links = links;
|
|
|
|
}
|
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: {
|
2019-07-17 10:02:49 +00:00
|
|
|
ReportFilters,
|
|
|
|
ReportLinks
|
2018-07-14 14:57:31 +00:00
|
|
|
}
|
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
</style>
|