2019-08-01 17:22:58 +05:30
|
|
|
<template>
|
2019-10-04 23:51:26 +05:30
|
|
|
<div v-on-outside-click="clearInput" class="relative">
|
2019-11-20 01:59:44 +05:30
|
|
|
<Dropdown :items="suggestions" class="text-sm h-full">
|
|
|
|
<template
|
|
|
|
v-slot="{
|
|
|
|
toggleDropdown,
|
|
|
|
highlightItemUp,
|
|
|
|
highlightItemDown,
|
|
|
|
selectHighlightedItem
|
|
|
|
}"
|
2019-08-01 17:22:58 +05:30
|
|
|
>
|
2019-11-20 01:59:44 +05:30
|
|
|
<div
|
2019-12-11 15:08:20 +05:30
|
|
|
class="rounded-md relative flex items-center overflow-hidden h-full"
|
2019-11-20 01:59:44 +05:30
|
|
|
>
|
|
|
|
<div class="absolute flex justify-center w-8">
|
|
|
|
<feather-icon name="search" class="w-3 h-3 text-gray-800" />
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="search"
|
2019-12-16 17:04:22 +05:30
|
|
|
class="bg-gray-200 text-sm pl-8 focus:outline-none h-full w-56"
|
2019-11-20 01:59:44 +05:30
|
|
|
placeholder="Search..."
|
|
|
|
autocomplete="off"
|
|
|
|
spellcheck="false"
|
|
|
|
v-model="inputValue"
|
|
|
|
@input="search"
|
|
|
|
ref="input"
|
|
|
|
@focus="$toggleDropdown = toggleDropdown"
|
|
|
|
@keydown.up="highlightItemUp"
|
|
|
|
@keydown.down="highlightItemDown"
|
|
|
|
@keydown.enter="selectHighlightedItem"
|
|
|
|
@keydown.tab="toggleDropdown(false)"
|
|
|
|
@keydown.esc="toggleDropdown(false)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Dropdown>
|
2019-08-01 17:22:58 +05:30
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2022-01-21 02:27:29 +05:30
|
|
|
import frappe from 'frappe';
|
2021-11-04 16:01:26 +05:30
|
|
|
import reports from '../../reports/view';
|
2019-11-20 01:59:44 +05:30
|
|
|
import Dropdown from '@/components/Dropdown';
|
2021-11-21 21:45:27 +05:30
|
|
|
import { routeTo } from '@/utils'
|
2019-08-01 17:22:58 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inputValue: '',
|
2019-11-20 01:59:44 +05:30
|
|
|
searchList: [],
|
|
|
|
suggestions: [],
|
|
|
|
$toggleDropdown: null
|
2019-08-01 17:22:58 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
2019-11-20 01:59:44 +05:30
|
|
|
Dropdown
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.makeSearchList();
|
2019-08-01 17:22:58 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2019-11-20 01:59:44 +05:30
|
|
|
async search() {
|
|
|
|
this.$toggleDropdown && this.$toggleDropdown(true);
|
2019-08-20 14:27:27 +05:30
|
|
|
|
2019-11-20 01:59:44 +05:30
|
|
|
this.suggestions = this.searchList.filter(d => {
|
|
|
|
let key = this.inputValue.toLowerCase();
|
|
|
|
return d.label.toLowerCase().includes(key);
|
2019-08-01 17:22:58 +05:30
|
|
|
});
|
2019-11-20 01:59:44 +05:30
|
|
|
|
|
|
|
if (this.suggestions.length === 0) {
|
|
|
|
this.suggestions = [{ label: 'No results found.' }];
|
|
|
|
}
|
2019-08-01 17:22:58 +05:30
|
|
|
},
|
2019-12-16 17:04:22 +05:30
|
|
|
clearInput() {
|
2019-08-01 17:22:58 +05:30
|
|
|
this.inputValue = '';
|
|
|
|
this.$emit('change', null);
|
|
|
|
},
|
2021-11-04 16:01:26 +05:30
|
|
|
async makeSearchList() {
|
2019-11-20 01:59:44 +05:30
|
|
|
const doctypes = this.getDoctypes();
|
|
|
|
const reports = this.getReports();
|
2019-11-26 11:45:14 +05:30
|
|
|
const views = this.getViews();
|
2019-11-20 01:59:44 +05:30
|
|
|
|
2019-11-26 11:45:14 +05:30
|
|
|
let searchList = [...doctypes, ...reports, ...views];
|
2019-11-20 01:59:44 +05:30
|
|
|
this.searchList = searchList.map(d => {
|
|
|
|
if (d.route) {
|
2021-11-21 21:45:27 +05:30
|
|
|
d.action = () => routeTo(d.route);
|
|
|
|
this.inputValue = '';
|
2019-08-01 17:22:58 +05:30
|
|
|
}
|
2019-11-20 01:59:44 +05:30
|
|
|
return d;
|
|
|
|
});
|
2019-08-01 17:22:58 +05:30
|
|
|
},
|
2019-11-20 01:59:44 +05:30
|
|
|
getDoctypes() {
|
|
|
|
let doctypes = Object.keys(frappe.models).sort();
|
|
|
|
let doctypeMetas = doctypes.map(doctype => frappe.getMeta(doctype));
|
|
|
|
let searchableDoctypes = doctypeMetas.filter(meta => {
|
|
|
|
return !meta.isSingle && !meta.isChild;
|
2019-08-01 17:22:58 +05:30
|
|
|
});
|
2019-11-20 01:59:44 +05:30
|
|
|
return searchableDoctypes.map(meta => {
|
2019-08-01 17:22:58 +05:30
|
|
|
return {
|
2019-11-20 01:59:44 +05:30
|
|
|
label: meta.label || meta.name,
|
|
|
|
route: `/list/${meta.name}`,
|
|
|
|
group: 'List'
|
2019-08-01 17:22:58 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2019-08-05 15:03:05 +05:30
|
|
|
getReports() {
|
2019-11-20 01:59:44 +05:30
|
|
|
return Object.values(reports).map(report => {
|
2019-08-05 15:03:05 +05:30
|
|
|
return {
|
2019-11-20 01:59:44 +05:30
|
|
|
label: report.title,
|
|
|
|
route: `/report/${report.method}`,
|
|
|
|
group: 'Reports'
|
2019-08-05 15:03:05 +05:30
|
|
|
};
|
|
|
|
});
|
2021-11-04 16:01:26 +05:30
|
|
|
|
2019-08-05 15:03:05 +05:30
|
|
|
},
|
2019-11-26 11:45:14 +05:30
|
|
|
getViews() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: 'Chart of Accounts',
|
|
|
|
route: '/chartOfAccounts',
|
|
|
|
group: 'List'
|
|
|
|
}
|
|
|
|
];
|
2019-08-01 17:22:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|