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 12*d27bb135SAndrew Geissler angular.module('app.serverHealth').controller('inventoryOverviewController', [ 13*d27bb135SAndrew 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 = false; 21ee27d754SIftekharul Islam 22428375e8SMichael Davis $scope.loading = true; 23c22425f2SIftekharul Islam APIUtils.getHardwares(function(data, originalData) { 24ee27d754SIftekharul Islam $scope.hardwares = data; 25ee27d754SIftekharul Islam $scope.originalData = JSON.stringify(originalData); 26428375e8SMichael Davis $scope.loading = false; 27ee27d754SIftekharul Islam }); 28ee27d754SIftekharul Islam 29171c6a1eSIftekharul Islam $scope.clear = function() { 30ba5e3f34SAndrew Geissler $scope.customSearch = ''; 31171c6a1eSIftekharul Islam $scope.searchTerms = []; 32ba5e3f34SAndrew Geissler }; 33171c6a1eSIftekharul Islam 34ee27d754SIftekharul Islam $scope.doSearchOnEnter = function(event) { 35*d27bb135SAndrew Geissler var search = 36*d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 37*d27bb135SAndrew Geissler if (event.keyCode === 13 && search.length >= 2) { 38ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 39*d27bb135SAndrew Geissler } else { 40ee27d754SIftekharul Islam if (search.length == 0) { 41ee27d754SIftekharul Islam $scope.searchTerms = []; 42ee27d754SIftekharul Islam } 43ee27d754SIftekharul Islam } 44ee27d754SIftekharul Islam }; 45ee27d754SIftekharul Islam 46ee27d754SIftekharul Islam $scope.doSearchOnClick = function() { 47*d27bb135SAndrew Geissler var search = 48*d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 49ee27d754SIftekharul Islam if (search.length >= 2) { 50ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 51*d27bb135SAndrew Geissler } else { 52ee27d754SIftekharul Islam if (search.length == 0) { 53ee27d754SIftekharul Islam $scope.searchTerms = []; 54ee27d754SIftekharul Islam } 55ee27d754SIftekharul Islam } 56ba5e3f34SAndrew Geissler }; 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++) { 63*d27bb135SAndrew Geissler if (hardware.search_text.indexOf( 64*d27bb135SAndrew Geissler $scope.searchTerms[i].toLowerCase()) == -1) 65*d27bb135SAndrew Geissler return false; 66ee27d754SIftekharul Islam } 67ee27d754SIftekharul Islam return true; 68ba5e3f34SAndrew Geissler }; 69ee27d754SIftekharul Islam } 70ba5e3f34SAndrew Geissler ]); 71cd789508SIftekharul Islam 72cd789508SIftekharul Islam})(angular); 73