Fixed laravel migration issue & completed tensorflow image search feature on defaul theme

This commit is contained in:
Pranshu Tomar 2020-06-11 18:34:16 +05:30
parent 21c73ab00c
commit c9dd20db7e
42 changed files with 482 additions and 51 deletions

View File

@ -12,5 +12,3 @@ Route::group(['middleware' => ['web']], function () {
});
Route::get('paypal/standard/ipn', 'Webkul\Paypal\Http\Controllers\StandardController@ipn')->name('paypal.standard.ipn');
Route::post('paypal/standard/ipn', 'Webkul\Paypal\Http\Controllers\StandardController@ipn')->name('paypal.standard.ipn');

View File

@ -356,13 +356,17 @@ class ProductRepository extends Repository
->where('product_flat.channel', $channel)
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key')
->where(function($sub_query) use ($term) {
$sub_query->where('product_flat.name', 'like', '%' . urldecode($term) . '%')
->orWhere('product_flat.short_description', 'like', '%' . urldecode($term) . '%');
})
->where(function($subQuery) use ($term) {
$queries = explode('_', $term);
foreach (array_map('trim', $queries) as $value) {
$subQuery->orWhere('product_flat.name', 'like', '%' . urldecode($value) . '%')
->orWhere('product_flat.short_description', 'like', '%' . urldecode($value) . '%');
}
})
->orderBy('product_id', 'desc');
})->paginate(16);
return $results;
}

View File

@ -3,6 +3,7 @@
namespace Webkul\Product\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Support\Facades\Storage;
use Webkul\Core\Eloquent\Repository;
use Webkul\Product\Repositories\ProductRepository;
@ -42,4 +43,15 @@ class SearchRepository extends Repository
return $products;
}
/**
* @param array $data
* @return void
*/
public function uploadSearchImage($data)
{
$path = request()->file('image')->store('product-search');
return Storage::url($path);
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,12 @@
/*!
* Sizzle CSS Selector Engine v2.3.4
* Sizzle CSS Selector Engine v2.3.5
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2019-04-08
* Date: 2020-03-14
*/
/*!
@ -27,7 +27,7 @@
*/
/*!
* jQuery JavaScript Library v3.4.1
* jQuery JavaScript Library v3.5.1
* https://jquery.com/
*
* Includes Sizzle.js
@ -37,7 +37,7 @@
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2019-05-01T21:04Z
* Date: 2020-05-04T22:49Z
*/
/**

View File

@ -1,4 +1,4 @@
{
"/js/shop.js": "/js/shop.js?id=6bb928c2e527b045a56b",
"/css/shop.css": "/css/shop.css?id=d1c42d10589004fac3f8"
"/js/shop.js": "/js/shop.js?id=382caa06d43f2cac5ee6",
"/css/shop.css": "/css/shop.css?id=5799059fc0844d8b4574"
}

View File

@ -4,8 +4,9 @@ namespace Webkul\Shop\Http\Controllers;
use Webkul\Shop\Http\Controllers\Controller;
use Webkul\Core\Repositories\SliderRepository;
use Webkul\Product\Repositories\SearchRepository;
class HomeController extends Controller
class HomeController extends Controller
{
/**
* SliderRepository object
@ -14,16 +15,29 @@ use Webkul\Core\Repositories\SliderRepository;
*/
protected $sliderRepository;
/**
* SearchRepository object
*
* @var \Webkul\Core\Repositories\SearchRepository
*/
protected $searchRepository;
/**
* Create a new controller instance.
*
* @param \Webkul\Core\Repositories\SliderRepository $sliderRepository
* @param \Webkul\Product\Repositories\SearchRepository $searchRepository
* @return void
*/
public function __construct(SliderRepository $sliderRepository)
public function __construct(
SliderRepository $sliderRepository,
SearchRepository $searchRepository
)
{
$this->sliderRepository = $sliderRepository;
$this->searchRepository = $searchRepository;
parent::__construct();
}
@ -39,10 +53,10 @@ use Webkul\Core\Repositories\SliderRepository;
$currentLocale = core()->getCurrentLocale();
$sliderData = $this->sliderRepository
->where('channel_id', $currentChannel->id)
->where('locale', $currentLocale->code)
->get()
->toArray();
->where('channel_id', $currentChannel->id)
->where('locale', $currentLocale->code)
->get()
->toArray();
return view($this->_config['view'], compact('sliderData'));
}
@ -56,4 +70,16 @@ use Webkul\Core\Repositories\SliderRepository;
{
abort(404);
}
/**
* Upload image for product search with machine learning
*
* @return \Illuminate\Http\Response
*/
public function upload()
{
$url = $this->searchRepository->uploadSearchImage(request()->all());
return $url;
}
}

