Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('myApp', ['ngRoute', 'ngResource', 'ngCookies', 'ngFileUpload']);
- app.config(function ($routeProvider) {
- $routeProvider.when('/viewjobs', {
- templateUrl: './views/viewjobs.htm',
- controller: 'userController'
- }).when('/viewAppliedjobs', {
- templateUrl: './views/viewapplied_jobs.htm',
- controller: 'userController'
- }).when('/uploadCV', {
- templateUrl: './views/uploadCV.htm',
- controller: 'userController'
- }).when('/editprofile', {
- templateUrl: './views/user_profile.htm',
- controller: 'userController'
- }).otherwise({ redirectTo: '/viewjobs' });
- });
- app.controller('userController', function ($rootScope, $scope, $window, $cookieStore, APIFactory, Upload, $location, $timeout) {
- $('#myModal').modal('show');
- $scope.username = $cookieStore.get('user').userName;
- $scope.isCVUploaded = $cookieStore.get('user').isCVUploaded;
- $scope.technologies = [
- {name: 'Java'},
- {name: 'Javascript'},
- {name: 'Node.js'},
- {name: 'Chotto'}
- ];
- $scope.signout = function () {
- $cookieStore.remove('user');
- $window.location.href = "/";
- }
- $scope.advancedSearch = function () {
- $("#advancedSearchModal").modal('show');
- }
- $scope.advancedCustomSearch = function(){
- console.log("In advancedCustomSearch");
- console.log($scope.search)
- var p = [];
- for (var i = 0; i < $scope.technologies.length; i++) {
- var item = $scope.technologies[i];
- if ( item.checked) {
- p.push(item.name)
- }
- }
- $scope.search.selectedSkill = p
- APIFactory.fetchCustomJobForSeeker($scope.search, function (data) {
- console.log($scope.search)
- console.log(data)
- $scope._jobs = data
- $("#advancedSearchModal").modal('hide');
- // if (data.count == 1) {
- // } else {
- // toastr["error"]("Username or Password is wrong.");
- // }
- });
- }
- $scope.applyForJob = function (job) {
- if ($scope.isCVUploaded == 0) {
- $("#warning").modal('show');
- } else {
- var user_job = {
- "jobId": job.jobId,
- "userId": $cookieStore.get('user').userId
- }
- APIFactory.applyForJob(user_job, function (data) {
- if (data.result == 1) {
- toastr["success"]("Application has been sent.");
- var index = $scope._jobs.indexOf(job);
- $scope._jobs.splice(index, 1);
- }
- });
- }
- }
- $scope.navigate = function () {
- $window.location.href = "/users.html";
- }
- $scope._jobs = APIFactory.fetchJobsForSeeker({ userId: $cookieStore.get('user').userId }, function (data) {
- for (var i in data) {
- data[i].jobdate = moment(data[i].jobdate).format("YYYY-MM-DD h:mm A");
- data[i].postedDate = moment(data[i].postedDate).format("YYYY-MM-DD h:mm A");
- }
- return data;
- });
- $scope.applied_jobs = APIFactory.fetchAppliedJobsForSeeker({ userId: $cookieStore.get('user').userId }, function (data) {
- for (var i in data) {
- data[i].jobdate = moment(data[i].jobdate).format("YYYY-MM-DD h:mm A");
- data[i].postedDate = moment(data[i].postedDate).format("YYYY-MM-DD h:mm A");
- }
- return data;
- });
- $scope.profile = APIFactory.fetchProfile({ userId: $cookieStore.get('user').userId }, function (data) {
- data.password=toCharCode(data.password.data);
- return data;
- });
- $scope.updateProfile = function (profile) {
- APIFactory.updateProfile(angular.toJson(profile), function (data) {
- if (data.result == 1) {
- toastr["success"]("Profile update has been successful.");
- $scope.navigate();
- }
- });
- }
- $scope.uploadFile = function () {
- var fileExtension = $("#file").val().split(".").pop();
- if (fileExtension == 'doc' || fileExtension == 'docx') {
- $("#file").css({ "border-color": "green" });
- var vm = this;
- if (vm.uploadForm.file.$valid) {
- Upload.upload({
- url: baseURL + '/users/upload/' + $cookieStore.get('user').userId,
- data: { file: vm.file }
- }).success(function (res) {
- if (res.status == 1) {
- $('#myModal').modal('hide');
- $timeout(function () {
- $location.path("/viewjobs")
- }, 500)
- var user = {
- "userId": $cookieStore.get('user').userId,
- "userName": $cookieStore.get('user').username,
- "isCVUploaded": 1
- }
- $cookieStore.put("user", user);
- toastr["success"](res.message);
- }
- }).then(function (resp) {
- }, function (resp) { //catch error
- console.log('Error status: ' + resp.status);
- $window.alert('Error status: ' + resp.status);
- }, function (evt) {
- console.log(evt);
- var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
- console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
- vm.progress = 'progress: ' + progressPercentage + '% '; // capture upload progress
- });
- }
- } else {
- $("#file").css({ "border-color": "red" });
- }
- }
- });
- var baseURL = "http://localhost:3000";
- app.factory('APIFactory', function ($resource) {
- return $resource(baseURL, { userId: "@userId" }, {
- applyForJob: { method: "PUT", url: baseURL + "/jobs/apply" },
- fetchProfile: { method: "GET", url: baseURL + "/users/profile/:userId" },
- updateProfile: { method: "PUT", url: baseURL + "/users" },
- fetchJobsForSeeker: { method: 'GET', url: baseURL + "/jobs/seeker/:userId", isArray: true },
- fetchAppliedJobsForSeeker: { method: 'GET', url: baseURL + "/jobs/seeker/applied/:userId", isArray: true },
- uploadFile: { method: 'POST', url: baseURL + "/users/upload/:userId" },
- fetchCustomJobForSeeker: {method: 'POST', url: baseURL + "/users/seeker/customsearch", isArray: true}
- });
- });
- function toCharCode(ascii_values) {
- var convertedCharCode="";
- for (var i = 0; i < ascii_values.length; i++) {
- convertedCharCode+=String.fromCharCode(ascii_values[i]);
- }
- return convertedCharCode;
- }
- toastr.options = {
- "closeButton": false,
- "debug": false,
- "newestOnTop": false,
- "progressBar": false,
- "positionClass": "toast-top-right",
- "preventDuplicates": false,
- "onclick": null,
- "showDuration": "300",
- "hideDuration": "1000",
- "timeOut": "5000",
- "extendedTimeOut": "1000",
- "showEasing": "swing",
- "hideEasing": "linear",
- "showMethod": "fadeIn",
- "hideMethod": "fadeOut"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement