-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert sort, filter, and toolbar modules directives to components (#376
) * Change version of angular-bootstrap to 2.2.x Downgrading a bit to avoid issue with 2.3.0: angular-ui/bootstrap#6364 * Convert sort, filter, and toolbar modules directives to components * Add restrict E to ng-docs, enforce single select on toolbar filtering.
- Loading branch information
1 parent
629ecea
commit 72945a7
Showing
19 changed files
with
486 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
angular.module('patternfly.filters').component('pfFilter', { | ||
bindings: { | ||
config: '=' | ||
}, | ||
templateUrl: 'filters/filter.html', | ||
controller: function () { | ||
'use strict'; | ||
|
||
var ctrl = this; | ||
|
||
ctrl.$onInit = function () { | ||
|
||
angular.extend(ctrl, | ||
{ | ||
addFilter: addFilter | ||
} | ||
); | ||
}; | ||
|
||
function filterExists (filter) { | ||
var foundFilter = _.find(ctrl.config.appliedFilters, {title: filter.title, value: filter.value}); | ||
return foundFilter !== undefined; | ||
} | ||
|
||
function enforceSingleSelect (filter) { | ||
_.remove(ctrl.config.appliedFilters, {title: filter.title}); | ||
} | ||
|
||
function addFilter (field, value) { | ||
var newFilter = { | ||
id: field.id, | ||
title: field.title, | ||
type: field.filterType, | ||
value: value | ||
}; | ||
if (!filterExists(newFilter)) { | ||
|
||
if (newFilter.type === 'select') { | ||
enforceSingleSelect(newFilter); | ||
} | ||
|
||
ctrl.config.appliedFilters.push(newFilter); | ||
|
||
if (ctrl.config.onFilterChange) { | ||
ctrl.config.onFilterChange(ctrl.config.appliedFilters); | ||
} | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @ngdoc directive | ||
* @name patternfly.filters.component:pfFilterFields | ||
* @restrict E | ||
* | ||
* @description | ||
* Directive for the filter bar's filter entry components | ||
* <br><br> | ||
* | ||
* @param {object} config configuration settings for the filters:<br/> | ||
* <ul style='list-style-type: none'> | ||
* <li>.fields - (Array) List of filterable fields containing: | ||
* <ul style='list-style-type: none'> | ||
* <li>.id - (String) Optional unique Id for the filter field, useful for comparisons | ||
* <li>.title - (String) The title to display for the filter field | ||
* <li>.placeholder - (String) Text to display when no filter value has been entered | ||
* <li>.filterType - (String) The filter input field type (any html input type, or 'select' for a select box) | ||
* <li>.filterValues - (Array) List of valid select values used when filterType is 'select' | ||
* </ul> | ||
* <li>.appliedFilters - (Array) List of the currently applied filters | ||
* </ul> | ||
* | ||
*/ | ||
angular.module('patternfly.filters').component('pfFilterFields', { | ||
bindings: { | ||
config: '=', | ||
addFilterFn: '<' | ||
}, | ||
templateUrl: 'filters/filter-fields.html', | ||
controller: function ($scope) { | ||
'use strict'; | ||
|
||
var ctrl = this; | ||
|
||
ctrl.$onInit = function () { | ||
angular.extend(ctrl, { | ||
selectField: selectField, | ||
selectValue: selectValue, | ||
onValueKeyPress: onValueKeyPress | ||
}); | ||
}; | ||
|
||
ctrl.$postLink = function () { | ||
$scope.$watch('config', function () { | ||
setupConfig(); | ||
}, true); | ||
}; | ||
|
||
function selectField (item) { | ||
ctrl.currentField = item; | ||
ctrl.config.currentValue = null; | ||
} | ||
|
||
function selectValue (filterValue) { | ||
if (angular.isDefined(filterValue)) { | ||
ctrl.addFilterFn(scope.currentField, filterValue); | ||
ctrl.config.currentValue = null; | ||
} | ||
} | ||
|
||
function onValueKeyPress (keyEvent) { | ||
if (keyEvent.which === 13) { | ||
ctrl.addFilterFn(ctrl.currentField, ctrl.config.currentValue); | ||
ctrl.config.currentValue = undefined; | ||
} | ||
} | ||
|
||
function setupConfig () { | ||
if (ctrl.fields === undefined) { | ||
ctrl.fields = []; | ||
} | ||
if (!ctrl.currentField) { | ||
ctrl.currentField = ctrl.config.fields[0]; | ||
ctrl.config.currentValue = null; | ||
} | ||
|
||
if (ctrl.config.currentValue === undefined) { | ||
ctrl.config.currentValue = null; | ||
} | ||
} | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.