searchController.js 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

19 20
'use strict';

21 22
angular.module('dgc.search').controller('SearchController', ['$scope', '$location', '$http', '$state', '$stateParams', 'SearchResource', 'NotificationService',
    function($scope, $location, $http, $state, $stateParams, SearchResource, NotificationService) {
23

24
        $scope.types = [];
25 26
        $scope.results = [];
        $scope.search = function(query) {
27 28
            $scope.results = [];
            NotificationService.reset();
29
            SearchResource.search($location.search(query).search(), function searchSuccess(response) {
30 31
                $scope.results = response;
                if ($scope.results.length < 1) {
32
                    NotificationService.error('No Result found', false);
33 34 35
                }
                $state.go('search.results', {}, {
                    location: false
36
                });
37 38
            }, function searchError(err) {
                NotificationService.error('Error occurred during executing search query, error status code = ' + err.status + ', status text = ' + err.statusText, false);
39 40
            });
        };
41

42 43 44 45
        $scope.typeAvailable = function() {
            return ['hive_table'].indexOf(this.result.type && this.result.type.toLowerCase()) > -1;
        };

46
        var urlParts = $location.url().split('?');
47
        $scope.query = urlParts.length > 1 ? urlParts[1] : null;
48
        if ($scope.query) {
49
            $scope.search($scope.query);
50 51 52
        }
    }
]);