sr-npm 1.7.1065 → 1.7.1066

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.
@@ -5,7 +5,7 @@ on:
5
5
  branches:
6
6
  - main
7
7
  workflow_dispatch:
8
-
8
+
9
9
  permissions:
10
10
  contents: write
11
11
  packages: write
@@ -39,6 +39,11 @@ const fieldTitlesInCMS={
39
39
  "brand": "Brands",
40
40
  category: "Category",
41
41
  visibility: "Visibility",
42
+ location: "Location",
43
+ employmenttype: "Employment Type",
44
+ contracttype: "Contract Type",
45
+ companysegment: "Company Segment",
46
+ storename: "Store Name",
42
47
  }
43
48
 
44
49
  const FiltersIds={
@@ -52,10 +57,21 @@ const FiltersIds={
52
57
  Visibility: 'Visibility',
53
58
  }
54
59
 
60
+ const possibleUrlParams=[
61
+ "brand",
62
+ "location",
63
+ "employmenttype",
64
+ "contracttype",
65
+ "visibility",
66
+ "category",
67
+ "companysegment",
68
+ "storename",
69
+ ]
55
70
 
56
71
  module.exports = {
57
72
  CAREERS_MULTI_BOXES_PAGE_CONSTS,
58
73
  FiltersIds,
59
74
  fieldTitlesInCMS,
60
75
  CATEGORY_CUSTOM_FIELD_ID_IN_CMS,
76
+ possibleUrlParams,
61
77
  }
@@ -31,6 +31,7 @@ const JOBS_COLLECTION_FIELDS = {
31
31
  MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
32
32
  EMPLOYMENT_TYPE: 'employmentType',
33
33
  RELEASED_DATE: 'releasedDate',
34
+ REF_ID: 'refId',
34
35
  }
35
36
  const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
36
37
  TITLE: 'title',
@@ -93,6 +94,7 @@ const COLLECTIONS_FIELDS = {
93
94
  {key: 'image', type: 'IMAGE' },
94
95
  {key:'employmentType', type: 'TEXT'},
95
96
  {key:'releasedDate', type: 'TEXT'},
97
+ {key:'refId', type: 'TEXT'},
96
98
  ],
97
99
  TEMPLATE_TYPE: [
98
100
  {key:'templateType', type: 'TEXT'},
package/backend/consts.js CHANGED
@@ -72,9 +72,6 @@ const TASKS = {
72
72
  }
73
73
  }
74
74
 
75
-
76
-
77
-
78
75
  const TASK_TYPE = {
79
76
  SCHEDULED: 'scheduled',
80
77
  EVENT: 'event',
@@ -92,10 +89,6 @@ const supportTeamsPageIds={
92
89
  VIDEO_TITLE: "#videoTitle",
93
90
  VIDEO_PLAYER: "#videoPlayer",
94
91
 
95
-
96
-
97
-
98
-
99
92
  RECENTLEY_ADDED_JOBS_ITEM: "#recentleyAddedJobsItem",
100
93
  JOB_LOCATION: "#jobLocation",
101
94
  JOB_TITLE: "#jobTitle",
@@ -137,12 +130,13 @@ const supportTeamsPageSections={
137
130
  VIDEO: "video",
138
131
  }
139
132
 
140
- module.exports = {
141
- TASKS_NAMES,
142
- TASK_TYPE,
143
- TASKS,
144
- QUERY_MAX_LIMIT,
145
- supportTeamsPageIds,
146
- LINKS,
147
- supportTeamsPageSections,
133
+
134
+ module.exports = {
135
+ TASKS_NAMES,
136
+ TASK_TYPE,
137
+ TASKS,
138
+ QUERY_MAX_LIMIT,
139
+ supportTeamsPageIds,
140
+ LINKS,
141
+ supportTeamsPageSections,
148
142
  };
package/backend/data.js CHANGED
@@ -1,13 +1,11 @@
1
1
  const { items: wixData } = require('@wix/data');
2
- const { fetchPositionsFromSRAPI, fetchJobDescription, htmlRichContentConverter } = require('./fetchPositionsFromSRAPI');
2
+ const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
3
3
  const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
4
4
  const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME,CUSTOM_VALUES_COLLECTION_FIELDS } = require('./collectionConsts');
5
5
  const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeString} = require('./utils');
6
6
  const { getAllPositions } = require('./queries');
7
7
  const { retrieveSecretVal, getTokenFromCMS ,getApiKeys} = require('./secretsData');
8
8
 
9
-
10
-
11
9
  let customValuesToJobs = {}
12
10
  let locationToJobs = {}
13
11
  let siteconfig;
@@ -21,6 +19,7 @@ async function getSiteConfig() {
21
19
  const queryresult = await wixData.query(COLLECTIONS.SITE_CONFIGS).find();
22
20
  siteconfig = queryresult.items[0];
23
21
  }
22
+
24
23
  function validatePosition(position) {
25
24
  if (!position.id) {
26
25
  throw new Error('Position id is required');
@@ -40,22 +39,22 @@ function validatePosition(position) {
40
39
  async function filterBasedOnBrand(positions) {
41
40
  try{
42
41
 
43
- const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
44
- validateSingleDesiredBrand(desiredBrand);
45
- console.log("filtering positions based on brand: ", desiredBrand);
46
- return positions.content.filter(position => {
47
- const brand = getBrand(position.customField);
48
- if (!brand) return false;
49
- return brand === desiredBrand;
50
- });
51
- } catch (error) {
52
- if(error.message==="[getTokenFromCMS], No desiredBrand found")
53
- {
54
- console.log("no desiredBrand found, fetching all positions")
55
- return positions.content;
42
+ const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
43
+ validateSingleDesiredBrand(desiredBrand);
44
+ console.log("filtering positions based on brand: ", desiredBrand);\
45
+ return positions.content.filter(position => {
46
+ const brand = getBrand(position.customField);
47
+ if (!brand) return false;
48
+ return brand === desiredBrand;
49
+ });
50
+ } catch (error) {
51
+ if(error.message==="[getTokenFromCMS], No desiredBrand found")
52
+ {
53
+ console.log("no desiredBrand found, fetching all positions")
54
+ return positions.content;
55
+ }
56
+ throw error;
56
57
  }
57
- throw error;
58
- }
59
58
  }
60
59
 
61
60
  function validateSingleDesiredBrand(desiredBrand) {
@@ -63,11 +62,12 @@ function validateSingleDesiredBrand(desiredBrand) {
63
62
  throw new Error("Desired brand must be a single brand");
64
63
  }
65
64
  }
66
- function getLocation(position,basicJob) {
67
65
 
66
+ function getLocation(position,basicJob) {
68
67
  locationToJobs[basicJob.cityText] ? locationToJobs[basicJob.cityText].push(position.id) : locationToJobs[basicJob.cityText]=[position.id]
69
68
 
70
69
  }
70
+
71
71
  function getVisibility(position,customFieldsValues) {
72
72
  if (!customFieldsValues["Visibility"]) {
73
73
  customFieldsValues["Visibility"] = {};
@@ -99,8 +99,8 @@ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,custom
99
99
  if (!customFieldsValues[fieldId]) {
100
100
  customFieldsValues[fieldId] = {};
101
101
  }
102
+
102
103
  customFieldsValues[fieldId][valueId] = valueLabel;
103
-
104
104
  customValuesToJobs[valueId] ? customValuesToJobs[valueId].add(position.id) : customValuesToJobs[valueId]=new Set([position.id])
105
105
  }
106
106
  }
@@ -140,7 +140,8 @@ async function saveJobsDataToCMS() {
140
140
  brand: siteconfig.disableMultiBrand==="false" ? getBrand(position.customField) : '',
141
141
  jobDescription: null, // Will be filled later
142
142
  employmentType: position.typeOfEmployment.label,
143
- releasedDate: position.releasedDate
143
+ releasedDate: position.releasedDate,
144
+ refId: position.refNumber
144
145
  };
145
146
 
146
147
  getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
@@ -269,13 +270,14 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
269
270
  const chunkPromises = chunk.map(async job => {
270
271
  try {
271
272
  const jobDetails = await fetchJobDescription(job._id);
272
- const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections);
273
273
  const jobLocation = fetchJobLocation(jobDetails);
274
274
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
275
+
276
+
275
277
  const updatedJob = {
276
278
  ...job,
277
279
  locationAddress: jobLocation,
278
- jobDescription: richContentDescription,
280
+ jobDescription: jobDetails.jobAd.sections,
279
281
  applyLink: applyLink,
280
282
  referFriendLink: referFriendLink,
281
283
  };
@@ -484,11 +486,14 @@ async function syncJobsFast() {
484
486
  await createCollections();
485
487
  await clearCollections();
486
488
  await fillSecretManagerMirror();
489
+
487
490
  console.log("saving jobs data to CMS");
488
491
  await saveJobsDataToCMS();
489
492
  console.log("saved jobs data to CMS successfully");
493
+
490
494
  console.log("saving jobs descriptions and location apply url to CMS");
491
495
  await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
496
+
492
497
  console.log("saved jobs descriptions and location apply url to CMS successfully");
493
498
  await aggregateJobs();
494
499
  await referenceJobs();
@@ -1,8 +1,9 @@
1
1
  const { fetch } = require('wix-fetch');
2
2
  const { TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
3
3
  const { getTokenFromCMS,getApiKeys } = require('./secretsData');
4
+
4
5
  async function makeSmartRecruitersRequest(path,templateType) {
5
- const baseUrl = 'https://api.smartrecruiters.com';
6
+ const baseUrl = 'https://api.smartrecruiters.com';
6
7
  const fullUrl = `${baseUrl}${path}`;
7
8
 
8
9
  try {
@@ -113,49 +114,11 @@ async function fetchJobDescription(jobId,testObject=undefined) {
113
114
  return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
114
115
  }
115
116
 
116
- async function htmlRichContentConverter(sections) {
117
-
118
- console.log("sections: are ",sections);
119
- const richContentObject = {}
120
- for (const section of sections) {
121
- console.log("section: is ",section);
122
- if (section.text) {
123
- const raw = JSON.stringify({
124
- content: section.text,
125
- });
126
- const requestOptions = {
127
- method: 'post',
128
- headers: {
129
- 'Content-Type': 'application/json',
130
- Cookie: 'XSRF-TOKEN=1753949844|p--a7HsuVjR4',
131
- Authorization: 'Bearer 2e19efe5f44d29d74480f5b744a5a90f19ba6ca7012ced19e7b14edb1ad6a641',
132
- },
133
- body: raw,
134
- };
135
- const response = await fetch(
136
- 'https://www.wixapis.com/data-sync/v1/abmp-content-converter',
137
- requestOptions
138
- );
139
- if (response.ok) {
140
- const data = await response.json();
141
- console.log("response is ok")
142
- richContentObject[section.title] = data.richContent.richContent;
143
- }
144
- else {
145
- throw new Error("Error converting html to rich content response: "+response);
146
- }
147
- }
148
- }
149
- console.log("richContentObject: are ",richContentObject);
150
- return richContentObject;
151
- }
152
-
153
117
 
154
118
 
155
119
 
156
120
  module.exports = {
157
121
  fetchPositionsFromSRAPI,
158
122
  fetchJobDescription,
159
- makeSmartRecruitersRequest,
160
- htmlRichContentConverter
123
+ makeSmartRecruitersRequest
161
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.1065",
3
+ "version": "1.7.1066",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,9 +1,11 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
- const { queryParams} = require('wix-location-frontend');
2
+
3
+ const { queryParams,onChange} = require('wix-location-frontend');
3
4
  const { location } = require("@wix/site-location");
4
- const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS} = require('../backend/careersMultiBoxesPageIds');
5
+ const {CAREERS_MULTI_BOXES_PAGE_CONSTS,FiltersIds,fieldTitlesInCMS,possibleUrlParams} = require('../backend/careersMultiBoxesPageIds');
5
6
  const { groupValuesByField, debounce, getAllRecords, getFieldById, getFieldByTitle,getCorrectOption,getOptionIndexFromCheckBox,loadPrimarySearchRepeater,bindPrimarySearch,primarySearch } = require('./pagesUtils');
6
7
 
8
+
7
9
  let dontUpdateThisCheckBox;
8
10
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
9
11
  const optionsByFieldId = new Map(); // fieldId -> [{label, value}] array of objects with label which is the valueLabel and value which is the valueId
@@ -22,6 +24,10 @@ const pagination = {
22
24
  currentPage: 1,
23
25
  };
24
26
  async function careersMultiBoxesPageOnReady(_$w,urlParams) {
27
+ //to handle back and forth , url changes
28
+ onChange(async ()=>{
29
+ await handleBackAndForth(_$w);
30
+ });
25
31
  await loadData(_$w);
26
32
  loadJobsRepeater(_$w);
27
33
  loadPrimarySearchRepeater(_$w);
@@ -29,6 +35,10 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
29
35
  loadSelectedValuesRepeater(_$w);
30
36
  bindSearchInput(_$w);
31
37
  loadPaginationButtons(_$w);
38
+
39
+ if (await window.formFactor() === "Mobile") {
40
+ handleFilterInMobile(_$w);
41
+ }
32
42
 
33
43
  await handleUrlParams(_$w, urlParams);
34
44
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.CLEAR_ALL_BUTTON_ID).onClick(async () => {
@@ -37,7 +47,15 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
37
47
 
38
48
  }
39
49
 
40
- async function clearAll(_$w) {
50
+ async function handleBackAndForth(_$w){
51
+ const newQueryParams=await location.query();
52
+ console.log("newQueryParams: ", newQueryParams);
53
+ await clearAll(_$w,true);
54
+ await handleUrlParams(_$w,newQueryParams);
55
+
56
+ }
57
+
58
+ async function clearAll(_$w,urlOnChange=false) {
41
59
  if(selectedByField.size>0 || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.SECONDARY_SEARCH_INPUT).value || _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value) {
42
60
  for(const field of allfields) {
43
61
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [];
@@ -48,34 +66,76 @@ async function clearAll(_$w) {
48
66
  secondarySearchIsFilled=false;
49
67
  currentJobs=alljobs;
50
68
  keywordAllJobs=undefined;
69
+ if(!urlOnChange) {
70
+ queryParams.remove(possibleUrlParams.concat(["keyword", "page"]));
71
+ }
51
72
  await updateJobsAndNumbersAndFilters(_$w,true);
52
73
  }
53
74
  }
54
75
 
76
+ function handleFilterInMobile(_$w) {
77
+ const searchResultsSelectors = [
78
+ CAREERS_PAGE_SELECTORS.RESULT_BOX,
79
+ CAREERS_PAGE_SELECTORS.PAGINATION_BTN,
80
+ CAREERS_PAGE_SELECTORS.HEAD_BTNS,
81
+ CAREERS_PAGE_SELECTORS.SELECTED_VALUES_REPEATER,
82
+ CAREERS_PAGE_SELECTORS.BUTTOM_TXT,
83
+ CAREERS_PAGE_SELECTORS.SECTION_24,
84
+ CAREERS_PAGE_SELECTORS.SECTION_3,
85
+ CAREERS_PAGE_SELECTORS.LINE_3,
86
+ CAREERS_PAGE_SELECTORS.FILTER_ICON];
87
+
88
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_ICON).onClick(()=>{
89
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_BOX).expand();
90
+ searchResultsSelectors.forEach(selector => {
91
+ _$w(selector).collapse();
92
+ });
93
+ });
94
+
95
+ const exitFilterBox = () => {
96
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_BOX).collapse();
97
+ searchResultsSelectors.forEach(selector => {
98
+ _$w(selector).expand();
99
+ });
100
+ }
101
+
102
+ _$w(CAREERS_PAGE_SELECTORS.EXIT_BUTTON).onClick(()=>{
103
+ exitFilterBox();
104
+ });
105
+
106
+ _$w(CAREERS_PAGE_SELECTORS.REFINE_SEARCH_BUTTON).onClick(()=>{
107
+ exitFilterBox();
108
+ });
109
+ }
110
+
55
111
 
56
112
  async function handleUrlParams(_$w,urlParams) {
57
113
  try {
58
114
  let applyFiltering=false;
59
-
115
+ let currentApplyFilterFlag=false;
116
+ //apply this first to determine all jobs
60
117
  if(urlParams.keyword) {
61
118
  applyFiltering=await primarySearch(_$w, decodeURIComponent(urlParams.keyword), alljobs);
62
119
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PRIMARY_SEARCH_INPUT).value=decodeURIComponent(urlParams.keyword);
63
120
  currentJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
64
121
  keywordAllJobs=_$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOB_RESULTS_REPEATER).data;
65
122
  }
66
- if(urlParams.brand) {
67
- applyFiltering=await handleParams(_$w,"brand",urlParams.brand)
68
- }
69
- if(urlParams.visibility) {
70
- applyFiltering=await handleParams(_$w,"visibility",urlParams.visibility)
71
- }
72
- if(urlParams.category) {
73
- applyFiltering=await handleParams(_$w,"category",urlParams.category)
123
+
124
+ for (const url of possibleUrlParams)
125
+ {
126
+ if(urlParams[url])
127
+ {
128
+ currentApplyFilterFlag=await handleParams(_$w,url,urlParams[url])
129
+ if(currentApplyFilterFlag) {
130
+ applyFiltering=true;
131
+ }
74
132
  }
75
-
133
+ currentApplyFilterFlag=false;
134
+ }
76
135
  if(applyFiltering || keywordAllJobs) {
77
136
  await updateJobsAndNumbersAndFilters(_$w);
78
137
  }
138
+
79
139
  if(urlParams.page) {
80
140
  if(Number.isNaN(Number(urlParams.page)) || Number(urlParams.page)<=1 || Number(urlParams.page)>Math.ceil(currentJobs.length/pagination.pageSize)) {
81
141
  console.warn("page number is invalid, removing page from url");
@@ -83,14 +143,14 @@ async function handleUrlParams(_$w,urlParams) {
83
143
  return;
84
144
  }
85
145
  pagination.currentPage=Number(urlParams.page);
86
- let paginationCurrentText=Number(urlParams.page)*pagination.pageSize
146
+ //let paginationCurrentText=urlParams.page;
87
147
  let startSlicIndex=pagination.pageSize*(pagination.currentPage-1);
88
148
  let endSlicIndex=(pagination.pageSize)*(pagination.currentPage);
89
149
  if(Number(urlParams.page)==Math.ceil(currentJobs.length/pagination.pageSize)) {
90
- paginationCurrentText=paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize));
150
+ // paginationCurrentText=(paginationCurrentText-(pagination.pageSize-(currentJobs.length%pagination.pageSize))).toString();
91
151
  endSlicIndex=currentJobs.length;
92
152
  }
93
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = paginationCurrentText.toString();
153
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = urlParams.page
94
154
  const jobsFirstPage=currentJobs.slice(startSlicIndex,endSlicIndex);
95
155
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
96
156
  handlePaginationButtons(_$w);
@@ -100,31 +160,49 @@ async function handleUrlParams(_$w,urlParams) {
100
160
  }
101
161
  }
102
162
 
103
- async function handleParams(_$w,param,value) {
163
+ async function handleParams(_$w,param,values) {
104
164
  let applyFiltering=false;
165
+ let valuesAsArray = values.split(',')
166
+ valuesAsArray=valuesAsArray.filter(value=>value.trim()!=='');
167
+
168
+ let selectedIndices=[];
169
+ const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
170
+
171
+ let existing = selectedByField.get(field._id) || [];
172
+ for(const value of valuesAsArray) {
173
+
105
174
  const decodedValue = decodeURIComponent(value);
106
- const field=getFieldByTitle(fieldTitlesInCMS[param],allfields);
175
+
107
176
  const options=optionsByFieldId.get(field._id);
108
- const option=getCorrectOption(decodedValue,options);
177
+
178
+ const option=getCorrectOption(decodedValue,options,param);
179
+
109
180
  if(option) {
110
181
  const optionIndex=getOptionIndexFromCheckBox(_$w(`#${FiltersIds[field.title]}CheckBox`).options,option.value);
111
- _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = [optionIndex];
112
- selectedByField.set(field._id, [option.value]);
182
+ selectedIndices.push(optionIndex);
183
+ existing.push(option.value);
113
184
  applyFiltering=true;
114
185
  dontUpdateThisCheckBox=field._id;
115
186
  }
116
187
  else {
117
188
  console.warn(`${param} value not found in dropdown options`);
118
189
  }
119
- return applyFiltering;
190
+ }
191
+
192
+ selectedByField.set(field._id, existing);
193
+ _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices=selectedIndices;
194
+
195
+ return applyFiltering;
196
+
120
197
  }
121
198
 
122
199
  function loadPaginationButtons(_$w) {
123
200
  try {
124
201
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_NEXT).onClick(async () => {
125
202
  let nextPageJobs=currentJobs.slice(pagination.pageSize*pagination.currentPage,pagination.pageSize*(pagination.currentPage+1));
126
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (nextPageJobs.length+pagination.pageSize*pagination.currentPage).toString();
203
+
127
204
  pagination.currentPage++;
205
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
128
206
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = nextPageJobs;
129
207
  handlePaginationButtons(_$w);
130
208
  });
@@ -132,7 +210,7 @@ async function handleParams(_$w,param,value) {
132
210
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.PAGE_BUTTON_PREVIOUS).onClick(async () => {
133
211
  let previousPageJobs=currentJobs.slice(pagination.pageSize*(pagination.currentPage-2),pagination.pageSize*(pagination.currentPage-1));
134
212
  pagination.currentPage--;
135
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = (pagination.pageSize*pagination.currentPage).toString();
213
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = pagination.currentPage.toString();
136
214
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = previousPageJobs;
137
215
  handlePaginationButtons(_$w);
138
216
  });
@@ -147,21 +225,22 @@ async function handleParams(_$w,param,value) {
147
225
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.SELECTED_VALUES_REPEATER_ITEM_LABEL).text = itemData.label || '';
148
226
  // Deselect this value from both the selected map and the multibox
149
227
  $item(CAREERS_MULTI_BOXES_PAGE_CONSTS.DESELECT_BUTTON_ID).onClick(async () => {
150
-
151
228
  const fieldId = itemData.fieldId;
152
229
  const valueId = itemData.valueId;
153
230
  dontUpdateThisCheckBox=fieldId;
154
231
  if (!fieldId || !valueId) return;
155
-
156
232
  const existing = selectedByField.get(fieldId) || [];
157
233
  const updated = existing.filter(v => v !== valueId);
234
+ const field=getFieldById(fieldId,allfields);
235
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
236
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
158
237
  if (updated.length) {
159
238
  selectedByField.set(fieldId, updated);
239
+ queryParams.add({ [fieldTitle] : updated.map(val=>encodeURIComponent(val)).join(',') });
160
240
  } else {
161
241
  selectedByField.delete(fieldId);
242
+ queryParams.remove([fieldTitle ]);
162
243
  }
163
-
164
- const field=getFieldById(fieldId,allfields);
165
244
  const currentVals = _$w(`#${FiltersIds[field.title]}CheckBox`).value || [];
166
245
  const nextVals = currentVals.filter(v => v !== valueId);
167
246
  _$w(`#${FiltersIds[field.title]}CheckBox`).value = nextVals;
@@ -208,8 +287,8 @@ async function loadJobsRepeater(_$w) {
208
287
 
209
288
  const jobsFirstPage=alljobs.slice(0,pagination.pageSize);
210
289
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
211
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
212
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = currentJobs.length.toString();
290
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1"
291
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(currentJobs.length/pagination.pageSize).toString();
213
292
  updateTotalJobsCountText(_$w);
214
293
  handlePaginationButtons(_$w);
215
294
  } catch (error) {
@@ -250,28 +329,35 @@ async function loadJobsRepeater(_$w) {
250
329
  else{
251
330
  originalOptions=value
252
331
  }
253
-
254
332
  optionsByFieldId.set(key, originalOptions);
255
333
  for (const val of allvaluesobjects) {
256
334
  counter[val.title]=val.count
257
335
  }
258
-
259
336
  countsByFieldId.set(key, new Map(originalOptions.map(o => [o.value, counter[o.label]])));
260
337
  updateOptionsUI(_$w,field.title, field._id, ''); // no search query
261
338
  _$w(`#${FiltersIds[field.title]}CheckBox`).selectedIndices = []; // start empty
262
339
  _$w(`#${FiltersIds[field.title]}CheckBox`).onChange(async (ev) => {
263
- console.log("i am here !!!!!")
264
- console.log("field.title: ",field.title)
265
- console.log("value: ",value)
266
340
  dontUpdateThisCheckBox=field._id;
267
341
  const selected = ev.target.value; // array of selected value IDs
268
- console.log("ev: ",ev)
269
- console.log("ev.target: ",ev.target)
342
+ let fieldTitle=field.title.toLowerCase().replace(' ', '');
343
+ fieldTitle==="brands"? fieldTitle="brand":fieldTitle;
344
+
270
345
  if (selected && selected.length) {
271
346
  selectedByField.set(field._id, selected);
347
+ if(fieldTitle==="brand" || fieldTitle==="storename") {
348
+ //in this case we need the label not valueid
349
+ const valueLabels=getValueFromValueId(selected,value);
350
+ queryParams.add({ [fieldTitle] : valueLabels.map(val=>encodeURIComponent(val)).join(',') });
351
+ }
352
+ else{
353
+ queryParams.add({ [fieldTitle] : selected.map(val=>encodeURIComponent(val)).join(',') });
354
+ }
355
+
272
356
  } else {
273
357
  selectedByField.delete(field._id);
358
+ queryParams.remove([fieldTitle ]);
274
359
  }
360
+
275
361
  await updateJobsAndNumbersAndFilters(_$w);
276
362
 
277
363
  });
@@ -289,8 +375,18 @@ async function loadJobsRepeater(_$w) {
289
375
  }
290
376
  }
291
377
 
378
+ function getValueFromValueId(valueIds,value) {
379
+ let valueLabels=[];
380
+ let currentVal
381
+ for(const valueId of valueIds) {
382
+ currentVal=value.find(val=>val.value===valueId);
383
+ if(currentVal) {
384
+ valueLabels.push(currentVal.label);
385
+ }
386
+ }
387
+ return valueLabels
388
+ }
292
389
 
293
-
294
390
  async function updateJobsAndNumbersAndFilters(_$w,clearAll=false) {
295
391
  await applyJobFilters(_$w); // re-query jobs
296
392
  await refreshFacetCounts(_$w,clearAll); // recompute and update counts in all lists
@@ -301,7 +397,6 @@ async function loadJobsRepeater(_$w) {
301
397
  function updateOptionsUI(_$w,fieldTitle, fieldId, searchQuery,clearAll=false) {
302
398
  let base = optionsByFieldId.get(fieldId) || [];
303
399
  const countsMap = countsByFieldId.get(fieldId) || new Map();
304
-
305
400
  if(dontUpdateThisCheckBox===fieldId && !clearAll)
306
401
  {
307
402
  dontUpdateThisCheckBox=null;
@@ -377,12 +472,15 @@ async function loadJobsRepeater(_$w) {
377
472
  finalFilteredJobs=tempFilteredJobs;
378
473
  tempFilteredJobs=[];
379
474
  }
475
+
380
476
  secondarySearchIsFilled? currentSecondarySearchJobs=finalFilteredJobs:currentJobs=finalFilteredJobs;
477
+
478
+
381
479
  let jobsFirstPage=[];
382
480
  secondarySearchIsFilled? jobsFirstPage=currentSecondarySearchJobs.slice(0,pagination.pageSize):jobsFirstPage=currentJobs.slice(0,pagination.pageSize);
383
481
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
384
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
385
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? currentSecondarySearchJobs.length.toString():currentJobs.length.toString();
482
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
483
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = secondarySearchIsFilled? Math.ceil(currentSecondarySearchJobs.length/pagination.pageSize).toString():Math.ceil(currentJobs.length/pagination.pageSize).toString();
386
484
  if(jobsFirstPage.length===0) {
387
485
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
388
486
  }
@@ -428,6 +526,7 @@ async function refreshFacetCounts(_$w,clearAll=false) {
428
526
 
429
527
  secondarySearchIsFilled? countJobsPerField(currentSecondarySearchJobs):countJobsPerField(currentJobs);
430
528
  for(const field of allfields) {
529
+
431
530
  const query = (_$w(`#${FiltersIds[field.title]}input`).value || '').toLowerCase().trim();
432
531
  clearAll? updateOptionsUI(_$w,field.title, field._id, '',true):updateOptionsUI(_$w,field.title, field._id, query);
433
532
  // no search query
@@ -480,9 +579,10 @@ async function secondarySearch(_$w,query) {
480
579
  currentSecondarySearchJobs=allsecondarySearchJobs;
481
580
  const jobsFirstPage=allsecondarySearchJobs.slice(0,pagination.pageSize);
482
581
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_REPEATER).data = jobsFirstPage;
483
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = jobsFirstPage.length.toString();
484
- _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = allsecondarySearchJobs.length.toString();
582
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationCurrentText).text = "1";
583
+ _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.paginationTotalCountText).text = Math.ceil(allsecondarySearchJobs.length/pagination.pageSize).toString();
485
584
  pagination.currentPage=1;
585
+
486
586
  if(jobsFirstPage.length===0) {
487
587
  await _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.JOBS_MULTI_STATE_BOX).changeState("noJobs");
488
588
  }