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