sr-npm 1.2.27 → 1.2.29

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": "1.2.27",
3
+ "version": "1.2.29",
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
 
package/pages/homePage.js CHANGED
@@ -8,37 +8,34 @@ const { location } = require('@wix/site-location');
8
8
  const {wixData} = require('wix-data');
9
9
  const { COLLECTIONS } = require('../backend/collectionConsts');
10
10
  const { bindPrimarySearch,getAllRecords,loadPrimarySearchRepeater } = require('./pagesUtils');
11
-
12
-
13
11
  let thisObjectVar;
14
12
  let searchByCityFlag=false;
15
13
  let loadedCategories=false;
16
-
17
14
  async function homePageOnReady(_$w,thisObject=null) {
15
+
18
16
  const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
19
17
  const siteconfig = queryResult.items[0];
20
-
21
18
  if(siteconfig.twg) {
22
- const allJobs = await getAllRecords(COLLECTIONS.JOBS);
23
- const allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
24
-
25
- bindPrimarySearch(_$w, allvaluesobjects, allJobs);
19
+ const allJobs=await getAllRecords(COLLECTIONS.JOBS);
20
+ const allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
21
+ bindPrimarySearch(_$w,allvaluesobjects,allJobs);
26
22
  loadPrimarySearchRepeater(_$w)
27
23
  console.log("siteconfig.twg: ",siteconfig.twg);
28
-
29
- if(siteconfig.twg === "external") {
30
- bindTeamRepeater(_$w)
31
- bindViewAllButton(_$w)
24
+ if(siteconfig.twg==="external") {
25
+ bindTeamRepeater(_$w)
26
+ bindViewAllButton(_$w)
32
27
  }
33
28
  }
34
29
  else{
35
- thisObjectVar=thisObject;
36
- bind(_$w);
37
- init(_$w);
30
+
31
+ thisObjectVar=thisObject;
32
+ await bind(_$w);
33
+ await init(_$w);
38
34
  }
35
+
39
36
  }
40
37
 
41
- function bind(_$w) {
38
+ function bind(_$w) {
42
39
 
43
40
  bindTeamRepeater(_$w);
44
41
 
@@ -11,7 +11,7 @@ function groupValuesByField(values, refKey) {
11
11
  if (!map.has(ref)) map.set(ref, []);
12
12
  map.get(ref).push({
13
13
  label: v.title ,
14
- value: v.valueId
14
+ value: v._id
15
15
  });
16
16
  }
17
17
  return map;
@@ -84,6 +84,9 @@ function groupValuesByField(values, refKey) {
84
84
  function loadPrimarySearchRepeater(_$w) {
85
85
 
86
86
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
87
+ if(!itemData.title) {
88
+ console.log("!!!!!!!!!!!! itemData has no title: ",itemData);
89
+ }
87
90
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_POSITION_BUTTON).label = itemData.title || '';
88
91
  });
89
92
 
@@ -121,74 +124,72 @@ function loadPrimarySearchRepeater(_$w) {
121
124
 
122
125
  }
123
126
 
124
- function bindPrimarySearch(_$w, allvaluesobjects, alljobs) {
127
+ function bindPrimarySearch(_$w,allvaluesobjects,alljobs) {
125
128
 
126
129
  const primarySearchDebounced = debounce(async () => {
127
130
  const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value || '').toLowerCase().trim();
128
131
  await primarySearch(_$w, query, alljobs);
129
- }, 300);
132
+ }, 1000);
130
133
 
131
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();
137
-
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
- });
145
-
146
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
147
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
148
- });
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, _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim(), alljobs);
142
+ }
143
+ else {
144
+ await loadCategoriesListPrimarySearch(_$w,allvaluesobjects);
145
+ }
146
+ });
149
147
 
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
- }
167
- });
148
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
149
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
150
+ });
168
151
 
169
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
170
- console.log("primary search button clicked");
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");
171
155
  console.log("_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value: ",_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
172
-
173
156
  if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
157
+ // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
174
158
  const baseUrl = await location.baseUrl();
175
159
  location.to(`${baseUrl}/search`);
176
- }
160
+
161
+ }
177
162
  else {
178
163
  let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
179
164
  const baseUrl = await location.baseUrl();
180
- location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
165
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
181
166
  }
182
- });
167
+ }
168
+ });
169
+
170
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_BUTTON).onClick(async () => {
171
+ console.log("primary search button clicked");
172
+ console.log("_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value: ",_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
173
+ if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
174
+ const baseUrl = await location.baseUrl();
175
+ location.to(`${baseUrl}/search`);
176
+ }
177
+ else {
178
+ let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
179
+ const baseUrl = await location.baseUrl();
180
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
181
+ }
182
+ });
183
+
184
+
183
185
  }
184
186
 
185
- async function loadCategoriesListPrimarySearch(_$w, allvaluesobjects) {
187
+ async function loadCategoriesListPrimarySearch(_$w,allvaluesobjects) {
186
188
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
187
-
188
189
  let categoryValues=[]
189
190
  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});
191
+ if(value.customField===CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
192
+ categoryValues.push({title:value.title+` (${value.count})` ,_id:value._id});
192
193
  }
193
194
  }
194
195
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
@@ -199,32 +200,36 @@ async function primarySearch(_$w,query,alljobs) {
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
+
204
+ let filteredJobs = alljobs.filter(job=>job.title.toLowerCase().includes(query));
203
205
  if(filteredJobs.length>0) {
206
+ console.log('filteredJobs is not empty');
204
207
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
205
208
  }
206
209
  else {
207
210
  console.log("searching by location")
208
- filteredJobs=alljobs.filter(job=>job.location.fullLocation.toLowerCase().includes(query));
209
- if(filteredJobs.length>0) {
211
+ filteredJobs = alljobs.filter(job=>job.location.fullLocation.toLowerCase().includes(query));
212
+ if (filteredJobs.length>0) {
210
213
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
211
214
  }
212
215
  else{
213
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
216
+ console.log('filteredJobs is empty');
217
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
214
218
  }
215
219
  }
220
+
221
+ console.log("filteredJobs: ",filteredJobs);
216
222
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data = filteredJobs
217
- return filteredJobs.length>0;
218
-
223
+ return filteredJobs.length>0;
219
224
  }
220
225
 
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
- }
226
+ async function getValueFromValueId(valueId) {
227
+ const result=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
228
+ console.log("result: ",result);
229
+ console.log("valueId: ",valueId);
230
+ return result.find(value=>value._id===valueId);
231
+
232
+ }
228
233
 
229
234
  async function getLatestJobsByValue(Value) {
230
235
  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;