sr-npm 1.7.95 → 1.7.96
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 +4 -2
- package/pages/careersPage.js +244 -0
- package/pages/homePage.js +110 -0
- package/pages/index.js +2 -0
- package/pages/positionPage.js +2 -2
- package/public/filterUtils.js +40 -0
- package/public/index.js +2 -0
- package/public/mapUtils.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sr-npm",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.96",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"@hisense-staging/velo-npm": "3.0.19",
|
|
21
21
|
"@wix/data": "^1.0.211",
|
|
22
22
|
"@wix/essentials": "^0.1.24",
|
|
23
|
-
"@wix/secrets": "^1.0.53"
|
|
23
|
+
"@wix/secrets": "^1.0.53",
|
|
24
|
+
"@wix/site-location": "^1.0.0",
|
|
25
|
+
"@wix/site-window": "^1.0.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"prettier": "^3.6.2"
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
const { getAllPositions } = require('../backend/queries');
|
|
2
|
+
const {wixData} = require('wix-data');
|
|
3
|
+
const { window } = require('@wix/site-window');
|
|
4
|
+
const { query,queryParams,to } = require("wix-location-frontend");
|
|
5
|
+
const {
|
|
6
|
+
debounce,
|
|
7
|
+
getFilter,
|
|
8
|
+
} = require('../public/filterUtils');
|
|
9
|
+
|
|
10
|
+
let currentLoadedItems =100;
|
|
11
|
+
const itemsPerPage = 100;
|
|
12
|
+
let allJobs=[]
|
|
13
|
+
const RESET_ALL = 'RESET_ALL';
|
|
14
|
+
let pageParamSet=0;
|
|
15
|
+
let thisObjectVar;
|
|
16
|
+
let queryPageVar;
|
|
17
|
+
let queryKeyWordVar;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async function careersPageOnReady(_$w,thisObject,queryPage,queryKeyWord) {
|
|
21
|
+
queryPageVar=queryPage;
|
|
22
|
+
queryKeyWordVar=queryKeyWord;
|
|
23
|
+
thisObjectVar=thisObject;
|
|
24
|
+
allJobs=await getAllPositions();
|
|
25
|
+
await handleUrlParams(_$w);
|
|
26
|
+
await activateAutoLoad(_$w);
|
|
27
|
+
await bind(_$w);
|
|
28
|
+
await init(_$w);
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
function activateAutoLoad(_$w)
|
|
34
|
+
{
|
|
35
|
+
_$w("#jobsDataset").onReady(() => {
|
|
36
|
+
updateCount(_$w);
|
|
37
|
+
_$w("#section2").onViewportEnter(() => {
|
|
38
|
+
if (currentLoadedItems<_$w("#jobsDataset").getTotalCount()) {
|
|
39
|
+
loadMoreJobs(_$w);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log("no more jobs")
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function loadMoreJobs(_$w) {
|
|
49
|
+
//const query = await location.query();
|
|
50
|
+
let shouldLoad = false;
|
|
51
|
+
if (pageParamSet == 0) {
|
|
52
|
+
shouldLoad = true;
|
|
53
|
+
} else if (query.page % 2 == pageParamSet % 2) {
|
|
54
|
+
shouldLoad = true;
|
|
55
|
+
} else {
|
|
56
|
+
pageParamSet = Number(pageParamSet) + 1;
|
|
57
|
+
}
|
|
58
|
+
if (shouldLoad) {
|
|
59
|
+
_$w("#jobsDataset").loadMore();
|
|
60
|
+
console.log("loading more jobs");
|
|
61
|
+
currentLoadedItems = currentLoadedItems + itemsPerPage;
|
|
62
|
+
const data = _$w("#positionsRepeater").data;
|
|
63
|
+
console.log("data length is : ", data.length);
|
|
64
|
+
setPageParamInUrl();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async function setPageParamInUrl() {
|
|
70
|
+
if(queryPageVar){
|
|
71
|
+
queryParams.add({ page: Number(queryPageVar) + 1 })
|
|
72
|
+
queryPageVar=Number(queryPageVar) + 1
|
|
73
|
+
}
|
|
74
|
+
else{
|
|
75
|
+
queryParams.add({ page: 2 })
|
|
76
|
+
queryPageVar=2
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
async function handleUrlParams(_$w) {
|
|
82
|
+
// const query = await location.query();
|
|
83
|
+
if (queryKeyWordVar) {
|
|
84
|
+
await handleKeyWordParam(_$w,queryKeyWordVar);
|
|
85
|
+
}
|
|
86
|
+
if (queryPageVar) {
|
|
87
|
+
await handlePageParam(_$w);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function handleKeyWordParam(_$w,keyWord) {
|
|
93
|
+
_$w('#searchInput').value = keyWord;
|
|
94
|
+
//const filter = await wixData.query("Jobs").contains("title", keyWord);
|
|
95
|
+
await $w("#jobsDataset").setFilter(wixData.filter().contains("title", keyWord));
|
|
96
|
+
await _$w("#jobsDataset").refresh();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function handlePageParam(_$w) {
|
|
100
|
+
|
|
101
|
+
if(allJobs.length/itemsPerPage<queryPageVar){
|
|
102
|
+
console.log(`max page is: ${allJobs.length/itemsPerPage}`)
|
|
103
|
+
queryParams.add({ page: allJobs.length/itemsPerPage })
|
|
104
|
+
}
|
|
105
|
+
if(queryPageVar<=1){
|
|
106
|
+
console.log("min page is : 2")
|
|
107
|
+
pageParamSet=2;
|
|
108
|
+
queryParams.add({ page: 2 })
|
|
109
|
+
}
|
|
110
|
+
if (queryPageVar) {
|
|
111
|
+
pageParamSet=queryPageVar;
|
|
112
|
+
//scrolls a bit to load the dataset data
|
|
113
|
+
await window.scrollTo(0, 200,{scrollAnimation:false});
|
|
114
|
+
for (let i = 2; i <= queryPageVar; i++) {
|
|
115
|
+
await _$w("#jobsDataset").loadMore();
|
|
116
|
+
currentLoadedItems=currentLoadedItems+itemsPerPage
|
|
117
|
+
}
|
|
118
|
+
// the timeout is to wait for the repeater to render, then scroll to the last item.
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
const data = _$w("#positionsRepeater").data;
|
|
121
|
+
if (data && data.length > 0) {
|
|
122
|
+
//the dataset each time it loads 100 items
|
|
123
|
+
const lastIndex = data.length - itemsPerPage;
|
|
124
|
+
_$w("#positionsRepeater").forEachItem(async ($item, itemData, index) => {
|
|
125
|
+
if (index === lastIndex) {
|
|
126
|
+
await $item("#positionItem").scrollTo();
|
|
127
|
+
console.log("finishied scrolling inside handlePageParam")
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, 200);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function bind(_$w) {
|
|
137
|
+
await _$w('#jobsDataset').onReady(async () => {
|
|
138
|
+
await updateCount(_$w);
|
|
139
|
+
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (await window.formFactor === "Mobile") {
|
|
143
|
+
_$w('#dropdownsContainer').collapse();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_$w('#positionsRepeater').onItemReady(async ($item, itemData) => {
|
|
147
|
+
$item('#positionItem').onClick(() => {
|
|
148
|
+
to(`${itemData['link-jobs-title']}`);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function init(_$w) {
|
|
154
|
+
const debouncedSearch = debounce(()=>applyFilters(_$w), 400,thisObjectVar);
|
|
155
|
+
|
|
156
|
+
_$w('#searchInput').onInput(debouncedSearch);
|
|
157
|
+
_$w('#dropdownDepartment, #dropdownLocation, #dropdownJobType').onChange(()=>applyFilters(_$w));
|
|
158
|
+
_$w('#resetFiltersButton, #clearSearch').onClick(()=>resetFilters(_$w));
|
|
159
|
+
|
|
160
|
+
_$w('#openFiltersButton').onClick(()=>{
|
|
161
|
+
_$w('#dropdownsContainer, #closeFiltersButton').expand();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
_$w('#closeFiltersButton').onClick(()=>{
|
|
165
|
+
_$w('#dropdownsContainer, #closeFiltersButton').collapse();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function applyFilters(_$w) {
|
|
170
|
+
|
|
171
|
+
const dropdownFiltersMapping = [
|
|
172
|
+
{ elementId: '#dropdownDepartment', field: 'department', value: _$w('#dropdownDepartment').value },
|
|
173
|
+
{ elementId: '#dropdownLocation', field: 'cityText', value: _$w('#dropdownLocation').value },
|
|
174
|
+
{ elementId: '#dropdownJobType', field: 'remote', value: _$w('#dropdownJobType').value},
|
|
175
|
+
{ elementId: '#searchInput', field: 'title', value: _$w('#searchInput').value }
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
let filters = [];
|
|
179
|
+
let value;
|
|
180
|
+
|
|
181
|
+
dropdownFiltersMapping.forEach(filter => {
|
|
182
|
+
// Handle RESET_ALL values
|
|
183
|
+
if (filter.value === RESET_ALL) {
|
|
184
|
+
_$w(filter.elementId).value = '';
|
|
185
|
+
filter.value = '';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// build filters
|
|
189
|
+
if (filter.value && filter.value.trim() !== '') {
|
|
190
|
+
if(filter.field === 'title'){
|
|
191
|
+
queryParams.add({ keyWord: filter.value });
|
|
192
|
+
}
|
|
193
|
+
if(filter.field === 'remote') {
|
|
194
|
+
value = filter.value === 'true';
|
|
195
|
+
} else {
|
|
196
|
+
value = filter.value;
|
|
197
|
+
}
|
|
198
|
+
filters.push({ field: filter.field, searchTerm: value });
|
|
199
|
+
}
|
|
200
|
+
else{
|
|
201
|
+
queryParams.remove(["keyWord" ]);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const filter = await getFilter(filters, 'and');
|
|
206
|
+
|
|
207
|
+
await _$w('#jobsDataset').setFilter(filter);
|
|
208
|
+
await _$w('#jobsDataset').refresh();
|
|
209
|
+
|
|
210
|
+
const count = await updateCount(_$w);
|
|
211
|
+
|
|
212
|
+
count ? _$w('#resultsMultiState').changeState('results') : _$w('#resultsMultiState').changeState('noResults');
|
|
213
|
+
|
|
214
|
+
// Update reset button state
|
|
215
|
+
const hasActiveFilters = filters.length > 0;
|
|
216
|
+
hasActiveFilters? _$w('#resetFiltersButton').enable() : _$w('#resetFiltersButton').disable();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function resetFilters(_$w) {
|
|
220
|
+
_$w('#searchInput, #dropdownDepartment, #dropdownLocation, #dropdownJobType').value = '';
|
|
221
|
+
|
|
222
|
+
await _$w('#jobsDataset').setFilter(wixData.filter());
|
|
223
|
+
await _$w('#jobsDataset').refresh();
|
|
224
|
+
|
|
225
|
+
_$w('#resultsMultiState').changeState('results');
|
|
226
|
+
|
|
227
|
+
_$w('#resetFiltersButton').disable();
|
|
228
|
+
|
|
229
|
+
await updateCount(_$w);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function updateCount(_$w) {
|
|
233
|
+
const count = await _$w('#jobsDataset').getTotalCount();
|
|
234
|
+
_$w('#numOfPositionText').text = `Showing ${count} Open Positions`;
|
|
235
|
+
|
|
236
|
+
return count;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
module.exports = {
|
|
243
|
+
careersPageOnReady,
|
|
244
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const {
|
|
2
|
+
debounce,
|
|
3
|
+
getFilter,
|
|
4
|
+
} = require('../public/filterUtils');
|
|
5
|
+
const { handleOnLocationClick } = require('../public/mapUtils');
|
|
6
|
+
const { location } = require('@wix/site-location');
|
|
7
|
+
let thisObjectVar;
|
|
8
|
+
async function homePageOnReady(_$w,thisObject) {
|
|
9
|
+
thisObjectVar=thisObject;
|
|
10
|
+
await bind(_$w);
|
|
11
|
+
await init(_$w);
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function bind(_$w) {
|
|
16
|
+
_$w('#teamRepeater').onItemReady(($item, itemData) => {
|
|
17
|
+
$item('#teamButton').label = `View ${itemData.count} Open Positions`;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
_$w('#citiesDataset').onReady(async () => {
|
|
21
|
+
const numOfItems = await _$w('#citiesDataset').getTotalCount();
|
|
22
|
+
const items = await _$w('#citiesDataset').getItems(0, numOfItems);
|
|
23
|
+
let baseUrl = await location.baseUrl();
|
|
24
|
+
const linkUrl = `${baseUrl}/positions`;
|
|
25
|
+
|
|
26
|
+
const markers = items.items.map(item => {
|
|
27
|
+
const location = item.locationAddress.location;
|
|
28
|
+
return {
|
|
29
|
+
location: {
|
|
30
|
+
latitude: location.latitude,
|
|
31
|
+
longitude: location.longitude
|
|
32
|
+
},
|
|
33
|
+
address: item.locationAddress.formatted,
|
|
34
|
+
description: `<a href=${linkUrl} target="_parent" rel="noopener noreferrer" style="color:#000000;text-decoration:underline;font-weight:bold;">View ${item.count} Open Positions</a>`
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
_$w('#googleMaps').setMarkers(markers);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function init(_$w) {
|
|
43
|
+
const debouncedInput = debounce(()=>handleSearchInput(_$w), 400,thisObjectVar);
|
|
44
|
+
|
|
45
|
+
_$w('#searchInput').onInput(debouncedInput);
|
|
46
|
+
_$w('#searchInput').maxLength = 40;
|
|
47
|
+
|
|
48
|
+
_$w('#searchInput').onKeyPress((event) => {
|
|
49
|
+
if (event.key === 'Enter') {
|
|
50
|
+
handleEnterPress(_$w('#searchInput').value);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
_$w('#searchInput').onFocus(() => {
|
|
55
|
+
if (_$w(`#resultsContainer`).collapsed) {
|
|
56
|
+
_$w(`#resultsContainer`).expand();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
_$w('#searchInput').onBlur(() => {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
if (!_$w(`#resultsContainer`).collapsed) {
|
|
63
|
+
_$w(`#resultsContainer`).collapse();
|
|
64
|
+
}
|
|
65
|
+
}, 250);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
_$w('#locationItem').onClick((event)=>{
|
|
69
|
+
handleOnLocationClick(event, '#locationsRepeater', '#googleMaps', _$w);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function handleSearchInput(_$w) {
|
|
74
|
+
let searchInput;
|
|
75
|
+
let count;
|
|
76
|
+
|
|
77
|
+
searchInput = _$w('#searchInput').value;
|
|
78
|
+
const trimmedInput = searchInput.trim();
|
|
79
|
+
|
|
80
|
+
const fieldsToSearch = [
|
|
81
|
+
{ field: 'title', searchTerm: trimmedInput },
|
|
82
|
+
{ field: 'cityText', searchTerm: trimmedInput }
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const filter = await getFilter(fieldsToSearch, 'or');
|
|
86
|
+
|
|
87
|
+
await _$w('#jobsDataset').setFilter(filter);
|
|
88
|
+
await _$w('#jobsDataset').refresh();
|
|
89
|
+
|
|
90
|
+
count = _$w('#jobsDataset').getTotalCount();
|
|
91
|
+
|
|
92
|
+
if (count > 0) {
|
|
93
|
+
_$w('#resultsContainer').expand();
|
|
94
|
+
_$w('#searchMultiStateBox').changeState('results');
|
|
95
|
+
} else {
|
|
96
|
+
_$w('#searchMultiStateBox').changeState('noResults');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function handleEnterPress(searchInput) {
|
|
101
|
+
const trimmedInput = searchInput.trim();
|
|
102
|
+
|
|
103
|
+
if (trimmedInput) {
|
|
104
|
+
location.to(`/positions?keyWord=${trimmedInput}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
homePageOnReady,
|
|
110
|
+
};
|
package/pages/index.js
CHANGED
package/pages/positionPage.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//const { items:wixData } = require('@wix/data');
|
|
2
|
+
const {wixData} = require('wix-data');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function getFilter(fieldsToSearch = [], mode = 'or') {
|
|
6
|
+
const baseFilter = wixData.filter();
|
|
7
|
+
// if no fields to search, return empty filter
|
|
8
|
+
if (fieldsToSearch.length === 0) {
|
|
9
|
+
return baseFilter;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// build filters
|
|
13
|
+
let filter;
|
|
14
|
+
fieldsToSearch.forEach(({ field, searchTerm }) => {
|
|
15
|
+
const condition = typeof searchTerm === 'boolean'
|
|
16
|
+
? baseFilter.eq(field, searchTerm)
|
|
17
|
+
: baseFilter.contains(field, searchTerm);
|
|
18
|
+
|
|
19
|
+
filter = filter
|
|
20
|
+
? (mode === 'or' ? filter.or(condition) : filter.and(condition))
|
|
21
|
+
: condition;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return filter;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function debounce(fn, delay = 400,thisObject) {
|
|
28
|
+
let timeout;
|
|
29
|
+
return function (...args) {
|
|
30
|
+
clearTimeout(timeout);
|
|
31
|
+
console.log("thisObject is: ", thisObject);
|
|
32
|
+
console.log("args is: ", args);
|
|
33
|
+
timeout = setTimeout(() => fn.apply(thisObject, args), delay);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
getFilter,
|
|
39
|
+
debounce
|
|
40
|
+
};
|
package/public/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function handleOnLocationClick(event, repeaterId, mapId, _$w) {
|
|
2
|
+
const FOCUS_ZOOM = 13;
|
|
3
|
+
const { itemId } = event.context;
|
|
4
|
+
const itemData = _$w(repeaterId).data.find(item => item._id === itemId);
|
|
5
|
+
|
|
6
|
+
const location = itemData.locationAddress.location;
|
|
7
|
+
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
_$w(mapId).setCenter(location);
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
_$w(mapId).setZoom(FOCUS_ZOOM);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
handleOnLocationClick
|
|
16
|
+
};
|