summaryrefslogtreecommitdiffstats
path: root/app/server-health/controllers/inventory-overview-controller.js
blob: 2563dd617901f532f7125ce257aaffa3ab20edb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
 * Controller for server
 *
 * @module app/serverHealth
 * @exports inventoryOverviewController
 * @name inventoryOverviewController
 */

window.angular && (function(angular) {
  'use strict';

  angular.module('app.serverHealth').controller('inventoryOverviewController', [
    '$scope', '$window', 'APIUtils', 'dataService',
    function($scope, $window, APIUtils, dataService) {
      $scope.dataService = dataService;
      $scope.hardwares = [];
      $scope.originalData = {};
      $scope.customSearch = '';
      $scope.searchTerms = [];
      $scope.loading = true;

      APIUtils.getHardwares(function(data, originalData) {
        $scope.hardwares = data;
        $scope.originalData = JSON.stringify(originalData);
        $scope.loading = false;
      });

      $scope.clear = function() {
        $scope.customSearch = '';
        $scope.searchTerms = [];
      };

      $scope.doSearchOnEnter = function(event) {
        var search =
            $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
        if (event.keyCode === 13 && search.length >= 2) {
          $scope.searchTerms = $scope.customSearch.split(' ');
        } else {
          if (search.length == 0) {
            $scope.searchTerms = [];
          }
        }
      };

      $scope.doSearchOnClick = function() {
        var search =
            $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
        if (search.length >= 2) {
          $scope.searchTerms = $scope.customSearch.split(' ');
        } else {
          if (search.length == 0) {
            $scope.searchTerms = [];
          }
        }
      };

      $scope.filterBySearchTerms = function(hardware) {
        if (!$scope.searchTerms.length) return true;

        for (var i = 0, length = $scope.searchTerms.length; i < length; i++) {
          if (hardware.search_text.indexOf(
                  $scope.searchTerms[i].toLowerCase()) == -1)
            return false;
        }
        return true;
      };
    }
  ]);
})(angular);
OpenPOWER on IntegriCloud