diff --git a/res/app/components/stf/logcat-table/logcat-table-directive.js b/res/app/components/stf/logcat-table/logcat-table-directive.js index fb285eae..a172bb9f 100644 --- a/res/app/components/stf/logcat-table/logcat-table-directive.js +++ b/res/app/components/stf/logcat-table/logcat-table-directive.js @@ -105,6 +105,40 @@ module.exports = clearTable() } + /** + * Validate filter.data object value and assign bordercolor to red if value + * doesn't match regex(pattern): + * - HH:mm:ss.SSS + * - H:mm:ss.SSS + * - :mm:SS.SSS + * - mm:ss.SSS + * - m:ss.SSS + * -... combinations + * in other case colour will be set to default. + * + * @param {event} event object + */ + scope.validateDate = function(e) { + var pattern = ['^(?:(?:([0-1]?\\d|2[0-3]):)?(:[0-5]\\d|[0-5]\\d):|\\d)', + '?(:[0-5]\\d|[0-5]\\d{1,2})?(\\.[0-9]?\\d{0,2}|:[0-5]?\\d{0,1})|(\\d{0,2})'].join([]) + var regex = new RegExp(pattern, 'g') + var inputValue = event.srcElement.value + var matchArray = inputValue.match(regex) + var isTextValid = false + if (matchArray) { + matchArray.forEach(function(item, index) { + if (item === inputValue) { + isTextValid = true + event.srcElement.style.borderColor = '' + } + }) + } + + if (isTextValid === false) { + event.srcElement.style.borderColor = 'red' + } + } + scope.$on('$destroy', function() { parent.removeEventListener('scroll', throttledScrollListener) }) diff --git a/res/app/control-panes/logs/logs-controller.js b/res/app/control-panes/logs/logs-controller.js index 86f91b98..a61b842c 100644 --- a/res/app/control-panes/logs/logs-controller.js +++ b/res/app/control-panes/logs/logs-controller.js @@ -34,7 +34,25 @@ module.exports = function LogsCtrl($scope, LogcatService) { angular.forEach(props, function(prop) { $scope.$watch('filters.' + prop, function(newValue, oldValue) { if (!angular.equals(newValue, oldValue)) { - LogcatService.filters[prop] = newValue + var transformedInput = '' + switch('filters.' + prop) { + case 'filters.pid': + transformedInput = newValue.replace(/[^0-9:]/g, '') + if (transformedInput !== newValue) { + $scope.filters.pid = transformedInput + } + break + case 'filters.tid': + transformedInput = newValue.replace(/[^0-9]/g, '') + if (transformedInput !== newValue) { + $scope.filters.tid = transformedInput + } + break + default: + transformedInput = newValue + } + + LogcatService.filters[prop] = transformedInput } }) }) diff --git a/res/app/control-panes/logs/logs.pug b/res/app/control-panes/logs/logs.pug index 4ae8afb6..2735e330 100644 --- a/res/app/control-panes/logs/logs.pug +++ b/res/app/control-panes/logs/logs.pug @@ -12,7 +12,7 @@ select(ng-model='filters.priority', ng-options='l.name for l in filters.levelNumbers') option(value='', disabled, selected) {{"Level"|translate}} td(width='10%') - input(ng-model='filters.date', type='text', placeholder='{{"Time"|translate}}').input-sm.form-control + input(ng-model='filters.date', type='text', placeholder='{{"Time"|translate}}', ng-keyup='validateDate(event=$event)').input-sm.form-control td(width='8%', ng-if='$root.platform == "native"') input(ng-model='filters.pid', type='text', placeholder='{{"PID"|translate}}').input-sm.form-control td(width='8%', ng-if='$root.platform == "native"')