diff --git a/spec/controllers/TeamImportDialogControllerSpec.js b/spec/controllers/TeamImportDialogControllerSpec.js index 4806f9ec..b2387bfc 100644 --- a/spec/controllers/TeamImportDialogControllerSpec.js +++ b/spec/controllers/TeamImportDialogControllerSpec.js @@ -53,6 +53,20 @@ describe('TeamImportDialogController',function() { expect($scope.importNumberExample).toEqual(''); expect($scope.importNameExample).toEqual(''); }); + + it('should correctly populate importLines when using a custom delimiter', function () { + $scope.importLines = []; + $scope.useCustomDelimiter = true; + $scope.delimiter = ","; + $scope.importRaw = "42,FooBar\n7,QuxMoo"; + $scope.$digest(); + expect($scope.importLines).toEqual([ + ['42','FooBar'], + ['7','QuxMoo'] + ]); + expect($scope.importNumberExample).toEqual('42'); + expect($scope.importNameExample).toEqual('FooBar'); + }) }); describe('handshake receive',function() { diff --git a/src/js/controllers/TeamImportDialogController.js b/src/js/controllers/TeamImportDialogController.js index e8e1c08a..ab08679a 100644 --- a/src/js/controllers/TeamImportDialogController.js +++ b/src/js/controllers/TeamImportDialogController.js @@ -1,21 +1,24 @@ -define('controllers/TeamImportDialogController',[ +define('controllers/TeamImportDialogController', [ 'services/ng-handshake', 'angular' -], function() { +], function () { var moduleName = 'TeamImportDialog'; - return angular.module(moduleName, []).controller('TeamImportDialogController',[ + return angular.module(moduleName, []).controller('TeamImportDialogController', [ '$scope', '$handshake', function ($scope, $handshake) { var defer; function parseData(data) { //parse raw import, split lines - var lines = data?data.split(/[\n\r]/):[]; + var lines = data ? data.split(/[\n\r]/) : []; if ($scope.importHeader) { lines.shift(); } - lines = lines.map(function(line) { + lines = lines.map(function (line) { + if ($scope.useCustomDelimiter) { + return line.split($scope.delimiter); + } //split by tab character return line.split(/\t/); }); @@ -24,8 +27,8 @@ define('controllers/TeamImportDialogController',[ $scope.importNameColumn = 2; if (lines[0]) { - $scope.importNumberExample = lines[0][$scope.importNumberColumn -1]; - $scope.importNameExample = lines[0][$scope.importNameColumn -1]; + $scope.importNumberExample = lines[0][$scope.importNumberColumn - 1]; + $scope.importNameExample = lines[0][$scope.importNameColumn - 1]; } else { $scope.importNumberExample = ''; $scope.importNameExample = ''; @@ -34,29 +37,38 @@ define('controllers/TeamImportDialogController',[ $scope.importLines = lines; } - $scope.$watch('importRaw',function(data) { + $scope.$watch('importRaw', function (data) { parseData($scope.importRaw); }); - $scope.$watch('importHeader',function(data) { + $scope.$watch('importHeader', function (data) { parseData($scope.importRaw); }); - $handshake.$on('importTeams',function(e) { + $scope.$watch('useCustomDelimiter', function (data) { + parseData($scope.importRaw) + }); + + $scope.$watch('delimiter', function (data) { + parseData($scope.importRaw) + }); + + + $handshake.$on('importTeams', function (e) { $scope.dialogVisible = true; defer = $handshake.defer(); return defer.promise; }); - $scope.ok = function() { + $scope.ok = function () { $scope.dialogVisible = false; - var teams = $scope.importLines.map(function(line) { + var teams = $scope.importLines.map(function (line) { return { - number: line[$scope.importNumberColumn -1], - name: line[$scope.importNameColumn -1] + number: line[$scope.importNumberColumn - 1], + name: line[$scope.importNameColumn - 1] }; }); - defer.resolve({teams:teams}); + defer.resolve({teams: teams}); }; $scope.cancel = function () { diff --git a/src/views/dialogs.html b/src/views/dialogs.html index b3e34e47..8ff39dc4 100644 --- a/src/views/dialogs.html +++ b/src/views/dialogs.html @@ -29,6 +29,11 @@

({{importNameExample}})

+

+ Use custom delimiter? (Default is tab, the delimiter used when pasting from excel)
+ + +

@@ -186,20 +191,20 @@

file_download Export naar USB - +