sr-npm 3.1.9 → 3.1.10
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 +10 -1
- package/backend/data.js +72 -54
- package/backend/queries.js +1 -1
- package/backend/secretsData.js +8 -3
- package/package.json +1 -1
- package/pages/careersMultiBoxesPage.js +75 -52
- package/pages/homePage.js +30 -21
- package/pages/pagesUtils.js +60 -71
- package/pages/positionPage.js +1 -4
- package/pages/supportTeamsPage.js +6 -6
- package/public/filterUtils.js +1 -1
|
@@ -11,6 +11,7 @@ const COLLECTIONS = {
|
|
|
11
11
|
SUPPORT_TEAMS: 'SupportTeams',
|
|
12
12
|
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
const JOBS_COLLECTION_FIELDS = {
|
|
15
16
|
LOCATION: 'location',
|
|
16
17
|
TITLE: 'title',
|
|
@@ -34,25 +35,31 @@ const JOBS_COLLECTION_FIELDS = {
|
|
|
34
35
|
RELEASED_DATE: 'releasedDate',
|
|
35
36
|
REF_ID: 'refId',
|
|
36
37
|
}
|
|
38
|
+
|
|
37
39
|
const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
|
|
38
40
|
TITLE: 'title',
|
|
39
41
|
COUNT: 'count',
|
|
40
42
|
IMAGE: 'image',
|
|
41
43
|
}
|
|
44
|
+
|
|
42
45
|
const CUSTOM_VALUES_COLLECTION_FIELDS = {
|
|
46
|
+
VALUE_ID: 'valueId',
|
|
43
47
|
TITLE: 'title',
|
|
44
48
|
CUSTOM_FIELD: 'customField',
|
|
45
49
|
MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
|
|
46
50
|
count: 'count',
|
|
47
51
|
JOB_IDS: 'jobIds',
|
|
48
52
|
}
|
|
53
|
+
|
|
49
54
|
const CUSTOM_FIELDS_COLLECTION_FIELDS = {
|
|
50
55
|
TITLE: 'title',
|
|
51
56
|
}
|
|
57
|
+
|
|
52
58
|
const BRANDS_COLLECTION_FIELDS = {
|
|
53
59
|
TITLE: 'title',
|
|
54
60
|
COUNT: 'count',
|
|
55
61
|
}
|
|
62
|
+
|
|
56
63
|
const CITIES_COLLECTION_FIELDS = {
|
|
57
64
|
TITLE: 'title',
|
|
58
65
|
CITY: 'city',
|
|
@@ -61,6 +68,7 @@ const CITIES_COLLECTION_FIELDS = {
|
|
|
61
68
|
COUNTRY: 'country',
|
|
62
69
|
JOB_IDS: 'jobIds',
|
|
63
70
|
}
|
|
71
|
+
|
|
64
72
|
const COLLECTIONS_FIELDS = {
|
|
65
73
|
AMOUNT_OF_JOBS_PER_DEPARTMENT: [
|
|
66
74
|
{key:'title', type: 'TEXT'},
|
|
@@ -85,7 +93,7 @@ const COLLECTIONS_FIELDS = {
|
|
|
85
93
|
{key:'language', type: 'TEXT'},
|
|
86
94
|
{key:'remote', type: 'BOOLEAN'},
|
|
87
95
|
{key:'jobDescription', type: 'OBJECT'},
|
|
88
|
-
{key:'multiRefJobsCustomValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES,referencingFieldKey:JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,referencingDisplayName:JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES } } },
|
|
96
|
+
{key:'multiRefJobsCustomValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES, referencingFieldKey:JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,referencingDisplayName:JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES } } },
|
|
89
97
|
{key:'cityText', type: 'TEXT'},
|
|
90
98
|
{key:'applyLink', type: 'URL'},
|
|
91
99
|
{key:'referFriendLink', type: 'URL'},
|
|
@@ -114,6 +122,7 @@ const COLLECTIONS_FIELDS = {
|
|
|
114
122
|
{ key: 'count', type: 'NUMBER' },
|
|
115
123
|
],
|
|
116
124
|
CUSTOM_VALUES: [
|
|
125
|
+
{key:'valueId', type: 'TEXT'},
|
|
117
126
|
{key:'title', type: 'TEXT'},
|
|
118
127
|
{key:'customField', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_FIELDS } } },
|
|
119
128
|
{key:'count', type: 'NUMBER'},
|
package/backend/data.js
CHANGED
|
@@ -40,7 +40,6 @@ function validatePosition(position) {
|
|
|
40
40
|
if (!position.location || !position.location.city || typeof position.location.remote !== 'boolean') {
|
|
41
41
|
throw new Error('Position location is required and must have a city and remote');
|
|
42
42
|
}
|
|
43
|
-
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async function filterBasedOnBrand(positions) {
|
|
@@ -93,78 +92,83 @@ function getEmploymentType(position,customFieldsValues) {
|
|
|
93
92
|
customValuesToJobs[position.typeOfEmployment.id] ? customValuesToJobs[position.typeOfEmployment.id].add(position.id) : customValuesToJobs[position.typeOfEmployment.id]=new Set([position.id])
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues) {
|
|
95
|
+
function getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, customFieldsValues) {
|
|
97
96
|
const customFieldsArray = Array.isArray(position?.customField) ? position.customField : [];
|
|
97
|
+
|
|
98
98
|
for (const field of customFieldsArray) {
|
|
99
99
|
if(EXCLUDED_CUSTOM_FIELDS.has(field.fieldLabel)) continue; //country and department are not custom fields, they are already in the job object
|
|
100
|
-
|
|
100
|
+
|
|
101
|
+
const fieldId = normalizeString(field.fieldId)
|
|
101
102
|
const fieldLabel = field.fieldLabel;
|
|
102
|
-
const valueId=normalizeString(field.valueId)
|
|
103
|
+
const valueId = normalizeString(field.valueId)
|
|
103
104
|
const valueLabel = field.valueLabel
|
|
104
105
|
customFieldsLabels[fieldId] = fieldLabel
|
|
106
|
+
|
|
105
107
|
// Build nested dictionary: fieldId -> { valueId: valueLabel }
|
|
106
108
|
if (!customFieldsValues[fieldId]) {
|
|
107
109
|
customFieldsValues[fieldId] = {};
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
customFieldsValues[fieldId][valueId] = valueLabel;
|
|
111
|
-
customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId]=new Set([position.id])
|
|
113
|
+
customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId] = new Set([position.id])
|
|
112
114
|
}
|
|
113
115
|
}
|
|
116
|
+
|
|
114
117
|
async function saveJobsDataToCMS() {
|
|
115
118
|
const positions = await fetchPositionsFromSRAPI();
|
|
116
119
|
const sourcePositions = await filterBasedOnBrand(positions);
|
|
117
120
|
const customFieldsLabels = {}
|
|
118
121
|
const customFieldsValues = {}
|
|
119
122
|
|
|
120
|
-
const {
|
|
123
|
+
const { templateType } = await getApiKeys();
|
|
121
124
|
if(siteconfig===undefined) {
|
|
122
125
|
await getSiteConfig();
|
|
123
126
|
}
|
|
124
127
|
// bulk insert to jobs collection without descriptions first
|
|
125
128
|
const jobsData = sourcePositions.map(position => {
|
|
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
|
-
|
|
129
|
+
const basicJob = {
|
|
130
|
+
_id: position.id,
|
|
131
|
+
title: position.name || '',
|
|
132
|
+
slug: generateSlug(position.name || ''),
|
|
133
|
+
department: position.department?.label || 'Other',
|
|
134
|
+
cityText: normalizeString(position.location?.city),
|
|
135
|
+
location: position.location && Object.keys(position.location).length > 0
|
|
136
|
+
? position.location
|
|
137
|
+
: {
|
|
138
|
+
countryCode: "",
|
|
139
|
+
country: "",
|
|
140
|
+
city: "",
|
|
141
|
+
postalCode: "",
|
|
142
|
+
address: "",
|
|
143
|
+
manual: false,
|
|
144
|
+
remote: false,
|
|
145
|
+
regionCode: ""
|
|
146
|
+
},
|
|
147
|
+
country: position.location?.country || '',
|
|
148
|
+
remote: position.location?.remote || false,
|
|
149
|
+
language: position.language?.label || '',
|
|
150
|
+
brand: siteconfig.disableMultiBrand==="false" ? getBrand(position.customField) : '',
|
|
151
|
+
jobDescription: null, // Will be filled later
|
|
152
|
+
employmentType: position.typeOfEmployment.label,
|
|
153
|
+
releasedDate: position.releasedDate,
|
|
154
|
+
refId: position.refNumber
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, customFieldsValues);
|
|
158
|
+
getEmploymentType(position, customFieldsValues);
|
|
159
|
+
getLocation(position,basicJob);
|
|
160
|
+
|
|
161
|
+
if(templateType === TEMPLATE_TYPE.INTERNAL){
|
|
162
|
+
getVisibility(position,customFieldsValues);
|
|
163
|
+
}
|
|
164
|
+
return basicJob;
|
|
162
165
|
});
|
|
163
166
|
|
|
164
167
|
if (siteconfig.customFields==="true") {
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
await populateCustomFieldsCollection(customFieldsLabels,templateType);
|
|
169
|
+
await populateCustomValuesCollection(customFieldsValues);
|
|
167
170
|
}
|
|
171
|
+
|
|
168
172
|
// Sort jobs by title (ascending, case-insensitive, numeric-aware)
|
|
169
173
|
jobsData.sort((a, b) => {
|
|
170
174
|
const titleA = a.title || '';
|
|
@@ -202,8 +206,8 @@ async function saveJobsDataToCMS() {
|
|
|
202
206
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
203
207
|
}
|
|
204
208
|
|
|
205
|
-
async function insertJobsReference(valueId) {
|
|
206
|
-
await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,
|
|
209
|
+
async function insertJobsReference(id, valueId) {
|
|
210
|
+
await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES, id, Array.from(customValuesToJobs[valueId]));
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
async function populateCustomFieldsCollection(customFields,templateType) {
|
|
@@ -222,33 +226,38 @@ async function populateCustomFieldsCollection(customFields,templateType) {
|
|
|
222
226
|
}
|
|
223
227
|
async function populateCustomValuesCollection(customFieldsValues) {
|
|
224
228
|
let valuesToinsert=[]
|
|
229
|
+
|
|
225
230
|
for (const fieldId of Object.keys(customFieldsValues)) {
|
|
226
231
|
const valuesMap = customFieldsValues[fieldId] || {};
|
|
232
|
+
|
|
227
233
|
for (const valueId of Object.keys(valuesMap)) {
|
|
228
234
|
valuesToinsert.push({
|
|
229
|
-
|
|
235
|
+
valueId,
|
|
230
236
|
title: valuesMap[valueId],
|
|
231
237
|
customField: fieldId,
|
|
232
|
-
count:customValuesToJobs[valueId].size,
|
|
233
|
-
jobIds:Array.from(customValuesToJobs[valueId]),
|
|
238
|
+
count: customValuesToJobs[valueId].size,
|
|
239
|
+
jobIds: Array.from(customValuesToJobs[valueId]),
|
|
234
240
|
})
|
|
235
241
|
}
|
|
236
|
-
|
|
237
242
|
}
|
|
238
243
|
await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
|
|
239
244
|
}
|
|
245
|
+
|
|
240
246
|
async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
|
|
241
247
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|
|
242
248
|
|
|
243
249
|
try {
|
|
244
250
|
let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
|
|
251
|
+
|
|
245
252
|
if (siteconfig.customFields==="true") {
|
|
246
|
-
let customValues=await getAllCustomValues();
|
|
253
|
+
let customValues = await getAllCustomValues();
|
|
254
|
+
|
|
247
255
|
console.log("inserting jobs references to custom values collection");
|
|
248
256
|
console.log("customValues: ",customValues)
|
|
249
257
|
console.log("customValues.items: ",customValues.items)
|
|
258
|
+
|
|
250
259
|
for (const value of customValues.items) {
|
|
251
|
-
await insertJobsReference(value._id);
|
|
260
|
+
await insertJobsReference(value._id, value.valueId);
|
|
252
261
|
}
|
|
253
262
|
console.log("inserted jobs references to custom values collection successfully");
|
|
254
263
|
}
|
|
@@ -360,10 +369,12 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
|
|
|
360
369
|
return { success: false, error: err.message };
|
|
361
370
|
}
|
|
362
371
|
}
|
|
372
|
+
|
|
363
373
|
async function getAllCustomValues() {
|
|
364
374
|
let customValuesQuery = await wixData.query(COLLECTIONS.CUSTOM_VALUES).limit(1000).find();
|
|
365
375
|
return customValuesQuery;
|
|
366
376
|
}
|
|
377
|
+
|
|
367
378
|
async function getJobsWithNoDescriptions() {
|
|
368
379
|
let jobswithoutdescriptionsQuery = await wixData
|
|
369
380
|
.query(COLLECTIONS.JOBS)
|
|
@@ -489,6 +500,7 @@ async function referenceJobs() {
|
|
|
489
500
|
}
|
|
490
501
|
|
|
491
502
|
async function syncJobsFast() {
|
|
503
|
+
try{
|
|
492
504
|
console.log("Syncing jobs fast");
|
|
493
505
|
await createCollections();
|
|
494
506
|
await clearCollections();
|
|
@@ -505,6 +517,12 @@ async function syncJobsFast() {
|
|
|
505
517
|
await aggregateJobs();
|
|
506
518
|
await referenceJobs();
|
|
507
519
|
console.log("syncing jobs fast finished successfully");
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
error.message="Error syncing jobs: "+error.message;
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
|
|
508
526
|
}
|
|
509
527
|
|
|
510
528
|
|
|
@@ -522,7 +540,7 @@ async function clearCollections() {
|
|
|
522
540
|
}
|
|
523
541
|
|
|
524
542
|
async function markTemplateAsExternal() {
|
|
525
|
-
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
|
|
543
|
+
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE, null, 'singleItem');
|
|
526
544
|
const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
527
545
|
templateType: TEMPLATE_TYPE.EXTERNAL
|
|
528
546
|
});
|
|
@@ -530,7 +548,7 @@ async function markTemplateAsExternal() {
|
|
|
530
548
|
}
|
|
531
549
|
|
|
532
550
|
async function markTemplateAsInternal() {
|
|
533
|
-
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
|
|
551
|
+
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE, null, 'singleItem');
|
|
534
552
|
const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
535
553
|
templateType: TEMPLATE_TYPE.INTERNAL
|
|
536
554
|
});
|
package/backend/queries.js
CHANGED
|
@@ -21,7 +21,7 @@ async function getPositionsByField(field, value) {
|
|
|
21
21
|
async function getPositionWithMultiRefField(jobId)
|
|
22
22
|
{
|
|
23
23
|
return wixData
|
|
24
|
-
.queryReferenced(COLLECTIONS.JOBS,jobId,JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
|
|
24
|
+
.queryReferenced(COLLECTIONS.JOBS, jobId,JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
|
|
25
25
|
.then(result => result.items);
|
|
26
26
|
}
|
|
27
27
|
|
package/backend/secretsData.js
CHANGED
|
@@ -37,9 +37,14 @@ const elevatedQuery = auth.elevate(wixData.query);
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async function getApiKeys() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
try{
|
|
41
|
+
const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
|
|
42
|
+
const templateType = await getTemplateTypeFromCMS();
|
|
43
|
+
return {companyId,templateType};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Error getting api keys: ", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ let allsecondarySearchJobs=[] // secondary search results that are displayed in
|
|
|
21
21
|
let currentSecondarySearchJobs=[] // current secondary search results that are displayed in the jobs repeater
|
|
22
22
|
let secondarySearchIsFilled=false // whether the secondary search is filled with results
|
|
23
23
|
let keywordAllJobs; // all jobs that are displayed in the jobs repeater when the keyword is filled
|
|
24
|
+
let ActivateURLOnchange=true; // whether to activate the url onchange
|
|
24
25
|
const pagination = {
|
|
25
26
|
pageSize: 10,
|
|
26
27
|
currentPage: 1,
|
|
@@ -33,7 +34,7 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
await loadData(_$w);
|
|
36
|
-
loadJobsRepeater(_$w);
|
|
37
|
+
await loadJobsRepeater(_$w); // if we remove the await here the job list will be flaky , it doesn't fill it properly
|
|
37
38
|
loadPrimarySearchRepeater(_$w);
|
|
38
39
|
await loadFilters(_$w);
|
|
39
40
|
loadSelectedValuesRepeater(_$w);
|
|
@@ -52,15 +53,23 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
async function handleBackAndForth(_$w){
|
|
56
|
+
if(ActivateURLOnchange) {
|
|
55
57
|
const newQueryParams=await location.query();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
console.log("newQueryParams: ", newQueryParams);
|
|
59
|
+
ActivateURLOnchange=false;
|
|
60
|
+
await clearAll(_$w,true);
|
|
61
|
+
await handleUrlParams(_$w,newQueryParams,true);
|
|
62
|
+
ActivateURLOnchange=true;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
else{
|
|
66
|
+
ActivateURLOnchange=true;
|
|
67
|
+
}
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
async function clearAll(_$w,urlOnChange=false) {
|
|
63
71
|
if(selectedByField.size>0 || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value) {
|
|
72
|
+
|
|
64
73
|
for(const field of allfields) {
|
|
65
74
|
_$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
|
|
66
75
|
}
|
|
@@ -71,9 +80,13 @@ async function clearAll(_$w,urlOnChange=false) {
|
|
|
71
80
|
currentJobs=alljobs;
|
|
72
81
|
keywordAllJobs=undefined;
|
|
73
82
|
if(!urlOnChange) {
|
|
83
|
+
console.log("inside clearAll removing url params");
|
|
84
|
+
ActivateURLOnchange=false;
|
|
74
85
|
queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
|
|
86
|
+
|
|
87
|
+
await updateJobsAndNumbersAndFilters(_$w,true);
|
|
75
88
|
}
|
|
76
|
-
|
|
89
|
+
|
|
77
90
|
}
|
|
78
91
|
}
|
|
79
92
|
|
|
@@ -113,16 +126,16 @@ function handleFilterInMobile(_$w) {
|
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
|
|
116
|
-
async function handleUrlParams(_$w,urlParams) {
|
|
129
|
+
async function handleUrlParams(_$w,urlParams,handleBackAndForth=false) {
|
|
117
130
|
try {
|
|
118
131
|
let applyFiltering=false;
|
|
119
132
|
let currentApplyFilterFlag=false;
|
|
120
133
|
//apply this first to determine all jobs
|
|
121
134
|
if(urlParams.keyword) {
|
|
122
|
-
applyFiltering
|
|
123
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value
|
|
124
|
-
currentJobs
|
|
125
|
-
keywordAllJobs
|
|
135
|
+
applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
|
|
136
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
|
|
137
|
+
currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
|
|
138
|
+
keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
for (const url of possibleUrlParams)
|
|
@@ -136,8 +149,9 @@ async function handleUrlParams(_$w,urlParams) {
|
|
|
136
149
|
}
|
|
137
150
|
currentApplyFilterFlag=false;
|
|
138
151
|
}
|
|
139
|
-
if(applyFiltering || keywordAllJobs) {
|
|
152
|
+
if(applyFiltering || keywordAllJobs || handleBackAndForth) {
|
|
140
153
|
await updateJobsAndNumbersAndFilters(_$w);
|
|
154
|
+
|
|
141
155
|
}
|
|
142
156
|
|
|
143
157
|
if(urlParams.page) {
|
|
@@ -176,17 +190,15 @@ async function handleParams(_$w,param,values) {
|
|
|
176
190
|
for(const value of valuesAsArray) {
|
|
177
191
|
|
|
178
192
|
const decodedValue = decodeURIComponent(value);
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const option=getCorrectOption(decodedValue,options,param);
|
|
193
|
+
const options = optionsByFieldId.get(field._id);
|
|
194
|
+
const option = getCorrectOption(decodedValue, options, param);
|
|
183
195
|
|
|
184
196
|
if(option) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
applyFiltering=true;
|
|
189
|
-
dontUpdateThisCheckBox=field._id;
|
|
197
|
+
const optionIndex = getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
|
|
198
|
+
selectedIndices.push(optionIndex);
|
|
199
|
+
existing.push(option.value);
|
|
200
|
+
applyFiltering = true;
|
|
201
|
+
dontUpdateThisCheckBox = field._id;
|
|
190
202
|
}
|
|
191
203
|
else {
|
|
192
204
|
console.warn(`${param} value not found in dropdown options`);
|
|
@@ -238,6 +250,7 @@ async function handleParams(_$w,param,values) {
|
|
|
238
250
|
const field=getFieldById(fieldId,allfields);
|
|
239
251
|
let fieldTitle=field.title.toLowerCase().replace(' ', '');
|
|
240
252
|
fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
|
|
253
|
+
ActivateURLOnchange=false;
|
|
241
254
|
if (updated.length) {
|
|
242
255
|
selectedByField.set(fieldId, updated);
|
|
243
256
|
queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
|
|
@@ -245,10 +258,12 @@ async function handleParams(_$w,param,values) {
|
|
|
245
258
|
selectedByField.delete(fieldId);
|
|
246
259
|
queryParams.remove([fieldTitle ]);
|
|
247
260
|
}
|
|
261
|
+
|
|
248
262
|
const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
|
|
249
263
|
const nextVals = currentVals.filter(v => v !== valueId);
|
|
250
264
|
_$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
|
|
251
265
|
await updateJobsAndNumbersAndFilters(_$w);
|
|
266
|
+
|
|
252
267
|
});
|
|
253
268
|
});
|
|
254
269
|
updateSelectedValuesRepeater(_$w);
|
|
@@ -264,14 +279,14 @@ async function loadData() {
|
|
|
264
279
|
currentJobs=alljobs;
|
|
265
280
|
}
|
|
266
281
|
if(Object.keys(valueToJobs).length === 0){
|
|
267
|
-
allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
|
|
282
|
+
allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
|
|
268
283
|
for (const value of allvaluesobjects) {
|
|
269
|
-
valueToJobs[value.
|
|
284
|
+
valueToJobs[value.valueId]= value.jobIds;
|
|
270
285
|
}
|
|
271
286
|
}
|
|
272
287
|
if(allfields.length===0) {
|
|
273
|
-
allfields=await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
|
|
274
|
-
allfields.push({_id:"Location",title:"Location"});
|
|
288
|
+
allfields = await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
|
|
289
|
+
allfields.push({ _id:"Location", title:"Location" });
|
|
275
290
|
}
|
|
276
291
|
} catch (error) {
|
|
277
292
|
console.error('Failed to load data:', error);
|
|
@@ -308,44 +323,47 @@ async function loadJobsRepeater(_$w) {
|
|
|
308
323
|
async function loadFilters(_$w) {
|
|
309
324
|
try {
|
|
310
325
|
// 1) Load all categories (fields)
|
|
311
|
-
const cities=await getAllRecords(COLLECTIONS.CITIES);
|
|
326
|
+
const cities = await getAllRecords(COLLECTIONS.CITIES);
|
|
312
327
|
for(const city of cities) {
|
|
313
|
-
valueToJobs[city._id]=city.jobIds;
|
|
328
|
+
valueToJobs[city._id] = city.jobIds;
|
|
314
329
|
}
|
|
315
330
|
// 2) Load all values once and group them by referenced field
|
|
316
331
|
let valuesByFieldId = groupValuesByField(allvaluesobjects, CUSTOM_VALUES_COLLECTION_FIELDS.CUSTOM_FIELD);
|
|
317
332
|
valuesByFieldId.set("Location",cities)
|
|
318
|
-
// Build CheckboxGroup options for this field
|
|
319
|
-
|
|
333
|
+
// Build CheckboxGroup options for this field
|
|
320
334
|
const counter={}
|
|
321
335
|
for(const city of cities) {
|
|
322
336
|
counter[city.city]=city.count
|
|
323
337
|
}
|
|
338
|
+
|
|
324
339
|
for(const [key, value] of valuesByFieldId) {
|
|
325
|
-
const field=getFieldById(key,allfields);
|
|
340
|
+
const field = getFieldById(key,allfields);
|
|
326
341
|
let originalOptions=[];
|
|
327
|
-
if(key==="Location") {
|
|
328
|
-
originalOptions=value.map(city=>({
|
|
342
|
+
if(key === "Location") {
|
|
343
|
+
originalOptions = value.map(city=>({
|
|
329
344
|
label: city.city,
|
|
330
345
|
value: city._id
|
|
331
346
|
}));
|
|
332
347
|
}
|
|
333
348
|
else{
|
|
334
|
-
originalOptions=value
|
|
349
|
+
originalOptions = value
|
|
335
350
|
}
|
|
351
|
+
|
|
336
352
|
optionsByFieldId.set(key, originalOptions);
|
|
353
|
+
|
|
337
354
|
for (const val of allvaluesobjects) {
|
|
338
355
|
counter[val.title]=val.count
|
|
339
356
|
}
|
|
340
357
|
countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
|
|
341
|
-
updateOptionsUI(_$w,field.title, field._id, ''); // no search query
|
|
358
|
+
updateOptionsUI(_$w, field.title, field._id, ''); // no search query
|
|
359
|
+
|
|
342
360
|
_$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
|
|
343
361
|
_$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
|
|
344
362
|
dontUpdateThisCheckBox=field._id;
|
|
345
363
|
const selected = ev.target.value; // array of selected value IDs
|
|
346
364
|
let fieldTitle=field.title.toLowerCase().replace(' ', '');
|
|
347
365
|
fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
|
|
348
|
-
|
|
366
|
+
ActivateURLOnchange=false;
|
|
349
367
|
if (selected && selected.length) {
|
|
350
368
|
selectedByField.set(field._id, selected);
|
|
351
369
|
if(fieldTitle==="brand" || fieldTitle==="storename") {
|
|
@@ -361,10 +379,11 @@ async function loadJobsRepeater(_$w) {
|
|
|
361
379
|
selectedByField.delete(field._id);
|
|
362
380
|
queryParams.remove([fieldTitle ]);
|
|
363
381
|
}
|
|
364
|
-
|
|
382
|
+
|
|
383
|
+
console.log("selectedByField: ",selectedByField)
|
|
365
384
|
await updateJobsAndNumbersAndFilters(_$w);
|
|
366
|
-
|
|
367
385
|
});
|
|
386
|
+
|
|
368
387
|
const runFilter = debounce(() => {
|
|
369
388
|
const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
|
|
370
389
|
updateOptionsUI(_$w, field.title, field._id, query);
|
|
@@ -379,11 +398,11 @@ async function loadJobsRepeater(_$w) {
|
|
|
379
398
|
}
|
|
380
399
|
}
|
|
381
400
|
|
|
382
|
-
function getValueFromValueId(valueIds,value) {
|
|
383
|
-
let valueLabels=[];
|
|
401
|
+
function getValueFromValueId(valueIds, value) {
|
|
402
|
+
let valueLabels = [];
|
|
384
403
|
let currentVal
|
|
385
|
-
for(const valueId of valueIds) {
|
|
386
|
-
currentVal=value.find(val=>val.value===valueId);
|
|
404
|
+
for (const valueId of valueIds) {
|
|
405
|
+
currentVal = value.find(val => val.value === valueId);
|
|
387
406
|
if(currentVal) {
|
|
388
407
|
valueLabels.push(currentVal.label);
|
|
389
408
|
}
|
|
@@ -392,10 +411,10 @@ function getValueFromValueId(valueIds,value) {
|
|
|
392
411
|
}
|
|
393
412
|
|
|
394
413
|
async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
|
|
395
|
-
await applyJobFilters(_$w); // re-query jobs
|
|
414
|
+
await applyJobFilters(_$w,clearAll); // re-query jobs
|
|
396
415
|
await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
|
|
397
416
|
await updateSelectedValuesRepeater(_$w);
|
|
398
|
-
updateTotalJobsCountText(_$w);
|
|
417
|
+
updateTotalJobsCountText(_$w);
|
|
399
418
|
}
|
|
400
419
|
|
|
401
420
|
function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
|
|
@@ -442,7 +461,8 @@ function getValueFromValueId(valueIds,value) {
|
|
|
442
461
|
}
|
|
443
462
|
}
|
|
444
463
|
|
|
445
|
-
async function applyJobFilters(_$w) {
|
|
464
|
+
async function applyJobFilters(_$w,clearAll=false) {
|
|
465
|
+
// if(!clearAll) {
|
|
446
466
|
let tempFilteredJobs=[];
|
|
447
467
|
let finalFilteredJobs=[];
|
|
448
468
|
secondarySearchIsFilled? finalFilteredJobs=allsecondarySearchJobs:finalFilteredJobs=alljobs;
|
|
@@ -476,12 +496,13 @@ function getValueFromValueId(valueIds,value) {
|
|
|
476
496
|
finalFilteredJobs=tempFilteredJobs;
|
|
477
497
|
tempFilteredJobs=[];
|
|
478
498
|
}
|
|
479
|
-
|
|
480
499
|
secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
|
|
481
500
|
|
|
482
501
|
|
|
483
502
|
let jobsFirstPage=[];
|
|
503
|
+
console.log("currentSecondarySearchJobs: ",currentSecondarySearchJobs)
|
|
484
504
|
secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
|
|
505
|
+
console.log("jobsFirstPage: ",jobsFirstPage)
|
|
485
506
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
|
|
486
507
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
|
|
487
508
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
|
|
@@ -494,6 +515,7 @@ function getValueFromValueId(valueIds,value) {
|
|
|
494
515
|
pagination.currentPage=1;
|
|
495
516
|
handlePaginationButtons(_$w);
|
|
496
517
|
}
|
|
518
|
+
// }
|
|
497
519
|
|
|
498
520
|
function handlePaginationButtons(_$w)
|
|
499
521
|
{
|
|
@@ -517,14 +539,15 @@ function handlePaginationButtons(_$w)
|
|
|
517
539
|
}
|
|
518
540
|
|
|
519
541
|
function handlePageUrlParam() {
|
|
542
|
+
ActivateURLOnchange=false;
|
|
520
543
|
if(pagination.currentPage==1)
|
|
521
544
|
{
|
|
545
|
+
|
|
522
546
|
queryParams.remove(["page"]);
|
|
523
547
|
}
|
|
524
548
|
else{
|
|
525
549
|
queryParams.add({ page: pagination.currentPage });
|
|
526
550
|
}
|
|
527
|
-
|
|
528
551
|
}
|
|
529
552
|
async function refreshFacetCounts(_$w,clearAll=false) {
|
|
530
553
|
|
|
@@ -543,7 +566,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
|
|
|
543
566
|
const currentJobsIds=jobs.map(job=>job._id);
|
|
544
567
|
|
|
545
568
|
for (const fieldId of fieldIds) {
|
|
546
|
-
let currentoptions=optionsByFieldId.get(fieldId)
|
|
569
|
+
let currentoptions = optionsByFieldId.get(fieldId)
|
|
547
570
|
let counter=new Map();
|
|
548
571
|
for(const option of currentoptions) {
|
|
549
572
|
for (const jobId of currentJobsIds) {
|
|
@@ -556,8 +579,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
|
|
|
556
579
|
}
|
|
557
580
|
}
|
|
558
581
|
|
|
559
|
-
|
|
560
|
-
function updateSelectedValuesRepeater(_$w) {
|
|
582
|
+
function updateSelectedValuesRepeater(_$w) {
|
|
561
583
|
const selectedItems = [];
|
|
562
584
|
for (const [fieldId, valueIds] of selectedByField.entries()) {
|
|
563
585
|
const opts = optionsByFieldId.get(fieldId) || [];
|
|
@@ -568,7 +590,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
|
|
|
568
590
|
}
|
|
569
591
|
}
|
|
570
592
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER).data = selectedItems;
|
|
571
|
-
|
|
593
|
+
}
|
|
572
594
|
|
|
573
595
|
|
|
574
596
|
|
|
@@ -600,15 +622,16 @@ async function secondarySearch(_$w,query) {
|
|
|
600
622
|
await refreshFacetCounts(_$w);
|
|
601
623
|
return allsecondarySearchJobs;
|
|
602
624
|
}
|
|
603
|
-
|
|
625
|
+
function bindSearchInput(_$w) {
|
|
604
626
|
try {
|
|
605
|
-
bindPrimarySearch(_$w,
|
|
627
|
+
bindPrimarySearch(_$w,allvaluesobjects,alljobs);
|
|
606
628
|
|
|
607
629
|
const secondarySearchDebounced = debounce(async () => {
|
|
608
630
|
const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || '').toLowerCase().trim();
|
|
609
631
|
await secondarySearch(_$w, query);
|
|
610
632
|
}, 150);
|
|
611
633
|
|
|
634
|
+
|
|
612
635
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).onInput(secondarySearchDebounced);
|
|
613
636
|
|
|
614
637
|
} catch (error) {
|
package/pages/homePage.js
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const {
|
|
2
|
+
debounce,
|
|
3
|
+
getFilter,
|
|
4
|
+
} = require('../public/filterUtils');
|
|
5
|
+
const { handleOnLocationClick } = require('../public/mapUtils');
|
|
6
|
+
const { filterBrokenMarkers } = require('../public/utils');
|
|
4
7
|
const { location } = require('@wix/site-location');
|
|
5
8
|
const {wixData} = require('wix-data');
|
|
6
9
|
const { COLLECTIONS } = require('../backend/collectionConsts');
|
|
7
|
-
const { bindPrimarySearch,
|
|
10
|
+
const { bindPrimarySearch,getAllRecords,loadPrimarySearchRepeater } = require('./pagesUtils');
|
|
11
|
+
|
|
8
12
|
|
|
9
13
|
let thisObjectVar;
|
|
10
14
|
let searchByCityFlag=false;
|
|
11
15
|
let loadedCategories=false;
|
|
12
16
|
|
|
13
|
-
async function homePageOnReady(_$w,thisObject
|
|
17
|
+
async function homePageOnReady(_$w,thisObject=null) {
|
|
14
18
|
const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
|
|
15
19
|
const siteconfig = queryResult.items[0];
|
|
16
20
|
|
|
17
21
|
if(siteconfig.twg) {
|
|
18
|
-
const
|
|
19
|
-
|
|
22
|
+
const allJobs = await getAllRecords(COLLECTIONS.JOBS);
|
|
23
|
+
const allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
|
|
24
|
+
|
|
25
|
+
bindPrimarySearch(_$w, allvaluesobjects, allJobs);
|
|
20
26
|
loadPrimarySearchRepeater(_$w)
|
|
21
27
|
console.log("siteconfig.twg: ",siteconfig.twg);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
|
|
29
|
+
if(siteconfig.twg === "external") {
|
|
30
|
+
bindTeamRepeater(_$w)
|
|
31
|
+
bindViewAllButton(_$w)
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
34
|
else{
|
|
28
|
-
thisObjectVar
|
|
35
|
+
thisObjectVar=thisObject;
|
|
29
36
|
bind(_$w);
|
|
30
37
|
init(_$w);
|
|
31
38
|
}
|
|
32
|
-
|
|
33
|
-
}
|
|
39
|
+
}
|
|
34
40
|
|
|
35
41
|
function bind(_$w) {
|
|
42
|
+
|
|
36
43
|
bindTeamRepeater(_$w);
|
|
37
44
|
|
|
45
|
+
|
|
38
46
|
_$w('#citiesDataset').onReady(async () => {
|
|
39
47
|
const numOfItems = await _$w('#citiesDataset').getTotalCount();
|
|
40
48
|
const items = await _$w('#citiesDataset').getItems(0, numOfItems);
|
|
@@ -48,8 +56,8 @@ function bind(_$w) {
|
|
|
48
56
|
latitude: location.latitude,
|
|
49
57
|
longitude: location.longitude
|
|
50
58
|
},
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
address: item.locationAddress.formatted,
|
|
60
|
+
title: item.title,
|
|
53
61
|
link: cityLinkUrl,
|
|
54
62
|
linkTitle:`View ${item.count} Open Positions`
|
|
55
63
|
};
|
|
@@ -98,6 +106,7 @@ function bindTeamRepeater(_$w) {
|
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
function bindViewAllButton(_$w) {
|
|
109
|
+
|
|
101
110
|
_$w('#viewAllCategoriesButton').onClick(()=>{
|
|
102
111
|
if(!loadedCategories) {
|
|
103
112
|
loadedCategories=true;
|
|
@@ -116,11 +125,11 @@ function bindViewAllButton(_$w) {
|
|
|
116
125
|
|
|
117
126
|
|
|
118
127
|
function init(_$w) {
|
|
119
|
-
const debouncedInput = debounce(()
|
|
128
|
+
const debouncedInput = debounce(()=>handleSearchInput(_$w), 400,thisObjectVar);
|
|
120
129
|
|
|
121
130
|
_$w('#searchInput').onInput(debouncedInput);
|
|
122
131
|
_$w('#searchInput').maxLength = 40;
|
|
123
|
-
_$w('#searchButton').onClick(()
|
|
132
|
+
_$w('#searchButton').onClick(()=>handleSearch(_$w('#searchInput').value));
|
|
124
133
|
|
|
125
134
|
_$w('#searchInput').onKeyPress((event) => {
|
|
126
135
|
if (event.key === 'Enter') {
|
|
@@ -165,17 +174,17 @@ async function handleSearchInput(_$w) {
|
|
|
165
174
|
count = _$w('#jobsDataset').getTotalCount();
|
|
166
175
|
|
|
167
176
|
if (count > 0) {
|
|
168
|
-
searchByCityFlag
|
|
177
|
+
searchByCityFlag=false;
|
|
169
178
|
_$w('#resultsContainer').expand();
|
|
170
179
|
_$w('#searchMultiStateBox').changeState('results');
|
|
171
180
|
} else {
|
|
172
|
-
filter
|
|
181
|
+
filter=await getFilter(searchByCity);
|
|
173
182
|
await _$w('#jobsDataset').setFilter(filter);
|
|
174
183
|
await _$w('#jobsDataset').refresh();
|
|
175
184
|
count = _$w('#jobsDataset').getTotalCount();
|
|
176
|
-
if(
|
|
185
|
+
if(count > 0)
|
|
177
186
|
{
|
|
178
|
-
searchByCityFlag
|
|
187
|
+
searchByCityFlag=true;
|
|
179
188
|
_$w('#resultsContainer').expand();
|
|
180
189
|
_$w('#searchMultiStateBox').changeState('results');
|
|
181
190
|
}
|
package/pages/pagesUtils.js
CHANGED
|
@@ -3,7 +3,6 @@ const { JOBS_COLLECTION_FIELDS,COLLECTIONS } = require('../backend/collectionCon
|
|
|
3
3
|
const { CAREERS_MULTI_BOXES_PAGE_CONSTS,CATEGORY_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
|
|
4
4
|
const { location } = require("@wix/site-location");
|
|
5
5
|
const { normalizeString } = require('../backend/utils');
|
|
6
|
-
const { getFilter } = require('../public/filterUtils');
|
|
7
6
|
|
|
8
7
|
function groupValuesByField(values, refKey) {
|
|
9
8
|
const map = new Map();
|
|
@@ -12,7 +11,7 @@ function groupValuesByField(values, refKey) {
|
|
|
12
11
|
if (!map.has(ref)) map.set(ref, []);
|
|
13
12
|
map.get(ref).push({
|
|
14
13
|
label: v.title ,
|
|
15
|
-
value: v.
|
|
14
|
+
value: v.valueId
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
17
|
return map;
|
|
@@ -85,9 +84,6 @@ function groupValuesByField(values, refKey) {
|
|
|
85
84
|
function loadPrimarySearchRepeater(_$w) {
|
|
86
85
|
|
|
87
86
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
|
|
88
|
-
if(!itemData.title) {
|
|
89
|
-
console.log("!!!!!!!!!!!! itemData has no title: ",itemData);
|
|
90
|
-
}
|
|
91
87
|
$item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_POSITION_BUTTON).label = itemData.title || '';
|
|
92
88
|
});
|
|
93
89
|
|
|
@@ -125,51 +121,55 @@ function loadPrimarySearchRepeater(_$w) {
|
|
|
125
121
|
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
function bindPrimarySearch(_$w, allvaluesobjects) {
|
|
129
|
-
|
|
130
|
-
const handleSearchInput = async () => { await primarySearch(_$w) }
|
|
124
|
+
function bindPrimarySearch(_$w, allvaluesobjects, alljobs) {
|
|
131
125
|
|
|
132
|
-
const primarySearchDebounced = debounce(() =>
|
|
126
|
+
const primarySearchDebounced = debounce(async () => {
|
|
127
|
+
const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value || '').toLowerCase().trim();
|
|
128
|
+
await primarySearch(_$w, query, alljobs);
|
|
129
|
+
}, 300);
|
|
133
130
|
|
|
134
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
|
|
131
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
|
|
135
132
|
await primarySearchDebounced();
|
|
136
133
|
});
|
|
137
134
|
|
|
138
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
|
|
139
|
-
|
|
140
|
-
if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()!=='') {
|
|
141
|
-
await primarySearch(_$w);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
await loadCategoriesListPrimarySearch(_$w,allvaluesobjects);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
135
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
|
|
136
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
|
|
147
137
|
|
|
148
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.
|
|
149
|
-
|
|
150
|
-
}
|
|
138
|
+
if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()!=='') {
|
|
139
|
+
await primarySearch(_$w, _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim(), alljobs);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
await loadCategoriesListPrimarySearch(_$w, allvaluesobjects);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
151
145
|
|
|
152
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.log("_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value: ",_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
|
|
156
|
-
if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
|
|
157
|
-
// _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
|
|
158
|
-
const baseUrl = await location.baseUrl();
|
|
159
|
-
location.to(`${baseUrl}/search`);
|
|
146
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
|
|
147
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
|
|
148
|
+
});
|
|
160
149
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
150
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onKeyPress(async (event) => {
|
|
151
|
+
if( event.key==='Enter') {
|
|
152
|
+
console.log("primary search input key pressed");
|
|
153
|
+
console.log("_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value: ",_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
|
|
154
|
+
|
|
155
|
+
if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
|
|
156
|
+
// _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
|
|
157
|
+
const baseUrl = await location.baseUrl();
|
|
158
|
+
location.to(`${baseUrl}/search`);
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
|
|
163
|
+
const baseUrl = await location.baseUrl();
|
|
164
|
+
location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
|
|
165
|
+
}
|
|
166
166
|
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
167
|
+
});
|
|
169
168
|
|
|
170
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
|
|
169
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
|
|
171
170
|
console.log("primary search button clicked");
|
|
172
171
|
console.log("_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value: ",_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
|
|
172
|
+
|
|
173
173
|
if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
|
|
174
174
|
const baseUrl = await location.baseUrl();
|
|
175
175
|
location.to(`${baseUrl}/search`);
|
|
@@ -182,60 +182,49 @@ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
|
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
async function loadCategoriesListPrimarySearch(_$w,allvaluesobjects) {
|
|
185
|
+
async function loadCategoriesListPrimarySearch(_$w, allvaluesobjects) {
|
|
186
186
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
|
|
187
|
+
|
|
187
188
|
let categoryValues=[]
|
|
188
189
|
for(const value of allvaluesobjects) {
|
|
189
|
-
if(value.customField===CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
|
|
190
|
-
categoryValues.push({title:value.title+` (${value.count})` ,_id:value.
|
|
190
|
+
if(value.customField === CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
|
|
191
|
+
categoryValues.push({title: value.title+` (${value.count})` , _id: value.valueId});
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
async function primarySearch(_$w) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if(query === undefined || query === '') {
|
|
197
|
+
async function primarySearch(_$w,query,alljobs) {
|
|
198
|
+
if(query.length===0 || query===undefined || query==='') {
|
|
200
199
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
|
|
201
200
|
return false;
|
|
202
201
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const searchByCity = [{field: 'location.fullLocation', searchTerm: query}];
|
|
206
|
-
|
|
207
|
-
let filter = await getFilter(searchByTitle);
|
|
208
|
-
|
|
209
|
-
await _$w('#jobsDataset').setFilter(filter);
|
|
210
|
-
await _$w('#jobsDataset').refresh();
|
|
211
|
-
|
|
212
|
-
let count = _$w('#jobsDataset').getTotalCount();
|
|
213
|
-
|
|
214
|
-
if( count > 0 ) {
|
|
215
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
|
|
202
|
+
let filteredJobs=alljobs.filter(job=>job.title.toLowerCase().includes(query));
|
|
203
|
+
if(filteredJobs.length>0) {
|
|
216
204
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
|
|
217
205
|
}
|
|
218
206
|
else {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
count = _$w('#jobsDataset').getTotalCount();
|
|
224
|
-
if (count > 0) {
|
|
225
|
-
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
|
|
207
|
+
console.log("searching by location")
|
|
208
|
+
filteredJobs=alljobs.filter(job=>job.location.fullLocation.toLowerCase().includes(query));
|
|
209
|
+
if(filteredJobs.length>0) {
|
|
226
210
|
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
|
|
227
211
|
}
|
|
228
212
|
else{
|
|
229
|
-
|
|
213
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
|
|
230
214
|
}
|
|
231
215
|
}
|
|
216
|
+
_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data = filteredJobs
|
|
217
|
+
return filteredJobs.length>0;
|
|
218
|
+
|
|
232
219
|
}
|
|
233
220
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
221
|
+
async function getValueFromValueId(valueId) {
|
|
222
|
+
const result = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
|
|
223
|
+
console.log("result: ",result);
|
|
224
|
+
console.log("valueId: ",valueId);
|
|
225
|
+
|
|
226
|
+
return result.find(value => value.valueId === valueId);
|
|
227
|
+
}
|
|
239
228
|
|
|
240
229
|
async function getLatestJobsByValue(Value) {
|
|
241
230
|
const jobs=Value.multiRefJobsCustomValues;
|
package/pages/positionPage.js
CHANGED
|
@@ -15,7 +15,6 @@ const {
|
|
|
15
15
|
console.log("positionPageOnReady called");
|
|
16
16
|
await bind(_$w);
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -58,7 +57,7 @@ async function getCategoryValue(customValues) {
|
|
|
58
57
|
_$w('#jobCategory').text = categoryValue.title;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
const relatedJobs = await getRelatedJobs({ categoryValueId:categoryValue._id, itemId: item._id ,limit:5});
|
|
60
|
+
const relatedJobs = await getRelatedJobs({ categoryValueId: categoryValue._id, itemId: item._id ,limit:5});
|
|
62
61
|
_$w('#relatedJobsRepNoDepartment').onItemReady(($item, itemData) => {
|
|
63
62
|
$item('#relatedJobTitle').text = itemData.title;
|
|
64
63
|
$item('#relatedJobLocation').text = itemData.location.fullLocation;
|
|
@@ -124,8 +123,6 @@ async function getCategoryValue(customValues) {
|
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
async function getRelatedJobs({ categoryValueId, itemId, limit = 1000 }) {
|
|
127
|
-
|
|
128
|
-
|
|
129
126
|
const relatedJobs=await wixData.query(COLLECTIONS.JOBS).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES).hasSome(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,[categoryValueId]).ne("_id",itemId).limit(limit).find();
|
|
130
127
|
return relatedJobs.items;
|
|
131
128
|
}
|
|
@@ -32,16 +32,16 @@ async function handlePeopleSection(_$w) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async function handleRecentJobsSection(_$w) {
|
|
35
|
-
|
|
36
|
-
|
|
37
35
|
if(supportTeamsPageIds.excludeValues.has(currentItem.title_fld)) {
|
|
38
36
|
console.log("Value is excluded , collapsing recently Jobs Section ");
|
|
39
|
-
await collapseSection(_$w,supportTeamsPageSections.RECENT_JOBS);
|
|
37
|
+
await collapseSection(_$w, supportTeamsPageSections.RECENT_JOBS);
|
|
40
38
|
return;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
40
|
+
|
|
41
|
+
const valueId = supportTeamsPageIds.valueToValueIdMap[currentItem.title_fld]
|
|
42
|
+
const Value = await getValueFromValueId(valueId);
|
|
43
|
+
|
|
44
|
+
if( Value === undefined ) {
|
|
45
45
|
console.log("Value is undefined , collapsing recently Jobs Section ");
|
|
46
46
|
await collapseSection(_$w,supportTeamsPageSections.RECENT_JOBS);
|
|
47
47
|
return;
|
package/public/filterUtils.js
CHANGED