View File

@ -18,6 +18,9 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
'view' => 'shop::search.search'
])->name('shop.search.index');
//Upload image for search product
Route::post('/upload-search-image', 'Webkul\Shop\Http\Controllers\HomeController@upload')->name('shop.image.search.upload');
//Country State Selector
Route::get('get/countries', 'Webkul\Core\Http\Controllers\CountryStateController@getCountries')->defaults('_config', [
'view' => 'shop::test'
@ -201,7 +204,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
//Customer Profile Edit Form Store
Route::post('profile/edit', 'Webkul\Customer\Http\Controllers\CustomerController@update')->defaults('_config', [
'redirect' => 'customer.profile.index'
])->name('customer.profile.edit');
])->name('customer.profile.store');
//Customer Profile Delete Form Store
Route::post('profile/destroy', 'Webkul\Customer\Http\Controllers\CustomerController@destroy')->defaults('_config', [
@ -225,7 +228,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
Route::post('addresses/create', 'Webkul\Customer\Http\Controllers\AddressController@store')->defaults('_config', [
'view' => 'shop::customers.account.address.address',
'redirect' => 'customer.address.index'
])->name('customer.address.create');
])->name('customer.address.store');
//Customer Address Edit Form Show
Route::get('addresses/edit/{id}', 'Webkul\Customer\Http\Controllers\AddressController@edit')->defaults('_config', [
@ -235,7 +238,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
//Customer Address Edit Form Store
Route::put('addresses/edit/{id}', 'Webkul\Customer\Http\Controllers\AddressController@update')->defaults('_config', [
'redirect' => 'customer.address.index'
])->name('customer.address.edit');
])->name('customer.address.update');
//Customer Address Make Default
Route::get('addresses/default/{id}', 'Webkul\Customer\Http\Controllers\AddressController@makeDefault')->name('make.default.address');

View File

