mirror of
https://github.com/ansible/awx.git
synced 2026-08-04 03:50:01 -02:30
Add truncate component
This commit is contained in:
43
awx/ui/client/lib/components/truncate/truncate.directive.js
Normal file
43
awx/ui/client/lib/components/truncate/truncate.directive.js
Normal file
@@ -0,0 +1,43 @@
|
||||
function atTruncateLink (scope, el, attr, ctrl) {
|
||||
let truncateController = ctrl;
|
||||
let string = attr.atTruncate;
|
||||
let maxlength = attr.maxlength;
|
||||
|
||||
truncateController.init(scope, string, maxlength);
|
||||
}
|
||||
|
||||
function AtTruncateController ($filter) {
|
||||
let vm = this;
|
||||
|
||||
let string,
|
||||
maxlength;
|
||||
|
||||
vm.init = (scope, _string_, _maxlength_) => {
|
||||
string = _string_;
|
||||
maxlength = _maxlength_;
|
||||
vm.truncatedString = $filter('limitTo')(string, maxlength, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function atTruncate($filter) {
|
||||
return {
|
||||
restrict: 'EA',
|
||||
replace: true,
|
||||
transclude: true,
|
||||
template: '<span>{{vm.truncatedString}}</span>',
|
||||
controller: AtTruncateController,
|
||||
controllerAs: 'vm',
|
||||
link: atTruncateLink,
|
||||
scope: {
|
||||
maxLength: '@'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
atTruncate.$inject = [
|
||||
'$filter'
|
||||
];
|
||||
|
||||
export default atTruncate;
|
||||
Reference in New Issue
Block a user