sr-npm 1.7.618 → 1.7.620

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.618",
3
+ "version": "1.7.620",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,14 +2,13 @@ const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = r
2
2
  const { items: wixData } = require('@wix/data');
3
3
  const {CAREERS_MULTI_BOXES_PAGE_CONSTS} = require('../backend/careersMultiBoxesPageIds');
4
4
 
5
- let valuesByFieldIdGlobal = null;
6
5
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
7
6
  const optionsByFieldId = new Map(); // fieldId -> [{label, value}]
8
7
  const countsByFieldId = new Map();
9
- let alljobs=[]
10
- let allvaluesobjects=[]
11
- let valueToJobs={}
12
- let currentJobs=[]
8
+ let alljobs=[] // all jobs in the database
9
+ let allvaluesobjects=[] // all values in the database
10
+ let valueToJobs={} // valueId -> array of jobIds
11
+ let currentJobs=[] // current jobs that are displayed in the jobs repeater
13
12
  async function careersMultiBoxesPageOnReady(_$w) {
14
13
  if(alljobs.length===0) {
15
14
  alljobs=await getAllRecords(COLLECTIONS.JOBS);
@@ -37,6 +36,7 @@ async function careersMultiBoxesPageOnReady(_$w) {
37
36
  const updated = existing.filter(v => v !== valueId);
38
37
  if (updated.length) {
39
38
  selectedByField.set(fieldId, updated);
39
+ console.log("selectedByField: ",selectedByField)
40
40
  } else {
41
41
  selectedByField.delete(fieldId);
42
42
  }
@@ -53,6 +53,7 @@ async function careersMultiBoxesPageOnReady(_$w) {
53
53
  await applyJobFilters(_$w,JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES);
54
54
  await refreshFacetCounts(_$w);
55
55
  await updateSelectedValuesRepeater(_$w);
56
+ updateTotalJobsCountText(_$w);
56
57
  });
57
58
  });
58
59
  await updateSelectedValuesRepeater(_$w);
@@ -65,15 +66,11 @@ async function loadJobs(_$w) {
65
66
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER_ITEM_LOCATION).text=itemData.location.fullLocation
66
67
  });
67
68
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = alljobs;
68
-
69
- // return wixData.query(COLLECTIONS.JOBS)
70
- // .find()
71
- // .then((res) => {
72
- // _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = res.items;
73
- // })
74
- // .catch((err) => {
75
- // console.error('Failed to load jobs:', err);
76
- // });
69
+ updateTotalJobsCountText(_$w);
70
+ }
71
+
72
+ function updateTotalJobsCountText(_$w) {
73
+ _$w('#totalJobsCountText').text = `${currentJobs.length} Jobs`;
77
74
  }
78
75
 
79
76
  async function loadFilters(_$w) {
@@ -105,6 +102,7 @@ async function loadJobs(_$w) {
105
102
  value: v._id
106
103
  }));
107
104
  optionsByFieldId.set(fieldId, originalOptions);
105
+ console.log("optionsByFieldId: ",optionsByFieldId)
108
106
  const counter={}
109
107
 
110
108
  for (const val of allvaluesobjects) {
@@ -112,11 +110,11 @@ async function loadJobs(_$w) {
112
110
  }
113
111
 
114
112
  countsByFieldId.set(fieldId, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
113
+ console.log("countsByFieldId: ",countsByFieldId)
115
114
 
116
115
  // Initialize UI
117
116
  updateOptionsUI($item, fieldId, ''); // no search query
118
117
 
119
- //$item(CHECKBOX_GROUP_ID).options = originalOptions;
120
118
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_REPEATER_ITEM_CHECKBOX).selectedIndices = []; // start empty
121
119
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_REPEATER_ITEM_CHECKBOX).onChange(async (ev) => {
122
120
  const selected = ev.target.value; // array of selected value IDs
@@ -128,7 +126,7 @@ async function loadJobs(_$w) {
128
126
  await applyJobFilters(_$w,JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES); // re-query jobs
129
127
  await refreshFacetCounts(_$w); // recompute and update counts in all lists
130
128
  await updateSelectedValuesRepeater(_$w);
131
-
129
+ updateTotalJobsCountText(_$w);
132
130
  });
133
131
 
134
132
  // Input typing -> only filter this list’s visible options (no Jobs query)
@@ -187,14 +185,10 @@ async function loadJobs(_$w) {
187
185
  value: o.value
188
186
  };
189
187
  });
190
- console.log("base: ",base)
191
- console.log("countsMap: ",countsMap)
192
- console.log("withCounts: ",withCounts)
193
188
  // Apply search
194
189
  const filtered = searchQuery
195
190
  ? withCounts.filter(o => (o.label || '').toLowerCase().includes(searchQuery))
196
191
  : withCounts;
197
- console.log("filte@$@#@#$red: ",filtered)
198
192
 
199
193
  // Preserve currently selected values that are still visible
200
194
  const prevSelected = $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_REPEATER_ITEM_CHECKBOX).value || [];
@@ -206,9 +200,6 @@ async function loadJobs(_$w) {
206
200
  }
207
201
 
