Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Restore filteredArray functionality #394

Merged
merged 1 commit into from
Apr 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions uw-frame-components/portal/widgets/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ define(['angular'], function(angular) {
}
};

/**
* Filter array for provided values of a given object -- used by some custom widgets (i.e. Leave Balances)
*
* @param {Array<Object>} array The array to filter
* @param {Object} object The array entry to search through
* @param {Array<String>} strings The string values to test against each entry
* @returns {Array<Object>} An array containing only the desired
*/
$scope.filteredArray = function(array, object, strings) {
$log.log('Filtering array for strings: ' + strings);
$log.log(array);
if (array && object && strings) {
var filteredArray = array.filter(function(entry) {
for (var i = 0; i < strings.length; i++) {
if (entry[object].indexOf(strings[i]) != -1) {
return true;
}
}
});
$log.log('Filtered array:');
$log.log(filteredArray);
return filteredArray;
} else {
return [];
}
};

/**
* Initialize scope variables before getting widget content
* @param template The provided custom HTML template
Expand Down