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,
|
2022-02-10 17:27:31 +05:30
|
|
|
selectHighlightedItem,
|
2019-11-20 01:59:44 +05:30
|
|
|
}"
|
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"
|
2022-03-30 16:27:45 +05:30
|
|
|
:placeholder="t`Search...`"
|
2019-11-20 01:59:44 +05:30
|
|
|
autocomplete="off"
|
|
|
|
spellcheck="false"
|
|
|
|
v-model="inputValue"
|
2022-02-11 11:25:07 +05:30
|
|
|
@input="
|
|
|
|
() => {
|
|
|
|
search();
|
|
|
|
toggleDropdown(true);
|
|
|
|
}
|
|
|
|
"
|
2019-11-20 01:59:44 +05:30
|
|
|
ref="input"
|
|
|
|
@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-03-30 16:27:45 +05:30
|
|
|
import frappe, { t } from 'frappe';
|
2022-04-20 12:08:47 +05:30
|
|
|
import Dropdown from 'src/components/Dropdown';
|
|
|
|
import { routeTo } from 'src/utils';
|
2022-03-30 16:27:45 +05:30
|
|
|
import reports from '../../reports/view';
|
2019-08-01 17:22:58 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inputValue: '',
|
2019-11-20 01:59:44 +05:30
|
|
|
searchList: [],
|
|
|
|
suggestions: [],
|
2019-08-01 17:22:58 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
2022-02-10 17:27:31 +05:30
|
|
|
Dropdown,
|
2019-11-20 01:59:44 +05:30
|
|
|
},
|
2022-02-10 17:27:31 +05:30
|
|
|
emits: ['change'],
|
2019-11-20 01:59:44 +05:30
|
|
|
mounted() {
|
|
|
|
this.makeSearchList();
|
2019-08-01 17:22:58 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2019-11-20 01:59:44 +05:30
|
|
|
async search() {
|
2022-02-10 17:27:31 +05:30
|
|
|
this.suggestions = this.searchList.filter((d) => {
|
2019-11-20 01:59:44 +05:30
|
|
|
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) {
|
2022-02-16 11:49:16 +05:30
|
|
|
this.suggestions = [{ label: t`No results found.` }];
|
2019-11-20 01:59:44 +05:30
|
|
|
}
|
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];
|
2022-02-10 17:27:31 +05:30
|
|
|
this.searchList = searchList.map((d) => {
|
2019-11-20 01:59:44 +05:30
|
|
|
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();
|
2022-02-10 17:27:31 +05:30
|
|
|
let doctypeMetas = doctypes.map((doctype) => frappe.getMeta(doctype));
|
|
|
|
let searchableDoctypes = doctypeMetas.filter((meta) => {
|
2019-11-20 01:59:44 +05:30
|
|
|
return !meta.isSingle && !meta.isChild;
|
2019-08-01 17:22:58 +05:30
|
|
|
});
|
2022-02-10 17:27:31 +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}`,
|
2022-02-10 17:27:31 +05:30
|
|
|
group: 'List',
|
2019-08-01 17:22:58 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2019-08-05 15:03:05 +05:30
|
|
|
getReports() {
|
2022-02-10 17:27:31 +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}`,
|
2022-02-10 17:27:31 +05:30
|
|
|
group: 'Reports',
|
2019-08-05 15:03:05 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2019-11-26 11:45:14 +05:30
|
|
|
getViews() {
|
|
|
|
return [
|
|
|
|
{
|
2022-02-16 11:49:16 +05:30
|
|
|
label: t`Chart of Accounts`,
|
2019-11-26 11:45:14 +05:30
|
|
|
route: '/chartOfAccounts',
|
2022-02-10 17:27:31 +05:30
|
|
|
group: 'List',
|
|
|
|
},
|
2019-11-26 11:45:14 +05:30
|
|
|
];
|
2022-02-10 17:27:31 +05:30
|
|
|
},
|
|
|
|
},
|
2019-08-01 17:22:58 +05:30
|
|
|
};
|
|
|
|
</script>
|
2022-02-11 11:25:07 +05:30
|
|
|
<style scoped>
|
|
|
|
input[type='search']::-webkit-search-decoration,
|
|
|
|
input[type='search']::-webkit-search-cancel-button,
|
|
|
|
input[type='search']::-webkit-search-results-button,
|
|
|
|
input[type='search']::-webkit-search-results-decoration {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|