2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 01:14:03 +00:00
books/ui/pages/Report/index.vue

126 lines
2.9 KiB
Vue
Raw Normal View History

2018-06-27 14:38:27 +00:00
<template>
2019-07-17 10:02:49 +00:00
<div>
<div class="p-4">
<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
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>
<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>
import DataTable from 'frappe-datatable';
import frappe from 'frappejs';
import ReportFilters from 'frappejs/ui/pages/Report/ReportFilters';
import ReportLinks from 'frappejs/ui/pages/Report/ReportLinks';
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;
2019-07-17 10:02:49 +00:00
},
linksExists() {
return (this.reportConfig.linkFields || []).length;
}
},
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();
},
methods: {
async getReportData(filters) {
let data = await frappe.call({
2019-07-17 10:02:49 +00:00
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();
}
2019-07-17 10:02:49 +00:00
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,
treeView: this.reportConfig.treeView || false,
cellHeight: 35
});
}
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
}
},
components: {
2019-07-17 10:02:49 +00:00
ReportFilters,
ReportLinks
}
};
2018-06-27 14:38:27 +00:00
</script>
<style>
.datatable {
font-size: 12px;
}
2018-06-27 14:38:27 +00:00
</style>