sr-npm 1.7.529 → 1.7.530

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,22 @@ const COLLECTIONS_FIELDS = {
97
97
  SMART_TOKEN: 'x-smarttoken',
98
98
  DESIRED_BRAND: 'desiredBrand',
99
99
  }
100
+
101
+ const URL_PARAMS = {
102
+ DEPARTMENT: "Department",
103
+ LOCATION: "Location",
104
+ BRAND: "Brand",
105
+ }
106
+ const DROPDOWN_IDS = {
107
+ DEPARTMENT: '#dropdownDepartment',
108
+ LOCATION: '#dropdownLocation',
109
+ BRAND: '#dropdownBrand',
110
+ }
111
+ const DROPDOWN_COLLECTIONS = {
112
+ DEPARTMENT: 'AmountOfJobsPerDepartment',
113
+ LOCATION: 'cities',
114
+ BRAND: 'Brands',
115
+ }
100
116
 
101
117
 
102
118
  module.exports = {
@@ -108,4 +124,7 @@ const COLLECTIONS_FIELDS = {
108
124
  BRANDS_COLLECTION_FIELDS,
109
125
  TEMPLATE_TYPE,
110
126
  TOKEN_NAME,
127
+ URL_PARAMS,
128
+ DROPDOWN_IDS,
129
+ DROPDOWN_COLLECTIONS,
111
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.529",
3
+ "version": "1.7.530",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ const {wixData} = require('wix-data');
3
3
  const { window } = require('@wix/site-window');
4
4
  const { query,queryParams,onChange} = require("wix-location-frontend");
5
5
  const { location } = require("@wix/site-location");
6
- const { COLLECTIONS } = require('../backend/collectionConsts');
6
+ const { COLLECTIONS, URL_PARAMS, DROPDOWN_IDS, DROPDOWN_COLLECTIONS } = require('../backend/collectionConsts');
7
7
 
8
8
  const {
9
9
  debounce,
@@ -25,21 +25,22 @@ const {
25
25
  let queryCustomFields={};
26
26
  let searchInputBlurredFirstTime=true;
27
27
  let deletedParam=false;
28
- async function careersPageOnReady(_$w,thisObject,queryParams,customFieldsObject=null) {
28
+ async function careersPageOnReady(_$w,thisObject,queryParams,customFieldsDropdownObject=null) {
29
29
  console.log("queryParams: ", queryParams);
30
+ console.log("customFieldsDropdownObject: ", customFieldsDropdownObject)
30
31
  await retrieveQueryParams(queryParams);
31
32
  thisObjectVar=thisObject;
32
33
  allJobs=await getAllPositions();
33
34
  await activateAutoLoad(_$w);
34
35
  await bind(_$w);
35
- await init(_$w);
36
+ await init(_$w,customFieldsDropdownObject);
36
37
  await handleBrandDropdown(_$w);
37
38
  await handleUrlParams(_$w);
38
39
 
39
40
 
40
41
  }
41
42
 
42
- async function retrieveQueryParams(queryParams){
43
+ async function retrieveQueryParams(queryParams,customFieldsDropdownObject=null){
43
44
  const { page, keyWord, department, location,jobType,brand } = queryParams;
44
45
  queryPageVar=page;
45
46
  queryKeyWordVar=keyWord;
@@ -47,14 +48,16 @@ queryDepartmentVar=department;
47
48
  queryLocationVar=location;
48
49
  queryJobTypeVar=jobType;
49
50
  queryBrandVar=brand;
50
- const customFieldKeys=await getCustomFieldKeys()
51
+ if(customFieldsDropdownObject){
52
+ const customFieldKeys=Object.keys(customFieldsDropdownObject);
51
53
  console.log("customFieldKeys: ", customFieldKeys)
52
54
  for(const customFieldKey of customFieldKeys)
53
55
  {
54
- queryCustomFields[customFieldKey]=queryParams[customFieldKey]
56
+ queryCustomFields[customFieldKey]={elementId:customFieldsDropdownObject[customFieldKey], field:customFieldKey, queryParamValue:queryParams[customFieldKey],queryParamKey:customFieldKey}
55
57
  }
56
58
  console.log("queryCustomFields",queryCustomFields)
57
59
  }
60
+ }
58
61
 
59
62
  function activateAutoLoad(_$w)
60
63
  {
@@ -111,16 +114,24 @@ async function handleUrlParams(_$w) {
111
114
  await handlePageParam(_$w);
112
115
  }
113
116
  if (queryDepartmentVar) {
114
- await handleDepartmentParam(_$w,queryDepartmentVar);
117
+ await handleGivenURLParam(_$w,URL_PARAMS.DEPARTMENT,queryDepartmentVar);
118
+ //await handleDepartmentParam(_$w,queryDepartmentVar);
115
119
  }
116
120
  if (queryLocationVar) {
117
- await handleLocationParam(_$w,queryLocationVar);
121
+ // await handleLocationParam(_$w,queryLocationVar);
122
+ await handleGivenURLParam(_$w,URL_PARAMS.LOCATION,queryLocationVar);
118
123
  }
119
124
  if (queryJobTypeVar) {
120
125
  await handleJobTypeParam(_$w,queryJobTypeVar);
121
126
  }
122
127
  if (queryBrandVar && _$w('#dropdownBrand').isVisible) { //if it is not visible, ignore it
123
- await handleBrandParam(_$w,queryBrandVar);
128
+ //await handleBrandParam(_$w,queryBrandVar);
129
+ await handleGivenURLParam(_$w,URL_PARAMS.BRAND,queryBrandVar);
130
+ }
131
+ if (queryCustomFields) {
132
+ for(const customFieldKey of Object.keys(queryCustomFields)){
133
+ await handleGivenURLParam(_$w,customFieldKey,queryCustomFields[customFieldKey].queryParamValue);
134
+ }
124
135
  }
125
136
  await applyFilters(_$w, true); // Skip URL update since we're handling initial URL params
126
137
  }
@@ -180,7 +191,7 @@ async function bind(_$w) {
180
191
 
181
192
  }
182
193
 
183
- function init(_$w) {
194
+ function init(_$w,customFieldsDropdownObject=null) {
184
195
  const debouncedSearch = debounce(()=>applyFilters(_$w), 400,thisObjectVar);
185
196
  _$w('#searchInput').onInput(debouncedSearch);
186
197
  _$w('#searchInput').onBlur(()=>{
@@ -194,6 +205,14 @@ function init(_$w) {
194
205
  console.log("dropdown onChange is triggered");
195
206
  applyFilters(_$w);
196
207
  });
208
+ if (customFieldsDropdownObject){
209
+ for(const customFieldKey of Object.keys(customFieldsDropdownObject)){
210
+ _$w(customFieldsDropdownObject[customFieldKey]).onChange(()=>{
211
+ console.log("custom field onChange is triggered");
212
+ applyFilters(_$w);
213
+ });
214
+ }
215
+ }
197
216
  _$w('#resetFiltersButton, #clearSearch').onClick(()=>resetFilters(_$w));
198
217
 
199
218
  _$w('#openFiltersButton').onClick(()=>{
@@ -260,17 +279,27 @@ async function handleBackAndForth(_$w){
260
279
 
261
280
  }
262
281
 
282
+ async function applyCustomFieldFilters(filters) {
283
+ for(const customFieldKey of Object.keys(queryCustomFields)){
284
+ filters.push({ field: customFieldKey, searchTerm: queryCustomFields[customFieldKey] });
285
+ }
286
+ }
287
+
263
288
  async function applyFilters(_$w, skipUrlUpdate = false) {
264
289
  console.log("applying filters");
265
290
  const dropdownFiltersMapping = [
266
- { elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value },
267
- { elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value },
268
- { elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value},
269
- { elementId: '#dropdownBrand', field: 'brand', value: _$w('#dropdownBrand').value},
270
- { elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value }
291
+ { elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value,queryParamKey:"department" },
292
+ { elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value,queryParamKey:"location" },
293
+ { elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value,queryParamKey:"jobType" },
294
+ { elementId: '#dropdownBrand', field: 'brand', value: _$w('#dropdownBrand').value,queryParamKey:"brand" },
295
+ { elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value,queryParamKey:"keyWord" }
271
296
  ];
297
+ //adding custom field filters to the dropdownFiltersMapping
298
+ for(const customFieldKey of Object.keys(queryCustomFields)){
299
+ dropdownFiltersMapping.push({ elementId: queryCustomFields[customFieldKey].elementId, field: queryCustomFields[customFieldKey].field, value: _$w(queryCustomFields[customFieldKey].elementId).value,queryParamKey:queryCustomFields[customFieldKey].queryParamKey });
300
+ }
272
301
  console.log("dropdownFiltersMapping: ", dropdownFiltersMapping);
273
-
302
+
274
303
 
275
304
 
276
305
  let filters = [];
@@ -289,23 +318,29 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
289
318
  if(filter.field === 'title'){
290
319
  queryParams.add({ keyWord: filter.value });
291
320
  }
292
- if(filter.field === 'department'){
293
- queryParams.add({ department: encodeURIComponent(filter.value) });
294
- }
295
- if(filter.field === 'cityText'){
296
- queryParams.add({ location: encodeURIComponent(filter.value) });
297
- }
298
- if(filter.field === 'remote'){
299
- if(filter.value === 'true'){
300
- queryParams.add({ jobType: encodeURIComponent("remote") });
321
+ else{
322
+ if(filter.field === 'remote'){
323
+ if(filter.value === 'true'){
324
+ queryParams.add({ jobType: encodeURIComponent("remote") });
325
+ }
326
+ else{
327
+ queryParams.add({ jobType: encodeURIComponent("onsite") });
328
+ }
301
329
  }
302
330
  else{
303
- queryParams.add({ jobType: encodeURIComponent("onsite") });
331
+ queryParams.add({ [filter.queryParamKey] : encodeURIComponent(filter.value) });
304
332
  }
305
333
  }
306
- if(filter.field === 'brand'){
307
- queryParams.add({ brand: encodeURIComponent(filter.value) });
308
- }
334
+ // if(filter.field === 'department'){
335
+ // queryParams.add({ department: encodeURIComponent(filter.value) });
336
+ // }
337
+ // if(filter.field === 'cityText'){
338
+ // queryParams.add({ location: encodeURIComponent(filter.value) });
339
+ // }
340
+
341
+ // if(filter.field === 'brand'){
342
+ // queryParams.add({ brand: encodeURIComponent(filter.value) });
343
+ // }
309
344
  }
310
345
  if(filter.field === 'remote') {
311
346
  value = filter.value === 'true';
@@ -316,28 +351,31 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
316
351
  }
317
352
  else{
318
353
  if (!skipUrlUpdate) {
319
- if(filter.field === 'title'){
320
- queryParams.remove(["keyWord" ]);
321
- }
322
- if(filter.field === 'department'){
323
- console.log("removing department from url")
324
- queryParams.remove(["department" ]);
325
- }
326
- if(filter.field === 'cityText'){
327
- console.log("removing location from url")
328
- queryParams.remove(["location" ]);
329
- }
330
- if(filter.field === 'remote'){
331
- console.log("removing jobType from url")
332
- queryParams.remove(["jobType" ]);
333
- }
334
- if(filter.field === 'brand'){
335
- console.log("removing brand from url")
336
- queryParams.remove(["brand" ]);
337
- }
354
+ queryParams.remove([filter.queryParamKey]);
355
+ // if(filter.field === 'title'){
356
+ // queryParams.remove(["keyWord" ]);
357
+ // }
358
+ // if(filter.field === 'department'){
359
+ // console.log("removing department from url")
360
+ // queryParams.remove(["department" ]);
361
+ // }
362
+ // if(filter.field === 'cityText'){
363
+ // console.log("removing location from url")
364
+ // queryParams.remove(["location" ]);
365
+ // }
366
+ // if(filter.field === 'remote'){
367
+ // console.log("removing jobType from url")
368
+ // queryParams.remove(["jobType" ]);
369
+ // }
370
+ // if(filter.field === 'brand'){
371
+ // console.log("removing brand from url")
372
+ // queryParams.remove(["brand" ]);
373
+ // }
338
374
  }
339
375
  }
340
376
  });
377
+
378
+ //applyCustomFieldFilters(filters);
341
379
 
342
380
  const filter = await getFilter(filters, 'and');
343
381
  await _$w('#jobsDataset').setFilter(filter);
@@ -359,6 +397,9 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
359
397
 
360
398
  async function resetFilters(_$w) {
361
399
  _$w('#searchInput, #dropdownDepartment, #dropdownLocation, #dropdownJobType, #dropdownBrand').value = '';
400
+ for(const customFieldKey of Object.keys(queryCustomFields)){
401
+ _$w(queryCustomFields[customFieldKey].elementId).value = '';
402
+ }
362
403
 
363
404
  await _$w('#jobsDataset').setFilter(wixData.filter());
364
405
  await _$w('#jobsDataset').refresh();
@@ -368,7 +409,9 @@ async function resetFilters(_$w) {
368
409
  _$w('#resetFiltersButton').disable();
369
410
 
370
411
  queryParams.remove(["keyWord", "department","page","location","jobType","brand"]);
371
-
412
+ for(const customFieldKey of Object.keys(queryCustomFields)){
413
+ queryParams.remove([queryCustomFields[customFieldKey].queryParamKey]);
414
+ }
372
415
 
373
416
  await updateCount(_$w);
374
417
  console.log("reseting map markers");
@@ -383,16 +426,30 @@ async function updateCount(_$w) {
383
426
  return count;
384
427
  }
385
428
 
429
+ async function handleGivenURLParam(_$w,param,value) {
430
+ const paramValue = decodeURIComponent(value);
431
+ let dropdownOptions = _$w(DROPDOWN_IDS[param]).options;
432
+ console.log("dropdown options:", dropdownOptions);
433
+ const optionsFromCMS=await wixData.query(DROPDOWN_COLLECTIONS[param]).find();
434
+ if(dropdownOptions.length!==optionsFromCMS.items.length+1){
435
+ fixDropdownOptions(DROPDOWN_IDS[param],optionsFromCMS, _$w);
436
+ }
437
+ const option=_$w(DROPDOWN_IDS[param]).options.find(option => option.value.toLowerCase() === paramValue.toLowerCase())
438
+ if(option){
439
+ _$w(DROPDOWN_IDS[param]).value = option.value;
440
+ }
441
+ else{
442
+ console.warn("param value not found in dropdown options");
443
+ queryParams.remove([param]);
444
+ }
445
+ }
446
+
386
447
  async function handleDepartmentParam(_$w,department) {
387
448
  const departmentValue = decodeURIComponent(department);
388
-
389
-
390
-
391
449
  let dropdownOptions = _$w('#dropdownDepartment').options;
392
450
  console.log("dropdown options:", dropdownOptions);
393
451
  const optionsFromCMS=await wixData.query("AmountOfJobsPerDepartment").find();
394
452
  //+1 because of the "All" option
395
-
396
453
  if(dropdownOptions.length!==optionsFromCMS.items.length+1){
397
454
  fixDropdownOptions('#dropdownDepartment',optionsFromCMS, _$w);
398
455
  }