grafana/public/app/angular/array_join.ts

31 lines
663 B
TypeScript
Raw Normal View History

import { isArray } 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: (scope: any, element: any, attr: any, ngModel: any) => {
function split_array(text: string) {
2017-12-20 05:33:33 -06:00
return (text || '').split(',');
}
function join_array(text: string) {
if (isArray(text)) {
2019-04-15 05:11:52 -05:00
return ((text || '') as any).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);