Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. var app = angular.module('myApp', ['ngRoute', 'ngResource', 'ngCookies', 'ngFileUpload']);
  2. app.config(function ($routeProvider) {
  3. $routeProvider.when('/viewjobs', {
  4. templateUrl: './views/viewjobs.htm',
  5. controller: 'userController'
  6. }).when('/viewAppliedjobs', {
  7. templateUrl: './views/viewapplied_jobs.htm',
  8. controller: 'userController'
  9. }).when('/uploadCV', {
  10. templateUrl: './views/uploadCV.htm',
  11. controller: 'userController'
  12. }).when('/editprofile', {
  13. templateUrl: './views/user_profile.htm',
  14. controller: 'userController'
  15. }).otherwise({ redirectTo: '/viewjobs' });
  16. });
  17.  
  18. app.controller('userController', function ($rootScope, $scope, $window, $cookieStore, APIFactory, Upload, $location, $timeout) {
  19. $('#myModal').modal('show');
  20. $scope.username = $cookieStore.get('user').userName;
  21. $scope.isCVUploaded = $cookieStore.get('user').isCVUploaded;
  22. $scope.technologies = [
  23. {name: 'Java'},
  24. {name: 'Javascript'},
  25. {name: 'Node.js'},
  26. {name: 'Chotto'}
  27. ];
  28.  
  29. $scope.signout = function () {
  30. $cookieStore.remove('user');
  31. $window.location.href = "/";
  32. }
  33.  
  34. $scope.advancedSearch = function () {
  35. $("#advancedSearchModal").modal('show');
  36. }
  37.  
  38. $scope.advancedCustomSearch = function(){
  39. console.log("In advancedCustomSearch");
  40. console.log($scope.search)
  41. var p = [];
  42. for (var i = 0; i < $scope.technologies.length; i++) {
  43. var item = $scope.technologies[i];
  44. if ( item.checked) {
  45. p.push(item.name)
  46. }
  47. }
  48. $scope.search.selectedSkill = p
  49. APIFactory.fetchCustomJobForSeeker($scope.search, function (data) {
  50. console.log($scope.search)
  51. console.log(data)
  52. $scope._jobs = data
  53. $("#advancedSearchModal").modal('hide');
  54. // if (data.count == 1) {
  55.  
  56. // } else {
  57. // toastr["error"]("Username or Password is wrong.");
  58. // }
  59. });
  60. }
  61.  
  62. $scope.applyForJob = function (job) {
  63. if ($scope.isCVUploaded == 0) {
  64. $("#warning").modal('show');
  65. } else {
  66. var user_job = {
  67. "jobId": job.jobId,
  68. "userId": $cookieStore.get('user').userId
  69. }
  70. APIFactory.applyForJob(user_job, function (data) {
  71. if (data.result == 1) {
  72. toastr["success"]("Application has been sent.");
  73. var index = $scope._jobs.indexOf(job);
  74. $scope._jobs.splice(index, 1);
  75. }
  76. });
  77. }
  78. }
  79. $scope.navigate = function () {
  80. $window.location.href = "/users.html";
  81. }
  82. $scope._jobs = APIFactory.fetchJobsForSeeker({ userId: $cookieStore.get('user').userId }, function (data) {
  83. for (var i in data) {
  84. data[i].jobdate = moment(data[i].jobdate).format("YYYY-MM-DD h:mm A");
  85. data[i].postedDate = moment(data[i].postedDate).format("YYYY-MM-DD h:mm A");
  86. }
  87. return data;
  88. });
  89. $scope.applied_jobs = APIFactory.fetchAppliedJobsForSeeker({ userId: $cookieStore.get('user').userId }, function (data) {
  90. for (var i in data) {
  91. data[i].jobdate = moment(data[i].jobdate).format("YYYY-MM-DD h:mm A");
  92. data[i].postedDate = moment(data[i].postedDate).format("YYYY-MM-DD h:mm A");
  93. }
  94. return data;
  95. });
  96. $scope.profile = APIFactory.fetchProfile({ userId: $cookieStore.get('user').userId }, function (data) {
  97. data.password=toCharCode(data.password.data);
  98. return data;
  99. });
  100. $scope.updateProfile = function (profile) {
  101. APIFactory.updateProfile(angular.toJson(profile), function (data) {
  102. if (data.result == 1) {
  103. toastr["success"]("Profile update has been successful.");
  104. $scope.navigate();
  105. }
  106. });
  107. }
  108. $scope.uploadFile = function () {
  109. var fileExtension = $("#file").val().split(".").pop();
  110. if (fileExtension == 'doc' || fileExtension == 'docx') {
  111. $("#file").css({ "border-color": "green" });
  112. var vm = this;
  113. if (vm.uploadForm.file.$valid) {
  114. Upload.upload({
  115. url: baseURL + '/users/upload/' + $cookieStore.get('user').userId,
  116. data: { file: vm.file }
  117. }).success(function (res) {
  118. if (res.status == 1) {
  119. $('#myModal').modal('hide');
  120. $timeout(function () {
  121. $location.path("/viewjobs")
  122. }, 500)
  123. var user = {
  124. "userId": $cookieStore.get('user').userId,
  125. "userName": $cookieStore.get('user').username,
  126. "isCVUploaded": 1
  127. }
  128. $cookieStore.put("user", user);
  129. toastr["success"](res.message);
  130. }
  131. }).then(function (resp) {
  132. }, function (resp) { //catch error
  133. console.log('Error status: ' + resp.status);
  134. $window.alert('Error status: ' + resp.status);
  135. }, function (evt) {
  136. console.log(evt);
  137. var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
  138. console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
  139. vm.progress = 'progress: ' + progressPercentage + '% '; // capture upload progress
  140. });
  141. }
  142. } else {
  143. $("#file").css({ "border-color": "red" });
  144. }
  145. }
  146. });
  147.  
  148. var baseURL = "http://localhost:3000";
  149. app.factory('APIFactory', function ($resource) {
  150. return $resource(baseURL, { userId: "@userId" }, {
  151. applyForJob: { method: "PUT", url: baseURL + "/jobs/apply" },
  152. fetchProfile: { method: "GET", url: baseURL + "/users/profile/:userId" },
  153. updateProfile: { method: "PUT", url: baseURL + "/users" },
  154. fetchJobsForSeeker: { method: 'GET', url: baseURL + "/jobs/seeker/:userId", isArray: true },
  155. fetchAppliedJobsForSeeker: { method: 'GET', url: baseURL + "/jobs/seeker/applied/:userId", isArray: true },
  156. uploadFile: { method: 'POST', url: baseURL + "/users/upload/:userId" },
  157. fetchCustomJobForSeeker: {method: 'POST', url: baseURL + "/users/seeker/customsearch", isArray: true}
  158. });
  159. });
  160.  
  161. function toCharCode(ascii_values) {
  162. var convertedCharCode="";
  163. for (var i = 0; i < ascii_values.length; i++) {
  164. convertedCharCode+=String.fromCharCode(ascii_values[i]);
  165. }
  166. return convertedCharCode;
  167. }
  168.  
  169. toastr.options = {
  170. "closeButton": false,
  171. "debug": false,
  172. "newestOnTop": false,
  173. "progressBar": false,
  174. "positionClass": "toast-top-right",
  175. "preventDuplicates": false,
  176. "onclick": null,
  177. "showDuration": "300",
  178. "hideDuration": "1000",
  179. "timeOut": "5000",
  180. "extendedTimeOut": "1000",
  181. "showEasing": "swing",
  182. "hideEasing": "linear",
  183. "showMethod": "fadeIn",
  184. "hideMethod": "fadeOut"
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement