Skip to content
This repository was archived by the owner on Jun 16, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/controllers/TeamImportDialogControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
42 changes: 27 additions & 15 deletions src/js/controllers/TeamImportDialogController.js
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessarily complex: just make $scope.delimiter the tab character by default, and always split on $scope.delimiter then.

return line.split($scope.delimiter);
}
//split by tab character
return line.split(/\t/);
});
Expand All @@ -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 = '';
Expand All @@ -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 () {
Expand Down
29 changes: 17 additions & 12 deletions src/views/dialogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ <h1>
<input type="text" ng-model="importNameColumn" size="3">
({{importNameExample}})
</p>
<p>
Use custom delimiter? (Default is tab, the delimiter used when pasting from excel) <br/>
<input type="checkbox" ng-model="useCustomDelimiter">
<input type="text" ng-model="delimiter">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This box should be disabled if useCustomDelimiter is false.
Or, make it a radio-button with Tab (Excel) as first option, and Custom [input field] as second?

</p>

<table>
<tr ng-repeat="line in importLines">
Expand Down Expand Up @@ -186,20 +191,20 @@ <h1>
</button>
<p>
<a href="{{exportdata}}" download="{{exportname}}" ng-show="exportvisible"><i class="material-icons">file_download</i> Export naar USB</a>

<div ng-hide="true" id="scoreexport">
<style>
#bodyranking{
background-color:#DEDEDE;
background-color:#DEDEDE;
background-repeat:no-repeat;
}
#rankingtable{
#rankingtable{
font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
text-align:center;
width:95%;
margin-left:auto;
margin-left:auto;
margin-right:auto;

}
#scoreexport{
border:1px solid black;
Expand All @@ -219,7 +224,7 @@ <h1>
color:white;
font-size:x-large;
white-space:nowrap;

}
.top{
background-color:silver;
Expand All @@ -229,7 +234,7 @@ <h1>
background-color:rgba(255, 255, 255, 0.8);

}
.out{
.out{
opacity: 0;
-webkit-transition: opacity 2s ease-in;
-moz-transition: opacity 2s ease-in;
Expand All @@ -246,24 +251,24 @@ <h1>
FLOWAMOUNT = angular.element(document.querySelector('[ng-controller="rankingCtrl"]')).scope().export.flowAmount;
// The amount of scores always visible at top
FIXEDSHOWNTOP = angular.element(document.querySelector('[ng-controller="rankingCtrl"]')).scope().export.fixedShownTop;
// Amount of seconds that the first page shows
// Amount of seconds that the first page shows
TIMEFORFRAME1 = angular.element(document.querySelector('[ng-controller="rankingCtrl"]')).scope().export.timeForFrame1;
// Amount of seconds that each scroll takes
// Amount of seconds that each scroll takes
TIMETHROUGHFRAMES = angular.element(document.querySelector('[ng-controller="rankingCtrl"]')).scope().export.timeThroughFrames;
// Amount of scores that move away and appear
FADEATONEGO = angular.element(document.querySelector('[ng-controller="rankingCtrl"]')).scope().export.fadeAtOneGo;

for(var p = 0 ; p <= FIXEDSHOWNTOP -1 ; p++){
document.getElementById('trrow'+p).className = 'top';

}
for(var q = FIXEDSHOWNTOP ; q <= TOTALAMOUNT -1 ; q++){
document.getElementById('trrow'+q).className = 'all';

}
for(var x = FLOWAMOUNT; x<(TOTALAMOUNT);x++){
document.getElementById('trrow'+x).style.visibility = 'hidden';
}
}
//alert(amount);
setTimeout(gotoNext,(TIMEFORFRAME1*1000));
}
Expand Down