-
Notifications
You must be signed in to change notification settings - Fork 90
Convert sort, filter, and toolbar modules directives to components #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @ngdoc directive | ||
* @name patternfly.filters.component:pfFilterFields | ||
* @restrict E | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe should this have a restrict E here to have the docs show the component correctly in the example code (instead of <ANY ... |
||
* @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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to refactor this as this component can't be used within Angular2 - will that be done in a separate PR so we can move this one forward? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is $postlink not supported in Angular2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been working on a separate PR to remove the $scope references, its a bit more work and I'd rather not try to address in this PR. @dtaylor113 $postLink is OK, it's the use of $scope that will be troublesome. |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the use of angular.extend to add functions to ctrl, I'm going to use that in my charts