sr-npm 3.1.7 → 3.1.9

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.
@@ -11,7 +11,6 @@ const COLLECTIONS = {
11
11
  SUPPORT_TEAMS: 'SupportTeams',
12
12
 
13
13
  }
14
-
15
14
  const JOBS_COLLECTION_FIELDS = {
16
15
  LOCATION: 'location',
17
16
  TITLE: 'title',
@@ -35,31 +34,25 @@ const JOBS_COLLECTION_FIELDS = {
35
34
  RELEASED_DATE: 'releasedDate',
36
35
  REF_ID: 'refId',
37
36
  }
38
-
39
37
  const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
40
38
  TITLE: 'title',
41
39
  COUNT: 'count',
42
40
  IMAGE: 'image',
43
41
  }
44
-
45
42
  const CUSTOM_VALUES_COLLECTION_FIELDS = {
46
- VALUE_ID: 'valueId',
47
43
  TITLE: 'title',
48
44
  CUSTOM_FIELD: 'customField',
49
45
  MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
50
46
  count: 'count',
51
47
  JOB_IDS: 'jobIds',
52
48
  }
53
-
54
49
  const CUSTOM_FIELDS_COLLECTION_FIELDS = {
55
50
  TITLE: 'title',
56
51
  }
57
-
58
52
  const BRANDS_COLLECTION_FIELDS = {
59
53
  TITLE: 'title',
60
54
  COUNT: 'count',
61
55
  }
62
-
63
56
  const CITIES_COLLECTION_FIELDS = {
64
57
  TITLE: 'title',
65
58
  CITY: 'city',
@@ -68,7 +61,6 @@ const CITIES_COLLECTION_FIELDS = {
68
61
  COUNTRY: 'country',
69
62
  JOB_IDS: 'jobIds',
70
63
  }
71
-
72
64
  const COLLECTIONS_FIELDS = {
73
65
  AMOUNT_OF_JOBS_PER_DEPARTMENT: [
74
66
  {key:'title', type: 'TEXT'},
@@ -93,7 +85,7 @@ const COLLECTIONS_FIELDS = {
93
85
  {key:'language', type: 'TEXT'},
94
86
  {key:'remote', type: 'BOOLEAN'},
95
87
  {key:'jobDescription', type: 'OBJECT'},
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 } } },
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 } } },
97
89
  {key:'cityText', type: 'TEXT'},
98
90
  {key:'applyLink', type: 'URL'},
99
91
  {key:'referFriendLink', type: 'URL'},
@@ -122,7 +114,6 @@ const COLLECTIONS_FIELDS = {
122
114
  { key: 'count', type: 'NUMBER' },
123
115
  ],
124
116
  CUSTOM_VALUES: [
125
- {key:'valueId', type: 'TEXT'},
126
117
  {key:'title', type: 'TEXT'},
127
118
  {key:'customField', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_FIELDS } } },
128
119
  {key:'count', type: 'NUMBER'},
package/backend/data.js CHANGED
@@ -40,6 +40,7 @@ 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
+
43
44
  }
44
45
 
45
46
  async function filterBasedOnBrand(positions) {
@@ -92,83 +93,78 @@ function getEmploymentType(position,customFieldsValues) {
92
93
  customValuesToJobs[position.typeOfEmployment.id] ? customValuesToJobs[position.typeOfEmployment.id].add(position.id) : customValuesToJobs[position.typeOfEmployment.id]=new Set([position.id])
93
94
  }
94
95
 
95
- function getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, customFieldsValues) {
96
+ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues) {
96
97
  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
-
101
- const fieldId = normalizeString(field.fieldId)
100
+ const fieldId=normalizeString(field.fieldId)
102
101
  const fieldLabel = field.fieldLabel;
103
- const valueId = normalizeString(field.valueId)
102
+ const valueId=normalizeString(field.valueId)
104
103
  const valueLabel = field.valueLabel
105
104
  customFieldsLabels[fieldId] = fieldLabel
106
-
107
105
  // Build nested dictionary: fieldId -> { valueId: valueLabel }
108
106
  if (!customFieldsValues[fieldId]) {
109
107
  customFieldsValues[fieldId] = {};
110
108
  }
111
109
 
112
110
  customFieldsValues[fieldId][valueId] = valueLabel;
113
- customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId] = new Set([position.id])
111
+ customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId]=new Set([position.id])
114
112
  }
115
113
  }
