blob: abdc9ffd5335e8fe12c7a7b4b292c0c383cd209d [file] [log] [blame]
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001window.angular && (function(angular) {
2 'use strict';
Iftekharul Islam8b4828a2017-04-19 14:37:55 -05003
Andrew Geisslerd27bb132018-05-24 11:07:27 -07004 angular.module('app.common.directives').directive('logSearchControl', [
5 'APIUtils',
6 function(APIUtils) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07007 return {
8 'restrict': 'E',
9 'template': require('./log-search-control.html'),
Andrew Geisslerd27bb132018-05-24 11:07:27 -070010 'controller': [
11 '$rootScope', '$scope', 'dataService', '$location',
12 function($rootScope, $scope, dataService, $location) {
13 $scope.dataService = dataService;
14 $scope.doSearchOnEnter = function(event) {
15 var search =
16 $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
17 if (event.keyCode === 13 && search.length >= 2) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070018 $scope.clearSearchItem();
Andrew Geisslerd27bb132018-05-24 11:07:27 -070019 $scope.addSearchItem(search);
20 } else {
21 if (search.length == 0) {
22 $scope.clearSearchItem();
23 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070024 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070025 };
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050026
Andrew Geisslerd27bb132018-05-24 11:07:27 -070027 $scope.clear = function() {
28 $scope.customSearch = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070029 $scope.clearSearchItem();
Andrew Geisslerd27bb132018-05-24 11:07:27 -070030 };
31
32 $scope.doSearchOnClick = function() {
33 var search =
34 $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
35 if (search.length >= 2) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070036 $scope.clearSearchItem();
Andrew Geisslerd27bb132018-05-24 11:07:27 -070037 $scope.addSearchItem(search);
38 } else {
39 if (search.length == 0) {
40 $scope.clearSearchItem();
41 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070042 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070043 };
44 }
45 ]
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070046 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -070047 }
48 ]);
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050049})(window.angular);