sr-npm 3.1.9 → 3.1.11

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.
@@ -1,4 +1,5 @@
1
1
  const CAREERS_MULTI_BOXES_PAGE_CONSTS={
2
+ JOBS_DATASET: '#jobsDataset',
2
3
  FILTER_REPEATER: '#filterReapter',
3
4
  JOBS_REPEATER: '#jobsReapter',
4
5
  JOBS_REPEATER_ITEM_TITLE: '#jobTitle',
@@ -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
- const fieldId=normalizeString(field.fieldId)
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 {companyId ,templateType} = await getApiKeys();
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
- 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;
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
- await populateCustomFieldsCollection(customFieldsLabels,templateType);
166
- await populateCustomValuesCollection(customFieldsValues);
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,valueId, Array.from(customValuesToJobs[valueId]));
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
- _id: valueId,
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
  });
@@ -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
 
@@ -37,9 +37,14 @@ const elevatedQuery = auth.elevate(wixData.query);
37
37
  }
38
38
 
39
39
  async function getApiKeys() {
40
- const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
41
- const templateType = await getTemplateTypeFromCMS();
42
- return {companyId,templateType};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "3.1.9",
3
+ "version": "3.1.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,18 @@ const { window } = require('@wix/site-window');
5
5
  const { queryParams,onChange} = require('wix-location-frontend');
6
6
  const { location } = require("@wix/site-location");
7
7
  const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS,possibleUrlParams} = require('../backend/careersMultiBoxesPageIds');
8
- const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle,getCorrectOption,getOptionIndexFromCheckBox,loadPrimarySearchRepeater,bindPrimarySearch,primarySearch } = require('./pagesUtils');
8
+ const { groupValuesByField,
9
+ debounce,
10
+ getAllRecords,
11
+ getFieldById,
12
+ getFieldByTitle,
13
+ getCorrectOption,
14
+ getOptionIndexFromCheckBox,
15
+ loadPrimarySearchRepeater,
16
+ bindPrimarySearch,
17
+ primarySearch,
18
+ getAllDatasetItems
19
+ } = require('./pagesUtils');
9
20
 
10
21
 
11
22
  let dontUpdateThisCheckBox;
@@ -21,6 +32,7 @@ let allsecondarySearchJobs=[] // secondary search results that are displayed in
21
32
  let currentSecondarySearchJobs=[] // current secondary search results that are displayed in the jobs repeater
22
33
  let secondarySearchIsFilled=false // whether the secondary search is filled with results
23
34
  let keywordAllJobs; // all jobs that are displayed in the jobs repeater when the keyword is filled
35
+ let ActivateURLOnchange=true; // whether to activate the url onchange
24
36
  const pagination = {
25
37
  pageSize: 10,
26
38
  currentPage: 1,
@@ -33,7 +45,7 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
33
45
  });
34
46
 
35
47
  await loadData(_$w);
36
- loadJobsRepeater(_$w);
48
+ await loadJobsRepeater(_$w); // if we remove the await here the job list will be flaky , it doesn't fill it properly
37
49
  loadPrimarySearchRepeater(_$w);
38
50
  await loadFilters(_$w);
39
51
  loadSelectedValuesRepeater(_$w);
@@ -52,15 +64,23 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
52
64
  }
53
65
 
54
66
  async function handleBackAndForth(_$w){
67
+ if(ActivateURLOnchange) {
55
68
  const newQueryParams=await location.query();
56
- console.log("newQueryParams: ", newQueryParams);
57
- await clearAll(_$w,true);
58
- await handleUrlParams(_$w,newQueryParams);
59
-
69
+ console.log("newQueryParams: ", newQueryParams);
70
+ ActivateURLOnchange=false;
71
+ await clearAll(_$w,true);
72
+ await handleUrlParams(_$w,newQueryParams,true);
73
+ ActivateURLOnchange=true;
74
+
75
+ }
76
+ else{
77
+ ActivateURLOnchange=true;
78
+ }
60
79
  }
