mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-1138: Remove wrapper-specific filter code. Make FilterPattern, etc. generic.
This commit is contained in:
		| @@ -48,12 +48,21 @@ angular.module('list').directive('guacFilter', [function guacFilter() { | ||||
|             placeholder : '&', | ||||
|  | ||||
|             /** | ||||
|              * An array objects to filter. A subset of this array will be | ||||
|              * An array of objects to filter. A subset of this array will be | ||||
|              * exposed as filteredItems. | ||||
|              * | ||||
|              * @type Array | ||||
|              */ | ||||
|             items : '&' | ||||
|             items : '&', | ||||
|  | ||||
|             /** | ||||
|              * An array of expressions to filter against for each object in the | ||||
|              * items array. These expressions must be Angular expressions | ||||
|              * which resolve to properties on the objects in the items array. | ||||
|              * | ||||
|              * @type String[] | ||||
|              */ | ||||
|             properties : '&' | ||||
|  | ||||
|         }, | ||||
|  | ||||
| @@ -68,7 +77,7 @@ angular.module('list').directive('guacFilter', [function guacFilter() { | ||||
|              * | ||||
|              * @type FilterPattern | ||||
|              */ | ||||
|             var filterPattern = new FilterPattern(); | ||||
|             var filterPattern = new FilterPattern($scope.properties()); | ||||
|  | ||||
|             /** | ||||
|              * The filter search string to use to restrict the displayed items. | ||||
|   | ||||
| @@ -23,8 +23,8 @@ | ||||
| /** | ||||
|  * A service for defining the FilterPattern class. | ||||
|  */ | ||||
| angular.module('list').factory('FilterPattern', [ | ||||
|     function defineFilterPattern() { | ||||
| angular.module('list').factory('FilterPattern', ['$parse', | ||||
|     function defineFilterPattern($parse) { | ||||
|  | ||||
|     /** | ||||
|      * Object which handles compilation of filtering predicates as used by | ||||
| @@ -32,8 +32,10 @@ angular.module('list').factory('FilterPattern', [ | ||||
|      * specified search string. | ||||
|      * | ||||
|      * @constructor | ||||
|      * @param {String[]} expressions  | ||||
|      *     The Angular expressions whose values are to be filtered. | ||||
|      */ | ||||
|     var FilterPattern = function FilterPattern() { | ||||
|     var FilterPattern = function FilterPattern(expressions) { | ||||
|  | ||||
|         /** | ||||
|          * Reference to this instance. | ||||
| @@ -53,6 +55,20 @@ angular.module('list').factory('FilterPattern', [ | ||||
|             return true; | ||||
|         }; | ||||
|  | ||||
|         /** | ||||
|          * Array of getters corresponding to the Angular expressions provided | ||||
|          * to the constructor of this class. The functions returns are those | ||||
|          * produced by the $parse service. | ||||
|          * | ||||
|          * @type Function[] | ||||
|          */ | ||||
|         var getters = []; | ||||
|  | ||||
|         // Parse all expressions | ||||
|         angular.forEach(expressions, function parseExpression(expression) { | ||||
|             getters.push($parse(expression)); | ||||
|         }); | ||||
|  | ||||
|         /** | ||||
|          * The current filtering predicate. | ||||
|          * | ||||
| @@ -79,22 +95,24 @@ angular.module('list').factory('FilterPattern', [ | ||||
|             // Convert to lower case for case insensitive matching             | ||||
|             pattern = pattern.toLowerCase(); | ||||
|  | ||||
|             // TODONT: Return predicate specific to a type of object this class should know nothing about | ||||
|             filterPattern.predicate = function oddlySpecificPredicate(wrapper) { | ||||
|             // Return predicate which matches against the value of any getter in the getters array | ||||
|             filterPattern.predicate = function matchAny(object) { | ||||
|  | ||||
|                 // Check to see if the search string matches the connection name | ||||
|                 if (wrapper.name.toLowerCase().indexOf(pattern) !== -1)  | ||||
|                     return true; | ||||
|                 // For each defined getter | ||||
|                 for (var i=0; i < getters.length; i++) { | ||||
|  | ||||
|                 // Check to see if the search string matches the username | ||||
|                 if (wrapper.activeConnection.username.toLowerCase().indexOf(pattern) !== -1)  | ||||
|                     return true; | ||||
|                     // Retrieve value of current getter | ||||
|                     var value = getters[i](object); | ||||
|  | ||||
|                 // Check to see if the search string matches the remote host | ||||
|                 if (wrapper.activeConnection.remoteHost.toLowerCase().indexOf(pattern) !== -1)  | ||||
|                     return true; | ||||
|                     // If the value matches the pattern, the whole object matches | ||||
|                     if (String(value).toLowerCase().indexOf(pattern) !== -1)  | ||||
|                         return true; | ||||
|  | ||||
|                 } | ||||
|  | ||||
|                 // No matches found | ||||
|                 return false; | ||||
|  | ||||
|             }; | ||||
|              | ||||
|         }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user