@ -38,7 +38,9 @@ $(document).ready(function () {
el: "#app",
data: {
modalIds: {}
modalIds: {},
show_loader: false
},
mounted: function () {
@ -114,6 +116,14 @@ $(document).ready(function () {
showModal(id) {
this.$set(this.modalIds, id, true);
},
showLoader() {
this.show_loader = true;
},
hideLoader() {
this.show_loader = false;
}
}
});

View File

@ -775,6 +775,7 @@ section.slider-block {
display: inline-flex;
justify-content: center;
align-items: center;
position: relative;
.search-field {
height: 38px;
@ -804,6 +805,21 @@ section.slider-block {
margin: 0px;
}
}
.image-search-container {
position: absolute;
right: 41px;
top: 7px;
background: #fff;
img {
display: none;
}
input {
display: none;
}
}
}
}
}
@ -4483,4 +4499,41 @@ section.review {
b {
font-weight: 500;
}
}
.image-search-result {
background-color: rgba(0, 65, 255, 0.1);
border: 1px solid #0041ff;
padding: 20px;
margin-bottom: 20px;
border-radius: 2px;
display: inline-block;
width: 100%;
.searched-image {
float: left;
img {
width: 150px;
height: auto;
box-shadow: rgba(0, 0, 0, 0.32) 1px 1px 3px 0px;
}
}
.searched-terms {
margin-left: 20px;
display: inline-block;
h3 {
margin-top: 0;
}
.term-list {
a {
padding: 5px 8px;
background: #fff;
margin-right: 10px;
}
}
}
}

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'لا توجد نتائج',
'page-title' => 'بحث',
'found-results' => 'تم العثور على نتائج البحث',
'found-result' => 'تم العثور على نتيجة البحث'
'found-result' => 'تم العثور على نتيجة البحث',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'Keine Ergebnisse gefunden',
'page-title' => config('app.name') . ' - Suchen',
'found-results' => 'Suchergebnisse gefunden',
'found-result' => 'Suchergebnis gefunden'
'found-result' => 'Suchergebnis gefunden',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'No Results Found',
'page-title' => config('app.name') . ' - Search',
'found-results' => 'Search Results Found',
'found-result' => 'Search Result Found'
'found-result' => 'Search Result Found',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -68,7 +68,8 @@ return [
'no-results' => 'No hay resultados',
'page-title' => 'Búsqueda',
'found-results' => 'No hay resultados de búsqueda',
'found-result' => 'Resultados de la búsqueda'
'found-result' => 'Resultados de la búsqueda',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'نتیجه ای پیدا نشد',
'page-title' => 'فروشگاه - جستجو',
'found-results' => 'نتایج جستجو یافت شد',
'found-result' => 'نتیجه جستجو یافت شد'
'found-result' => 'نتیجه جستجو یافت شد',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'Nessun risultato trovato',
'page-title' => config('app.name') . ' - Cerca',
'found-results' => 'Risultati trovati',
'found-result' => 'Risultato trovato'
'found-result' => 'Risultato trovato',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -68,7 +68,8 @@ return [
'no-results' => 'お探しの条件に合う検索結果が見つかりませんでした。',
'page-title' => '検索',
'found-results' => '検索結果',
'found-result' => '検索結果'
'found-result' => '検索結果',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -70,7 +70,8 @@ return [
'no-results' => 'No Results Found',
'page-title' => config('app.name') . ' - Search',
'found-results' => 'Search Results Found',
'found-result' => 'Search Result Found'
'found-result' => 'Search Result Found',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'Nie znaleziono wyników',
'page-title' => config('app.name') . ' - Szukaj',
'found-results' => 'Dostępne wyniki wyszukiwania',
'found-result' => 'Dostępny wynik wyszukiwania'
'found-result' => 'Dostępny wynik wyszukiwania',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [
@ -79,7 +80,7 @@ return [
'add-review-page-title' => 'Dodaj recenzję',
'write-review' => 'Napisz recenzję',
'review-title' => 'Nadaj opinii tytuł',
'product-review-page-title' => ''Opinia o produkcie',
'product-review-page-title' => 'Opinia o produkcie',
'rating-reviews' => 'Oceny i recenzje',
'submit' => 'WYŚLIJ',
'delete-all' => 'Wszystkie recenzje zostały pomyślnie usunięte',
@ -113,7 +114,8 @@ return [
'success' => 'Konto utworzone pomyślnie.',
'success-verify' => 'Konto zostało utworzone pomyślnie, wysłano wiadomość e-mail w celu weryfikacji.',
'success-verify-email-unsent' => 'Konto zostało utworzone pomyślnie, lecz e-mail weryfikacyjny nie został wysłany.',
'failed' => 'Błąd! Nie można utworzyć konta, spróbuj ponownie później.' => 'Twoje konto jest już zweryfikowane lub spróbuj ponownie wysłać nowy e-mail weryfikacyjny.',
'failed' => 'Błąd! Nie można utworzyć konta, spróbuj ponownie później.',
'success-verify-email-unsent' => 'Twoje konto jest już zweryfikowane lub spróbuj ponownie wysłać nowy e-mail weryfikacyjny.',
'verification-not-sent' => 'Błąd! Problem z wysłaniem e-maila weryfikacyjnego, spróbuj ponownie później.',
'verification-sent' => 'Wysłano e-mail weryfikacyjny',
'verified' => 'Twoje konto zostało zweryfikowane, spróbuj się teraz zalogować.',
@ -205,7 +207,7 @@ return [
'make-default' => 'Ustaw jako domyślny',
'default' => 'Domyślny',
'contact' => 'Kontakt',
'confirm-delete' => ''Czy na pewno chcesz usunąć ten adres?',
'confirm-delete' => 'Czy na pewno chcesz usunąć ten adres?',
'default-delete' => 'Nie można zmienić domyślnego adresu .',
'enter-password' => 'Wprowadź hasło.',
],
@ -463,7 +465,7 @@ return [
'quantity-error' => 'Żądana ilość nie jest dostępna.',
'cart-subtotal' => 'Suma częściowa koszyka',
'cart-remove-action' => 'Czy na pewno chcesz to zrobić ?',
'partial-cart-update' => 'Tylko niektóre produkty zostały zaktualizowane' => '',
'partial-cart-update' => 'Tylko niektóre produkty zostały zaktualizowane',
'event' => [
'expired' => 'To wydarzenie wygasło.'
]

View File

@ -71,7 +71,8 @@ return [
'no-results' => 'Nenhum resultado encontrado',
'page-title' => 'Buscar',
'found-results' => 'Resultados da pesquisa encontrados',
'found-result' => 'Resultado da pesquisa encontrado'
'found-result' => 'Resultado da pesquisa encontrado',
'analysed-keywords' => 'Analysed Keywords'
],
'reviews' => [

View File

@ -19,7 +19,7 @@
{!! view_render_event('bagisto.shop.customers.account.address.create.before') !!}
<form id="customer-address-form" method="post" action="{{ route('customer.address.create') }}" @submit.prevent="onSubmit">
<form id="customer-address-form" method="post" action="{{ route('customer.address.store') }}" @submit.prevent="onSubmit">
<div class="account-table-content">
@csrf

View File

@ -19,7 +19,7 @@
{!! view_render_event('bagisto.shop.customers.account.address.edit.before', ['address' => $address]) !!}
<form id="customer-address-form" method="post" action="{{ route('customer.address.edit', $address->id) }}" @submit.prevent="onSubmit">
<form id="customer-address-form" method="post" action="{{ route('customer.address.update', $address->id) }}" @submit.prevent="onSubmit">
<div class="account-table-content">
@method('PUT')

View File

@ -21,7 +21,7 @@
{!! view_render_event('bagisto.shop.customers.account.profile.edit.before', ['customer' => $customer]) !!}
<form method="post" action="{{ route('customer.profile.edit') }}" @submit.prevent="onSubmit">
<form method="post" action="{{ route('customer.profile.store') }}" @submit.prevent="onSubmit">
<div class="edit-form">
@csrf

View File

@ -18,7 +18,10 @@
<form role="search" action="{{ route('shop.search.index') }}" method="GET" style="display: inherit;">
<input type="search" name="term" class="search-field" placeholder="{{ __('shop::app.header.search-text') }}" required>
<image-search-component></image-search-component>
<div class="search-icon-wrapper">
<button class="" class="background: none;">
<i class="icon icon-search"></i>
</button>
@ -194,6 +197,90 @@
</div>
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"></script>
<script type="text/x-template" id="image-search-component-template">
<div>
<label class="image-search-container" for="image-search-container">
<i class="icon camera-icon"></i>
<input type="file" id="image-search-container" ref="image_search_input" v-on:change="uploadImage()"/>
<img id="uploaded-image-url" :src="uploaded_image_url"/>
</label>
</div>
</script>
<script>
Vue.component('image-search-component', {
template: '#image-search-component-template',
data: function() {
return {
uploaded_image_url: ''
}
},
methods: {
uploadImage: function() {
var self = this;
self.$root.showLoader();
var formData = new FormData();
formData.append('image', this.$refs.image_search_input.files[0]);
axios.post("{{ route('shop.image.search.upload') }}", formData, {headers: {'Content-Type': 'multipart/form-data'}})
.then(function(response) {
self.uploaded_image_url = response.data;
var net;
async function app() {
var analysedResult = [];
var queryString = '';
net = await mobilenet.load();
const imgElement = document.getElementById('uploaded-image-url');
const result = await net.classify(imgElement);
result.forEach(function(value) {
queryString = value.className.split(',');
if (queryString.length > 1) {
analysedResult = analysedResult.concat(queryString)
} else {
analysedResult.push(queryString[0])
}
})
localStorage.searched_image_url = self.uploaded_image_url;
queryString = localStorage.searched_terms = analysedResult.join('_');
self.$root.hideLoader();
window.location.href = "{{ route('shop.search.index') }}" + '?term=' + queryString + '&image-search=1';
}
app();
})
.catch(function() {
self.$root.hideLoader();
});
}
}
});
</script>
<script>
$(document).ready(function() {

View File

@ -81,6 +81,8 @@
</p>
</div>
@endif
<overlay-loader :is-open="show_loader"></overlay-loader>
</div>
<script type="text/javascript">

View File

@ -5,6 +5,10 @@
@endsection
@section('content-wrapper')
@if (request('image-search'))
<image-search-result-component></image-search-result-component>
@endif
@if (! $results)
{{ __('shop::app.search.no-results') }}
@endif
@ -39,4 +43,47 @@
@endif
</div>
@endif
@endsection
@endsection
@push('scripts')
<script type="text/x-template" id="image-search-result-component-template">
<div class="image-search-result">
<div class="searched-image">
<img :src="searched_image_url"/>
</div>
<div class="searched-terms">
<h3>{{ __('shop::app.search.analysed-keywords') }}</h3>
<div class="term-list">
<a v-for="term in searched_terms" :href="'{{ route('shop.search.index') }}?term=' + term">
@{{ term }}
</a>
</div>
</div>
</div>
</script>
<script>
Vue.component('image-search-result-component', {
template: '#image-search-result-component-template',
data: function() {
return {
searched_image_url: localStorage.searched_image_url,
searched_terms: []
}
},
created: function() {
this.searched_terms = localStorage.searched_terms.split('_');
console.log(this.searched_terms)
}
});
</script>
@endpush

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="3.2"/><path d="M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/></svg>

After

Width:  |  Height:  |  Size: 324 B

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/ui.js": "/js/ui.js?id=5c5ae91d95c2c0668124",
"/css/ui.css": "/css/ui.css?id=676aac66854686c7def3"
"/js/ui.js": "/js/ui.js?id=b56f2fff2a85ae08608f",
"/css/ui.css": "/css/ui.css?id=881ed8b3d2e495260a71"
}

Binary file not shown.

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="3.2"/><path d="M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/></svg>

After

Width:  |  Height:  |  Size: 324 B

View File

@ -22,6 +22,7 @@ import DateComponent from './components/date';
import TimeComponent from './components/time';
import SwatchPicker from './components/swatch-picker';
import Debounce from './directives/debounce';
import OverlayLoader from './components/overlay-loader';
Vue.component('flash-wrapper', FlashWrapper);
Vue.component('flash', Flash);
@ -45,6 +46,7 @@ Vue.component('date', DateComponent);
Vue.component("time-component", TimeComponent);
Vue.component('swatch-picker', SwatchPicker);
Vue.directive('debounce', Debounce);
Vue.component('overlay-loader', OverlayLoader);
Vue.filter('truncate', function (value, limit, trail) {
if (! value)
value = '';

View File

@ -0,0 +1,31 @@
<template>
<div class="overlay-loader" v-if="isLoaderOpen">
<div id="loader" class="cp-spinner cp-round"></div>
</div>
</template>
<script>
export default {
props: ['id', 'isOpen'],
computed: {
isLoaderOpen () {
this.addClassToBody();
return this.isOpen;
}
},
methods: {
addClassToBody () {
var body = document.querySelector("body");
if (this.isOpen) {
body.classList.add("modal-open");
} else {
body.classList.remove("modal-open");
}
}
}
}
</script>

View File

@ -1165,4 +1165,13 @@ modal {
font-weight: bold;
}
}
}
.overlay-loader {
position: fixed;
z-index: 11;
top: 50%;
left: 50%;
margin-top: -24px;
margin-left: -24px;
}

View File

@ -340,4 +340,10 @@
width: 17px;
height: 17px;
background-image: url("../images/Icon-star.svg");
}
.camera-icon {
background-image: url("../images/Camera.svg");
width: 24px;
height: 24px;
}

View File

@ -55,7 +55,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
]);
Route::get('/items-count', 'ShopController@getItemsCount')
->name('velocity.product.details');
->name('velocity.product.item-count');
Route::get('/detailed-products', 'ShopController@getDetailedProducts')
->name('velocity.product.details');

View File

@ -13,7 +13,7 @@
{!! view_render_event('bagisto.shop.customers.account.address.create.before') !!}
<form method="post" action="{{ route('customer.address.create') }}" @submit.prevent="onSubmit">
<form method="post" action="{{ route('customer.address.store') }}" @submit.prevent="onSubmit">
<div class="account-table-content">
@csrf

View File

@ -13,7 +13,7 @@
{!! view_render_event('bagisto.shop.customers.account.address.edit.before', ['address' => $address]) !!}
<form method="post" action="{{ route('customer.address.edit', $address->id) }}" @submit.prevent="onSubmit">
<form method="post" action="{{ route('customer.address.update', $address->id) }}" @submit.prevent="onSubmit">
<div class="account-table-content">
@method('PUT')

View File

@ -22,7 +22,7 @@
method="POST"
@submit.prevent="onSubmit"
class="account-table-content"
action="{{ route('customer.profile.edit') }}">
action="{{ route('customer.profile.store') }}">
@csrf
{!! view_render_event('bagisto.shop.customers.account.profile.edit_form_controls.before', ['customer' => $customer]) !!}

128
tensor.js vendored Normal file
View File

@ -0,0 +1,128 @@
(function anonymous() {
define(['jquery', 'Magento_Ui/js/modal/modal', '@tensorflow/tfjs', '@tensorflow/netjs'], function ($, modal, tf, mobilenet) {
'use strict';
$.widget('image.search', {
options: {},
_create: function () {
var self = this;
$(document).ready(function () {
$('div#searched-image img').attr('src', localStorage.searchedImage);
$('div#searched-image img').error(function () {
$('.wk-image-search').hide();
});
let queryText = localStorage.queryText;
if (queryText != undefined) {
$('div#related-suggestions').empty();
$('div#related-suggestions').append('<h5>Filter by analyzed keywords</h5>');
$.each(queryText.split('+'), function (i, v) {
$('div#related-suggestions').append('<a href="' +
self.options.searchUrl + '?q=' + v.trim() + '&imagesearch"><span class="wk-search-terms">' + v.trim() + '</span></a>');
});
}
if (self.options.deleteNow && localStorage.searchedImage) {
$.post({
url: self.options.deleteImageUrl,
data: {
url: localStorage.searchedImage
},
error: function (resp) {}
});
}
if (!self.options.hideBreadcrumbs) {
$('input#search').val('');
$('div.breadcrumbs').show();
$('div.page-title-wrapper').show();
}
if (self.options.hideBreadcrumbs) {
$('input#search').val('');
}
});
$('#uploader').change(function () {
$("body div#upload-box").hide();
$('div.wk-loading-mask').removeClass('wk-display-none');
var file_data = $('#uploader').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: self.options.processorUrl,
type: 'POST',
processData: false,
contentType: false,
data: form_data,
success: function (data) {
if (data) {
$('#image-to-be-search').attr('src', data);
let net, analysed_data = '',
terms_array = [],
imgUrlCurr, queryText;
async function app() {
net = await mobilenet.load();
let imgEl = document.getElementById('image-to-be-search');
const result = await net.classify(imgEl);
$.each(result, function (index, value) {
analysed_data = analysed_data + ',' + value.className.split(',');
});
analysed_data = analysed_data.replace(/,/g, "+");
queryText = analysed_data.substring(1);
localStorage.queryText = queryText;
imgUrlCurr = $('#image-to-be-search').attr('src');
localStorage.imgUrlDel = localStorage.searchedImage;
localStorage.searchedImage = imgUrlCurr;
$('.wk-loading-mask').addClass('wk-display-none');
window.location.href = self.options.searchUrl + '?q=' + queryText + '&imagesearch';
}
app();
}
},
error: function (resp) {}
});
});
$("body").on('click', function (e) {
if (e.target.className != 'fa fa-camera' && e.target.id != 'browse-label' && e.target.id != 'upload-box') {
$("body div#upload-box").slideUp();
}
});
$("#icon").on('click', function () {
$("body div#upload-box").slideToggle();
});
}
});
return $.image.search;
});
})