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