-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
300 lines (236 loc) · 9.79 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// api id&key
const api = {
id: 'app_id=e7b64108',
key: 'app_key=abd49ecf0971e54d1ce59cf3e232ae09'
}
// List of parameters after v1/api/jobs/
const country = {
gb: 'gb', // United Kingdom
us: 'us', // United States
at: 'at', // Austria
au: 'au', // Australia
be: 'be', // Belgium
br: 'br', // Brazil
ca: 'ca', // Canada
ch: 'ch', // Switzerland
de: 'de', // Germany
es: 'es', // Spain
fr: 'fr', // France
in: 'in', // India
it: 'it', // Italy
mx: 'mx', // Mexico
nl: 'nl', // Netherlands
nz: 'nz', // New Zealand
pl: 'pl', // Poland
sg: 'sg', // Singapore
za: 'za', // South Africa
}
/*
List of parameters after v1/api/jobs/country/
Adzuna::API::Response::Categories {
results (array[Adzuna::API::Response::Category]): An array of all the categories discovered as Adzuna::API::Response::Category objects.
}
Adzuna::API::Response::Category {
tag (string): The string which should be passed to search endpoint using the "category" query parameter.,
label (string): A text string describing the category, suitable for display.
}
*/
const categories = {
accountingFinanceJobs: 'accounting-finance-jobs',
itJobs: 'it-jobs',
salesJobs: 'sales-jobs',
customerServicesJobs: 'customer-services-jobs',
engineeringJobs: 'engineering-jobs',
hrJobs: 'hr-jobs',
healthcareNursingJobs: 'healthcare-nursing-jobs',
hospitalityCateringJobs: 'hospitality-catering-jobs',
prAdvertisingMarketingJobs: 'pr-advertising-marketing-jobs',
logisticsWarehouseJobs: 'logistics-warehouse-jobs',
teachingJobs: 'teaching-jobs',
tradeConstructionJobs: 'trade-construction-jobs',
adminJobs: 'admin-jobs',
legalJobs: 'legal-jobs',
creativeDesignJobs: 'creative-design-jobs',
graduateJobs: 'graduate-jobs',
retailJobs: 'retail-jobs',
consultancyJobs: 'consultancy-jobs',
manufacturingJobs: 'manufacturing-jobs',
scientificQaJobs: 'scientific-qa-jobs',
socialWorkJobs: 'social-work-jobs',
travelJobs: 'travel-jobs',
energyOilGasJobs: 'energy-oil-gas-jobs',
propertyJobs: 'property-jobs',
charityVoluntaryJobs: 'charity-voluntary-jobs',
domesticHelpCleaningJobs: 'domestic-help-cleaning-jobs',
maintenanceJobs: 'maintenance-jobs',
partTimeJobs: 'part-time-jobs',
otherGeneralJobs: 'other-general-jobs',
unknown: 'unknown'
};
/*
Adzuna::API::Response::SalaryHistogram {
histogram (undefined, optional): The distribution of jobs by salary.
Returns an array of salaries and the number of live jobs pay as much or more than each salary.
}
*/
var histogram; // extra
/*
Adzuna::API::Response::TopCompanies {
leaderboard (array[Adzuna::API::Response::Company], optional): A list of companies, ordered by the number of jobs they are advertising. Only companies in Adzunaâs index will show up in these results. To suggest an addition to this index please email: info [at] adzuna [dot] com
}
Adzuna::API::Response::Company {
count (integer, optional): The total number of job advertisements posted by this company. Only provided for statistics queries.,
canonical_name (string, optional): A normalised string of the company name.,
average_salary (number, optional): The average salary in job advertisements posted by this company. Only provided for statistics queries.,
display_name (string, optional): The name of the company, in the form provided by the advertiser.
}
*/
var topCompanies; // extra
/*
Adzuna::API::Response::JobGeoData {
locations (array[Adzuna::API::Response::LocationJobs], optional): The number of live job ads in any given location, followed by a list of sub-locations and the number of live jobs in each of them, ordered from most jobs to least. Locations with 0 jobs are not returned.
}
Adzuna::API::Response::LocationJobs {
count (integer, optional): The number of jobs advertised at this location.,
location (Adzuna::API::Response::Location, optional): The location being described.
}
Adzuna::API::Response::Location {
area (array[string], optional): A description of the location, as an array of strings, each refining the location more than the previous.,
display_name (string, optional): A human readable name for the location.
}
*/
var geodata; // extra
/*
Adzuna::API::Response::HistoricalSalary {
month (undefined, optional): A series of average salary values, by month, for all jobs with a given category, title and/or location. This is only available for locations with significant numbers (20 or more) of jobs. Dates are formatted as ISO 8601 month/year. Salaries are given in local currency.
}
*/
var history; // extra
var page = 1; // event listener to go to next page
// this part of the URL doesn't change
const beginningURL = `https://api.adzuna.com/v1/api/jobs/`;
var url = `${beginningURL}${country.us}/search/${page}?${api.id}&${api.key}&results_per_page=50`;
function onRequest(setURL) {
$.get(setURL, (data) => {
console.log(data);
console.log(`page number = ${page}`);
console.log(setURL);
$('#job-results').empty();
data.results.forEach( (job) => {
// I know this part works
const companyName = job.company.display_name;
let salary = ''
if (job.salary_min === undefined && job.salary_max === undefined) {
salary = '';
}
else if (job.salary_min === job.salary_max) {
salary = (job.salary_min).toLocaleString("en-US");
}
else if (job.salary_min) {
salary = (job.salary_min).toLocaleString("en-US");
}
else if (job.salary_max) {
salary = (job.salary_max).toLocaleString("en-US");
}
else {
salary = `${(job.salary_min).toLocaleString("en-US")} - ${(job.salary_max).toLocaleString("en-US")}`;
}
let contractTime = job.contract_time;
if (contractTime === 'full_time') {
contractTime = 'Full-time';
}
else if (contractTime === 'part_time') {
contractTime = 'Part-time';
}
else {
contractTime = ``;
}
const department = job.category.label;
const jobTitle = job.title;
const jobDescription = job.description;
const link = job.redirect_url;
// need to make a variable that holds the dom elements before appending
const $span = $('<span></span>').attr('class', 'job').css({
"display": "block",
"border": "2px solid black",
"box-sizing": "border-box",
"padding": "4px",
"width": "80vw",
"height": "fit-content",
"margin": "10px"
});
const $spanh2 = $('<h2></h2>').attr('class', 'company-name').text(companyName);
const $spanh4 = $('<h4></h4>').attr('class', 'department').text(`${contractTime} | $${salary} | ${department}`);
const $spanh3 = $('<h3></h3>').attr('class', 'job-title').text(jobTitle);
const $spandiv = $('<div></div>').attr('class', 'job-description').text(jobDescription);
const $spana = $('<a></a>').attr({
'href': link,
'target': '_blank'
}).text('Read More');
$span.append($spanh2).append($spanh4).append($spanh3).append($spandiv).append($spana);
$('#job-results').append($span);
})
let $previousButton = $('<a></a>').attr({
'href': '#',
'class': 'previous'
}).text('Previous').css({
"display": "inline-block",
"padding": "8px 16px",
"float": "left",
"width": "39%"
})
let $nextButton = $('<a></a>').attr({
'href': '#',
'class': 'next'
}).text('Next').css({
"display": "inline-block",
"padding": "8px 16px",
"float": "left",
"width": "39%"
})
$('#job-results').append($previousButton);
if (page === 1) {
$('.previous').hide();
}
$('#job-results').append($nextButton);
if (data.results.length < 50) {
$('.next').hide();
}
$('.previous').on("click", () => {
$('.next').show();
--page;
let search = $('input').val().split(' ').join('%20');
let category = $('select').val();
if (category === "no-selection") {
category = '';
}
var url = `${beginningURL}${country.us}/search/${page}?${api.id}&${api.key}&results_per_page=50&what=${search}&category=${category}`;
onRequest(url);
});
$('.next').on("click", () => {
$('.previous').show();
++page;
let search = $('input').val().split(' ').join('%20');
let category = $('select').val();
if (category === "no-selection") {
category = '';
}
var url = `${beginningURL}${country.us}/search/${page}?${api.id}&${api.key}&results_per_page=50&what=${search}&category=${category}`;
onRequest(url);
});
})
}
// testing
var onSubmit = $('#submit').on('click', (e) => {
e.preventDefault();
page = 1;
// Gets user input as string and places %20 between multiple words (URL requires this)
let search = $('input').val().split(' ').join('%20');
let category = $('select').val();
if (category === "no-selection") {
category = '';
}
var url = `${beginningURL}${country.us}/search/${page}?${api.id}&${api.key}&results_per_page=50&what=${search}&category=${category}`;
onRequest(url);
})
onRequest(url);