Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 759c5b0

Browse files
committed
make load/save work with errors
1 parent 0dabf39 commit 759c5b0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

client/js/scanctrl.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function ScanCtrl($scope, ScanSvc) {
1212
var pending = 0;
1313
var selectedFile = 0;
1414
var codeMirror_index = 0;
15-
$scope.loadPossible = false;
16-
localforage.length(function(len) {
17-
$scope.loadPossible = (len == 3);
18-
});
1915

2016
$scope.run = function (source, filename) {
2117
//empty last scan
@@ -183,6 +179,9 @@ function ScanCtrl($scope, ScanSvc) {
183179
var serializedResults = JSON.stringify($scope.results, includedAttributes);
184180
localforage.setItem('results', serializedResults, function() { });
185181

182+
var serializedErrors = JSON.stringify($scope.errors);
183+
localforage.setItem('errors', serializedErrors, function() { });
184+
186185
var serializedInputFiles = $scope.inputFiles.map( function(el) { return {data: el.asText(), name: el.name }; });
187186
localforage.setItem("inputFiles", JSON.stringify(serializedInputFiles), function(r) { });
188187

@@ -195,15 +194,19 @@ function ScanCtrl($scope, ScanSvc) {
195194
};
196195

197196
//TODO loadstate isn't called anymore, need to make it work with new workflow
198-
$scope.loadState = function() {
199-
// restore results as is
197+
//TODO -> call loadState() around in main.js, line 36 (using the scanCtrlScope) and expose "reset" button in the UI.
198+
$scope.restoreState = function() {
199+
var apply = false;
200200
localforage.getItem('results', function (results_storage) {
201-
if(!results_storage){
202-
alert('No previous scan found.')
203-
}
204201
$scope.results = JSON.parse(results_storage);
205-
$scope.$apply();
202+
apply = true;
206203
});
204+
localforage.getItem('errors', function (errors_storage) {
205+
if (errors_storage) {
206+
$scope.errors = JSON.parse(errors_storage);
207+
apply = true;
208+
}
209+
});
207210
// restore files, by creating JSZip things :)
208211
localforage.getItem("inputFiles", function(inputFiles_storage) {
209212
// mimic behavior from handleFileUpload
@@ -223,8 +226,9 @@ function ScanCtrl($scope, ScanSvc) {
223226
document.getElementById("doScan_" + i).checked = checkboxes[i];
224227
}
225228
});
226-
$scope.$apply();
229+
apply = true;
227230
});
231+
if (apply) { $scope.$apply(); }
228232
};
229233

230234
$scope.selectAll = function () {

0 commit comments

Comments
 (0)