blob: 7dc89af633606344e65e4ff5e7d61f86cc44e449 [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 */
8
9window.angular && (function (angular) {
10 'use strict';
11
12 angular
Iftekharul Islamcd789502017-04-19 14:37:55 -050013 .module('app.serverHealth')
Michael Davis994a93b2017-04-18 10:01:04 -050014 .controller('inventoryOverviewController', [
Gunnar Millseedefd32018-02-28 17:02:34 -060015 '$scope',
16 '$window',
17 'APIUtils',
Michael Davis994a93b2017-04-18 10:01:04 -050018 'dataService',
Iftekharul Islamcd789502017-04-19 14:37:55 -050019 function($scope, $window, APIUtils, dataService){
Michael Davis994a93b2017-04-18 10:01:04 -050020 $scope.dataService = dataService;
Iftekharul Islamee27d752017-07-05 15:54:31 -050021 $scope.hardwares = [];
22 $scope.originalData = {};
23 $scope.customSearch = "";
24 $scope.searchTerms = [];
Michael Davis428375e2017-08-01 15:48:34 -050025 $scope.loading = false;
Iftekharul Islamee27d752017-07-05 15:54:31 -050026
Iftekharul Islamc22425f2017-09-06 10:04:14 -050027 $scope.loading = true;
Iftekharul Islamee27d752017-07-05 15:54:31 -050028 APIUtils.getHardwares(function(data, originalData){
29 $scope.hardwares = data;
30 $scope.originalData = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -050031 $scope.loading = false;
Iftekharul Islamee27d752017-07-05 15:54:31 -050032 });
33
Iftekharul Islam171c6a12017-08-11 08:35:47 -050034 $scope.clear = function(){
35 $scope.customSearch = "";
36 $scope.searchTerms = [];
37 }
38
Iftekharul Islamee27d752017-07-05 15:54:31 -050039 $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 Millseedefd32018-02-28 17:02:34 -060064 if(!$scope.searchTerms.length) return true;
Iftekharul Islamee27d752017-07-05 15:54:31 -050065
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 Davis994a93b2017-04-18 10:01:04 -050071 }
72 ]
73 );
74
75})(angular);