diff --git a/res/app/components/stf/filter-string/filter-string-service.js b/res/app/components/stf/filter-string/filter-string-service.js new file mode 100644 index 00000000..694f7160 --- /dev/null +++ b/res/app/components/stf/filter-string/filter-string-service.js @@ -0,0 +1,53 @@ +var _ = require('lodash') + +module.exports = function FilterStringServiceFactory() { + var service = {} + + /** + * Filters integer + * + * @param searchValue + * @param str + * @returns {boolean} true if matched + */ + service.filterInteger = function (searchValue, str) { + var matched = true + matched = service.filterString(searchValue + '', str + '') + return matched + } + + /** + * Filters string + * + * @param searchValue + * @param str + * @returns {boolean} true if matched + */ + service.filterString = function (searchValue, str) { + var matched = true + var searchLowerCase = searchValue.toLowerCase() + var searchContent = searchValue.slice(1) + var searchContentLowerCase = searchLowerCase.slice(1) + switch (searchValue.charAt(0)) { + case '/': + var lastSlash = searchContent.lastIndexOf('/') + if (lastSlash !== -1) { + var pattern = searchContent.substring(0, lastSlash) + var flags = searchContent.substring(lastSlash + 1) + var regex = new RegExp(pattern, flags) + matched = !_.isNull(str.match(regex)) + } else { + matched = true // Regex is not complete, don't filter yet + } + break + case '!': + matched = str.toLowerCase().indexOf(searchContentLowerCase) === -1 + break + default: + matched = str.toLowerCase().indexOf(searchLowerCase) !== -1 + } + return matched + } + + return service +} diff --git a/res/app/components/stf/filter-string/filter-string-spec.js b/res/app/components/stf/filter-string/filter-string-spec.js new file mode 100644 index 00000000..64c08500 --- /dev/null +++ b/res/app/components/stf/filter-string/filter-string-spec.js @@ -0,0 +1,11 @@ +describe('FilterStringService', function() { + + beforeEach(module('stf.filter-string')); + + it('should ...', inject(function(FilterStringService) { + + //expect(FilterStringService.doSomething()).toEqual('something'); + + })); + +}) \ No newline at end of file diff --git a/res/app/components/stf/filter-string/index.js b/res/app/components/stf/filter-string/index.js new file mode 100644 index 00000000..4ffca91d --- /dev/null +++ b/res/app/components/stf/filter-string/index.js @@ -0,0 +1,4 @@ +module.exports = angular.module('stf.filter-string', [ + +]) + .factory('FilterStringService', require('./filter-string-service')) diff --git a/res/app/components/stf/logcat/index.js b/res/app/components/stf/logcat/index.js index fb4c4d07..5e12d2d1 100644 --- a/res/app/components/stf/logcat/index.js +++ b/res/app/components/stf/logcat/index.js @@ -1,4 +1,4 @@ module.exports = angular.module('stf.logcat', [ - + require('stf/filter-string').name ]) .factory('LogcatService', require('./logcat-service')) diff --git a/res/app/components/stf/logcat/logcat-service.js b/res/app/components/stf/logcat/logcat-service.js index e98d9dea..cfc16a26 100644 --- a/res/app/components/stf/logcat/logcat-service.js +++ b/res/app/components/stf/logcat/logcat-service.js @@ -1,7 +1,7 @@ var _ = require('lodash') var _s = require('underscore.string') -module.exports = function LogcatServiceFactory(socket, DeviceService) { +module.exports = function LogcatServiceFactory(socket, DeviceService, FilterStringService) { var service = {} service.started = false service.maxEntriesBuffer = 5000 @@ -11,10 +11,36 @@ module.exports = function LogcatServiceFactory(socket, DeviceService) { numberOfEntries: 0, entries: [ ], - levelNumber: null, levelNumbers: [] } + var _filters = {} + + function defineFilterProperties(properties) { + _.forEach(properties, function (prop) { + Object.defineProperty(service.filters, prop, { + get: function () { + return _filters[prop] + }, + set: function (value) { + _filters[prop] = value ? value : null + service.filters.filterLines() + } + }) + }) + } + + defineFilterProperties([ + 'levelNumber', + 'message', + 'pid', + 'tid', + 'dateLabel', + 'date', + 'tag', + 'priority' + ]) + service.entries = [ ] @@ -57,13 +83,15 @@ module.exports = function LogcatServiceFactory(socket, DeviceService) { return data } - socket.on('logcat.entry', function (data) { + socket.on('logcat.entry', function (rawData) { service.numberOfEntries++ - service.entries.push(enhanceEntry(data)) + service.entries.push(enhanceEntry(rawData)) - if (true) { - service.addEntryListener(data) + if (typeof(service.addEntryListener) === 'function') { + if (filterLine(rawData)) { + service.addEntryListener(rawData) + } } }) @@ -72,5 +100,43 @@ module.exports = function LogcatServiceFactory(socket, DeviceService) { service.entries = [] } + service.filters.filterLines = function () { + console.log(_filters) + service.filters.entries = _.filter(service.entries, filterLine) + + console.log(service.filters.entries) + } + + function filterLine(line) { + const enabled = true + var filters = service.filters + + var matched = true + if (enabled) { + if (!_.isEmpty(filters.priority)) { + matched &= line.priority >= filters.priority.number + } + if (!_.isEmpty(filters.date)) { + matched &= FilterStringService.filterString(filters.date, line.dateLabel) + } + if (!_.isEmpty(filters.pid)) { + matched &= FilterStringService.filterInteger(filters.pid, line.pid) + } + if (!_.isEmpty(filters.tid)) { + matched &= FilterStringService.filterInteger(filters.tid, line.tid) + } + if (!_.isEmpty(filters.tag)) { + matched &= FilterStringService.filterString(filters.tag, line.tag) + } + if (!_.isEmpty(filters.message)) { + matched &= FilterStringService.filterString(filters.message, line.message) + } + } else { + matched = true + } + return matched + } + + return service } diff --git a/res/app/control-panes/logs/logs-controller.js b/res/app/control-panes/logs/logs-controller.js index 6f3f6bef..dc7d1c1d 100644 --- a/res/app/control-panes/logs/logs-controller.js +++ b/res/app/control-panes/logs/logs-controller.js @@ -4,10 +4,12 @@ module.exports = function LogsCtrl($scope, LogcatService) { $scope.logEntries = LogcatService.entries - $scope.filters = LogcatService.filters - $scope.started = LogcatService.started + $scope.filters = {} + + $scope.filters.levelNumbers = LogcatService.filters.levelNumbers + $scope.$watch('started', function (newValue, oldValue) { if (newValue !== oldValue) { LogcatService.started = newValue @@ -28,4 +30,30 @@ module.exports = function LogsCtrl($scope, LogcatService) { LogcatService.clear() } + function defineFilterWatchers(props) { + angular.forEach(props, function (prop) { + $scope.$watch('filters.' + prop, function (newValue, oldValue) { + if (!angular.equals(newValue, oldValue)) { + LogcatService.filters[prop] = newValue + } + }) + }) + } + + defineFilterWatchers([ + 'levelNumber', + 'message', + 'pid', + 'tid', + 'dateLabel', + 'date', + 'tag', + 'priority' + ]) + +// $scope.$watchCollection('filters', function (newValue, oldValue) { +// console.log(newValue) +// }); + + } diff --git a/res/app/control-panes/logs/logs.jade b/res/app/control-panes/logs/logs.jade index f9dbe335..0eb4bb8d 100644 --- a/res/app/control-panes/logs/logs.jade +++ b/res/app/control-panes/logs/logs.jade @@ -15,7 +15,7 @@ .widget-content //nothing-to-show(ng-show='!hasLines', message='No logs captured', icon='fa-list-alt') - //table.table.table-condensed(ng-show='filtering.show') + //table.table.table-condensed(ng-show='filters.show') // @@ -38,23 +38,23 @@ span(ng-if='started') {{"Stop"|translate}} span(ng-if='!started') {{"Get"|translate}} //td(width='10%') - select(ng-model='filtering.deviceName', ng-options='d for d in filtering.devicesList') + select(ng-model='filters.deviceName', ng-options='d for d in filters.devicesList') option(value='') {{"Device"|translate}} td(width='6%') - select(ng-model='filters.levelNumber', ng-options='l.name for l in filters.levelNumbers') - option(value='') {{"Level"|translate}} + 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='filtering.date', type='text', placeholder='{{"Time"|translate}}') + input(ng-model='filters.date', type='text', placeholder='{{"Time"|translate}}') td(width='8%', ng-if='$root.platform == "native"') - input(ng-model='filtering.pid', type='text', placeholder='{{"PID"|translate}}') + input(ng-model='filters.pid', type='text', placeholder='{{"PID"|translate}}') td(width='8%', ng-if='$root.platform == "native"') - input(ng-model='filtering.tid', type='text', placeholder='{{"TID"|translate}}') + input(ng-model='filters.tid', type='text', placeholder='{{"TID"|translate}}') //td(width='14%', ng-if='$root.platform == "native"') - input(ng-model='filtering.app', type='text', placeholder='{{"App"|translate}}') + input(ng-model='filters.app', type='text', placeholder='{{"App"|translate}}') td(width='14%', ng-if='$root.platform == "native"') - input(ng-model='filtering.tag', type='text', placeholder='{{"Tag"|translate}}') + input(ng-model='filters.tag', type='text', placeholder='{{"Tag"|translate}}') td(width='40%') - input(ng-model='filtering.message', type='text', placeholder='{{"Text"|translate}}') + input(ng-model='filters.message', type='text', placeholder='{{"Text"|translate}}') td(width='0') button(ng-click='clearTable()', ng-disabled='false', title='{{"Clear"|translate}}').btn.btn-xs.btn-danger-outline i.fa.fa-trash-o