blob: 81fd833488d39e754cf35cc60a6904afd683d98b [file] [log] [blame]
Michael Davis994a93b2017-04-18 10:01:04 -05001/**
Iftekharul Islamcd789502017-04-19 14:37:55 -05002 * Controller for server
Michael Davis994a93b2017-04-18 10:01:04 -05003 *
Iftekharul Islamcd789502017-04-19 14:37:55 -05004 * @module app/serverHealth
5 * @exports inventoryOverviewController
6 * @name inventoryOverviewController
Michael Davis994a93b2017-04-18 10:01:04 -05007 * @version 0.1.0
8 */
9
10window.angular && (function (angular) {
11 'use strict';
12
13 angular
Iftekharul Islamcd789502017-04-19 14:37:55 -050014 .module('app.serverHealth')
Michael Davis994a93b2017-04-18 10:01:04 -050015 .controller('inventoryOverviewController', [
16 '$scope',
17 '$window',
18 'APIUtils',
19 'dataService',
Iftekharul Islamcd789502017-04-19 14:37:55 -050020 function($scope, $window, APIUtils, dataService){
Michael Davis994a93b2017-04-18 10:01:04 -050021 $scope.dataService = dataService;
Iftekharul Islamee27d752017-07-05 15:54:31 -050022 $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 Davis994a93b2017-04-18 10:01:04 -050064 }
65 ]
66 );
67
68})(angular);