2018-06-27 14:38:27 +00:00
|
|
|
<template>
|
2019-07-17 10:02:49 +00:00
|
|
|
<div>
|
|
|
|
<div class="p-4">
|
2019-07-18 10:41:15 +00:00
|
|
|
<div class="row pb-4">
|
|
|
|
<h4 class="col-6 d-flex">{{ reportConfig.title }}</h4>
|
|
|
|
<report-links class="col-6 d-flex pr-0 flex-row-reverse" v-if="linksExists" :links="links"></report-links>
|
|
|
|
</div>
|
2019-07-17 10:02:49 +00:00
|
|
|
<div class="row pb-4">
|
|
|
|
<report-filters
|
2019-07-18 10:41:15 +00:00
|
|
|
class="col-12 pr-0"
|
2019-07-17 10:02:49 +00:00
|
|
|
v-if="filtersExists"
|
|
|
|
:filters="reportConfig.filterFields"
|
|
|
|
:filterDefaults="filters"
|
|
|
|
@change="getReportData"
|
|
|
|
></report-filters>
|
|
|
|
</div>
|
2019-07-18 10:41:15 +00:00
|
|
|
<div class="pt-2 pr-3" 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';
|
2019-07-18 10:41:15 +00:00
|
|
|
import ReportFilters from 'frappejs/ui/pages/Report/ReportFilters';
|
|
|
|
import ReportLinks from 'frappejs/ui/pages/Report/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-18 10:41:15 +00:00
|
|
|
watch: {
|
|
|
|
reportName() {
|
|
|
|
//FIX: Report's data forwards to next consecutively changed report
|
|
|
|
this.getReportData(this.filters);
|
|
|
|
}
|
|
|
|
},
|
2019-07-17 10:02:49 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
links: []
|
|
|
|
};
|
|
|
|
},
|
|
|
|
async created() {
|
|
|
|
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,
|
2019-07-18 10:41:15 +00:00
|
|
|
data: rows,
|
|
|
|
treeView: this.reportConfig.treeView || false,
|
|
|
|
cellHeight: 35
|
2018-09-06 08:34:45 +00:00
|
|
|
});
|
|
|
|
}
|
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>
|
2019-07-18 10:41:15 +00:00
|
|
|
.datatable {
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
2018-06-27 14:38:27 +00:00
|
|
|
</style>
|