mirror of
https://github.com/openstf/stf
synced 2025-10-03 17:59:28 +02:00
Merge pull request #1074 from lukzeg/fix/TID_PID_input_validator
#1050: Feature -add filter.tid/filter.pid/filter.data input validator
This commit is contained in:
commit
eb96dfe2a5
3 changed files with 54 additions and 2 deletions
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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"')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue