Created
October 10, 2020 06:34
-
-
Save izshreyansh/2d6dd32ccbf5c3823375915cf6dff512 to your computer and use it in GitHub Desktop.
Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let algoliasearch = require('algoliasearch'); | |
let client = algoliasearch(process.env.MIX_ALGOLIA_APP_ID, process.env.MIX_ALGOLIA_SECRET); | |
let products = client.initIndex('products'); | |
let ebay_orders = client.initIndex('ebay_orders'); | |
let ebay_products = client.initIndex('ebay_products'); | |
let amazon_orders = client.initIndex('amazon_orders'); | |
let amazon_products = client.initIndex('amazon_products'); | |
$('#magicSearch').autocomplete( | |
{ hint: true }, [ | |
{ | |
source: $.fn.autocomplete.sources.hits(products, { hitsPerPage: 2 }), | |
displayKey: 'name', | |
templates: { | |
header: '<h5 class="m-3 text-muted text-uppercase">Products</h5>', | |
suggestion: function(suggestion) { | |
return '<a href="'+window.location.origin+'/products/'+suggestion.id+'/edit">' + suggestion.name + '</a>'; | |
}, | |
/* footer: function() { | |
return "<br/><div class='text-right mb-2 mr-2'><img src='/images/algolia.png' class='img'></div>"; | |
},*/ | |
/*empty: function(query, isEmpty) { | |
return '<div class="m-4"><span> No Results Found</span></div>'; | |
}*/ | |
} | |
}, | |
{ | |
source: $.fn.autocomplete.sources.hits(ebay_orders, { hitsPerPage: 2 }), | |
displayKey: 'salesRecordNumber', | |
templates: { | |
header: '<h5 class="m-3 text-muted text-uppercase">Ebay Order</h5>', | |
suggestion: function(suggestion) { | |
return '<a href="'+window.location.origin+'/ebay/orders/'+suggestion.orderId+'/edit">' + | |
'<label>' + suggestion.salesRecordNumber + '</lable>' + | |
'<p><small class="small-5">Payment Status: ' + suggestion.orderPaymentStatus + ' | Type: '+ | |
suggestion.fulfillmentType | |
+'</small></p>' + | |
'</a>'; | |
} | |
} | |
}, | |
{ | |
source: $.fn.autocomplete.sources.hits(ebay_products, { hitsPerPage: 2 }), | |
displayKey: 'name', | |
templates: { | |
header: '<h5 class="m-3 text-muted text-uppercase">Ebay Product</h5>', | |
suggestion: function(suggestion) { | |
return '<a class="small-3" href="'+window.location.origin+'/ebay/items/'+suggestion.ItemID+'">' + | |
'<label>' + suggestion.Title + '</lable>' + | |
'<p><small class="small-5">Item ID: ' + suggestion.ItemID +'</small></p>' + | |
'</a>'; | |
} | |
} | |
}, | |
{ | |
source: $.fn.autocomplete.sources.hits(amazon_orders, { hitsPerPage: 2 }), | |
displayKey: 'name', | |
templates: { | |
header: '<h5 class="m-3 text-muted text-uppercase">Amazon Order</h5>', | |
suggestion: function(suggestion) { | |
return '<a class="small-3" href="'+window.location.origin+'/amazon/orders/'+suggestion.orderId+'/edit">' + | |
'<label>' + suggestion.orderId + '</lable>' + | |
'<p><small class="small-5">Item ID: ' + suggestion.buyerName +'</small></p>' + | |
'</a>'; | |
} | |
} | |
}, | |
{ | |
source: $.fn.autocomplete.sources.hits(amazon_products, { hitsPerPage: 2 }), | |
displayKey: 'name', | |
templates: { | |
header: '<h5 class="m-3 text-muted text-uppercase">Amazon Products</h5>', | |
suggestion: function(suggestion) { | |
return '<a class="small-3" href="'+window.location.origin+'/amazon/products/'+suggestion.asin+'">' + | |
'<label>' + suggestion.asin + '</lable>' + | |
'<p><small class="small-5">' + suggestion.item_name +'</small></p>' + | |
'</a>'; | |
} | |
} | |
}, | |
]) | |
/*.on('autocomplete:selected', function(event, suggestion, dataset) { | |
window.location.href = window.location.origin+'/products/'+suggestion.id+'/edit'; | |
});*/ | |
/* | |
$('#ebay-search-input').autocomplete( | |
{ hint: true }, [ | |
]).on('autocomplete:selected', function(event, suggestion, dataset) { | |
window.location.href = window.location.origin+'/ebay/orders/'+suggestion.id+'/edit'; | |
}); | |
$('#ebay-items-search-input').autocomplete( | |
{ hint: true }, [ | |
, | |
]).on('autocomplete:selected', function(event, suggestion, dataset) { | |
window.location.href = window.location.origin+'/ebay/items/'+suggestion.ItemID; | |
}); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Vue = require('vue'); | |
new Vue({ | |
el: '#TntSearch', | |
data: function() { | |
return { | |
result: [], | |
searchTerm:null, | |
searchResource: 'Product' | |
} | |
}, | |
methods: { | |
search: function () { | |
var vm = this; | |
axios.post('/search',{searchTerm: this.searchTerm, searchResource: this.searchResource}) | |
.then(function(response) { | |
vm.result = response.data; | |
}); | |
}, | |
removeSearch: function () { | |
setTimeout(() => { | |
this.result = []; | |
}, 500); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment