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