sr-npm 1.7.705 → 1.7.706

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.705",
3
+ "version": "1.7.706",
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
2
  const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds} = require('../backend/careersMultiBoxesPageIds');
3
3
  const { query,queryParams,onChange} = require("wix-location-frontend");
4
- const { groupValuesByField, debounce, getAllRecords } = require('./pagesUtils');
4
+ const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle } = require('./pagesUtils');
5
5
 
6
6
  let dontUpdateThisCheckBox;
7
7
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
@@ -37,8 +37,11 @@ async function handleUrlParams(_$w,urlParams) {
37
37
  console.log("brandValue: ", brandValue);
38
38
  console.log("selectedByField: ", selectedByField);
39
39
  console.log("optionsByFieldId: ", optionsByFieldId);
40
+ console.log("allfields: ", allfields);
41
+ const field=getFieldByTitle("brand",allfields);
42
+ console.log("field: ", field);
40
43
  //await updateJobsAndNumbersAndFilters(_$w);
41
-
44
+
42
45
  }
43
46
  }
44
47
 
@@ -80,13 +83,14 @@ async function loadSelectedValuesRepeater(_$w) {
80
83
  selectedByField.delete(fieldId);
81
84
  }
82
85
 
83
- for(const field of allfields) {
84
- if(field._id===fieldId) {
85
- const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
86
- const nextVals = currentVals.filter(v => v !== valueId);
87
- _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
88
- }
89
- }
86
+ const field=getFieldById(fieldId,allfields);
87
+
88
+
89
+ const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
90
+ const nextVals = currentVals.filter(v => v !== valueId);
91
+ _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
92
+
93
+
90
94
  await updateJobsAndNumbersAndFilters(_$w);
91
95
  });
92
96
  });
@@ -146,47 +150,46 @@ async function loadJobsRepeater(_$w) {
146
150
  counter[city.city]=city.count
147
151
  }
148
152
  for(const [key, value] of valuesByFieldId) {
149
- for(const field of allfields) {
150
- if(field._id===key) {
151
- let originalOptions=[];
152
- if(key==="Location") {
153
- originalOptions=value.map(city=>({
154
- label: city.city,
155
- value: city._id
156
- }));
157
- }
158
- else{
159
- originalOptions=value
160
- }
153
+ const field=getFieldById(key,allfields);
154
+ let originalOptions=[];
155
+ if(key==="Location") {
156
+ originalOptions=value.map(city=>({
157
+ label: city.city,
158
+ value: city._id
159
+ }));
160
+ }
161
+ else{
162
+ originalOptions=value
163
+ }
161
164
 
162
- optionsByFieldId.set(key, originalOptions);
163
- for (const val of allvaluesobjects) {
164
- counter[val.title]=val.totalJobs
165
- }
165
+ optionsByFieldId.set(key, originalOptions);
166
+ for (const val of allvaluesobjects) {
167
+ counter[val.title]=val.totalJobs
168
+ }
166
169
 
167
- countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
168
- updateOptionsUI(_$w,field.title, field._id, ''); // no search query
169
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
170
- _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
171
- dontUpdateThisCheckBox=field._id;
172
- const selected = ev.target.value; // array of selected value IDs
173
- if (selected && selected.length) {
174
- selectedByField.set(field._id, selected);
175
- } else {
176
- selectedByField.delete(field._id);
177
- }
178
- await updateJobsAndNumbersAndFilters(_$w);
179
-
180
- });
170
+ countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
171
+ updateOptionsUI(_$w,field.title, field._id, ''); // no search query
172
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
173
+ _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
174
+ dontUpdateThisCheckBox=field._id;
175
+ const selected = ev.target.value; // array of selected value IDs
176
+ if (selected && selected.length) {
177
+ selectedByField.set(field._id, selected);
178
+ } else {
179
+ selectedByField.delete(field._id);
180
+ }
181
+ await updateJobsAndNumbersAndFilters(_$w);
182
+
183
+ });
181
184
 
182
- const runFilter = debounce(() => {
183
- const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
184
- updateOptionsUI(_$w, field.title, field._id, query);
185
- }, 150);
185
+ const runFilter = debounce(() => {
186
+ const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
187
+ updateOptionsUI(_$w, field.title, field._id, query);
188
+ }, 150);
186
189
 
187
- _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
188
- }
189
- }
190
+ _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
191
+
192
+
190
193
  }
191
194
  await refreshFacetCounts(_$w);
192
195
 
@@ -195,6 +198,8 @@ async function loadJobsRepeater(_$w) {
195
198
  }
196
199
  }
197
200
 
201
+
202
+
198
203
  async function updateJobsAndNumbersAndFilters(_$w) {
199
204
  await applyJobFilters(_$w); // re-query jobs
200
205
  await refreshFacetCounts(_$w); // recompute and update counts in all lists
@@ -37,8 +37,18 @@ function groupValuesByField(values, refKey) {
37
37
  return items;
38
38
  }
39
39
 
40
+ function getFieldById(fieldId,allFields) {
41
+ return allFields.find(field=>field._id===fieldId);
42
+ }
43
+
44
+ function getFieldByTitle(title,allFields) {
45
+ return allFields.find(field=>field.title===title);
46
+ }
47
+
40
48
  module.exports = {
41
49
  groupValuesByField,
42
50
  debounce,
43
51
  getAllRecords,
52
+ getFieldById,
53
+ getFieldByTitle,
44
54
  }