-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainController.js
386 lines (353 loc) · 10.1 KB
/
mainController.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
app.factory('profilesFactory', function($http) {
// pull in job or candidate profiles
var profiles = {};
profiles.getJobs = function(){
return $http.post("jobs_mysql.php");
}
profiles.getCandidates = function(){
return $http.post("candidates_mysql.php");
}
return profiles;
});
app.controller('mainController', function($scope, $rootScope, $http, profilesFactory){
// use factory to get job and candidates profiles
var getProfiles = function(){
// if user is logged in
if ($rootScope.current_user !== ""){
if ($rootScope.profile_type === "candidate"){
profilesFactory.getJobs().then(function(response){
$rootScope.profiles = response.data.jobs;
// parse skills variable
var profiles_len = Object.keys($rootScope.profiles).length;
$rootScope.len = profiles_len;
for (var i = 0; i < profiles_len; i++){
if ($rootScope.profiles[i].skills[0]=="0"){
$rootScope.profiles[i].skills1 = "No";
} else {
$rootScope.profiles[i].skills1 = "Yes";
}
if ($rootScope.profiles[i].skills[1]=="0"){
$rootScope.profiles[i].skills2 = "No";
} else {
$rootScope.profiles[i].skills2 = "Yes";
}
if ($rootScope.profiles[i].skills[2]=="0"){
$rootScope.profiles[i].skills3 = "No";
} else {
$rootScope.profiles[i].skills3 = "Yes";
}
}
});
}
else{ // if user is a job
profilesFactory.getCandidates().then(function(response){
$rootScope.profiles = response.data.candidates;
var profiles_len = Object.keys($rootScope.profiles).length;
$rootScope.len = profiles_len;
for (var i = 0; i < profiles_len; i++){
if ($rootScope.profiles[i].skills[0]=="0"){
$rootScope.profiles[i].skills1 = "No";
} else {
$rootScope.profiles[i].skills1 = "Yes";
}
if ($rootScope.profiles[i].skills[1]=="0"){
$rootScope.profiles[i].skills2 = "No";
} else {
$rootScope.profiles[i].skills2 = "Yes";
}
if ($rootScope.profiles[i].skills[2]=="0"){
$rootScope.profiles[i].skills3 = "No";
} else {
$rootScope.profiles[i].skills3 = "Yes";
}
}
});
}
}
}
// switch to next profile and save the input (if its a like)
$scope.swipeRight = function(){
var audio = new Audio('Swish-sound-effect.mp3');
audio.play();
$http({
url: "like.php",
method: "POST",
data: {
"liker": $rootScope.current_user,
"liked": $rootScope.profiles[$rootScope.index].username
}
}).then(function(response){
if (response.data.success === false){
alert(response.data.message);
}
});
// update list of matches
showMatches();
// switch to next profile
$rootScope.index = $rootScope.index + 1;
if ($rootScope.index + 1 > $rootScope.profiles.length ){
alert("no profiles left to swipe");
}
}
// switch to next profile
$scope.swipeLeft = function(){
var audio = new Audio('fail-trombone-01.mp3');
audio.play();
$rootScope.index = $rootScope.index + 1;
if ($rootScope.index + 1 > $rootScope.profiles.length ){
alert("no profiles left to swipe");
}
}
var showMatches = function(){
if ($rootScope.current_user !== ""){
$http({
url: "show_matches.php",
method: "POST"
}).then(function(response){
if (response.data.success === false){
alert(response.data.message);
}else{
// alert when you have a new match
if ($rootScope.matchCount !== -1){
var matches = response.data.matches;
var new_len = Object.keys(matches).length
if (new_len > $rootScope.matchCount){
var audio = new Audio('Good-idea-bell.mp3');
audio.play();
alert("You have a new match");
}
}
// get lengths and initialize variables for saving match info
$rootScope.matches = response.data.matches;
$rootScope.matchCount = Object.keys($rootScope.matches).length;
var matches_temp = $rootScope.matches;
var profiles_len = Object.keys($rootScope.profiles).length;
$rootScope.matches_info = [];
// save match info into rootScope variable
if ($rootScope.profile_type === "job"){
for (var i = 0; i < profiles_len; i++){
if (matches_temp.indexOf($rootScope.profiles[i].username) !== -1){
var matchholder = $rootScope.profiles[i].first_name +
" " + $rootScope.profiles[i].last_name + " - " + $rootScope.profiles[i].education;
$rootScope.matches_info.push(matchholder);
}
}
} else {
for (var i = 0; i < profiles_len; i++){
if (matches_temp.indexOf($rootScope.profiles[i].username) !== -1){
var matchholder = $rootScope.profiles[i].company_name + " - " + $rootScope.profiles[i].title;
$rootScope.matches_info.push(matchholder);
}
}
}
}
});
}
}
var getSuggestion = function(location){
$http({
url: "suggestion.php",
method: "POST",
data: {'location': location}
}).then(function(response){
$rootScope.suggestion= response.data.suggestion;
});
}
// parse skills variable
var assessSkills = function(skills){
$rootScope.headerBool = 0;
$rootScope.skills1Bool = 0;
$rootScope.skills2Bool = 0;
$rootScope.skills3Bool = 0;
if ($rootScope.profile_type === "candidate"){
if (skills[0] === "0"){
$rootScope.headerBool = 1;
$rootScope.skills1Bool = 1;
}
if (skills[1] === "0"){
$rootScope.headerBool = 1;
$rootScope.skills2Bool = 1;
}
if (skills[2] === "0"){
$rootScope.headerBool = 1;
$rootScope.skills3Bool = 1;
}
}
}
$scope.login = function(login){
if ($rootScope.current_user === undefined || $rootScope.current_user === ""){
$http({
url: "login.php",
method: "POST",
data: {'profile_type': login.profile_type,
'username': login.username,
'password': login.password
}
}).then(function(response){
if (response.data.success === false){
alert(response.data.message);
}else{
// initalize scope variables
$rootScope.profile_type = login.profile_type;
$rootScope.current_user = login.username;
$rootScope.matchCount = -1;
$rootScope.index = 0;
$rootScope.logBool = 1;
alert("login success!");
// call functions
getProfiles();
showMatches();
getSuggestion(response.data.location);
var skills = response.data.skills;
assessSkills(skills);
// save current profile
$rootScope.current_profile = response.data;
if ($rootScope.current_profile.skills[0]=="0"){
$rootScope.current_profile.skills1 = "No";
} else {
$rootScope.current_profile.skills1 = "Yes";
}
if ($rootScope.current_profile.skills[1]=="0"){
$rootScope.current_profile.skills2 = "No";
} else {
$rootScope.current_profile.skills2 = "Yes";
}
if ($rootScope.current_profile.skills[2]=="0"){
$rootScope.current_profile.skills3 = "No";
} else {
$rootScope.current_profile.skills3 = "Yes";
}
}
});
}
else{
alert("Please logout first");
}
}
$scope.logout = function(){
if ($rootScope.current_user !== ""){
$http({
url: "logout.php",
method: "POST"
}).then(function(response){
alert("logout success!");
// set scope variables back to nothing
$rootScope.profiles = "";
$rootScope.matches = "";
$rootScope.matches_info = "";
$rootScope.current_user = "";
$rootScope.logBool = 0;
$rootScope.profile_type = '';
$rootScope.headerBool = 0;
$rootScope.skills1Bool = 0;
$rootScope.skills2Bool = 0;
$rootScope.skills3Bool = 0;
});
}else{
alert("there is no user logged in")
}
}
$scope.like = function(profile){
$http({
url: "like.php",
method: "POST",
data: {"liker": $rootScope.current_user,
"liked": profile.username}
}).then(function(response){
});
}
$scope.editCandidate = function(candidate_info){
// parse info skills checkboxes
var skills = '';
if (candidate_info.edit_skills1){
skills += '1';
}
else{
skills += '0';
}
if (candidate_info.edit_skills2){
skills += '1';
}
else{
skills += '0';
}
if (candidate_info.edit_skills3){
skills += '1';
}
else{
skills += '0';
}
// make http request to database
$http({
url: "edit_profile.php",
method: "POST",
data: {'profile_type': $rootScope.profile_type,
'username': $rootScope.current_user,
'password': candidate_info.edit_p,
'first': candidate_info.edit_first,
'last': candidate_info.edit_last,
'cloc': candidate_info.edit_cloc,
'dloc': candidate_info.edit_dloc,
'job': candidate_info.edit_job,
'edu': candidate_info.edit_edu,
'major': candidate_info.edit_major,
'gpa': candidate_info.edit_gpa,
'sal': candidate_info.edit_sal,
'fun': candidate_info.edit_fun,
'skills': skills
}
}).then(function(response){
if (response.data.success === false){
alert(response.data.message);
}else{
alert("you have successfully edited your profile!");
$rootScope.current_profile = response.data;
assessSkills(skills);
}
});
}
$scope.editJob = function(job_info){
var skills = '';
if (job_info.edit_company_skills1){
skills += '1';
}
else{
skills += '0';
}
if (job_info.edit_company_skills2){
skills += '1';
}
else{
skills += '0';
}
if (job_info.edit_company_skills3){
skills += '1';
}
else{
skills += '0';
}
// make http request to database
$http({
url: "edit_profile.php",
method: "POST",
data: {'profile_type': $rootScope.profile_type,
'username': $rootScope.current_user,
'password': job_info.edit_company_p,
'name': job_info.edit_company_name,
'loc': job_info.edit_company_loc,
'title': job_info.edit_title,
'industry': job_info.edit_industry,
'sal': job_info.edit_company_sal,
'desc': job_info.edit_desc,
'skills': skills
}
}).then(function(response){
if (response.data.success === false){
alert(response.data.message);
}else{
alert("you have successfully edited your profile!");
$rootScope.current_profile = response.data;
}
});
}
});