2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 18:24:40 +00:00
books/src/pages/ListView/ListView.vue

112 lines
2.7 KiB
Vue
Raw Normal View History

<template>
<div class="flex flex-col">
<PageHeader>
2019-11-19 16:56:08 +00:00
<h1 slot="title" class="text-2xl font-bold" v-if="title">{{ title }}</h1>
<template slot="actions">
2019-11-21 19:20:30 +00:00
<FilterDropdown
ref="filterDropdown"
@change="applyFilter"
:fields="meta.fields"
/>
<Button class="ml-2" :icon="true" type="primary" @click="makeNewDoc">
2019-11-19 16:56:08 +00:00
<feather-icon name="plus" class="w-4 h-4 text-white" />
</Button>
<SearchBar class="ml-2" />
</template>
</PageHeader>
2019-11-08 19:57:56 +00:00
<div class="flex-1 flex h-full">
2019-11-21 19:20:30 +00:00
<List
ref="list"
:listConfig="listConfig"
:filters="filters"
class="flex-1"
2021-10-27 03:51:03 +00:00
@makeNewDoc="makeNewDoc"
2019-11-21 19:20:30 +00:00
/>
2019-10-04 20:18:10 +00:00
</div>
</div>
</template>
<script>
import frappe from 'frappejs';
// import Observable from 'frappejs/utils/observable';
import PageHeader from '@/components/PageHeader';
import Button from '@/components/Button';
import SearchBar from '@/components/SearchBar';
import List from './List';
2018-10-22 20:32:37 +00:00
import listConfigs from './listConfig';
// import Icon from '@/components/Icon';
2019-11-21 19:20:30 +00:00
import FilterDropdown from '@/components/FilterDropdown';
2021-11-21 16:15:27 +00:00
import { routeTo } from '@/utils'
export default {
name: 'ListView',
props: ['doctype', 'filters'],
components: {
PageHeader,
List,
Button,
2019-11-21 19:20:30 +00:00
SearchBar,
// Icon,
2019-11-21 19:20:30 +00:00
FilterDropdown
},
activated() {
2019-11-21 19:20:30 +00:00
if (typeof this.filters === 'object') {
this.$refs.filterDropdown.setFilter(this.filters);
}
},
methods: {
async makeNewDoc() {
2018-10-22 20:32:37 +00:00
const doctype = this.listConfig.doctype;
const doc = await frappe.getNewDoc(doctype);
if (this.listConfig.filters) {
doc.set(this.listConfig.filters);
}
2019-08-14 07:43:49 +00:00
if (this.filters) {
doc.set(this.filters);
}
let path = this.getFormPath(doc.name);
2021-11-21 16:15:27 +00:00
routeTo(path);
2018-10-22 20:32:37 +00:00
doc.on('afterInsert', () => {
let path = this.getFormPath(doc.name);
this.$router.replace(path);
2018-10-22 20:32:37 +00:00
});
},
2019-11-21 19:20:30 +00:00
applyFilter(filters) {
this.$refs.list.updateData(filters);
},
getFormPath(name) {
if (this.listConfig.formRoute) {
let path = this.listConfig.formRoute(name);
return path;
}
return {
path: `/list/${this.doctype}`,
query: {
edit: 1,
doctype: this.doctype,
name
}
};
2018-10-22 20:32:37 +00:00
}
},
computed: {
2019-11-21 19:20:30 +00:00
meta() {
return frappe.getMeta(this.doctype);
},
2018-10-22 20:32:37 +00:00
listConfig() {
if (listConfigs[this.doctype]) {
return listConfigs[this.doctype];
2019-08-01 13:00:52 +00:00
} else {
return {
title: this.doctype,
doctype: this.doctype,
2019-11-21 19:20:30 +00:00
columns: this.meta.getKeywordFields()
};
2019-08-01 13:00:52 +00:00
}
2019-08-14 07:43:49 +00:00
},
title() {
2019-11-21 19:20:30 +00:00
return this.listConfig.title || this.doctype;
}
}
};
</script>