[hub] add SearchInput

This commit is contained in:
Prateeksha Singh 2018-08-23 13:52:41 +05:30
parent 6e5b9a8f9b
commit d7d2bb261b
4 changed files with 62 additions and 24 deletions

View File

@ -23,6 +23,11 @@ export default {
item_id() { item_id() {
return this.is_local ? 'item_code' : 'hub_item_code'; return this.is_local ? 'item_code' : 'hub_item_code';
} }
},
watch: {
items() {
frappe.dom.handle_broken_images($(this.$el));
}
} }
} }
</script> </script>

View File

@ -3,6 +3,12 @@
class="marketplace-page" class="marketplace-page"
:data-page-name="page_name" :data-page-name="page_name"
> >
<search-input
placeholder="Search Items ..."
:on_search="get_valid_items"
v-model="search_value"
>
</search-input>
<item-cards-container <item-cards-container
:items="valid_items" :items="valid_items"
:is_local="1" :is_local="1"
@ -12,6 +18,7 @@
</template> </template>
<script> <script>
import SearchInput from './SearchInput.vue';
import ItemCardsContainer from './ItemCardsContainer.vue'; import ItemCardsContainer from './ItemCardsContainer.vue';
export default { export default {
@ -24,31 +31,22 @@ export default {
}; };
}, },
components: { components: {
SearchInput,
ItemCardsContainer ItemCardsContainer
}, },
// watch: {
// // whenever search term changes, this function will run
// question: function (newQuestion, oldQuestion) {
// this.answer = 'Waiting for you to stop typing...'
// this.debouncedGetAnswer()
// }
// },
created() { created() {
this.get_valid_items(); this.get_valid_items();
}, },
methods: { methods: {
get_valid_items() { get_valid_items() {
var vm = this;
frappe.call( frappe.call(
'erpnext.hub_node.api.get_valid_items', 'erpnext.hub_node.api.get_valid_items',
{ {
search_value: this.search_value search_value: this.search_value
} }
) )
.then(function (r) { .then((r) => {
vm.valid_items = r.message; this.valid_items = r.message;
frappe.dom.handle_broken_images(this.$wrapper);
}) })
} }
} }

View File

@ -0,0 +1,32 @@
<template>
<div class="hub-search-container">
<input
type="text"
class="form-control"
:placeholder="placeholder"
:value="value"
@input="on_input">
</div>
</template>
<script>
export default {
props: {
placeholder: String,
value: String,
on_search: Function
},
methods: {
on_input(event) {
this.$emit('input', event.target.value);
this.on_search();
// TODO: Debouncing doesn't fire search
// frappe.utils.debounce(this.on_search, 500);
}
}
};
</script>
<style lang="scss" scoped>
</style>

View File

@ -8,29 +8,32 @@ import PublishPage from '../components/PublishPage.vue';
erpnext.hub.Publish = class Publish { erpnext.hub.Publish = class Publish {
constructor(parent) { constructor(parent) {
this.items_data_to_publish = {};
this.unpublished_items = [];
this.fetched_items = [];
this.fetched_items_dict = {};
this.$wrapper = $(`<div id="vue-area">`).appendTo($(parent)); this.$wrapper = $(`<div id="vue-area">`).appendTo($(parent));
frappe.app = new Vue({ new Vue({
render: h => h(PublishPage), render: h => h(PublishPage)
mounted() {
console.log('Mounted For Publish page');
},
}).$mount('#vue-area'); }).$mount('#vue-area');
} }
show() { show() {
this.$wrapper.show(); $('[data-page-name="publish"]').show();
} }
hide() { hide() {
this.$wrapper.hide(); $('[data-page-name="publish"]').hide();
} }
// this.items_data_to_publish = {};
// this.unpublished_items = [];
// this.fetched_items = [];
// this.fetched_items_dict = {};
show_message(message) { show_message(message) {
this.$wrapper.prepend(NotificationMessage(message)); this.$wrapper.prepend(NotificationMessage(message));
} }