grafana/public/app/core/directives/array_join.ts

30 lines
615 B
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
import coreModule from '../core_module';
export function arrayJoin() {
2017-12-20 05:33:33 -06:00
'use strict';
2015-09-11 14:04:02 -05:00
return {
2017-12-20 05:33:33 -06:00
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
function split_array(text) {
2017-12-20 05:33:33 -06:00
return (text || '').split(',');
}
function join_array(text) {
2015-09-11 14:04:02 -05:00
if (_.isArray(text)) {
2017-12-20 05:33:33 -06:00
return (text || '').join(',');
} else {
return text;
}
}
ngModel.$parsers.push(split_array);
ngModel.$formatters.push(join_array);
2017-12-20 05:33:33 -06:00
},
};
}
2017-12-20 05:33:33 -06:00
coreModule.directive('arrayJoin', arrayJoin);