arrayJoin.js 713 B

1234567891011121314151617181920212223242526272829303132333435
  1. define([
  2. 'angular',
  3. 'app',
  4. 'lodash'
  5. ],
  6. function (angular, app, _) {
  7. 'use strict';
  8. angular
  9. .module('grafana.directives')
  10. .directive('arrayJoin', function() {
  11. return {
  12. restrict: 'A',
  13. require: 'ngModel',
  14. link: function(scope, element, attr, ngModel) {
  15. function split_array(text) {
  16. return (text || '').split(',');
  17. }
  18. function join_array(text) {
  19. if(_.isArray(text)) {
  20. return (text || '').join(',');
  21. } else {
  22. return text;
  23. }
  24. }
  25. ngModel.$parsers.push(split_array);
  26. ngModel.$formatters.push(join_array);
  27. }
  28. };
  29. });
  30. });