sr-npm 1.7.697 → 1.7.699

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.697",
3
+ "version": "1.7.699",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
- const { items: wixData } = require('@wix/data');
3
2
  const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds} = require('../backend/careersMultiBoxesPageIds');
4
- const { groupValuesByField } = require('./pagesUtils');
3
+ const { groupValuesByField, debounce, getAllRecords } = require('./pagesUtils');
4
+
5
5
  let dontUpdateThisCheckBox;
6
6
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
7
7
  const optionsByFieldId = new Map(); // fieldId -> [{label, value}] array of objects with label which is the valueLabel and value which is the valueId
@@ -15,19 +15,28 @@ const pagination = {
15
15
  pageSize: 10,
16
16
  currentPage: 1,
17
17
  };
18
- async function careersMultiBoxesPageOnReady(_$w) {
18
+ async function careersMultiBoxesPageOnReady(_$w,queryParams) {
19
19
  await loadData(_$w);
20
20
  await loadJobsRepeater(_$w);
21
21
  await loadFilters(_$w);
22
22
  await loadSelectedValuesRepeater(_$w);
23
23
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CLEAR_ALL_BUTTON_ID).onClick(async () => {
24
+ if(selectedByField.size>0) {
24
25
  selectedByField.clear();
25
- await applyJobFilters(_$w);
26
- await refreshFacetCounts(_$w,true);
27
- await updateSelectedValuesRepeater(_$w);
28
- updateTotalJobsCountText(_$w);
26
+ await updateJobsAndNumbersAndFilters(_$w,true);
27
+ }
29
28
  });
30
29
  await loadPaginationButtons(_$w);
30
+ await handleUrlParams(_$w,queryParams);
31
+ }
32
+
33
+ async function handleUrlParams(_$w,queryParams) {
34
+ if(queryParams.Brand) {
35
+ const brandValue = decodeURIComponent(queryParams.Brand);
36
+ console.log("brandValue: ", brandValue);
37
+ console.log("selectedByField: ", selectedByField);
38
+ console.log("optionsByFieldId: ", optionsByFieldId);
39
+ }
31
40
  }
32
41
 
33
42
  async function loadPaginationButtons(_$w) {
@@ -75,10 +84,7 @@ async function loadSelectedValuesRepeater(_$w) {
75
84
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
76
85
  }
77
86
  }
78
- await applyJobFilters(_$w);
79
- await refreshFacetCounts(_$w);
80
- await updateSelectedValuesRepeater(_$w);
81
- updateTotalJobsCountText(_$w);
87
+ await updateJobsAndNumbersAndFilters(_$w);
82
88
  });
83
89
  });
84
90
  await updateSelectedValuesRepeater(_$w);
@@ -166,16 +172,15 @@ async function loadJobsRepeater(_$w) {
166
172
  } else {
167
173
  selectedByField.delete(field._id);
168
174
  }
169
- await applyJobFilters(_$w); // re-query jobs
170
- await refreshFacetCounts(_$w); // recompute and update counts in all lists
171
- await updateSelectedValuesRepeater(_$w);
172
- updateTotalJobsCountText(_$w);
175
+ await updateJobsAndNumbersAndFilters(_$w);
176
+
173
177
  });
174
178
 
175
179
  const runFilter = debounce(() => {
176
180
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
177
181
  updateOptionsUI(_$w, field.title, field._id, query);
178
182
  }, 150);
183
+
179
184
  _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
180
185
  }
181
186
  }
@@ -187,30 +192,13 @@ async function loadJobsRepeater(_$w) {
187
192
  }
188
193
  }
189
194
 
190
-
191
- async function getAllRecords(collectionId) {
192
- let q = wixData.query(collectionId).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
193
-
194
-
195
- const items = [];
196
- let res = await q.limit(1000).find();
197
- items.push(...res.items);
198
-
199
- while (res.hasNext()) {
200
- res = await res.next();
201
- items.push(...res.items);
202
- }
203
- return items;
195
+ async function updateJobsAndNumbersAndFilters(_$w) {
196
+ await applyJobFilters(_$w); // re-query jobs
197
+ await refreshFacetCounts(_$w); // recompute and update counts in all lists
198
+ await updateSelectedValuesRepeater(_$w);
199
+ updateTotalJobsCountText(_$w);
204
200
  }
205
201
 
206
- const debounce = (fn, ms = 150) => {
207
- let t;
208
- return (...args) => {
209
- clearTimeout(t);
210
- t = setTimeout(() => fn(...args), ms);
211
- };
212
- };
213
-
214
202
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
215
203
  let base = optionsByFieldId.get(fieldId) || [];
216
204
  const countsMap = countsByFieldId.get(fieldId) || new Map();
@@ -31,7 +31,7 @@ if(siteconfig===undefined) {
31
31
  siteconfig = queryResult.items[0];
32
32
  }
33
33
  if(siteconfig.customFields==="true") {
34
- await careersMultiBoxesPageOnReady(_$w);
34
+ await careersMultiBoxesPageOnReady(_$w,queryParams);
35
35
  }
36
36
  else{
37
37
  console.log("queryParams: ", queryParams);
@@ -1,3 +1,6 @@
1
+ const { items: wixData } = require('@wix/data');
2
+ const { JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
3
+
1
4
  function groupValuesByField(values, refKey) {
2
5
  const map = new Map();
3
6
  for (const v of values) {
@@ -11,6 +14,31 @@ function groupValuesByField(values, refKey) {
11
14
  return map;
12
15
  }
13
16
 
17
+ const debounce = (fn, ms = 150) => {
18
+ let t;
19
+ return (...args) => {
20
+ clearTimeout(t);
21
+ t = setTimeout(() => fn(...args), ms);
22
+ };
23
+ };
24
+
25
+ async function getAllRecords(collectionId) {
26
+ let q = wixData.query(collectionId).include(JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES)
27
+
28
+
29
+ const items = [];
30
+ let res = await q.limit(1000).find();
31
+ items.push(...res.items);
32
+
33
+ while (res.hasNext()) {
34
+ res = await res.next();
35
+ items.push(...res.items);
36
+ }
37
+ return items;
38
+ }
39
+
14
40
  module.exports = {
15
41
  groupValuesByField,
42
+ debounce,
43
+ getAllRecords,
16
44
  }