sr-npm 1.7.533 → 1.7.536
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/.github/workflows/update-sites.yml +27 -0
- package/backend/collectionConsts.js +22 -21
- package/backend/data.js +35 -16
- package/backend/queries.js +0 -9
- package/package.json +1 -1
- package/pages/careersPage.js +59 -133
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Update Sites After Release Main
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
packages: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
update-sites:
|
|
15
|
+
uses: psdevteamenterprise/ci-workflows/.github/workflows/publish-and-notify.yml@main
|
|
16
|
+
with:
|
|
17
|
+
sites_to_update: "[{repo: 'psdevteamenterprise/tests-site', secret: 'WIX_PS_API_KEY'},
|
|
18
|
+
{repo: 'psdevteamenterprise/external-template', secret: 'WIX_SR_API_KEY'},
|
|
19
|
+
{repo: 'psdevteamenterprise/internal', secret: 'WIX_SR_API_KEY'}]"
|
|
20
|
+
|
|
21
|
+
secrets:
|
|
22
|
+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
23
|
+
NPM_TOKEN: ${{ secrets.PS_NPM_TOKEN }}
|
|
24
|
+
GH_APP_ID: ${{ secrets.GH_APP_ID }}
|
|
25
|
+
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
|
26
|
+
WIX_PS_API_KEY: ${{ secrets.WIX_PS_API_KEY }}
|
|
27
|
+
WIX_SR_API_KEY: ${{ secrets.WIX_SR_API_KEY }}
|
|
@@ -5,6 +5,8 @@ const COLLECTIONS = {
|
|
|
5
5
|
TEMPLATE_TYPE: 'templateType',
|
|
6
6
|
SECRET_MANAGER_MIRROR: 'SecretManagerMirror',
|
|
7
7
|
BRANDS: 'Brands',
|
|
8
|
+
CUSTOM_VALUES:'CustomValues',
|
|
9
|
+
CUSTOM_FIELDS:'CustomFields',
|
|
8
10
|
}
|
|
9
11
|
const JOBS_COLLECTION_FIELDS = {
|
|
10
12
|
LOCATION: 'location',
|
|
@@ -23,13 +25,21 @@ const JOBS_COLLECTION_FIELDS = {
|
|
|
23
25
|
REFER_FRIEND_LINK: 'referFriendLink',
|
|
24
26
|
BRAND: 'brand',
|
|
25
27
|
BRAND_REF: 'brandRef',
|
|
26
|
-
|
|
28
|
+
CUSTOM_VALUES: 'customValues',
|
|
29
|
+
|
|
27
30
|
}
|
|
28
31
|
const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
|
|
29
32
|
TITLE: 'title',
|
|
30
33
|
COUNT: 'count',
|
|
31
34
|
IMAGE: 'image',
|
|
32
35
|
}
|
|
36
|
+
const CUSTOM_VALUES_COLLECTION_FIELDS = {
|
|
37
|
+
TITLE: 'title',
|
|
38
|
+
CUSTOM_FIELD: 'customField',
|
|
39
|
+
}
|
|
40
|
+
const CUSTOM_FIELDS_COLLECTION_FIELDS = {
|
|
41
|
+
TITLE: 'title',
|
|
42
|
+
}
|
|
33
43
|
const BRANDS_COLLECTION_FIELDS = {
|
|
34
44
|
TITLE: 'title',
|
|
35
45
|
COUNT: 'count',
|
|
@@ -63,6 +73,7 @@ const COLLECTIONS_FIELDS = {
|
|
|
63
73
|
{key:'language', type: 'TEXT'},
|
|
64
74
|
{key:'remote', type: 'BOOLEAN'},
|
|
65
75
|
{key:'jobDescription', type: 'OBJECT'},
|
|
76
|
+
{key:'customValues', type: 'MULTI-REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES } } },
|
|
66
77
|
{key:'cityText', type: 'TEXT'},
|
|
67
78
|
{key:'applyLink', type: 'URL'},
|
|
68
79
|
{key:'referFriendLink', type: 'URL'},
|
|
@@ -70,7 +81,6 @@ const COLLECTIONS_FIELDS = {
|
|
|
70
81
|
{key:'departmentref', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT } } },
|
|
71
82
|
{key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CITIES } } },
|
|
72
83
|
{key:'brandRef', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.BRANDS } } },
|
|
73
|
-
{ key: 'customFields', type: 'ARRAY' },
|
|
74
84
|
{ key: 'image', type: 'IMAGE' },
|
|
75
85
|
],
|
|
76
86
|
TEMPLATE_TYPE: [
|
|
@@ -84,6 +94,13 @@ const COLLECTIONS_FIELDS = {
|
|
|
84
94
|
{key:'title', type: 'TEXT'},
|
|
85
95
|
{ key: 'count', type: 'NUMBER' },
|
|
86
96
|
],
|
|
97
|
+
CUSTOM_VALUES: [
|
|
98
|
+
{key:'title', type: 'TEXT'},
|
|
99
|
+
{key:'customField', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_FIELDS } } },
|
|
100
|
+
],
|
|
101
|
+
CUSTOM_FIELDS: [
|
|
102
|
+
{key:'title', type: 'TEXT'},
|
|
103
|
+
],
|
|
87
104
|
};
|
|
88
105
|
|
|
89
106
|
|
|
@@ -97,22 +114,6 @@ const COLLECTIONS_FIELDS = {
|
|
|
97
114
|
SMART_TOKEN: 'x-smarttoken',
|
|
98
115
|
DESIRED_BRAND: 'desiredBrand',
|
|
99
116
|
}
|
|
100
|
-
|
|
101
|
-
const URL_PARAMS = {
|
|
102
|
-
DEPARTMENT: "Department",
|
|
103
|
-
LOCATION: "Location",
|
|
104
|
-
BRAND: "Brand",
|
|
105
|
-
}
|
|
106
|
-
const DROPDOWN_IDS = {
|
|
107
|
-
DEPARTMENT: '#dropdownDepartment',
|
|
108
|
-
LOCATION: '#dropdownLocation',
|
|
109
|
-
BRAND: '#dropdownBrand',
|
|
110
|
-
}
|
|
111
|
-
const DROPDOWN_COLLECTIONS = {
|
|
112
|
-
DEPARTMENT: 'AmountOfJobsPerDepartment',
|
|
113
|
-
LOCATION: 'cities',
|
|
114
|
-
BRAND: 'Brands',
|
|
115
|
-
}
|
|
116
117
|
|
|
117
118
|
|
|
118
119
|
module.exports = {
|
|
@@ -122,9 +123,9 @@ const COLLECTIONS_FIELDS = {
|
|
|
122
123
|
AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS,
|
|
123
124
|
CITIES_COLLECTION_FIELDS,
|
|
124
125
|
BRANDS_COLLECTION_FIELDS,
|
|
126
|
+
CUSTOM_FIELDS_COLLECTION_FIELDS,
|
|
127
|
+
CUSTOM_VALUES_COLLECTION_FIELDS,
|
|
125
128
|
TEMPLATE_TYPE,
|
|
126
129
|
TOKEN_NAME,
|
|
127
|
-
|
|
128
|
-
DROPDOWN_IDS,
|
|
129
|
-
DROPDOWN_COLLECTIONS,
|
|
130
|
+
|
|
130
131
|
};
|
package/backend/data.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { items: wixData } = require('@wix/data');
|
|
2
2
|
const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
|
|
3
3
|
const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
|
|
4
|
-
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
4
|
+
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME,CUSTOM_VALUES_COLLECTION_FIELDS,CUSTOM_FIELDS_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 } = require('./secretsData');
|
|
@@ -28,6 +28,7 @@ function validatePosition(position) {
|
|
|
28
28
|
|
|
29
29
|
async function filterBasedOnBrand(positions) {
|
|
30
30
|
try{
|
|
31
|
+
|
|
31
32
|
const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
|
|
32
33
|
validateSingleDesiredBrand(desiredBrand);
|
|
33
34
|
console.log("filtering positions based on brand: ", desiredBrand);
|
|
@@ -51,23 +52,21 @@ function validateSingleDesiredBrand(desiredBrand) {
|
|
|
51
52
|
throw new Error("Desired brand must be a single brand");
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
function addCustomFields(basicJob, position) {
|
|
55
|
+
function getCustomFieldsAndValuesFromPosition(position,customFields) {
|
|
56
56
|
const customFieldsArray = Array.isArray(position?.customField) ? position.customField : [];
|
|
57
|
-
const customFields = {};
|
|
58
57
|
for (const field of customFieldsArray) {
|
|
59
58
|
if(field.fieldLabel==="Country" || field.fieldLabel==="Department") continue; //country and department are not custom fields, they are already in the job object
|
|
60
59
|
const label = field.fieldLabel==="Brands" ? "brand" : field.fieldLabel
|
|
61
60
|
const key = normalizeString(label);
|
|
62
61
|
const value = field.valueLabel
|
|
63
|
-
customFields[key] = value
|
|
62
|
+
customFields[key] ? customFields[key].add(value) : customFields[key]=new Set([value])
|
|
64
63
|
}
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
async function saveJobsDataToCMS() {
|
|
69
67
|
const positions = await fetchPositionsFromSRAPI();
|
|
70
68
|
const sourcePositions = await filterBasedOnBrand(positions);
|
|
69
|
+
const customFields = {}
|
|
71
70
|
// bulk insert to jobs collection without descriptions first
|
|
72
71
|
const jobsData = sourcePositions.map(position => {
|
|
73
72
|
const basicJob = {
|
|
@@ -90,13 +89,15 @@ async function saveJobsDataToCMS() {
|
|
|
90
89
|
country: position.location?.country || '',
|
|
91
90
|
remote: position.location?.remote || false,
|
|
92
91
|
language: position.language?.label || '',
|
|
93
|
-
|
|
92
|
+
brand: getBrand(position.customField),
|
|
94
93
|
jobDescription: null, // Will be filled later
|
|
95
94
|
};
|
|
96
|
-
|
|
97
|
-
return
|
|
95
|
+
getCustomFieldsAndValuesFromPosition(position,customFields);
|
|
96
|
+
return basicJob;
|
|
98
97
|
});
|
|
99
|
-
|
|
98
|
+
console.log("customFields: ", customFields);
|
|
99
|
+
populateCustomFieldsCollection(customFields);
|
|
100
|
+
populateCustomValuesCollection(customFields);
|
|
100
101
|
// Sort jobs by title (ascending, case-insensitive, numeric-aware)
|
|
101
102
|
jobsData.sort((a, b) => {
|
|
102
103
|
const titleA = a.title || '';
|
|
@@ -135,6 +136,21 @@ async function saveJobsDataToCMS() {
|
|
|
135
136
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
function populateCustomFieldsCollection(customFields) {
|
|
140
|
+
for(const key of Object.keys(customFields)){
|
|
141
|
+
wixData.save(COLLECTIONS.CUSTOM_FIELDS, {
|
|
142
|
+
title: key,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function populateCustomValuesCollection(customFields) {
|
|
147
|
+
for(const key of Object.keys(customFields)){
|
|
148
|
+
wixData.save(COLLECTIONS.CUSTOM_VALUES, {
|
|
149
|
+
title: key,
|
|
150
|
+
customField: customFields[key],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
138
154
|
async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
139
155
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|
|
140
156
|
|
|
@@ -292,6 +308,7 @@ async function referenceJobsToField({ referenceField, sourceCollection, jobField
|
|
|
292
308
|
return rest;
|
|
293
309
|
});
|
|
294
310
|
|
|
311
|
+
|
|
295
312
|
// Bulk update in chunks of 1000
|
|
296
313
|
const chunkSize = 1000;
|
|
297
314
|
await chunkedBulkOperation({
|
|
@@ -341,7 +358,9 @@ async function createCollections() {
|
|
|
341
358
|
createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
|
|
342
359
|
createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
343
360
|
createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR),
|
|
344
|
-
createCollectionIfMissing(COLLECTIONS.BRANDS, COLLECTIONS_FIELDS.BRANDS)
|
|
361
|
+
createCollectionIfMissing(COLLECTIONS.BRANDS, COLLECTIONS_FIELDS.BRANDS),
|
|
362
|
+
createCollectionIfMissing(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.CUSTOM_VALUES),
|
|
363
|
+
createCollectionIfMissing(COLLECTIONS.CUSTOM_FIELDS, CUSTOM_FIELDS_COLLECTION_FIELDS.CUSTOM_FIELDS)
|
|
345
364
|
]);
|
|
346
365
|
console.log("finished creating Collections");
|
|
347
366
|
}
|
|
@@ -353,7 +372,6 @@ async function aggregateJobs() {
|
|
|
353
372
|
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
|
|
354
373
|
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.BRAND, collection: COLLECTIONS.BRANDS })
|
|
355
374
|
]);
|
|
356
|
-
|
|
357
375
|
console.log("finished aggregating jobs");
|
|
358
376
|
}
|
|
359
377
|
|
|
@@ -362,21 +380,22 @@ async function referenceJobs() {
|
|
|
362
380
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT });
|
|
363
381
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT });
|
|
364
382
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.BRAND_REF, sourceCollection: COLLECTIONS.BRANDS, jobField: JOBS_COLLECTION_FIELDS.BRAND });
|
|
383
|
+
await referenceJobsToField({referenceField:JOBS_COLLECTION_FIELDS.CUSTOM_VALUES,sourceCollection:COLLECTIONS.CUSTOM_VALUES,jobField:JOBS_COLLECTION_FIELDS.CUSTOM_VALUES} )
|
|
365
384
|
console.log("finished referencing jobs");
|
|
366
385
|
}
|
|
367
386
|
|
|
368
387
|
async function syncJobsFast() {
|
|
369
388
|
console.log("Syncing jobs fast");
|
|
370
|
-
|
|
389
|
+
await createCollections();
|
|
371
390
|
// await clearCollections();
|
|
372
391
|
// await fillSecretManagerMirror();
|
|
373
392
|
console.log("saving jobs data to CMS");
|
|
374
393
|
await saveJobsDataToCMS();
|
|
375
|
-
console.log("saved jobs data to CMS successfully");
|
|
394
|
+
// console.log("saved jobs data to CMS successfully");
|
|
376
395
|
// console.log("saving jobs descriptions and location apply url to CMS");
|
|
377
396
|
// await saveJobsDescriptionsAndLocationApplyUrlToCMS();
|
|
378
397
|
// console.log("saved jobs descriptions and location apply url to CMS successfully");
|
|
379
|
-
|
|
398
|
+
// await aggregateJobs();
|
|
380
399
|
// await referenceJobs();
|
|
381
400
|
// console.log("syncing jobs fast finished successfully");
|
|
382
401
|
}
|
package/backend/queries.js
CHANGED
|
@@ -18,16 +18,7 @@ async function getPositionsByField(field, value) {
|
|
|
18
18
|
.then(result => result.items);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
async function getCustomFieldKeys() {
|
|
22
|
-
return wixData
|
|
23
|
-
.query(COLLECTIONS.JOBS)
|
|
24
|
-
.eq("title", "bayan - custom field 3")
|
|
25
|
-
.find()
|
|
26
|
-
.then(result => result.items[0].customFieldsNames);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
21
|
module.exports = {
|
|
30
22
|
getAllPositions,
|
|
31
23
|
getPositionsByField,
|
|
32
|
-
getCustomFieldKeys
|
|
33
24
|
};
|
package/package.json
CHANGED
package/pages/careersPage.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const { getAllPositions
|
|
1
|
+
const { getAllPositions } = require('../backend/queries');
|
|
2
2
|
const {wixData} = require('wix-data');
|
|
3
3
|
const { window } = require('@wix/site-window');
|
|
4
4
|
const { query,queryParams,onChange} = require("wix-location-frontend");
|
|
5
5
|
const { location } = require("@wix/site-location");
|
|
6
|
-
const { COLLECTIONS
|
|
6
|
+
const { COLLECTIONS } = require('../backend/collectionConsts');
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
debounce,
|
|
@@ -22,43 +22,29 @@ const {
|
|
|
22
22
|
let queryLocationVar;
|
|
23
23
|
let queryJobTypeVar;
|
|
24
24
|
let queryBrandVar;
|
|
25
|
-
let queryCustomFields={};
|
|
26
25
|
let searchInputBlurredFirstTime=true;
|
|
27
26
|
let deletedParam=false;
|
|
28
|
-
async function careersPageOnReady(_$w,thisObject,queryParams
|
|
27
|
+
async function careersPageOnReady(_$w,thisObject,queryParams) {
|
|
29
28
|
console.log("queryParams: ", queryParams);
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const { page, keyWord, department, location,jobType,brand } = queryParams;
|
|
30
|
+
queryPageVar=page;
|
|
31
|
+
queryKeyWordVar=keyWord;
|
|
32
|
+
queryDepartmentVar=department;
|
|
33
|
+
queryLocationVar=location;
|
|
34
|
+
queryJobTypeVar=jobType;
|
|
35
|
+
queryBrandVar=brand;
|
|
32
36
|
thisObjectVar=thisObject;
|
|
33
37
|
allJobs=await getAllPositions();
|
|
34
38
|
await activateAutoLoad(_$w);
|
|
35
39
|
await bind(_$w);
|
|
36
|
-
await init(_$w
|
|
40
|
+
await init(_$w);
|
|
37
41
|
await handleBrandDropdown(_$w);
|
|
38
42
|
await handleUrlParams(_$w);
|
|
39
43
|
|
|
40
44
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
const { page, keyWord, department, location,jobType,brand } = queryParams;
|
|
45
|
-
queryPageVar=page;
|
|
46
|
-
queryKeyWordVar=keyWord;
|
|
47
|
-
queryDepartmentVar=department;
|
|
48
|
-
queryLocationVar=location;
|
|
49
|
-
queryJobTypeVar=jobType;
|
|
50
|
-
queryBrandVar=brand;
|
|
51
|
-
if(customFieldsDropdownObject){
|
|
52
|
-
const customFieldKeys=Object.keys(customFieldsDropdownObject);
|
|
53
|
-
console.log("customFieldKeys: ", customFieldKeys)
|
|
54
|
-
for(const customFieldKey of customFieldKeys)
|
|
55
|
-
{
|
|
56
|
-
queryCustomFields[customFieldKey]={elementId:customFieldsDropdownObject[customFieldKey], field:customFieldKey, queryParamValue:queryParams[customFieldKey],queryParamKey:customFieldKey}
|
|
57
|
-
}
|
|
58
|
-
console.log("queryCustomFields",queryCustomFields)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
47
|
+
|
|
62
48
|
function activateAutoLoad(_$w)
|
|
63
49
|
{
|
|
64
50
|
_$w("#jobsDataset").onReady(() => {
|
|
@@ -114,26 +100,16 @@ async function handleUrlParams(_$w) {
|
|
|
114
100
|
await handlePageParam(_$w);
|
|
115
101
|
}
|
|
116
102
|
if (queryDepartmentVar) {
|
|
117
|
-
await
|
|
118
|
-
//await handleDepartmentParam(_$w,queryDepartmentVar);
|
|
103
|
+
await handleDepartmentParam(_$w,queryDepartmentVar);
|
|
119
104
|
}
|
|
120
105
|
if (queryLocationVar) {
|
|
121
|
-
|
|
122
|
-
await handleGivenURLParam(_$w,URL_PARAMS.LOCATION,queryLocationVar);
|
|
106
|
+
await handleLocationParam(_$w,queryLocationVar);
|
|
123
107
|
}
|
|
124
108
|
if (queryJobTypeVar) {
|
|
125
109
|
await handleJobTypeParam(_$w,queryJobTypeVar);
|
|
126
110
|
}
|
|
127
111
|
if (queryBrandVar && _$w('#dropdownBrand').isVisible) { //if it is not visible, ignore it
|
|
128
|
-
|
|
129
|
-
await handleGivenURLParam(_$w,URL_PARAMS.BRAND,queryBrandVar);
|
|
130
|
-
}
|
|
131
|
-
if (queryCustomFields) {
|
|
132
|
-
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
133
|
-
if(queryCustomFields[customFieldKey].queryParamValue){
|
|
134
|
-
await handleGivenURLParam(_$w,customFieldKey,queryCustomFields[customFieldKey].queryParamValue,true);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
112
|
+
await handleBrandParam(_$w,queryBrandVar);
|
|
137
113
|
}
|
|
138
114
|
await applyFilters(_$w, true); // Skip URL update since we're handling initial URL params
|
|
139
115
|
}
|
|
@@ -193,7 +169,7 @@ async function bind(_$w) {
|
|
|
193
169
|
|
|
194
170
|
}
|
|
195
171
|
|
|
196
|
-
function init(_$w
|
|
172
|
+
function init(_$w) {
|
|
197
173
|
const debouncedSearch = debounce(()=>applyFilters(_$w), 400,thisObjectVar);
|
|
198
174
|
_$w('#searchInput').onInput(debouncedSearch);
|
|
199
175
|
_$w('#searchInput').onBlur(()=>{
|
|
@@ -207,14 +183,6 @@ function init(_$w,customFieldsDropdownObject=null) {
|
|
|
207
183
|
console.log("dropdown onChange is triggered");
|
|
208
184
|
applyFilters(_$w);
|
|
209
185
|
});
|
|
210
|
-
if (customFieldsDropdownObject){
|
|
211
|
-
for(const customFieldKey of Object.keys(customFieldsDropdownObject)){
|
|
212
|
-
_$w(customFieldsDropdownObject[customFieldKey]).onChange(()=>{
|
|
213
|
-
console.log("custom field onChange is triggered");
|
|
214
|
-
applyFilters(_$w);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
186
|
_$w('#resetFiltersButton, #clearSearch').onClick(()=>resetFilters(_$w));
|
|
219
187
|
|
|
220
188
|
_$w('#openFiltersButton').onClick(()=>{
|
|
@@ -281,27 +249,17 @@ async function handleBackAndForth(_$w){
|
|
|
281
249
|
|
|
282
250
|
}
|
|
283
251
|
|
|
284
|
-
async function applyCustomFieldFilters(filters) {
|
|
285
|
-
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
286
|
-
filters.push({ field: customFieldKey, searchTerm: queryCustomFields[customFieldKey] });
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
252
|
async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
291
253
|
console.log("applying filters");
|
|
292
254
|
const dropdownFiltersMapping = [
|
|
293
|
-
{ elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value
|
|
294
|
-
{ elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value
|
|
295
|
-
{ elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value
|
|
296
|
-
{ elementId: '#dropdownBrand', field: 'brand', value: _$w('#dropdownBrand').value
|
|
297
|
-
{ elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value
|
|
255
|
+
{ elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value },
|
|
256
|
+
{ elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value },
|
|
257
|
+
{ elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value},
|
|
258
|
+
{ elementId: '#dropdownBrand', field: 'brand', value: _$w('#dropdownBrand').value},
|
|
259
|
+
{ elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value }
|
|
298
260
|
];
|
|
299
|
-
//adding custom field filters to the dropdownFiltersMapping
|
|
300
|
-
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
301
|
-
dropdownFiltersMapping.push({ elementId: queryCustomFields[customFieldKey].elementId, field: queryCustomFields[customFieldKey].field, value: _$w(queryCustomFields[customFieldKey].elementId).value,queryParamKey:queryCustomFields[customFieldKey].queryParamKey });
|
|
302
|
-
}
|
|
303
261
|
console.log("dropdownFiltersMapping: ", dropdownFiltersMapping);
|
|
304
|
-
|
|
262
|
+
|
|
305
263
|
|
|
306
264
|
|
|
307
265
|
let filters = [];
|
|
@@ -320,29 +278,23 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
|
320
278
|
if(filter.field === 'title'){
|
|
321
279
|
queryParams.add({ keyWord: filter.value });
|
|
322
280
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
281
|
+
if(filter.field === 'department'){
|
|
282
|
+
queryParams.add({ department: encodeURIComponent(filter.value) });
|
|
283
|
+
}
|
|
284
|
+
if(filter.field === 'cityText'){
|
|
285
|
+
queryParams.add({ location: encodeURIComponent(filter.value) });
|
|
286
|
+
}
|
|
287
|
+
if(filter.field === 'remote'){
|
|
288
|
+
if(filter.value === 'true'){
|
|
289
|
+
queryParams.add({ jobType: encodeURIComponent("remote") });
|
|
331
290
|
}
|
|
332
291
|
else{
|
|
333
|
-
queryParams.add({
|
|
292
|
+
queryParams.add({ jobType: encodeURIComponent("onsite") });
|
|
334
293
|
}
|
|
335
294
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
// if(filter.field === 'cityText'){
|
|
340
|
-
// queryParams.add({ location: encodeURIComponent(filter.value) });
|
|
341
|
-
// }
|
|
342
|
-
|
|
343
|
-
// if(filter.field === 'brand'){
|
|
344
|
-
// queryParams.add({ brand: encodeURIComponent(filter.value) });
|
|
345
|
-
// }
|
|
295
|
+
if(filter.field === 'brand'){
|
|
296
|
+
queryParams.add({ brand: encodeURIComponent(filter.value) });
|
|
297
|
+
}
|
|
346
298
|
}
|
|
347
299
|
if(filter.field === 'remote') {
|
|
348
300
|
value = filter.value === 'true';
|
|
@@ -353,32 +305,28 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
|
353
305
|
}
|
|
354
306
|
else{
|
|
355
307
|
if (!skipUrlUpdate) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// }
|
|
308
|
+
if(filter.field === 'title'){
|
|
309
|
+
queryParams.remove(["keyWord" ]);
|
|
310
|
+
}
|
|
311
|
+
if(filter.field === 'department'){
|
|
312
|
+
console.log("removing department from url")
|
|
313
|
+
queryParams.remove(["department" ]);
|
|
314
|
+
}
|
|
315
|
+
if(filter.field === 'cityText'){
|
|
316
|
+
console.log("removing location from url")
|
|
317
|
+
queryParams.remove(["location" ]);
|
|
318
|
+
}
|
|
319
|
+
if(filter.field === 'remote'){
|
|
320
|
+
console.log("removing jobType from url")
|
|
321
|
+
queryParams.remove(["jobType" ]);
|
|
322
|
+
}
|
|
323
|
+
if(filter.field === 'brand'){
|
|
324
|
+
console.log("removing brand from url")
|
|
325
|
+
queryParams.remove(["brand" ]);
|
|
326
|
+
}
|
|
376
327
|
}
|
|
377
328
|
}
|
|
378
329
|
});
|
|
379
|
-
|
|
380
|
-
//applyCustomFieldFilters(filters);
|
|
381
|
-
console.log("dropdownFiltersMapping after applying filters: ", dropdownFiltersMapping);
|
|
382
330
|
|
|
383
331
|
const filter = await getFilter(filters, 'and');
|
|
384
332
|
await _$w('#jobsDataset').setFilter(filter);
|
|
@@ -400,9 +348,6 @@ async function applyFilters(_$w, skipUrlUpdate = false) {
|
|
|
400
348
|
|
|
401
349
|
async function resetFilters(_$w) {
|
|
402
350
|
_$w('#searchInput, #dropdownDepartment, #dropdownLocation, #dropdownJobType, #dropdownBrand').value = '';
|
|
403
|
-
for(const customFieldKey of Object.keys(queryCustomFields)){
|
|
404
|
-
_$w(queryCustomFields[customFieldKey].elementId).value = '';
|
|
405
|
-
}
|
|
406
351
|
|
|
407
352
|
await _$w('#jobsDataset').setFilter(wixData.filter());
|
|
408
353
|
await _$w('#jobsDataset').refresh();
|
|
@@ -412,9 +357,7 @@ async function resetFilters(_$w) {
|
|
|
412
357
|
_$w('#resetFiltersButton').disable();
|
|
413
358
|
|
|
414
359
|
queryParams.remove(["keyWord", "department","page","location","jobType","brand"]);
|
|
415
|
-
|
|
416
|
-
queryParams.remove([queryCustomFields[customFieldKey].queryParamKey]);
|
|
417
|
-
}
|
|
360
|
+
|
|
418
361
|
|
|
419
362
|
await updateCount(_$w);
|
|
420
363
|
console.log("reseting map markers");
|
|
@@ -429,33 +372,16 @@ async function updateCount(_$w) {
|
|
|
429
372
|
return count;
|
|
430
373
|
}
|
|
431
374
|
|
|
432
|
-
async function handleGivenURLParam(_$w,param,value,isCustomField=false) {
|
|
433
|
-
const paramValue = decodeURIComponent(value);
|
|
434
|
-
let dropdownOptions = _$w(DROPDOWN_IDS[param]).options;
|
|
435
|
-
console.log("dropdown options:", dropdownOptions);
|
|
436
|
-
let optionsFromCMS;
|
|
437
|
-
if(!isCustomField){
|
|
438
|
-
optionsFromCMS=await wixData.query(DROPDOWN_COLLECTIONS[param]).find();
|
|
439
|
-
if(dropdownOptions.length!==optionsFromCMS.items.length+1){
|
|
440
|
-
fixDropdownOptions(DROPDOWN_IDS[param],optionsFromCMS, _$w);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
const option=_$w(DROPDOWN_IDS[param]).options.find(option => option.value.toLowerCase() === paramValue.toLowerCase())
|
|
444
|
-
if(option){
|
|
445
|
-
_$w(DROPDOWN_IDS[param]).value = option.value;
|
|
446
|
-
}
|
|
447
|
-
else{
|
|
448
|
-
console.warn("param value not found in dropdown options");
|
|
449
|
-
queryParams.remove([param]);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
375
|
async function handleDepartmentParam(_$w,department) {
|
|
454
376
|
const departmentValue = decodeURIComponent(department);
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
455
380
|
let dropdownOptions = _$w('#dropdownDepartment').options;
|
|
456
381
|
console.log("dropdown options:", dropdownOptions);
|
|
457
382
|
const optionsFromCMS=await wixData.query("AmountOfJobsPerDepartment").find();
|
|
458
383
|
//+1 because of the "All" option
|
|
384
|
+
|
|
459
385
|
if(dropdownOptions.length!==optionsFromCMS.items.length+1){
|
|
460
386
|
fixDropdownOptions('#dropdownDepartment',optionsFromCMS, _$w);
|
|
461
387
|
}
|