blob: c5e618984ed6ebd12ceb9a7112aac1dc2a7d2291 [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
35 $scope.doSearchOnEnter = function (event) {
36 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
37 if (event.keyCode === 13 &&
38 search.length >= 2) {
39 $scope.searchTerms = $scope.customSearch.split(" ");
40 }else{
41 if(search.length == 0){
42 $scope.searchTerms = [];
43 }
44 }
45 };
46
47 $scope.doSearchOnClick = function() {
48 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
49 if (search.length >= 2) {
50 $scope.searchTerms = $scope.customSearch.split(" ");
51 }else{
52 if(search.length == 0){
53 $scope.searchTerms = [];
54 }
55 }
56 }
57
58 $scope.filterBySearchTerms = function(hardware){
59
60 if(!$scope.searchTerms.length) return true;
61
62 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
63 if(hardware.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
64 }
65 return true;
66 }
Michael Davis994a93b2017-04-18 10:01:04 -050067 }
68 ]
69 );
70
71})(angular);