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