116
-
117
114
  async function saveJobsDataToCMS() {
118
115
  const positions = await fetchPositionsFromSRAPI();
119
116
  const sourcePositions = await filterBasedOnBrand(positions);
120
117
  const customFieldsLabels = {}
121
118
  const customFieldsValues = {}
122
119
 
123
- const { templateType } = await getApiKeys();
120
+ const {companyId ,templateType} = await getApiKeys();
124
121
  if(siteconfig===undefined) {
125
122
  await getSiteConfig();
126
123
  }
127
124
  // bulk insert to jobs collection without descriptions first
128
125
  const jobsData = sourcePositions.map(position => {
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;
126
+
127
+ const basicJob = {
128
+ _id: position.id,
129
+ title: position.name || '',
130
+ slug: generateSlug(position.name || ''),
131
+ department: position.department?.label || 'Other',
132
+ cityText: normalizeString(position.location?.city),
133
+ location: position.location && Object.keys(position.location).length > 0
134
+ ? position.location
135
+ : {
136
+ countryCode: "",
137
+ country: "",
138
+ city: "",
139
+ postalCode: "",
140
+ address: "",
141
+ manual: false,
142
+ remote: false,
143
+ regionCode: ""
144
+ },
145
+ country: position.location?.country || '',
146
+ remote: position.location?.remote || false,
147
+ language: position.language?.label || '',
148
+ brand: siteconfig.disableMultiBrand==="false" ? getBrand(position.customField) : '',
149
+ jobDescription: null, // Will be filled later
150
+ employmentType: position.typeOfEmployment.label,
151
+ releasedDate: position.releasedDate,
152
+ refId: position.refNumber
153
+ };
154
+
155
+ getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
156
+ getEmploymentType(position,customFieldsValues);
157
+ getLocation(position,basicJob);
158
+ if(templateType===TEMPLATE_TYPE.INTERNAL){
159
+ getVisibility(position,customFieldsValues);
160
+ }
161
+ return basicJob;
165
162
  });
166
163
 
167
164
  if (siteconfig.customFields==="true") {
168
- await populateCustomFieldsCollection(customFieldsLabels,templateType);
169
- await populateCustomValuesCollection(customFieldsValues);
165
+ await populateCustomFieldsCollection(customFieldsLabels,templateType);
166
+ await populateCustomValuesCollection(customFieldsValues);
170
167
  }
171
-
172
168
  // Sort jobs by title (ascending, case-insensitive, numeric-aware)
173
169
  jobsData.sort((a, b) => {
174
170
  const titleA = a.title || '';
@@ -206,8 +202,8 @@ async function saveJobsDataToCMS() {
206
202
  console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
207
203
  }
208
204
 
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]));
205
+ async function insertJobsReference(valueId) {
206
+ await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, Array.from(customValuesToJobs[valueId]));
211
207
  }
212
208
 
213
209
  async function populateCustomFieldsCollection(customFields,templateType) {
@@ -226,38 +222,33 @@ async function populateCustomFieldsCollection(customFields,templateType) {
226
222
  }
227
223
  async function populateCustomValuesCollection(customFieldsValues) {
228
224
  let valuesToinsert=[]
229
-
230
225
  for (const fieldId of Object.keys(customFieldsValues)) {
231
226
  const valuesMap = customFieldsValues[fieldId] || {};
232
-
233
227
  for (const valueId of Object.keys(valuesMap)) {
234
228
  valuesToinsert.push({
235
- valueId,
229
+ _id: valueId,
236
230
  title: valuesMap[valueId],
237
231
  customField: fieldId,
238
- count: customValuesToJobs[valueId].size,
239
- jobIds: Array.from(customValuesToJobs[valueId]),
232
+ count:customValuesToJobs[valueId].size,
233
+ jobIds:Array.from(customValuesToJobs[valueId]),
240
234
  })
241
235
  }
236
+
242
237
  }
243
238
  await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
244
239
  }
245
-
246
240
  async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
247
241
  console.log('🚀 Starting job descriptions update process for ALL jobs');
248
242
 
249
243
  try {
250
244
  let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
251
-
252
245
  if (siteconfig.customFields==="true") {
253
- let customValues = await getAllCustomValues();
254
-
246
+ let customValues=await getAllCustomValues();
255
247
  console.log("inserting jobs references to custom values collection");
256
248
  console.log("customValues: ",customValues)
257
249
  console.log("customValues.items: ",customValues.items)
258
-
259
250
  for (const value of customValues.items) {
260
- await insertJobsReference(value._id, value.valueId);
251
+ await insertJobsReference(value._id);
261
252
  }
262
253
  console.log("inserted jobs references to custom values collection successfully");
263
254
  }
@@ -369,12 +360,10 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
369
360
  return { success: false, error: err.message };
370
361
  }
371
362
  }
