2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

Code to handle onloadFilters for reports

This commit is contained in:
Suraj Shetty 2018-07-14 20:27:31 +05:30
parent bd9521cec4
commit a69b73e47c
2 changed files with 67 additions and 55 deletions

View File

@ -4,40 +4,49 @@
v-for="docfield in filters" v-for="docfield in filters"
:key="docfield.fieldname" :key="docfield.fieldname"
:docfield="docfield" :docfield="docfield"
:value="$data[docfield.fieldname]" :value="$data.filterValues[docfield.fieldname]"
@change="updateValue(docfield.fieldname, $event)"/> @change="updateValue(docfield.fieldname, $event)"/>
</div> </div>
</template> </template>
<script> <script>
import FrappeControl from 'frappejs/ui/components/controls/FrappeControl' import FrappeControl from 'frappejs/ui/components/controls/FrappeControl';
export default { export default {
props: ['filters'], props: ['filters', 'filterDefaults'],
data () { data() {
const filterValues = {}; const filterValues = {};
for (let filter of this.filters) { for (let filter of this.filters) {
filterValues[filter.fieldname] = ''; filterValues[filter.fieldname] =
} this.filterDefaults[filter.fieldname] || null;
return {filterValues};
},
provide() {
return {
dynamicLinkTarget: (reference) => {
return this.filterValues[reference]
}
};
},
methods: {
updateValue(fieldname, value) {
this.filterValues[fieldname] = value;
this.$emit('change', this.filterValues)
}
},
components: {
FrappeControl
} }
} return { filterValues };
},
created() {
const hasOnloadFilters = Object.values(this.filterValues).filter(
value => value !== null
).length;
if (hasOnloadFilters) {
this.$emit('change', this.filterValues);
}
},
provide() {
return {
dynamicLinkTarget: reference => {
return this.filterValues[reference];
}
};
},
methods: {
updateValue(fieldname, value) {
this.filterValues[fieldname] = value;
this.$emit('change', this.filterValues);
}
},
components: {
FrappeControl
}
};
</script> </script>
<style> <style>
</style> </style>

View File

@ -2,43 +2,46 @@
<div> <div>
<div class="p-4"> <div class="p-4">
<h4 class="pb-2">{{ reportConfig.title }}</h4> <h4 class="pb-2">{{ reportConfig.title }}</h4>
<report-filters v-if="reportConfig.filterFields.length" :filters="reportConfig.filterFields" @change="getReportData"></report-filters> <report-filters v-if="reportConfig.filterFields.length" :filters="reportConfig.filterFields" :filterDefaults="filters" @change="getReportData"></report-filters>
<div class="pt-2" ref="datatable" v-once></div> <div class="pt-2" ref="datatable" v-once></div>
</div> </div>
<not-found v-if="!reportConfig" /> <not-found v-if="!reportConfig" />
</div> </div>
</template> </template>
<script> <script>
import DataTable from 'frappe-datatable' import DataTable from 'frappe-datatable';
import frappe from 'frappejs' import frappe from 'frappejs';
import ReportFilters from './ReportFilters' import ReportFilters from './ReportFilters';
import utils from 'frappejs/client/ui/utils' import utils from 'frappejs/client/ui/utils';
export default { export default {
props: ['reportName', 'reportConfig'], name: 'Report',
computed: { props: ['reportName', 'reportConfig', 'filters'],
reportColumns() { computed: {
return utils.convertFieldsToDatatableColumns(this.reportConfig.getColumns()) reportColumns() {
} return utils.convertFieldsToDatatableColumns(
}, this.reportConfig.getColumns()
methods: { );
getReportData(filters) {
frappe.methods[this.reportConfig.method](filters).then(data => {
if (this.datatable) {
this.datatable.refresh(data || [])
} else {
this.datatable = new DataTable(this.$refs.datatable, {
columns: this.reportColumns,
data: data || [],
});
}
})
}
},
components: {
ReportFilters,
} }
} },
methods: {
getReportData(filters) {
frappe.methods[this.reportConfig.method](filters).then(data => {
if (this.datatable) {
this.datatable.refresh(data || []);
} else {
this.datatable = new DataTable(this.$refs.datatable, {
columns: this.reportColumns,
data: data || []
});
}
});
}
},
components: {
ReportFilters
}
};
</script> </script>
<style> <style>
</style> </style>