sr-npm 1.7.529 → 1.7.531
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.
- package/backend/collectionConsts.js +19 -0
- package/backend/data.js +3 -1
- package/package.json +1 -1
- package/pages/careersPage.js +114 -53
|
@@ -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/backend/data.js
CHANGED
|
@@ -56,6 +56,7 @@ function addCustomFields(basicJob, position) {
|
|
|
56
56
|
const customFieldsArray = Array.isArray(position?.customField) ? position.customField : [];
|
|
57
57
|
const customFields = {};
|
|
58
58
|
for (const field of customFieldsArray) {
|
|
59
|
+
if(field.fieldLabel==="Country" || field.fieldLabel==="Department") continue; //country and department are not custom fields, they are already in the job object
|
|
59
60
|
const label = field.fieldLabel==="Brands" ? "brand" : field.fieldLabel
|
|
60
61
|
const key = normalizeString(label);
|
|
61
62
|
const value = field.valueLabel
|
|
@@ -352,6 +353,7 @@ async function aggregateJobs() {
|
|
|
352
353
|
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
|
|
353
354
|
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.BRAND, collection: COLLECTIONS.BRANDS })
|
|
354
355
|
]);
|
|
356
|
+
|
|
355
357
|
console.log("finished aggregating jobs");
|
|
356
358
|
}
|
|
357
359
|
|
|
@@ -374,7 +376,7 @@ async function syncJobsFast() {
|
|
|
374
376
|
// console.log("saving jobs descriptions and location apply url to CMS");
|
|
375
377
|
// await saveJobsDescriptionsAndLocationApplyUrlToCMS();
|
|
376
378
|
// console.log("saved jobs descriptions and location apply url to CMS successfully");
|
|
377
|
-
|
|
379
|
+
// await aggregateJobs();
|
|
378
380
|
// await referenceJobs();
|
|
379
381
|
// console.log("syncing jobs fast finished successfully");
|
|
380
382
|
}
|
package/package.json
CHANGED
package/pages/careersPage.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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
|
|
117
|
+
await handleGivenURLParam(_$w,URL_PARAMS.DEPARTMENT,queryDepartmentVar);
|
|
118
|
+
//await handleDepartmentParam(_$w,queryDepartmentVar);
|
|
115
119
|
}
|
|
116
120
|
if (queryLocationVar) {
|
|
117
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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({
|
|
331
|
+
queryParams.add({ [filter.queryParamKey] : encodeURIComponent(filter.value) });
|
|
304
332
|
}
|
|
305
333
|
}
|
|
306
|
-
if(filter.field === '
|
|
307
|
-
|
|
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,32 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
|
316
351
|
}
|
|
317
352
|
else{
|
|
318
353
|
if (!skipUrlUpdate) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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);
|
|
379
|
+
console.log("dropdownFiltersMapping after applying filters: ", dropdownFiltersMapping);
|
|
341
380
|
|
|
342
381
|
const filter = await getFilter(filters, 'and');
|
|
343
382
|
await _$w('#jobsDataset').setFilter(filter);
|
|
@@ -359,6 +398,9 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
|
359
398
|
|
|
360
399
|
async function resetFilters(_$w) {
|
|
361
400
|
_$w('#searchInput, #dropdownDepartment, #dropdownLocation, #dropdownJobType, #dropdownBrand').value = '';
|
|
401
|
+
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
402
|
+
_$w(queryCustomFields[customFieldKey].elementId).value = '';
|
|
403
|
+
}
|
|
362
404
|
|
|
363
405
|
await _$w('#jobsDataset').setFilter(wixData.filter());
|
|
364
406
|
await _$w('#jobsDataset').refresh();
|
|
@@ -368,7 +410,9 @@ async function resetFilters(_$w) {
|
|
|
368
410
|
_$w('#resetFiltersButton').disable();
|
|
369
411
|
|
|
370
412
|
queryParams.remove(["keyWord", "department","page","location","jobType","brand"]);
|
|
371
|
-
|
|
413
|
+
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
414
|
+
queryParams.remove([queryCustomFields[customFieldKey].queryParamKey]);
|
|
415
|
+
}
|
|
372
416
|
|
|
373
417
|
await updateCount(_$w);
|
|
374
418
|
console.log("reseting map markers");
|
|
@@ -383,16 +427,33 @@ async function updateCount(_$w) {
|
|
|
383
427
|
return count;
|
|
384
428
|
}
|
|
385
429
|
|
|
430
|
+
async function handleGivenURLParam(_$w,param,value,isCustomField=false) {
|
|
431
|
+
const paramValue = decodeURIComponent(value);
|
|
432
|
+
let dropdownOptions = _$w(DROPDOWN_IDS[param]).options;
|
|
433
|
+
console.log("dropdown options:", dropdownOptions);
|
|
434
|
+
let optionsFromCMS;
|
|
435
|
+
if(!isCustomField){
|
|
436
|
+
optionsFromCMS=await wixData.query(DROPDOWN_COLLECTIONS[param]).find();
|
|
437
|
+
if(dropdownOptions.length!==optionsFromCMS.items.length+1){
|
|
438
|
+
fixDropdownOptions(DROPDOWN_IDS[param],optionsFromCMS, _$w);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const option=_$w(DROPDOWN_IDS[param]).options.find(option => option.value.toLowerCase() === paramValue.toLowerCase())
|
|
442
|
+
if(option){
|
|
443
|
+
_$w(DROPDOWN_IDS[param]).value = option.value;
|
|
444
|
+
}
|
|
445
|
+
else{
|
|
446
|
+
console.warn("param value not found in dropdown options");
|
|
447
|
+
queryParams.remove([param]);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
386
451
|
async function handleDepartmentParam(_$w,department) {
|
|
387
452
|
const departmentValue = decodeURIComponent(department);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
453
|
let dropdownOptions = _$w('#dropdownDepartment').options;
|
|
392
454
|
console.log("dropdown options:", dropdownOptions);
|
|
393
455
|
const optionsFromCMS=await wixData.query("AmountOfJobsPerDepartment").find();
|
|
394
456
|
//+1 because of the "All" option
|
|
395
|
-
|
|
396
457
|
if(dropdownOptions.length!==optionsFromCMS.items.length+1){
|
|
397
458
|
fixDropdownOptions('#dropdownDepartment',optionsFromCMS, _$w);
|
|
398
459
|
}
|