372
-
373
363
  async function getAllCustomValues() {
374
364
  let customValuesQuery = await wixData.query(COLLECTIONS.CUSTOM_VALUES).limit(1000).find();
375
365
  return customValuesQuery;
376
366
  }
377
-
378
367
  async function getJobsWithNoDescriptions() {
379
368
  let jobswithoutdescriptionsQuery = await wixData
380
369
  .query(COLLECTIONS.JOBS)
@@ -533,7 +522,7 @@ async function clearCollections() {
533
522
  }
534
523
 
535
524
  async function markTemplateAsExternal() {
536
- await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE, null, 'singleItem');
525
+ await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
537
526
  const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
538
527
  templateType: TEMPLATE_TYPE.EXTERNAL
539
528
  });
@@ -541,7 +530,7 @@ async function markTemplateAsExternal() {
541
530
  }
542
531
 
543
532
  async function markTemplateAsInternal() {
544
- await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE, null, 'singleItem');
533
+ await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
545
534
  const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
546
535
  templateType: TEMPLATE_TYPE.INTERNAL
547
536
  });
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -119,10 +119,10 @@ async function handleUrlParams(_$w,urlParams) {
119
119
  let currentApplyFilterFlag=false;
120
120
  //apply this first to determine all jobs
121
121
  if(urlParams.keyword) {
122
- applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
123
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
124
- currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
125
- keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
122
+ applyFiltering = await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
123
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value = decodeURIComponent(urlParams.keyword);
124
+ currentJobs = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
125
+ keywordAllJobs = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
126
126
  }
127
127
 
128
128
  for (const url of possibleUrlParams)
@@ -176,15 +176,17 @@ async function handleParams(_$w,param,values) {
176
176
  for(const value of valuesAsArray) {
177
177
 
178
178
  const decodedValue = decodeURIComponent(value);
179
- const options = optionsByFieldId.get(field._id);
180
- const option = getCorrectOption(decodedValue, options, param);
179
+
180
+ const options=optionsByFieldId.get(field._id);
181
+
182
+ const option=getCorrectOption(decodedValue,options,param);
181
183
 
182
184
  if(option) {
183
- const optionIndex = getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
184
- selectedIndices.push(optionIndex);
185
- existing.push(option.value);
186
- applyFiltering = true;
187
- dontUpdateThisCheckBox = field._id;
185
+ const optionIndex=getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
186
+ selectedIndices.push(optionIndex);
187
+ existing.push(option.value);
188
+ applyFiltering=true;
189
+ dontUpdateThisCheckBox=field._id;
188
190
  }
189
191
  else {
190
192
  console.warn(`${param} value not found in dropdown options`);
@@ -262,14 +264,14 @@ async function loadData() {
262
264
  currentJobs=alljobs;
263
265
  }
264
266
  if(Object.keys(valueToJobs).length === 0){
265
- allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
267
+ allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
266
268
  for (const value of allvaluesobjects) {
267
- valueToJobs[value.valueId]= value.jobIds;
269
+ valueToJobs[value._id]= value.jobIds;
268
270
  }
269
271
  }
270
272
  if(allfields.length===0) {
271
- allfields = await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
272
- allfields.push({ _id:"Location", title:"Location" });
273
+ allfields=await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
274
+ allfields.push({_id:"Location",title:"Location"});
273
275
  }
274
276
  } catch (error) {
275
277
  console.error('Failed to load data:', error);
@@ -306,67 +308,63 @@ async function loadJobsRepeater(_$w) {
306
308
  async function loadFilters(_$w) {
307
309
  try {
308
310
  // 1) Load all categories (fields)
309
- const cities = await getAllRecords(COLLECTIONS.CITIES);
311
+ const cities=await getAllRecords(COLLECTIONS.CITIES);
310
312
  for(const city of cities) {
311
- valueToJobs[city._id] = city.jobIds;
313
+ valueToJobs[city._id]=city.jobIds;
312
314
  }
313
315
  // 2) Load all values once and group them by referenced field
314
316
  let valuesByFieldId = groupValuesByField(allvaluesobjects, CUSTOM_VALUES_COLLECTION_FIELDS.CUSTOM_FIELD);
315
317
  valuesByFieldId.set("Location",cities)
316
-
317
- // Build CheckboxGroup options for this field
318
+ // Build CheckboxGroup options for this field
319
+
318
320
  const counter={}
319
321
  for(const city of cities) {
320
322
  counter[city.city]=city.count
321
323
  }
322
-
323
324
  for(const [key, value] of valuesByFieldId) {
324
- const field = getFieldById(key,allfields);
325
+ const field=getFieldById(key,allfields);
325
326
  let originalOptions=[];
326
- if(key === "Location") {
327
- originalOptions = value.map(city=>({
327
+ if(key==="Location") {
328
+ originalOptions=value.map(city=>({
328
329
  label: city.city,
329
330
  value: city._id
330
331
  }));
331
332
  }
332
333
  else{
333
- originalOptions = value
334
+ originalOptions=value
334
335
  }
335
-
336
336
  optionsByFieldId.set(key, originalOptions);
337
-
338
337
  for (const val of allvaluesobjects) {
339
338
  counter[val.title]=val.count
340
339
  }
341
340
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
342
- updateOptionsUI(_$w, field.title, field._id, ''); // no search query
343
-
341
+ updateOptionsUI(_$w,field.title, field._id, ''); // no search query
344
342
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
345
343
  _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
346
- dontUpdateThisCheckBox = field._id;
347
- const selected = ev.target.value; // array of selected value IDs
348
- let fieldTitle=field.title.toLowerCase().replace(' ', '');
349
- fieldTitle === "brands"? fieldTitle = "brand" : fieldTitle;
350
-
351
- if (selected && selected.length) {
352
- selectedByField.set(field._id, selected);
353
- if(fieldTitle==="brand" || fieldTitle==="storename") {
354
- //in this case we need the label not valueid
355
- const valueLabels = getValueFromValueId(selected, value);
356
- queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
357
- }
358
- else{
359
- queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
360
- }
361
-
362
- } else {
363
- selectedByField.delete(field._id);
364
- queryParams.remove([fieldTitle ]);
344
+ dontUpdateThisCheckBox=field._id;
345
+ const selected = ev.target.value; // array of selected value IDs
346
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
347
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
348
+
349
+ if (selected && selected.length) {
350
+ selectedByField.set(field._id, selected);
351
+ if(fieldTitle==="brand" || fieldTitle==="storename") {
352
+ //in this case we need the label not valueid
353
+ const valueLabels=getValueFromValueId(selected,value);
354
+ queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
355
+ }
356
+ else{
357
+ queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
365
358
  }
359
+
360
+ } else {
361
+ selectedByField.delete(field._id);
362
+ queryParams.remove([fieldTitle ]);
363
+ }
366
364
 
367
365
  await updateJobsAndNumbersAndFilters(_$w);
366
+
368
367
  });
369
-
370
368
  const runFilter = debounce(() => {
371
369
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
372
370
  updateOptionsUI(_$w, field.title, field._id, query);
@@ -381,11 +379,11 @@ async function loadJobsRepeater(_$w) {
381
379
  }
382
380
  }
383
381
 
384
- function getValueFromValueId(valueIds, value) {
385
- let valueLabels = [];
382
+ function getValueFromValueId(valueIds,value) {
383
+ let valueLabels=[];
386
384
  let currentVal
387
- for (const valueId of valueIds) {
388
- currentVal = value.find(val => val.value === valueId);
385
+ for(const valueId of valueIds) {
386
+ currentVal=value.find(val=>val.value===valueId);
389
387
  if(currentVal) {
390
388
  valueLabels.push(currentVal.label);
391
389
  }
@@ -545,7 +543,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
545
543
  const currentJobsIds=jobs.map(job=>job._id);
546
544
 
547
545
  for (const fieldId of fieldIds) {
548
- let currentoptions = optionsByFieldId.get(fieldId)
546
+ let currentoptions=optionsByFieldId.get(fieldId)
549
547
  let counter=new Map();
550
548
  for(const option of currentoptions) {
551
549
  for (const jobId of currentJobsIds) {
@@ -558,7 +556,8 @@ async function refreshFacetCounts(_$w,clearAll=false) {
558
556
  }
559
557
  }
560
558
 
561
- function updateSelectedValuesRepeater(_$w) {
559
+
560
+ function updateSelectedValuesRepeater(_$w) {
562
561
  const selectedItems = [];
563
562
  for (const [fieldId, valueIds] of selectedByField.entries()) {
564
563
  const opts = optionsByFieldId.get(fieldId) || [];
@@ -569,7 +568,7 @@ function updateSelectedValuesRepeater(_$w) {
569
568
  }
570
569
  }
571
570
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER).data = selectedItems;
572
- }
571
+ }
573
572
 
574
573
 
575
574
 
@@ -601,16 +600,15 @@ async function secondarySearch(_$w,query) {
601
600
  await refreshFacetCounts(_$w);
602
601
  return allsecondarySearchJobs;
603
602
  }
604
- function bindSearchInput(_$w) {
603
+ function bindSearchInput(_$w) {
605
604
  try {
606
- bindPrimarySearch(_$w,allvaluesobjects,alljobs);
605
+ bindPrimarySearch(_$w, allvaluesobjects);
607
606
 
608
607
  const secondarySearchDebounced = debounce(async () => {
609
608
  const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || '').toLowerCase().trim();
610
609
  await secondarySearch(_$w, query);
611
610
  }, 150);
612
611
 
613
-
614
612
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).onInput(secondarySearchDebounced);
615
613
 
616
614
  } catch (error) {
package/pages/homePage.js CHANGED
@@ -1,48 +1,40 @@
1
- const {
2
- debounce,
3
- getFilter,
4
- } = require('../public/filterUtils');
5
- const { handleOnLocationClick } = require('../public/mapUtils');
6
- const { filterBrokenMarkers } = require('../public/utils');
1
+ const { debounce, getFilter } = require('../public/filterUtils');
2
+ const { handleOnLocationClick } = require('../public/mapUtils');
3
+ const { filterBrokenMarkers } = require('../public/utils');
7
4
  const { location } = require('@wix/site-location');
8
5
  const {wixData} = require('wix-data');
9
6
  const { COLLECTIONS } = require('../backend/collectionConsts');
10
- const { bindPrimarySearch,getAllRecords,loadPrimarySearchRepeater } = require('./pagesUtils');
11
-
7
+ const { bindPrimarySearch, getAllRecords, loadPrimarySearchRepeater } = require('./pagesUtils');
12
8
 
13
9
  let thisObjectVar;
14
10
  let searchByCityFlag=false;
15
11
  let loadedCategories=false;
16
12
 
17
- async function homePageOnReady(_$w,thisObject=null) {
13
+ async function homePageOnReady(_$w,thisObject = null) {
18
14
  const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
19
15
  const siteconfig = queryResult.items[0];
20
16
 
21
17
  if(siteconfig.twg) {
22
- const allJobs = await getAllRecords(COLLECTIONS.JOBS);
23
- const allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
24
-
25
- bindPrimarySearch(_$w, allvaluesobjects, allJobs);
18
+ const allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
19
+ bindPrimarySearch(_$w, allvaluesobjects);
26
20
  loadPrimarySearchRepeater(_$w)
27
21
  console.log("siteconfig.twg: ",siteconfig.twg);
28
-
29
- if(siteconfig.twg === "external") {
30
- bindTeamRepeater(_$w)
31
- bindViewAllButton(_$w)
22
+ if(siteconfig.twg==="external") {
23
+ bindTeamRepeater(_$w)
24
+ bindViewAllButton(_$w)
32
25
  }
33
26
  }
34
27
  else{
35
- thisObjectVar=thisObject;
28
+ thisObjectVar = thisObject;
36
29
  bind(_$w);
37
30
  init(_$w);
38
31
  }
39
- }
32
+
33
+ }
40
34
 
41
35
  function bind(_$w) {
42
-
43
36
  bindTeamRepeater(_$w);
44
37
 
45
-
46
38
  _$w('#citiesDataset').onReady(async () => {
47
39
  const numOfItems = await _$w('#citiesDataset').getTotalCount();
48
40
  const items = await _$w('#citiesDataset').getItems(0, numOfItems);
@@ -56,8 +48,8 @@ function bind(_$w) {
56
48
  latitude: location.latitude,
57
49
  longitude: location.longitude
58
50
  },
59
- address: item.locationAddress.formatted,
60
- title: item.title,
51
+ address: item.locationAddress.formatted,
52
+ title: item.title,
61
53
  link: cityLinkUrl,
62
54
  linkTitle:`View ${item.count} Open Positions`
63
55
  };
@@ -106,7 +98,6 @@ function bindTeamRepeater(_$w) {
106
98
  }
107
99
 
108
100
  function bindViewAllButton(_$w) {
109
-
110
101
  _$w('#viewAllCategoriesButton').onClick(()=>{
111
102
  if(!loadedCategories) {
112
103
  loadedCategories=true;
@@ -125,11 +116,11 @@ function bindViewAllButton(_$w) {
125
116
 
126
117
 
127
118
  function init(_$w) {
128
- const debouncedInput = debounce(()=>handleSearchInput(_$w), 400,thisObjectVar);
119
+ const debouncedInput = debounce(() => handleSearchInput(_$w), 400, thisObjectVar);
129
120
 
130
121
  _$w('#searchInput').onInput(debouncedInput);
131
122
  _$w('#searchInput').maxLength = 40;
132
- _$w('#searchButton').onClick(()=>handleSearch(_$w('#searchInput').value));
123
+ _$w('#searchButton').onClick(() => handleSearch(_$w('#searchInput').value));
133
124
 
134
125
  _$w('#searchInput').onKeyPress((event) => {
135
126
  if (event.key === 'Enter') {
@@ -174,17 +165,17 @@ async function handleSearchInput(_$w) {
174
165
  count = _$w('#jobsDataset').getTotalCount();
175
166
 
176
167
  if (count > 0) {
177
- searchByCityFlag=false;
168
+ searchByCityFlag = false;
178
169
  _$w('#resultsContainer').expand();
179
170
  _$w('#searchMultiStateBox').changeState('results');
180
171
  } else {
181
- filter=await getFilter(searchByCity);
172
+ filter = await getFilter(searchByCity);
182
173
  await _$w('#jobsDataset').setFilter(filter);
183
174
  await _$w('#jobsDataset').refresh();
184
175
  count = _$w('#jobsDataset').getTotalCount();
185
- if(count > 0)
176
+ if( count > 0 )
186
177
  {
187
- searchByCityFlag=true;
178
+ searchByCityFlag = true;
188
179
  _$w('#resultsContainer').expand();
189
180
  _$w('#searchMultiStateBox').changeState('results');
190
181
  }
@@ -3,6 +3,7 @@ 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');
6
7
 
7
8
  function groupValuesByField(values, refKey) {
8
9
  const map = new Map();
@@ -11,7 +12,7 @@ function groupValuesByField(values, refKey) {
11
12
  if (!map.has(ref)) map.set(ref, []);
12
13
  map.get(ref).push({
13
14
  label: v.title ,
14
- value: v.valueId
15
+ value: v._id
15
16
  });
16
17
  }
17
18
  return map;
@@ -84,6 +85,9 @@ function groupValuesByField(values, refKey) {
84
85
  function loadPrimarySearchRepeater(_$w) {
85
86
 
86
87
  _$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
+ }
87
91
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_POSITION_BUTTON).label = itemData.title || '';
88
92
  });
89
93
 
@@ -121,55 +125,51 @@ function loadPrimarySearchRepeater(_$w) {
121
125
 
122
126
  }
123
127
 
124
- function bindPrimarySearch(_$w, allvaluesobjects, alljobs) {
128
+ function bindPrimarySearch(_$w, allvaluesobjects) {
129
+
130
+ const handleSearchInput = async () => { await primarySearch(_$w) }
125
131
 
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);
132
+ const primarySearchDebounced = debounce(() => handleSearchInput(), 400);
130
133
 
131
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
134
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
132
135
  await primarySearchDebounced();
133
136
  });
134
137
 
135
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
136
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
138
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
139
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
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
+ });
137
147
 
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
- });
148
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
149
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
150
+ });
145
151
 
146
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
147
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
148
- });
152
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onKeyPress(async (event) => {
153
+ if( event.key==='Enter') {
154
+ console.log("primary search input key pressed");
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`);
149
160
 
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
- }
161
+ }
162
+ else {
163
+ let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
164
+ const baseUrl = await location.baseUrl();
165
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
166
166
  }
167
- });
167
+ }
168
+ });
168
169
 
169
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
170
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
170
171
  console.log("primary search button clicked");
171
172
  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,49 +182,60 @@ function loadPrimarySearchRepeater(_$w) {
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
-
188
187
  let categoryValues=[]
189
188
  for(const value of allvaluesobjects) {
190
- if(value.customField === CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
191
- categoryValues.push({title: value.title+` (${value.count})` , _id: value.valueId});
189
+ if(value.customField===CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
190
+ categoryValues.push({title:value.title+` (${value.count})` ,_id:value._id});
192
191
  }
193
192
  }
194
193
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
195
194
  }
196
195
 
197
- async function primarySearch(_$w,query,alljobs) {
198
- if(query.length===0 || query===undefined || query==='') {
196
+ async function primarySearch(_$w) {
197
+ const query = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value?.toLowerCase().trim() || '';
198
+
199
+ if(query === undefined || query === '') {
199
200
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
200
201
  return false;
201
202
  }
202
- let filteredJobs=alljobs.filter(job=>job.title.toLowerCase().includes(query));
203
- if(filteredJobs.length>0) {
203
+
204
+ const searchByTitle = [{field: 'title', searchTerm: query}];
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();
204
216
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
205
217
  }
206
218
  else {
207
- console.log("searching by location")
208
- filteredJobs=alljobs.filter(job=>job.location.fullLocation.toLowerCase().includes(query));
209
- if(filteredJobs.length>0) {
219
+ filter = await getFilter(searchByCity);
220
+ await _$w('#jobsDataset').setFilter(filter);
221
+ await _$w('#jobsDataset').refresh();
222
+
223
+ count = _$w('#jobsDataset').getTotalCount();
224
+ if (count > 0) {
225
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
210
226
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
211
227
  }
212
228
  else{
213
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
229
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
214
230
  }
215
231
  }
216
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data = filteredJobs
217
- return filteredJobs.length>0;
218
-
219
232
  }
220
233
 
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
- }
234
+ async function getValueFromValueId(valueId) {
235
+ const result = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
236
+ return result.find(value => value._id === valueId);
237
+
238
+ }
228
239
 
229
240
  async function getLatestJobsByValue(Value) {
230
241
  const jobs=Value.multiRefJobsCustomValues;
@@ -58,7 +58,7 @@ async function getCategoryValue(customValues) {
58
58
  _$w('#jobCategory').text = categoryValue.title;
59
59
  }
60
60
 
61
- const relatedJobs = await getRelatedJobs({ categoryValueId: categoryValue._id, itemId: item._id ,limit:5});
61
+ const relatedJobs = await getRelatedJobs({ categoryValueId:categoryValue._id, itemId: item._id ,limit:5});
62
62
  _$w('#relatedJobsRepNoDepartment').onItemReady(($item, itemData) => {
63
63
  $item('#relatedJobTitle').text = itemData.title;
64
64
  $item('#relatedJobLocation').text = itemData.location.fullLocation;
@@ -124,6 +124,8 @@ async function getCategoryValue(customValues) {
124
124
  }
125
125
 
126
126
  async function getRelatedJobs({ categoryValueId, itemId, limit = 1000 }) {
127
+
128
+
127
129
  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();
128
130
  return relatedJobs.items;
129
131
  }
@@ -32,16 +32,16 @@ async function handlePeopleSection(_$w) {
32
32
  }
33
33
 
34
34
  async function handleRecentJobsSection(_$w) {
35
+
36
+
35
37
  if(supportTeamsPageIds.excludeValues.has(currentItem.title_fld)) {
36
38
  console.log("Value is excluded , collapsing recently Jobs Section ");
37
- await collapseSection(_$w, supportTeamsPageSections.RECENT_JOBS);
39
+ await collapseSection(_$w,supportTeamsPageSections.RECENT_JOBS);
38
40
  return;
39
41
  }
40
-
41
- const valueId = supportTeamsPageIds.valueToValueIdMap[currentItem.title_fld]
42
- const Value = await getValueFromValueId(valueId);
43
-
44
- if( Value === undefined ) {
42
+ const valueId=supportTeamsPageIds.valueToValueIdMap[currentItem.title_fld]
43
+ const Value=await getValueFromValueId(valueId);
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;
@@ -23,7 +23,7 @@ function getFilter(fieldsToSearch = [], mode = 'or') {
23
23
  return filter;
24
24
  }
25
25
 
26
- function debounce(fn, delay = 400,thisObject) {
26
+ function debounce(fn, delay = 400, thisObject) {
27
27
  let timeout;
28
28
  return function (...args) {
29
29
  clearTimeout(timeout);