Commits

André Walker committed 71b185b

Fix general bugs in search

Comments (0)

Files changed (7)

lib/PerlPro/Schema/ResultSet/Job.pm

         push @conditions, { 'attributes.attribute' => { -in => $filters->{attributes} } };
     }
 
-    # TODO: deal with wages_for, hours and hours_by
+    # TODO: deal with hours and hours_by
     if ($filters->{salary_from}) {
         push @conditions, { 'me.wages' => { '>=' => $filters->{salary_from} } };
     }
         push @conditions, { 'me.wages' => { '<=' => $filters->{salary_to} } };
     }
 
+    if ($filters->{wages_for}) {
+        push @conditions, { 'me.wages_for' => $filters->{wages_for} };
+    }
+
     if ($filters->{contract_types}) {
         push @conditions, { 'me.contract_type' => { -in => $filters->{contract_types} } };
     }
 
     if (my $l = $filters->{location}) {
-        push @conditions, { 'me.is_telecommute' => !!$filters->{is_telecommute} };
         push @conditions, {
            -or => [
                 { 'job_location.city' => { -ilike => "%$l%" } },
         };
     }
 
+    if ($filters->{is_telecommute}) {
+        push @conditions, { 'me.is_telecommute' => 1 };
+    }
+
     my $search = {
         -and => \@conditions
     };

lib/PerlPro/Web/Controller/Public/Job.pm

         filters => {},
         page    => 1, # $q->{page},
         rows    => 100, # $q->{rows},
+
     );
 
     if (my $ct = $q->{contract_types}) {
 
     if (my $l = $q->{location}) {
         $params{filters}{location} = $l;
-        $params{filters}{is_telecommute} = $q->{is_telecommute};
     }
 
     if (my $s = $q->{salary_from}) {
         $params{filters}{salary_to} = $s;
     }
 
+    if (my $w = $q->{wages_for}) {
+        $params{filters}{wages_for} = $w;
+    }
+
     if (my $s = $q->{terms}) {
         $params{filters}{term} = $s;
     }
 
+    if (defined $q->{is_telecommute}) {
+        $params{filters}{is_telecommute} = 1;
+    }
+
     $ctx->stash(
         current_view => 'JSON',
         json_data    => $ctx->model->grid_search(%params),

root/src/public/job/list.tx

     </div><!-- end .col-md-12 -->
 </div><!-- end .row -->
 
-<div class="content" id="job-list">
-    <!-- company info -->
+<div class="content ng-cloak" id="job-list">
     <div class="row">
+        <div class="col-lg-12" ng-show="!server_error && jobs.length === 0">
+            <div class="alert alert-info">
+                <p><: $l('Nenhum resultado encontrado.') :></p>
+            </div>
+        </div>
+
+        <div class="col-lg-12" ng-show="server_error">
+            <div class="alert alert-danger">
+                <p><: $l('Ocorreu um erro no servidor ao efetuar esta busca. Tente novamente mais tarde.') :></p>
+            </div>
+        </div>
 
         <!-- one-job start -->
         <div class="col-md-4" ng-repeat="job in jobs">

root/src/public/wrapper.tx

 
     <head>
         <title>PerlPro</title>
-        <link href="//cdnjs.cloudflare.com/ajax/libs/qtip2/2.1.0/jquery.qtip.min.css" rel="stylesheet">
         <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
         <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
         <link href="<: $static_uri :>/css/style.css" rel="stylesheet">
 
                         <div class="col-md-6">
                             <div class="pullright">
-                                <form method="get" action="/search">
+                                <form method="get" action="<: $uri('/jobs') :>" id="job_search_form">
                                     <div class="input-group">
-                                        <input type="text" class="form-control" placeholder="Encontre uma vaga">
+                                        <input type="text" class="form-control" placeholder="Encontre uma vaga" id="job_search_terms">
                                         <span class="input-group-btn">
                                             <button class="btn btn-warning" type="submit"><: $l('Buscar') :></button>
                                         </span>
 
         <script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
         <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
-        <script src="//cdnjs.cloudflare.com/ajax/libs/qtip2/2.1.0/jquery.qtip.min.js"></script>
-        <script src="<: $static_uri :>/js/main.js"></script>
+        <script src="<: $static_uri :>/js/public.js"></script>
 
     </body>
-</html>
+</html>

root/src/public/wrapper_search.tx

         <link href="<: $static_uri :>/css/style.css" rel="stylesheet">
         <meta charset="utf-8">
         <link href="<: $uri('/favicon.ico') :>" rel="shortcut icon">
+        <style type="text/css">
+            .ng-cloak { display: none; }
+        </style>
     </head>
 
     <body ng-controller="JobListController">
                             </div><!-- end .modal -->
 
                             <!-- location modal -->
+                            <form ng-submit="close_and_reload()">
                             <div class="modal fade" id="modal-location" tabindex="-1" role="dialog" aria-hidden="true">
                                 <div class="modal-dialog">
                                     <div class="modal-content">
 
                                         <div class="modal-footer">
                                             <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
-                                            <button type="button" class="btn btn-primary" ng-click="close_and_reload()">Filtrar</button>
+                                            <button type="submit" class="btn btn-primary" ng-click="close_and_reload()">Filtrar</button>
                                         </div><!-- end .modal-footer -->
 
                                     </div><!-- end .modal-content -->
                                 </div><!-- end .modal-dialog -->
                             </div><!-- end .modal -->
+                            </form>
 
                             <!-- payment modal -->
+                            <form ng-submit="close_and_reload()">
                             <div class="modal fade" id="modal-payment" tabindex="-1" role="dialog" aria-hidden="true">
                                 <div class="modal-dialog">
                                     <div class="modal-content">
                                                     <input type="text" class="form-control" id="salary_to" ng-model="filters.salary_to" placeholder="Valor máximo">
                                                 </div>
 
+                                                <p>&nbsp;</p>
+
+                                                <div class="form-group">por</div>
+
                                                 <div class="form-group">
                                                     <label class="sr-only" for="wages_for">Período</label>
                                                     <select class="form-control" id="wages_for" ng-model="filters.wages_for">
-                                                        <option>Período</option>
+                                                        <option value="" selected>Período</option>
                                                         <option value="month">Mês</option>
                                                         <option value="hour">Hora</option>
                                                         <option value="project">Projeto</option>
 
                                         <div class="modal-footer">
                                             <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
-                                            <button type="button" class="btn btn-primary" ng-click="close_and_reload()">Filtrar</button>
+                                            <button type="submit" class="btn btn-primary" ng-click="close_and_reload()">Filtrar</button>
                                         </div><!-- end .modal-footer -->
 
                                     </div><!-- end .modal-content -->
                                 </div><!-- end .modal-dialog -->
                             </div><!-- end .modal -->
+                            </form>
 
                         </div>
 

root/static/js/public.js

 jQuery(function ($) {
-    $('.company-access button').qtip({
-        content: {
-            title: 'Fazer Login',
-            text: $('#login_form')
-        },
-        style: {
-            classes: 'qtip-bootstrap'
-        },
-        position: {
-            at: 'bottom center',
-            my: 'top right'
-        },
-        show: {
-            event: 'click'
-        },
-        hide: {
-            event: 'click'
-        }
-    });
-
-
-    $('.one-filter').each( function(){
-
-        $( this ).qtip({
-            content: {
-                title: $( '.filter-title', this ).html(),
-                text: $( '.filter-content', this )
-            },
-            style: {
-                classes: 'qtip-bootstrap'
-            },
-            position: {
-                at: 'bottom center',
-                my: 'top center'
-            },
-            show: {
-                event: 'click'
-            },
-            hide: {
-                event: 'click'
-            },
-            events: {
-                show: function() {
-                    $('.qtip').hide();
-                }
-            }
-        });
-
-    });
-
-    $( '.add-filter' ).click( function() {
-        var value = $( this ).parent().find( 'input[type="text"]' ).val();
-
-        if( value != '' ){
-            var html = '<li>'+value+' <i class="icon-remove-sign"></i></li>';
-            $( this ).parent().parent().find( '.selected-filters' ).append( html );
-
-            $( '.icon-remove-sign' ).click( function() {
-                $( this ).parent().remove();
-            });
-        }
-    });
-
     $( '#job_search_form' ).submit(function () {
 
-        return false;
-    });
-
-    $( 'form.requirements' ).submit( function() {
-        var values = $(this).find( 'input[type="text"]' ).val().split(',');
-        var value;
-        var ul = $(this).find( 'ul.requirements' );
-        var found;
-
-        for (var i = 0; i < values.length; i++) {
-            value = values[i];
-
-            if ( value === '' ) {
-                continue;
-            }
-
-            found = false;
-
-            ul.find('li').each(function () {
-                if ($(this).text().replace(/^\s+/,'').replace(/\s+$/,'') === value) {
-                    found = true;
-                    return false;
-                }
-            });
-
-            if (found) {
-                continue;
-            }
-
-            ul.append( '<li>' + value + ' <a href="#" class="remove-requirement"><i class="icon-remove-sign"></i></a></li>' );
-        }
-
-        $(this).find('.remove-requirement').unbind('click');
-        $(this).find('.remove-requirement').click( function() {
-            var ul = $(this).parent().parent();
-            $(this).parent().remove();
-            update_empty(ul);
-            return false;
-        });
-
-        $(this)[0].reset();
-        update_empty($(this).find('ul.requirements'));
+        setTimeout(function () {
+            window.location = '/jobs#?terms=' + encodeURIComponent($('#job_search_terms').val());
+        }, 100);
 
         return false;
     });
-
-    $('div.btn-radio,div.btn-checkbox').each(function () {
-        var data_for = $(this).data('input-for');
-        var real_el  = $('[name="'+data_for+'"]');
-        var value    = real_el.val().split(',');
-
-        $(this).find('button.active').removeClass('active');
-
-        $(this).find('button').each(function () {
-            if (in_array($(this).val(), value) >= 0) {
-                $(this).addClass('active');
-            }
-        });
-
-        $(this).find('button').click(function () {
-            var s = real_el.val();
-            var current_value = s ? s.split(',') : [];
-            var btnval = $(this).val();
-            var pos = in_array(btnval, current_value);
-            if (pos >= 0 && $(this).parent().hasClass('btn-checkbox')) {
-                for (var i = pos; i < current_value.length-1; i++) {
-                    current_value[i] = current_value[i+1];
-                }
-                current_value.pop();
-            }
-            else {
-                current_value.push(btnval);
-            }
-            real_el.val(current_value.join(','));
-        });
-    });
-
-    $('ul.requirements > li > a.remove-requirement').click( function() {
-        var ul = $(this).parent().parent();
-        $(this).parent().remove();
-        update_empty(ul);
-        return false;
-    });
-
-    function update_empty(w) {
-        if (w.find('li').not('.zero').size() === 0) {
-            w.find('li.zero').show();
-        }
-        else {
-            w.find('li.zero').hide();
-        }
-    }
-
-    function in_array(needle, haystack) {
-        for (var i = 0; i < haystack.length; i++) {
-            if (haystack[i] === needle) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-
-    $('ul.requirements').each(function () {
-        update_empty($(this));
-    });
-
-    $("#company_search").typeahead({
-        source: function (query, process) {
-            var companies = [];
-
-            return $.get('/companies/' + query, function (data) {
-                $.each(data.companies, function (key, value) {
-                    // TODO: save the key, because that's what we'll actually
-                    // use to search
-                    companies.push(value);
-                });
-
-                process(companies);
-            });
-        },
-        updater: function (item) {
-            // TODO
-            return item;
-        }
-    });
-
-    $("#attribute_search").typeahead({
-        source: function (query, process) {
-            return $.get('/attributes/' + query, function (data) {
-                process(data.attributes);
-            });
-        },
-        updater: function (item) {
-            // TODO
-            return item;
-        }
-    });
-
-    $("#city_search").typeahead({
-        source: function (query, process) {
-            $.getJSON('http://dev.virtualearth.net/REST/v1/Locations?countryRegion=BR&locality=' + encodeURIComponent(query) + '&c=pt-br&output=json&maxResults=30&jsonp=?&key=Ak3hUY8K4w522FcOQlCwpN7Nt6iZCgNbjZYyIePw2UI-pPzltCRbqO3-dfJT2pds').done(function (data) {
-                var results = [];
-                if (data.resourceSets && data.resourceSets.length > 0) {
-                    $.each(data.resourceSets[0].resources, function (i, item) {
-                        if (results.length > 10) {
-                            return false;
-                        }
-                        if (item.entityType === "PopulatedPlace" && in_array(item.address.locality, results) < 0) {
-                            results.push(item.address.locality);
-                        }
-                    });
-                    process(results);
-                }
-            });
-        },
-        updater: function (item) {
-            // TODO
-            return item;
-        }
-    });
 });

root/static/js/search.js

 function JobListController($scope, $http, $location) {
     $scope.filters = {
-        "is_telecommute": false,
         "contract_types": {
-            "clt": false,
-            "pj": false,
+            "clt":        false,
+            "pj":         false,
             "internship": false,
-            "freelance": false
+            "freelance":  false
         },
-        "attributes":      [],
-        "companies":       [],
-        "location":        '',
-        "salary_from":     null,
-        "salary_to":       null,
-        "terms":           ''
+        "is_telecommute": false,
+        "attributes":     [],
+        "companies":      [],
+        "location":       '',
+        "salary_from":    '',
+        "salary_to":      '',
+        "wages_for":      '',
+        "terms":          ''
     };
+    $scope.server_error = false;
+    $scope.jobs = [];
 
     $scope.close_and_reload = function () {
         $scope.fetch_results();
         var p = serialize_params();
         $http.get('/ajax_search', { params: p }).
             success(function (data) {
+                $scope.server_error = false;
                 $scope.jobs  = data.items;
                 $scope.pager = data.pager;
             }).
             error(function () {
-                alert('Houve um erro na requisição da pesquisa.');
+                $scope.server_error = true;
             });
     };
 
             $scope.filters.is_telecommute = !!s.is_telecommute;
         }
 
-        angular.forEach([ "location", "salary_from", "salary_to", "terms" ], function (item) {
+        angular.forEach([ "location", "salary_from", "salary_to", "wages_for", "terms" ], function (item) {
             if (s.hasOwnProperty(item)) {
                 $scope.filters[item] = s[item];
             }
         }
         if ($scope.filters.location) {
             p.location = $scope.filters.location;
-            p.is_telecommute = $scope.filters.is_telecommute;
+        }
+        if ($scope.filters.is_telecommute) {
+            p.is_telecommute = 1;
         }
         if ($scope.filters.salary_from) {
             p.salary_from = $scope.filters.salary_from;
         if ($scope.filters.salary_to) {
             p.salary_to = $scope.filters.salary_to;
         }
+        if ($scope.filters.wages_for) {
+            p.wages_for = $scope.filters.wages_for;
+        }
         if ($scope.filters.terms) {
             p.terms = $scope.filters.terms;
         }