xref: /openbmc/phosphor-webui/app/server-health/controllers/inventory-overview-controller.js (revision 4ddda586452cb65560bba645ef30e92200633405)
1cd789508SIftekharul Islam/**
2cd789508SIftekharul Islam * Controller for server
3cd789508SIftekharul Islam *
4cd789508SIftekharul Islam * @module app/serverHealth
5cd789508SIftekharul Islam * @exports inventoryOverviewController
6cd789508SIftekharul Islam * @name inventoryOverviewController
7cd789508SIftekharul Islam */
8cd789508SIftekharul Islam
9cd789508SIftekharul Islamwindow.angular && (function(angular) {
10cd789508SIftekharul Islam  'use strict';
11cd789508SIftekharul Islam
12d27bb135SAndrew Geissler  angular.module('app.serverHealth').controller('inventoryOverviewController', [
13d27bb135SAndrew Geissler    '$scope', '$window', 'APIUtils', 'dataService',
14cd789508SIftekharul Islam    function($scope, $window, APIUtils, dataService) {
15cd789508SIftekharul Islam      $scope.dataService = dataService;
16ee27d754SIftekharul Islam      $scope.hardwares = [];
17ee27d754SIftekharul Islam      $scope.originalData = {};
18ba5e3f34SAndrew Geissler      $scope.customSearch = '';
19ee27d754SIftekharul Islam      $scope.searchTerms = [];
20428375e8SMichael Davis      $scope.loading = true;
21*9181e873SGunnar Mills
22c22425f2SIftekharul Islam      APIUtils.getHardwares(function(data, originalData) {
23ee27d754SIftekharul Islam        $scope.hardwares = data;
24ee27d754SIftekharul Islam        $scope.originalData = JSON.stringify(originalData);
25428375e8SMichael Davis        $scope.loading = false;
26ee27d754SIftekharul Islam      });
27ee27d754SIftekharul Islam
28171c6a1eSIftekharul Islam      $scope.clear = function() {
29ba5e3f34SAndrew Geissler        $scope.customSearch = '';
30171c6a1eSIftekharul Islam        $scope.searchTerms = [];
31ba5e3f34SAndrew Geissler      };
32171c6a1eSIftekharul Islam
33ee27d754SIftekharul Islam      $scope.doSearchOnEnter = function(event) {
34d27bb135SAndrew Geissler        var search =
35d27bb135SAndrew Geissler            $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
36d27bb135SAndrew Geissler        if (event.keyCode === 13 && search.length >= 2) {
37ba5e3f34SAndrew Geissler          $scope.searchTerms = $scope.customSearch.split(' ');
38d27bb135SAndrew Geissler        } else {
39ee27d754SIftekharul Islam          if (search.length == 0) {
40ee27d754SIftekharul Islam            $scope.searchTerms = [];
41ee27d754SIftekharul Islam          }
42ee27d754SIftekharul Islam        }
43ee27d754SIftekharul Islam      };
44ee27d754SIftekharul Islam
45ee27d754SIftekharul Islam      $scope.doSearchOnClick = function() {
46d27bb135SAndrew Geissler        var search =
47d27bb135SAndrew Geissler            $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
48ee27d754SIftekharul Islam        if (search.length >= 2) {
49ba5e3f34SAndrew Geissler          $scope.searchTerms = $scope.customSearch.split(' ');
50d27bb135SAndrew Geissler        } else {
51ee27d754SIftekharul Islam          if (search.length == 0) {
52ee27d754SIftekharul Islam            $scope.searchTerms = [];
53ee27d754SIftekharul Islam          }
54ee27d754SIftekharul Islam        }
55ba5e3f34SAndrew Geissler      };
56ee27d754SIftekharul Islam
57ee27d754SIftekharul Islam      $scope.filterBySearchTerms = function(hardware) {
58ee27d754SIftekharul Islam        if (!$scope.searchTerms.length) return true;
59ee27d754SIftekharul Islam
60ee27d754SIftekharul Islam        for (var i = 0, length = $scope.searchTerms.length; i < length; i++) {
61d27bb135SAndrew Geissler          if (hardware.search_text.indexOf(
62d27bb135SAndrew Geissler                  $scope.searchTerms[i].toLowerCase()) == -1)
63d27bb135SAndrew Geissler            return false;
64ee27d754SIftekharul Islam        }
65ee27d754SIftekharul Islam        return true;
66ba5e3f34SAndrew Geissler      };
67ee27d754SIftekharul Islam    }
68ba5e3f34SAndrew Geissler  ]);
69cd789508SIftekharul Islam})(angular);
70