61
80
 
62
81
  async function clearAll(_$w,urlOnChange=false) {
63
82
  if(selectedByField.size>0 || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value) {
83
+
64
84
  for(const field of allfields) {
65
85
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
66
86
  }
@@ -71,9 +91,13 @@ async function clearAll(_$w,urlOnChange=false) {
71
91
  currentJobs=alljobs;
72
92
  keywordAllJobs=undefined;
73
93
  if(!urlOnChange) {
94
+ console.log("inside clearAll removing url params");
95
+ ActivateURLOnchange=false;
74
96
  queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
97
+
98
+ await updateJobsAndNumbersAndFilters(_$w,true);
75
99
  }
76
- await updateJobsAndNumbersAndFilters(_$w,true);
100
+
77
101
  }
78
102
  }
79
103
 
@@ -113,16 +137,19 @@ function handleFilterInMobile(_$w) {
113
137
  }
114
138
 
115
139
 
116
- async function handleUrlParams(_$w,urlParams) {
140
+ async function handleUrlParams(_$w,urlParams,handleBackAndForth=false) {
117
141
  try {
118
142
  let applyFiltering=false;
119
143
  let currentApplyFilterFlag=false;
120
144
  //apply this first to determine all jobs
121
145
  if(urlParams.keyword) {
122
- applyFiltering = await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
146
+ applyFiltering = await primarySearch(_$w, decodeURIComponent(urlParams.keyword));
123
147
  _$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;
148
+
149
+ const items = await getAllDatasetItems(_$w, CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_DATASET);
150
+
151
+ currentJobs = items;
152
+ keywordAllJobs = items;
126
153
  }
127
154
 
128
155
  for (const url of possibleUrlParams)
@@ -136,9 +163,11 @@ async function handleUrlParams(_$w,urlParams) {
136
163
  }
137
164
  currentApplyFilterFlag=false;
138
165
  }
139
- if(applyFiltering || keywordAllJobs) {
140
- await updateJobsAndNumbersAndFilters(_$w);
141
- }
166
+
167
+ if(applyFiltering || keywordAllJobs || handleBackAndForth) {
168
+ await updateJobsAndNumbersAndFilters(_$w);
169
+
170
+ }
142
171
 
143
172
  if(urlParams.page) {
144
173
  if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
@@ -176,17 +205,15 @@ async function handleParams(_$w,param,values) {
176
205
  for(const value of valuesAsArray) {
177
206
 
178
207
  const decodedValue = decodeURIComponent(value);
179
-
180
- const options=optionsByFieldId.get(field._id);
181
-
182
- const option=getCorrectOption(decodedValue,options,param);
208
+ const options = optionsByFieldId.get(field._id);
209
+ const option = getCorrectOption(decodedValue, options, param);
183
210
 
184
211
  if(option) {
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;
212
+ const optionIndex = getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
213
+ selectedIndices.push(optionIndex);
214
+ existing.push(option.value);
215
+ applyFiltering = true;
216
+ dontUpdateThisCheckBox = field._id;
190
217
  }
191
218
  else {
192
219
  console.warn(`${param} value not found in dropdown options`);
@@ -238,6 +265,7 @@ async function handleParams(_$w,param,values) {
238
265
  const field=getFieldById(fieldId,allfields);
239
266
  let fieldTitle=field.title.toLowerCase().replace(' ', '');
240
267
  fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
268
+ ActivateURLOnchange=false;
241
269
  if (updated.length) {
242
270
  selectedByField.set(fieldId, updated);
243
271
  queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
@@ -245,10 +273,12 @@ async function handleParams(_$w,param,values) {
245
273
  selectedByField.delete(fieldId);
246
274
  queryParams.remove([fieldTitle ]);
247
275
  }
276
+
248
277
  const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
249
278
  const nextVals = currentVals.filter(v => v !== valueId);
250
279
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
251
280
  await updateJobsAndNumbersAndFilters(_$w);
281
+
252
282
  });
253
283
  });
254
284
  updateSelectedValuesRepeater(_$w);
@@ -264,14 +294,14 @@ async function loadData() {
264
294
  currentJobs=alljobs;
265
295
  }
266
296
  if(Object.keys(valueToJobs).length === 0){
267
- allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
297
+ allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
268
298
  for (const value of allvaluesobjects) {
269
- valueToJobs[value._id]= value.jobIds;
299
+ valueToJobs[value.valueId]= value.jobIds;
270
300
  }
271
301
  }
272
302
  if(allfields.length===0) {
273
- allfields=await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
274
- allfields.push({_id:"Location",title:"Location"});
303
+ allfields = await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
304
+ allfields.push({ _id:"Location", title:"Location" });
275
305
  }
276
306
  } catch (error) {
277
307
  console.error('Failed to load data:', error);
@@ -308,44 +338,47 @@ async function loadJobsRepeater(_$w) {
308
338
  async function loadFilters(_$w) {
309
339
  try {
310
340
  // 1) Load all categories (fields)
311
- const cities=await getAllRecords(COLLECTIONS.CITIES);
341
+ const cities = await getAllRecords(COLLECTIONS.CITIES);
312
342
  for(const city of cities) {
313
- valueToJobs[city._id]=city.jobIds;
343
+ valueToJobs[city._id] = city.jobIds;
314
344
  }
315
345
  // 2) Load all values once and group them by referenced field
316
346
  let valuesByFieldId = groupValuesByField(allvaluesobjects, CUSTOM_VALUES_COLLECTION_FIELDS.CUSTOM_FIELD);
317
347
  valuesByFieldId.set("Location",cities)
318
- // Build CheckboxGroup options for this field
319
-
348
+ // Build CheckboxGroup options for this field
320
349
  const counter={}
321
350
  for(const city of cities) {
322
351
  counter[city.city]=city.count
323
352
  }
353
+
324
354
  for(const [key, value] of valuesByFieldId) {
325
- const field=getFieldById(key,allfields);
355
+ const field = getFieldById(key,allfields);
326
356
  let originalOptions=[];
327
- if(key==="Location") {
328
- originalOptions=value.map(city=>({
357
+ if(key === "Location") {
358
+ originalOptions = value.map(city=>({
329
359
  label: city.city,
330
360
  value: city._id
331
361
  }));
332
362
  }
333
363
  else{
334
- originalOptions=value
364
+ originalOptions = value
335
365
  }
366
+
336
367
  optionsByFieldId.set(key, originalOptions);
368
+
337
369
  for (const val of allvaluesobjects) {
338
370
  counter[val.title]=val.count
339
371
  }
340
372
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
341
- updateOptionsUI(_$w,field.title, field._id, ''); // no search query
373
+ updateOptionsUI(_$w, field.title, field._id, ''); // no search query
374
+
342
375
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
343
376
  _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
344
377
  dontUpdateThisCheckBox=field._id;
345
378
  const selected = ev.target.value; // array of selected value IDs
346
379
  let fieldTitle=field.title.toLowerCase().replace(' ', '');
347
380
  fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
348
-
381
+ ActivateURLOnchange=false;
349
382
  if (selected && selected.length) {
350
383
  selectedByField.set(field._id, selected);
351
384
  if(fieldTitle==="brand" || fieldTitle==="storename") {
@@ -361,10 +394,11 @@ async function loadJobsRepeater(_$w) {
361
394
  selectedByField.delete(field._id);
362
395
  queryParams.remove([fieldTitle ]);
363
396
  }
364
-
397
+
398
+ console.log("selectedByField: ",selectedByField)
365
399
  await updateJobsAndNumbersAndFilters(_$w);
366
-
367
400
  });
401
+
368
402
  const runFilter = debounce(() => {
369
403
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
370
404
  updateOptionsUI(_$w, field.title, field._id, query);
@@ -379,11 +413,11 @@ async function loadJobsRepeater(_$w) {
379
413
  }
380
414
  }
381
415
 
382
- function getValueFromValueId(valueIds,value) {
383
- let valueLabels=[];
416
+ function getValueFromValueId(valueIds, value) {
417
+ let valueLabels = [];
384
418
  let currentVal
385
- for(const valueId of valueIds) {
386
- currentVal=value.find(val=>val.value===valueId);
419
+ for (const valueId of valueIds) {
420
+ currentVal = value.find(val => val.value === valueId);
387
421
  if(currentVal) {
388
422
  valueLabels.push(currentVal.label);
389
423
  }
@@ -392,10 +426,10 @@ function getValueFromValueId(valueIds,value) {
392
426
  }
393
427
 
394
428
  async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
395
- await applyJobFilters(_$w); // re-query jobs
429
+ await applyJobFilters(_$w,clearAll); // re-query jobs
396
430
  await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
397
431
  await updateSelectedValuesRepeater(_$w);
398
- updateTotalJobsCountText(_$w);
432
+ updateTotalJobsCountText(_$w);
399
433
  }
400
434
 
401
435
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
@@ -476,12 +510,13 @@ function getValueFromValueId(valueIds,value) {
476
510
  finalFilteredJobs=tempFilteredJobs;
477
511
  tempFilteredJobs=[];
478
512
  }
479
-
480
513
  secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
481
514
 
482
515
 
483
516
  let jobsFirstPage=[];
517
+ console.log("currentSecondarySearchJobs: ",currentSecondarySearchJobs)
484
518
  secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
519
+ console.log("jobsFirstPage: ",jobsFirstPage)
485
520
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
486
521
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
487
522
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
@@ -493,7 +528,7 @@ function getValueFromValueId(valueIds,value) {
493
528
  }
494
529
  pagination.currentPage=1;
495
530
  handlePaginationButtons(_$w);
496
- }
531
+ }
497
532
 
498
533
  function handlePaginationButtons(_$w)
499
534
  {
@@ -517,14 +552,15 @@ function handlePaginationButtons(_$w)
517
552
  }
518
553
 
519
554
  function handlePageUrlParam() {
555
+ ActivateURLOnchange=false;
520
556
  if(pagination.currentPage==1)
521
557
  {
558
+
522
559
  queryParams.remove(["page"]);
523
560
  }
524
561
  else{
525
562
  queryParams.add({ page: pagination.currentPage });
526
563
  }
527
-
528
564
  }
529
565
  async function refreshFacetCounts(_$w,clearAll=false) {
530
566
 
@@ -543,7 +579,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
543
579
  const currentJobsIds=jobs.map(job=>job._id);
544
580
 
545
581
  for (const fieldId of fieldIds) {
546
- let currentoptions=optionsByFieldId.get(fieldId)
582
+ let currentoptions = optionsByFieldId.get(fieldId)
547
583
  let counter=new Map();
548
584
  for(const option of currentoptions) {
549
585
  for (const jobId of currentJobsIds) {
@@ -556,8 +592,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
556
592
  }
557
593
  }
558
594
 
559
-
560
- function updateSelectedValuesRepeater(_$w) {
595
+ function updateSelectedValuesRepeater(_$w) {
561
596
  const selectedItems = [];
562
597
  for (const [fieldId, valueIds] of selectedByField.entries()) {
563
598
  const opts = optionsByFieldId.get(fieldId) || [];
@@ -568,7 +603,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
568
603
  }
569
604
  }
570
605
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER).data = selectedItems;
571
- }
606
+ }
572
607
 
573
608
 
574
609
 
@@ -602,9 +637,9 @@ async function secondarySearch(_$w,query) {
602
637
  }
603
638
  function bindSearchInput(_$w) {
604
639
  try {
605
- bindPrimarySearch(_$w, allvaluesobjects);
640
+ bindPrimarySearch(_$w, allvaluesobjects);
606
641
 
607
- const secondarySearchDebounced = debounce(async () => {
642
+ const secondarySearchDebounced = debounce(async () => {
608
643
  const query = (_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || '').toLowerCase().trim();
609
644
  await secondarySearch(_$w, query);
610
645
  }, 150);
package/pages/homePage.js CHANGED
@@ -14,14 +14,16 @@ async function homePageOnReady(_$w,thisObject = null) {
14
14
  const queryResult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
15
15
  const siteconfig = queryResult.items[0];
16
16
 
17
+
17
18
  if(siteconfig.twg) {
18
- const allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
19
+ const allvaluesobjects = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
19
20
  bindPrimarySearch(_$w, allvaluesobjects);
20
21
  loadPrimarySearchRepeater(_$w)
21
22
  console.log("siteconfig.twg: ",siteconfig.twg);
22
- if(siteconfig.twg==="external") {
23
- bindTeamRepeater(_$w)
24
- bindViewAllButton(_$w)
23
+
24
+ if(siteconfig.twg === "external") {
25
+ bindTeamRepeater(_$w)
26
+ bindViewAllButton(_$w)
25
27
  }
26
28
  }
27
29
  else{
@@ -12,133 +12,147 @@ function groupValuesByField(values, refKey) {
12
12
  if (!map.has(ref)) map.set(ref, []);
13
13
  map.get(ref).push({
14
14
  label: v.title ,
15
- value: v._id
15
+ value: v.valueId
16
16
  });
17
17
  }
18
18
  return map;
19
- }
19
+ }
20
20
 
21
- const debounce = (fn, ms = 150) => {
22
- let t;
23
- return (...args) => {
24
- clearTimeout(t);
25
- t = setTimeout(() => fn(...args), ms);
26
- };
21
+ const debounce = (fn, ms = 150) => {
22
+ let t;
23
+ return (...args) => {
24
+ clearTimeout(t);
25
+ t = setTimeout(() => fn(...args), ms);
27
26
  };
27
+ };
28
28
 
29
- async function getAllRecords(collectionId) {
30
- const q = wixData.query(collectionId).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
31
-
32
-
33
- const items = [];
34
- let res = await q.limit(1000).find();
35
- items.push(...res.items);
36
-
37
- while (res.hasNext()) {
38
- res = await res.next();
39
- items.push(...res.items);
40
- }
41
- return items;
29
+ async function getAllDatasetItems(_$w, datasetSelector) {
30
+ await _$w(datasetSelector).onReadyAsync();
31
+
32
+ let items = [];
33
+ let data = await _$w(datasetSelector).getItems(0, 1000);
34
+ items.push(...data.items);
35
+
36
+ while (_$w(datasetSelector).hasNextPage()) {
37
+ const nextItems = await _$w(datasetSelector).nextPage();
38
+ items.push(...nextItems);
42
39
  }
43
40
 
44
- async function getAllRecordsWithoutMultiRef(collectionId) {
45
- const q = wixData.query(collectionId)
46
-
47
-
48
- const items = [];
49
- let res = await q.limit(1000).find();
41
+ return items;
42
+ }
43
+
44
+ async function getAllRecords(collectionId) {
45
+ const q = wixData.query(collectionId).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
46
+
47
+
48
+ const items = [];
49
+ let res = await q.limit(1000).find();
50
+ items.push(...res.items);
51
+
52
+ while (res.hasNext()) {
53
+ res = await res.next();
50
54
  items.push(...res.items);
51
-
52
- while (res.hasNext()) {
53
- res = await res.next();
54
- items.push(...res.items);
55
- }
56
- return items;
57
55
  }
56
+ return items;
57
+ }
58
+
59
+ async function getAllRecordsWithoutMultiRef(collectionId) {
60
+ const q = wixData.query(collectionId)
58
61
 
59
- function getFieldById(fieldId,allFields) {
60
- return allFields.find(field=>field._id===fieldId);
61
- }
62
62
 
63
- function getFieldByTitle(title,allFields) {
64
- return allFields.find(field=>field.title===title);
63
+ const items = [];
64
+ let res = await q.limit(1000).find();
65
+ items.push(...res.items);
66
+
67
+ while (res.hasNext()) {
68
+ res = await res.next();
69
+ items.push(...res.items);
65
70
  }
71
+ return items;
72
+ }
66
73
 
67
- function getCorrectOption(value,options,param) {
68
- const standardizedValue = normalizeString(value.toLowerCase())
69
- if(param==="employmenttype") //employmenttype have a problematic value
70
- {
71
- return options.find(option=>normalizeString(option.value.toLowerCase())===standardizedValue);
72
- }
73
- return options.find(option=>normalizeString(option.label.toLowerCase())===standardizedValue);
74
+ function getFieldById(fieldId,allFields) {
75
+ return allFields.find(field=>field._id===fieldId);
76
+ }
77
+
78
+ function getFieldByTitle(title,allFields) {
79
+ return allFields.find(field=>field.title===title);
80
+ }
81
+
82
+ function getCorrectOption(value,options,param) {
83
+ const standardizedValue = normalizeString(value.toLowerCase())
84
+ if(param==="employmenttype") //employmenttype have a problematic value
85
+ {
86
+ return options.find(option=>normalizeString(option.value.toLowerCase())===standardizedValue);
74
87
  }
88
+ return options.find(option=>normalizeString(option.label.toLowerCase())===standardizedValue);
89
+ }
75
90
 
76
- function getOptionIndexFromCheckBox(options,value) {
77
- const normalizedValue=normalizeString(value.toLowerCase());
78
- for(let index=0;index<options.length;index++) {
79
- if(normalizeString(options[index].value.toLowerCase())===normalizedValue) {
80
- return index;
81
- }
91
+ function getOptionIndexFromCheckBox(options,value) {
92
+ const normalizedValue=normalizeString(value.toLowerCase());
93
+ for(let index=0;index<options.length;index++) {
94
+ if(normalizeString(options[index].value.toLowerCase())===normalizedValue) {
95
+ return index;
82
96
  }
83
97
  }
98
+ }
84
99
 
85
100
  function loadPrimarySearchRepeater(_$w) {
101
+
102
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER_ITEM).onClick((event) => {
103
+ const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
104
+ const clickedItemData = data.find(
105
+ (item) => item._id === event.context.itemId,
106
+
107
+ );
86
108
 
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
- }
91
- $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_POSITION_BUTTON).label = itemData.title || '';
92
- });
93
-
94
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER_ITEM).onClick((event) => {
95
- const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
96
- const clickedItemData = data.find(
97
- (item) => item._id === event.context.itemId,
98
-
99
- );
100
- // 'link-jobs-title' or 'link-copy-of-jobs-title'
101
- const linkKey = Object.keys(clickedItemData).find(
102
- key => key.startsWith('link') && key.includes('jobs') && key.includes('title')
103
- );
104
- if (linkKey && clickedItemData[linkKey] ) {
105
- if(clickedItemData[linkKey].includes("copy-of-jobs")) {
106
- clickedItemData[linkKey]=clickedItemData[linkKey].replace("copy-of-jobs","jobs")
107
- }
108
- location.to(clickedItemData[linkKey]);
109
+ // 'link-jobs-title' or 'link-copy-of-jobs-title'
110
+ const linkKey = Object.keys(clickedItemData).find(
111
+ key => key.startsWith('link') && key.includes('jobs') && key.includes('title')
112
+ );
113
+ if (linkKey && clickedItemData[linkKey] ) {
114
+ if(clickedItemData[linkKey].includes("copy-of-jobs")) {
115
+ clickedItemData[linkKey]=clickedItemData[linkKey].replace("copy-of-jobs","jobs")
109
116
  }
117
+ location.to(clickedItemData[linkKey]);
118
+ }
110
119
 
111
- });
112
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
113
- $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_CATEGORY_BUTTON).label = itemData.title || '';
114
- });
115
-
116
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER_ITEM).onClick(async (event) => {
117
- const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data;
118
- const clickedItemData = data.find(
119
- (item) => item._id === event.context.itemId,
120
- );
121
- const baseUrl = await location.baseUrl();
122
- const encodedCategory=encodeURIComponent(clickedItemData._id);
123
- location.to(`${baseUrl}/search?category=${encodedCategory}`);
124
- });
120
+ });
121
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).onItemReady(async ($item, itemData) => {
122
+ $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_CATEGORY_BUTTON).label = itemData.title || '';
123
+ });
124
+
125
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER_ITEM).onClick(async (event) => {
126
+ const data = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data;
127
+ const clickedItemData = data.find(
128
+ (item) => item._id === event.context.itemId,
129
+ );
130
+ const baseUrl = await location.baseUrl();
131
+ const encodedCategory=encodeURIComponent(clickedItemData._id);
132
+ location.to(`${baseUrl}/search?category=${encodedCategory}`);
133
+ });
125
134
 
126
135
  }
127
136
 
128
137
  function bindPrimarySearch(_$w, allvaluesobjects) {
129
138
 
130
- const handleSearchInput = async () => { await primarySearch(_$w) }
139
+ const handleSearchInput = async () => {
140
+ const query = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value?.toLowerCase().trim() || '';
141
+ await primarySearch(_$w, query);
142
+ }
131
143
 
132
- const primarySearchDebounced = debounce(() => handleSearchInput(), 400);
144
+ const primarySearchDebounced = debounce(() => handleSearchInput(), 400);
133
145
 
134
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
135
- await primarySearchDebounced();
136
- });
146
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onInput(async () => {
147
+ await primarySearchDebounced();
148
+ });
137
149
 
138
150
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onClick(async () => {
139
151
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
152
+
140
153
  if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()!=='') {
141
- await primarySearch(_$w);
154
+ const query = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value?.toLowerCase().trim() || '';
155
+ await primarySearch(_$w, query);
142
156
  }
143
157
  else {
144
158
  await loadCategoriesListPrimarySearch(_$w,allvaluesobjects);
@@ -150,9 +164,7 @@ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).onMouseOut(async () => {
150
164
  });
151
165
 
152
166
  _$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);
167
+ if( event.key === 'Enter') {
156
168
  if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
157
169
  // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).collapse();
158
170
  const baseUrl = await location.baseUrl();
@@ -168,95 +180,97 @@ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).onKeyPress(async (even
168
180
  });
169
181
 
170
182
  _$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
+ if(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value.trim()==='') {
184
+ const baseUrl = await location.baseUrl();
185
+ location.to(`${baseUrl}/search`);
186
+ }
187
+ else {
188
+ let encodedKeyWord=encodeURIComponent(_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value);
189
+ const baseUrl = await location.baseUrl();
190
+ location.to(`${baseUrl}/search?keyword=${encodedKeyWord}`);
191
+ }
192
+ });
183
193
  }
184
194
 
185
- async function loadCategoriesListPrimarySearch(_$w,allvaluesobjects) {
186
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
187
- let categoryValues=[]
188
- 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._id});
191
- }
195
+ async function loadCategoriesListPrimarySearch(_$w, allvaluesobjects) {
196
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
197
+
198
+ let categoryValues=[]
199
+ for(const value of allvaluesobjects) {
200
+ if(value.customField === CATEGORY_CUSTOM_FIELD_ID_IN_CMS) {
201
+ categoryValues.push({title: value.title+` (${value.count})` , _id: value.valueId});
192
202
  }
193
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
203
+ }
204
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CATEGORY_RESULTS_REPEATER).data = categoryValues;
194
205
  }
195
206
 
196
- async function primarySearch(_$w) {
197
- const query = _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value?.toLowerCase().trim() || '';
207
+ async function primarySearch(_$w, query) {
208
+ if(query === undefined || query === '') {
209
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
210
+ return false;
211
+ }
198
212
 
199
- if(query === undefined || query === '') {
200
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("categoryResults");
201
- return false;
202
- }
213
+ const searchByTitle = [{field: 'title', searchTerm: query}];
214
+ const searchByCity = [{field: 'location.fullLocation', searchTerm: query}];
215
+
216
+ let filter = await getFilter(searchByTitle);
203
217
 
204
- const searchByTitle = [{field: 'title', searchTerm: query}];
205
- const searchByCity = [{field: 'location.fullLocation', searchTerm: query}];
218
+ await _$w('#jobsDataset').setFilter(filter);
219
+ await _$w('#jobsDataset').refresh();
206
220
 
207
- let filter = await getFilter(searchByTitle);
221
+ let count = _$w('#jobsDataset').getTotalCount();
208
222
 
223
+ if( count > 0 ) {
224
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
225
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
226
+ }
227
+ else {
228
+ filter = await getFilter(searchByCity);
209
229
  await _$w('#jobsDataset').setFilter(filter);
210
230
  await _$w('#jobsDataset').refresh();
211
231
 
212
- let count = _$w('#jobsDataset').getTotalCount();
213
-
214
- if( count > 0 ) {
232
+ count = _$w('#jobsDataset').getTotalCount();
233
+ if (count > 0) {
215
234
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.RESULTS_CONTAINER).expand();
216
235
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
217
236
  }
218
- else {
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();
226
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("jobResults");
227
- }
228
- else{
229
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
230
- }
237
+ else{
238
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_MULTI_BOX).changeState("noResults");
231
239
  }
232
240
  }
233
241
 
234
- async function getValueFromValueId(valueId) {
235
- const result = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
236
- return result.find(value => value._id === valueId);
237
-
238
- }
242
+ return count > 0;
243
+ }
239
244
 
240
- async function getLatestJobsByValue(Value) {
241
- const jobs=Value.multiRefJobsCustomValues;
242
- const latestJobs = jobs
243
- .sort((a, b) => new Date(b.releasedDate) - new Date(a.releasedDate))
244
- .slice(0, 5);
245
- return latestJobs;
246
- }
245
+ async function getValueFromValueId(valueId) {
246
+ const result = await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
247
+ console.log("result: ",result);
248
+ console.log("valueId: ",valueId);
249
+
250
+ return result.find(value => value.valueId === valueId);
251
+ }
252
+
253
+ async function getLatestJobsByValue(Value) {
254
+ const jobs=Value.multiRefJobsCustomValues;
255
+ const latestJobs = jobs
256
+ .sort((a, b) => new Date(b.releasedDate) - new Date(a.releasedDate))
257
+ .slice(0, 5);
258
+ return latestJobs;
259
+ }
247
260
 
248
- module.exports = {
249
- groupValuesByField,
250
- debounce,
251
- getAllRecords,
252
- getFieldById,
253
- getFieldByTitle,
254
- getCorrectOption,
255
- getOptionIndexFromCheckBox,
256
- loadPrimarySearchRepeater,
257
- bindPrimarySearch,
258
- primarySearch,
259
- getLatestJobsByValue,
260
- getValueFromValueId,
261
- getAllRecordsWithoutMultiRef
261
+ module.exports = {
262
+ groupValuesByField,
263
+ debounce,
264
+ getAllRecords,
265
+ getFieldById,
266
+ getFieldByTitle,
267
+ getCorrectOption,
268
+ getOptionIndexFromCheckBox,
269
+ loadPrimarySearchRepeater,
270
+ bindPrimarySearch,
271
+ primarySearch,
272
+ getLatestJobsByValue,
273
+ getValueFromValueId,
274
+ getAllRecordsWithoutMultiRef,
275
+ getAllDatasetItems
262
276
  }
@@ -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
- const valueId=supportTeamsPageIds.valueToValueIdMap[currentItem.title_fld]
43
- const Value=await getValueFromValueId(valueId);
44
- if(Value===undefined) {
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;