searchController.js 1.19 KB
Newer Older
1 2
'use strict';

3 4
angular.module('dgc.search').controller('SearchController', ['$scope', '$location', '$http', '$state', '$stateParams', 'SearchResource', 'NotificationService',
    function($scope, $location, $http, $state, $stateParams, SearchResource, NotificationService) {
5

6
        $scope.types = [];
7 8
        $scope.results = [];
        $scope.search = function(query) {
9 10
            $scope.results = [];
            NotificationService.reset();
11
            SearchResource.search($location.search(query).search(), function(response) {
12 13
                $scope.results = response;
                if ($scope.results.length < 1) {
14
                    NotificationService.error('No Result found', false);
15 16 17
                }
                $state.go('search.results', {}, {
                    location: false
18 19 20
                });
            });
        };
21

22 23 24 25
        $scope.typeAvailable = function() {
            return ['hive_table'].indexOf(this.result.type && this.result.type.toLowerCase()) > -1;
        };

26
        var urlParts = $location.url().split('?');
27
        $scope.query = urlParts.length > 1 ? urlParts[1] : null;
28
        if ($scope.query) {
29
            $scope.search($scope.query);
30 31 32
        }
    }
]);