208
202
  async function applyJobFilters(_$w,filterByField) {
209
- console.log("applying job filters")
210
- console.log("selectedByField: ",selectedByField)
211
-
212
203
  let q = wixData.query(COLLECTIONS.JOBS)
213
204
 
214
205
  // AND across categories, OR within each category
@@ -221,103 +212,26 @@ async function loadJobs(_$w) {
221
212
  await q.find()
222
213
  .then(async (res) => { _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = res.items;
223
214
  await updateCurrentJobs(res);
224
- // currentJobs=res.items.map(job=>job._id);
225
- console.log("updated currentJobs adfger fucniton: ",currentJobs)
226
215
  })
227
216
  .catch((err) => { console.error('Failed to filter jobs:', err); });
228
217
  }
229
218
 
230
219
 
231
- async function refreshFacetCounts(_$w) {
232
- // if (!valuesByFieldIdGlobal)
233
- // {
234
- // return;
235
- // }
236
-
220
+ async function refreshFacetCounts(_$w) {
237
221
  console.log("current countsByFieldId: ",countsByFieldId)
238
222
  const fieldIds = Array.from(optionsByFieldId.keys());
239
223
  for (const fieldId of fieldIds) {
240
224
  let currentoptions=optionsByFieldId.get(fieldId)
241
- //console.log("currentoptions@@@@@@@@@@@@@: ",currentoptions)
242
225
  let counter=new Map();
243
226
  for(const option of currentoptions) {
244
- console.log("currentJobs length: ",currentJobs.length)
245
227
  for (const jobId of currentJobs) {
246
228
  if (valueToJobs[option.value].includes(jobId)) {
247
229
  counter.set(option.value, (counter.get(option.value) || 0) + 1);
248
230
  }
249
231
  }
250
232
  }
251
- console.log("counter: ",counter)
252
- console.log("fieldId: ",fieldId)
253
233
  countsByFieldId.set(fieldId, counter);
254
234
  }
255
- console.log("new countsByFieldId: ",countsByFieldId)
256
- // for (const valueId of Object.keys(valueToJobs)) {
257
- // for (const jobId of currentJobs) {
258
- // if (valueToJobs[valueId].includes(jobId)) {
259
- // counter.set(valueId, (countsByFieldId.get(valueId) || 0) + 1);
260
- // }
261
- // }
262
- // }
263
- // }
264
- // for (const valueId of Object.keys(valueToJobs)) {
265
- // for (const jobId of currentJobs) {
266
- // if (valueToJobs[valueId].includes(jobId)) {
267
- // counter.set(valueId, (countsByFieldId.get(valueId) || 0) + 1);
268
- // }
269
- // }
270
- // }
271
-
272
-
273
-
274
-
275
-
276
- // // Run per-field queries in parallel
277
- // const tasks = fieldIds.map(async (fieldId) => {
278
- // // Build query with selections from all other fields
279
- // let q = wixData.query(COLLECTIONS.JOBS);
280
- // for (const [fid, values] of selectedByField.entries()) {
281
- // if (fid !== fieldId && values && values.length) {
282
- // q = q.hasSome(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES, values);
283
- // }
284
- // }
285
-
286
- // // Fetch all matching jobs (paged)
287
- // const jobs = await findAll(q);
288
-
289
-
290
- // // Prepare a set of valid option IDs for this field
291
- // const options = optionsByFieldId.get(fieldId) || [];
292
- // const optionSet = new Set(options.map(o => o.value));
293
-
294
- // // Tally counts
295
- // const counts = new Map(); // valueId -> count
296
- // for (const job of jobs) {
297
- // const referencedfield= await wixData.queryReferenced(COLLECTIONS.JOBS, job, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
298
- // //console.log("referencedfield: ",referencedfield)
299
- // const vals = referencedfield.items
300
- // //const vals = job[JOB_VALUES_FIELD] || [];
301
- // for (const val of vals) {
302
- // if (optionSet.has(val._id)) {
303
- // counts.set(val._id, (counts.get(val._id) || 0) + 1);
304
- // }
305
- // }
306
-
307
- // }
308
-
309
- // // Ensure every option has a count (zero if absent)
310
- // for (const o of options) {
311
- // if (!counts.has(o.value))
312
- // {
313
- // counts.set(o.value, 0);}
314
- // }
315
-
316
- // countsByFieldId.set(fieldId, counts);
317
- // });
318
-
319
- // await Promise.all(tasks);
320
-
321
235
  // // After counts are ready, update all items currently rendered
322
236
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_REPEATER).forEachItem(($item, itemData) => {
323
237
  const query = ($item(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_LABEL).value || '').toLowerCase().trim();
@@ -337,7 +251,6 @@ async function refreshFacetCounts(_$w) {
337
251
  }
338
252
 
339
253
  function updateSelectedValuesRepeater(_$w) {
340
- console.log("updating selected values repeater")
341
254
  const selectedItems = [];
342
255
  for (const [fieldId, valueIds] of selectedByField.entries()) {
343
256
  const opts = optionsByFieldId.get(fieldId) || [];
@@ -345,7 +258,8 @@ async function refreshFacetCounts(_$w) {
345
258
  for (const id of valueIds) {
346
259
  const label = byId.get(id);
347
260
  if (label) {
348
- selectedItems.push({ _id: `${fieldId}:${id}`, label, fieldId, valueId: id });
261
+ //selectedItems.push({ _id: `${fieldId}:${id}`, label, fieldId, valueId: id });
262
+ selectedItems.push({ label, fieldId, valueId: id });
349
263
  }
350
264
  }
351
265
  }
@@ -364,18 +278,6 @@ async function refreshFacetCounts(_$w) {
364
278
  console.log("updated currentJobs inisde new function: ",currentJobs)
365
279
  }
366
280
 
367
- async function findAll(q) {
368
- const out = [];
369
- let res = await q.limit(1000).find();
370
- out.push(...res.items);
371
- while (res.hasNext()) {
372
- res = await res.next();
373
- out.push(...res.items);
374
- }
375
- return out;
376
- }
377
-
378
-
379
281
  module.exports = {
380
282
  careersMultiBoxesPageOnReady
381
283
  };