refactor: moved array join directive to typecrtipt
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
export * from './directives/cool_dir'
|
||||
export * from './directives/array_join'
|
||||
export * from './routes/module_loader'
|
||||
export * from './filters/filters'
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import angular = require('angular');
|
||||
import _ = require('lodash');
|
||||
|
||||
export function ArrayJoin()
|
||||
{
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attr, ngModel) {
|
||||
|
||||
function split_array(text) {
|
||||
return (text || '').split(',');
|
||||
}
|
||||
|
||||
function join_array(text) {
|
||||
if(_.isArray(text)) {
|
||||
return (text || '').join(',');
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
ngModel.$parsers.push(split_array);
|
||||
ngModel.$formatters.push(join_array);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
angular.module('grafana.directives').directive('arrayJoin', ArrayJoin);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
export class CoolDir {
|
||||
getName() : string {
|
||||
return "CoolDir";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
define([
|
||||
'./arrayJoin',
|
||||
'./dashUpload',
|
||||
'./grafanaSimplePanel',
|
||||
'./dashEditLink',
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'app',
|
||||
'lodash'
|
||||
],
|
||||
function (angular, app, _) {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('grafana.directives')
|
||||
.directive('arrayJoin', function() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attr, ngModel) {
|
||||
|
||||
function split_array(text) {
|
||||
return (text || '').split(',');
|
||||
}
|
||||
|
||||
function join_array(text) {
|
||||
if(_.isArray(text)) {
|
||||
return (text || '').join(',');
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
ngModel.$parsers.push(split_array);
|
||||
ngModel.$formatters.push(join_array);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user