-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstructor.js.html
More file actions
235 lines (188 loc) · 9.63 KB
/
Copy pathconstructor.js.html
File metadata and controls
235 lines (188 loc) · 9.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>constructor.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="EcomSearch.html">EcomSearch</a><ul class='methods'><li data-type='method'><a href="EcomSearch.html#fetch">fetch</a></li><li data-type='method'><a href="EcomSearch.html#getBrands">getBrands</a></li><li data-type='method'><a href="EcomSearch.html#getCategories">getCategories</a></li><li data-type='method'><a href="EcomSearch.html#getItems">getItems</a></li><li data-type='method'><a href="EcomSearch.html#getPriceRange">getPriceRange</a></li><li data-type='method'><a href="EcomSearch.html#getSpecs">getSpecs</a></li><li data-type='method'><a href="EcomSearch.html#getTermSuggestions">getTermSuggestions</a></li><li data-type='method'><a href="EcomSearch.html#getTotalCount">getTotalCount</a></li><li data-type='method'><a href="EcomSearch.html#mergeFilter">mergeFilter</a></li><li data-type='method'><a href="EcomSearch.html#removeFilter">removeFilter</a></li><li data-type='method'><a href="EcomSearch.html#reset">reset</a></li><li data-type='method'><a href="EcomSearch.html#setBrandIds">setBrandIds</a></li><li data-type='method'><a href="EcomSearch.html#setBrandNames">setBrandNames</a></li><li data-type='method'><a href="EcomSearch.html#setCategoryIds">setCategoryIds</a></li><li data-type='method'><a href="EcomSearch.html#setCategoryNames">setCategoryNames</a></li><li data-type='method'><a href="EcomSearch.html#setPageNumber">setPageNumber</a></li><li data-type='method'><a href="EcomSearch.html#setPageSize">setPageSize</a></li><li data-type='method'><a href="EcomSearch.html#setPriceRange">setPriceRange</a></li><li data-type='method'><a href="EcomSearch.html#setProductIds">setProductIds</a></li><li data-type='method'><a href="EcomSearch.html#setSearchTerm">setSearchTerm</a></li><li data-type='method'><a href="EcomSearch.html#setSkus">setSkus</a></li><li data-type='method'><a href="EcomSearch.html#setSortOrder">setSortOrder</a></li><li data-type='method'><a href="EcomSearch.html#setSpec">setSpec</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-@ecomplus_search-engine.html">@ecomplus/search-engine</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addGlobalFilter">addGlobalFilter</a></li><li><a href="global.html#setSalesChannel">setSalesChannel</a></li><li><a href="global.html#setWarehouse">setWarehouse</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">constructor.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* JS lib to handle products search with E-Com Plus stores.
* {@link https://github.com/ecomclub/search-engine GitHub}
*
* @module @ecomplus/search-engine
* @author E-Com Club <ti@e-com.club>
* @return {@link EcomSearch}
* @see EcomSearch
*
* @example
* // ES import default
* import EcomSearch from '@ecomplus/search-engine'
*
* @example
* // With CommonJS
* const EcomSearch = require('@ecomplus/search-engine')
*
* @example
* <!-- Global `EcomSearch` from CDN on browser -->
* <script src="https://cdn.jsdelivr.net/npm/@ecomplus/search-engine/dist/ecom-search.var.min.js"></script>
*
* @example
* <!-- Bundle from CDN with `ecomUtils`, `ecomClient`, `_.cloneDeep` and `_.merge` -->
* <script src="https://cdn.jsdelivr.net/npm/@ecomplus/search-engine/dist/ecom-search.bundle.min.js"></script>
*/
import { $ecomConfig } from '@ecomplus/utils'
import fetch from './methods/fetch'
import reset from './methods/reset'
import setSearchTerm from './methods/set-search-term'
import setPageNumber from './methods/set-page-number'
import setPageSize from './methods/set-page-size'
import setSortOrder from './methods/set-sort-order'
import mergeFilter from './methods/merge-filter'
import removeFilter from './methods/remove-filter'
import setSpec from './methods/set-spec'
import setCategoryNames from './methods/set-category-names'
import setCategoryIds from './methods/set-category-ids'
import setBrandNames from './methods/set-brand-names'
import setBrandIds from './methods/set-brand-ids'
import setSkus from './methods/set-skus'
import setProductIds from './methods/set-product-ids'
import setPriceRange from './methods/set-price-range'
import getItems from './methods/get-items'
import getTotalCount from './methods/get-total-count'
import getTermSuggestions from './methods/get-term-suggestions'
import getBrands from './methods/get-brands'
import getCategories from './methods/get-categories'
import getPriceRange from './methods/get-price-range'
import getSpecs from './methods/get-specs'
const _key = 'ecomSeachHistory'
const _storage = typeof window === 'object' && window.localStorage
export default function (storeId, storageKey = _key, localStorage = _storage) {
const self = this
/**
* Respective Store ID number.
* @name EcomSearch#storeId
* @type {number}
*/
this.storeId = storeId || $ecomConfig.get('store_id')
/**
* Item key to handle persistent [search history]{@link EcomSearch#history} data
* with [localStorage]{@link EcomSearch#localStorage}.
* @name EcomSearch#storageKey
* @type {string|null}
*/
this.storageKey = storageKey
/**
* [Storage interface]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}.
* @name EcomSearch#localStorage
* @type {object}
*/
this.localStorage = localStorage
/**
* Search terms history.
* @name EcomSearch#history
* @type {array<string>}
*/
this.history = []
/**
* Current
* [Query DSL]{@link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html}
* for [Search API]{@link https://developers.e-com.plus/docs/api/#/search/items/items}
* request body.
* <br>
* You can edit this object to manually set Query DSL properties,
* or you can use instance methods listed below.
* @name EcomSearch#dsl
* @type {object}
*/
this.dsl = {}
/**
* Last search result object obtained with the
* [fetch method]{@link EcomSearch#fetch}.
* @name EcomSearch#result
* @type {result|undefined}
*/
this.result = undefined
// instance methods
this.fetch = (isSimpleSearch, axiosConfig) => fetch(self, isSimpleSearch, axiosConfig)
this.reset = () => reset(self)
this.setSearchTerm = term => setSearchTerm(self, term)
this.setPageNumber = page => setPageNumber(self, page)
this.setPageSize = limit => setPageSize(self, limit)
this.setSortOrder = enumOrder => setSortOrder(self, enumOrder)
this.mergeFilter = (filter, occur) => mergeFilter(self, filter, occur)
this.removeFilter = (field, occur) => removeFilter(self, field, occur)
this.setSpec = (gridId, textOptions) => setSpec(self, gridId, textOptions)
this.setCategoryNames = categoryNames => setCategoryNames(self, categoryNames)
this.setCategoryIds = categoryIds => setCategoryIds(self, categoryIds)
this.setBrandNames = brandNames => setBrandNames(self, brandNames)
this.setBrandIds = brandIds => setBrandIds(self, brandIds)
this.setSkus = skus => setSkus(self, skus)
this.setProductIds = productIds => setProductIds(self, productIds)
this.setPriceRange = (minPrice, maxPrice) => setPriceRange(self, minPrice, maxPrice)
this.getItems = result => getItems(self, result)
this.getTotalCount = result => getTotalCount(self, result)
this.getTermSuggestions = result => getTermSuggestions(self, result)
this.getBrands = result => getBrands(self, result)
this.getCategories = result => getCategories(self, result)
this.getPriceRange = result => getPriceRange(self, result)
this.getSpecs = result => getSpecs(self, result)
// preset query object
reset(self)
if (localStorage && storageKey) {
// try to preset search history from storage
const history = localStorage.getItem(storageKey)
if (typeof history === 'string') {
self.history = history.split('||')
}
}
}
/**
* Construct a new search engine instance object.
* @class EcomSearch
* @param {number} [storeId=$ecomConfig.get('store_id')] - Preset Store ID number
* @param {string|null} [storageKey='ecomSeachHistory'] - Item key to persist search history data
* @param {object} [localStorage=window.localStorage] -
* [Local Storage interface]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}
*
* @example
const search = new EcomSearch()
*
* @example
// Defining Store ID other than the configured on `$ecomConfig`
const storeId = 2000
const search = new EcomSearch(storeId)
*/
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Feb 22 2023 20:40:42 GMT-0300 (Brasilia Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>