blob: fae3a096baeb11a12a7e7c9225c4a115a1400183 [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 = [];
Michael Davis428375e2017-08-01 15:48:34 -050026 $scope.loading = false;
Iftekharul Islamee27d752017-07-05 15:54:31 -050027
28 APIUtils.getHardwares(function(data, originalData){
Michael Davis428375e2017-08-01 15:48:34 -050029 $scope.loading = true;
Iftekharul Islamee27d752017-07-05 15:54:31 -050030 $scope.hardwares = data;
31 $scope.originalData = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -050032 $scope.loading = false;
Iftekharul Islamee27d752017-07-05 15:54:31 -050033 });
34
Iftekharul Islam171c6a12017-08-11 08:35:47 -050035 $scope.clear = function(){
36 $scope.customSearch = "";
37 $scope.searchTerms = [];
38 }
39
Iftekharul Islamee27d752017-07-05 15:54:31 -050040 $scope.doSearchOnEnter = function (event) {
41 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
42 if (event.keyCode === 13 &&
43 search.length >= 2) {
44 $scope.searchTerms = $scope.customSearch.split(" ");
45 }else{
46 if(search.length == 0){
47 $scope.searchTerms = [];
48 }
49 }
50 };
51
52 $scope.doSearchOnClick = function() {
53 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
54 if (search.length >= 2) {
55 $scope.searchTerms = $scope.customSearch.split(" ");
56 }else{
57 if(search.length == 0){
58 $scope.searchTerms = [];
59 }
60 }
61 }
62
63 $scope.filterBySearchTerms = function(hardware){
64
65 if(!$scope.searchTerms.length) return true;
66
67 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
68 if(hardware.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
69 }
70 return true;
71 }
Michael Davis994a93b2017-04-18 10:01:04 -050072 }
73 ]
74 );
75
76})(angular);