2018-10-10 18:51:03 +00:00
|
|
|
<template>
|
2019-10-13 21:19:28 +00:00
|
|
|
<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>
|
2019-10-13 21:19:28 +00:00
|
|
|
<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" />
|
2019-10-13 21:19:28 +00:00
|
|
|
</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>
|
2018-10-10 18:51:03 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import frappe from 'frappejs';
|
2021-08-18 15:36:32 +00:00
|
|
|
// import Observable from 'frappejs/utils/observable';
|
2018-10-10 18:51:03 +00:00
|
|
|
import PageHeader from '@/components/PageHeader';
|
2019-10-05 21:42:08 +00:00
|
|
|
import Button from '@/components/Button';
|
|
|
|
import SearchBar from '@/components/SearchBar';
|
2018-10-10 18:51:03 +00:00
|
|
|
import List from './List';
|
2018-10-22 20:32:37 +00:00
|
|
|
import listConfigs from './listConfig';
|
2021-08-18 15:36:32 +00:00
|
|
|
// 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'
|
2018-10-10 18:51:03 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ListView',
|
2019-10-11 09:55:50 +00:00
|
|
|
props: ['doctype', 'filters'],
|
2018-10-10 18:51:03 +00:00
|
|
|
components: {
|
|
|
|
PageHeader,
|
2019-10-05 21:42:08 +00:00
|
|
|
List,
|
|
|
|
Button,
|
2019-11-21 19:20:30 +00:00
|
|
|
SearchBar,
|
2021-08-18 15:36:32 +00:00
|
|
|
// Icon,
|
2019-11-21 19:20:30 +00:00
|
|
|
FilterDropdown
|
2018-10-10 18:51:03 +00:00
|
|
|
},
|
2019-12-11 12:24:02 +00:00
|
|
|
activated() {
|
2019-11-21 19:20:30 +00:00
|
|
|
if (typeof this.filters === 'object') {
|
|
|
|
this.$refs.filterDropdown.setFilter(this.filters);
|
|
|
|
}
|
2018-10-22 19:10:45 +00:00
|
|
|
},
|
2018-10-10 18:51:03 +00:00
|
|
|
methods: {
|
2019-10-11 09:55:50 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-10-11 09:55:50 +00:00
|
|
|
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', () => {
|
2019-10-11 09:55:50 +00:00
|
|
|
let path = this.getFormPath(doc.name);
|
|
|
|
this.$router.replace(path);
|
2018-10-22 20:32:37 +00:00
|
|
|
});
|
2019-10-11 09:55:50 +00:00
|
|
|
},
|
2019-11-21 19:20:30 +00:00
|
|
|
applyFilter(filters) {
|
|
|
|
this.$refs.list.updateData(filters);
|
|
|
|
},
|
2019-10-11 09:55:50 +00:00
|
|
|
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() {
|
2019-10-11 09:55:50 +00:00
|
|
|
if (listConfigs[this.doctype]) {
|
|
|
|
return listConfigs[this.doctype];
|
2019-08-01 13:00:52 +00:00
|
|
|
} else {
|
2019-10-13 12:03:01 +00:00
|
|
|
return {
|
|
|
|
title: this.doctype,
|
|
|
|
doctype: this.doctype,
|
2019-11-21 19:20:30 +00:00
|
|
|
columns: this.meta.getKeywordFields()
|
2019-10-13 21:19:28 +00:00
|
|
|
};
|
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;
|
2018-10-10 18:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-01 11:52:58 +00:00
|
|
|
};
|
2018-10-10 18:51:03 +00:00
|
|
|
</script>
|