blob: 2563dd617901f532f7125ce257aaffa3ab20edb9 [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
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
Michael Davis994a93b2017-04-18 10:01:04 -050011
Andrew Geisslerd27bb132018-05-24 11:07:27 -070012 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 Geisslerd27bb132018-05-24 11:07:27 -070020 $scope.loading = true;
Gunnar Mills9181e872018-08-28 15:33:57 -050021
Andrew Geisslerd27bb132018-05-24 11:07:27 -070022 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 Geisslerba5e3f32018-05-24 10:58:00 -070029 $scope.customSearch = '';
30 $scope.searchTerms = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -070031 };
Iftekharul Islamee27d752017-07-05 15:54:31 -050032
Andrew Geisslerd27bb132018-05-24 11:07:27 -070033 $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 Geisslerba5e3f32018-05-24 10:58:00 -070041 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070042 }
43 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070044
Andrew Geisslerd27bb132018-05-24 11:07:27 -070045 $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 Geisslerba5e3f32018-05-24 10:58:00 -070053 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070054 }
55 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070056
Andrew Geisslerd27bb132018-05-24 11:07:27 -070057 $scope.filterBySearchTerms = function(hardware) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070058 if (!$scope.searchTerms.length) return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070059
Andrew Geisslerd27bb132018-05-24 11:07:27 -070060 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 Davis994a93b2017-04-18 10:01:04 -050069})(angular);