sr-npm 1.7.704 → 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.704",
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,7 +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);
44
+
41
45
  }
42
46
  }
43
47
 
@@ -79,13 +83,14 @@ async function loadSelectedValuesRepeater(_$w) {
79
83
  selectedByField.delete(fieldId);
80
84
  }
81
85
 
82
- for(const field of allfields) {
83
- if(field._id===fieldId) {
84
- const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
85
- const nextVals = currentVals.filter(v => v !== valueId);
86
- _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
87
- }
88
- }
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
+
89
94
  await updateJobsAndNumbersAndFilters(_$w);
90
95
  });
91
96
  });
@@ -145,47 +150,46 @@ async function loadJobsRepeater(_$w) {
145
150
  counter[city.city]=city.count
146
151
  }
147
152
  for(const [key, value] of valuesByFieldId) {
148
- for(const field of allfields) {
149
- if(field._id===key) {
150
- let originalOptions=[];
151
- if(key==="Location") {
152
- originalOptions=value.map(city=>({
153
- label: city.city,
154
- value: city._id
155
- }));
156
- }
157
- else{
158
- originalOptions=value
159
- }
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
+ }
160
164
 
161
- optionsByFieldId.set(key, originalOptions);
162
- for (const val of allvaluesobjects) {
163
- counter[val.title]=val.totalJobs
164
- }
165
+ optionsByFieldId.set(key, originalOptions);
166
+ for (const val of allvaluesobjects) {
167
+ counter[val.title]=val.totalJobs
168
+ }
165
169
 
166
- countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
167
- updateOptionsUI(_$w,field.title, field._id, ''); // no search query
168
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
169
- _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
170
- dontUpdateThisCheckBox=field._id;
171
- const selected = ev.target.value; // array of selected value IDs
172
- if (selected && selected.length) {
173
- selectedByField.set(field._id, selected);
174
- } else {
175
- selectedByField.delete(field._id);
176
- }
177
- await updateJobsAndNumbersAndFilters(_$w);
178
-
179
- });
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
+ });
180
184
 
181
- const runFilter = debounce(() => {
182
- const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
183
- updateOptionsUI(_$w, field.title, field._id, query);
184
- }, 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);
185
189
 
186
- _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
187
- }
188
- }
190
+ _$w(`#${FiltersIds[field.title]}input`).onInput(runFilter);
191
+
192
+
189
193
  }
190
194
  await refreshFacetCounts(_$w);
191
195
 
@@ -194,6 +198,8 @@ async function loadJobsRepeater(_$w) {
194
198
  }
195
199
  }
196
200
 
201
+
202
+
197
203
  async function updateJobsAndNumbersAndFilters(_$w) {
198
204
  await applyJobFilters(_$w); // re-query jobs
199
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
  }