Skip to content

Commit

Permalink
Added ability to export/import data
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Levin committed Apr 6, 2015
1 parent 3b4594b commit 01ffa6f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bu.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@
font-weight: bold;
color: red;
margin-right: 10px;
}
.rawData textarea {
margin-top: 20px;
width: 100%;
min-height: 300px;
}
1 change: 1 addition & 0 deletions bu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ buApp.config(['$routeProvider',
$routeProvider.when('/home', {templateUrl: 'views/home.html'}).
when('/exam1', {templateUrl: 'views/exam1.html'}).
when('/exam2/:level?', {templateUrl: 'views/exam2.html'}).
when('/rawdata', {templateUrl: 'views/raw-data.html'}).
otherwise({redirectTo: '/home'});
}
]);
Expand Down
15 changes: 15 additions & 0 deletions controllers/homeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,20 @@ buApp.controller('homeController', ['$scope', '$location', 'storage', 'shared',
if (idx >= 0)
$scope.diploma = diplomaTable[idx].name;
};
$scope.exportSelected = function () {
var exportData = [];
for (var i = 0; i < $scope.history.length; i++) {
var examData = $scope.history[i];
if ($scope.inSelection(examData.key)) {
exportData.push(examData);
}
}
shared.exportData = exportData;
$location.path('/rawdata');
};
$scope.goToImport = function () {
shared.exportData = null;
$location.path('/rawdata');
};
}]);

23 changes: 23 additions & 0 deletions controllers/rawDataController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
buApp.controller('rawDataController', ['$scope', '$location', 'storage', 'shared', function ($scope, $location, storage, shared) {
if (shared.exportData) {
$scope.rawdata = toJsonString(shared.exportData);
$scope.exporting = true;
}

$scope.importData = function () {
var data = fromJsonString($scope.rawdata);
if (!$.isArray(data)) {
alert("Invalid data");
return;
}
for (var i=0; i<data.length; i++) {
var examData = data[i];
if (!examData.key) {
alert("Invalid data");
return;
}
storage.store(examData);
}
$location.path('/');
};
}]);
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src="controllers/homeController.js"></script>
<script src="controllers/exam1Controller.js"></script>
<script src="controllers/exam2Controller.js"></script>
<script src="controllers/rawDataController.js"></script>
<link href="bu.css" rel="stylesheet"/>

</head>
Expand Down
6 changes: 4 additions & 2 deletions views/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ <h3>Billiard University</h3>
</div>
<h3>History</h3>
<div>
<a href="" ng-click="deleteSelected()" ng-show="history.length > 0">Clear</a>
<a href="" ng-click="deleteAll()" ng-show="history.length > 0">Clear All</a>
<button ng-click="deleteAll()" ng-show="history.length > 0">Clear All</button>
<button ng-click="deleteSelected()" ng-show="selection.length > 0">Clear</button>
<button ng-click="exportSelected()" ng-show="selection.length > 0">Export</button>
<button ng-click="goToImport()">Import</button>
</div>
<div style="margin-bottom: 10px">
Best combined score is {{bestScore}}
Expand Down
6 changes: 6 additions & 0 deletions views/raw-data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div ng-controller="rawDataController" class="rawData">
<h3>{{exporting ? 'Export' : 'Import'}} data</h3>
<button ng-show="!exporting" ng-click="importData()">Import</button>
<textarea ng-model="rawdata">
</textarea>
</div>

0 comments on commit 01ffa6f

Please sign in to comment.