-
Notifications
You must be signed in to change notification settings - Fork 0
/
restoreState.js
61 lines (58 loc) · 2.12 KB
/
restoreState.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Required Node Packages
var async = require('async');
var minimongo = require('minimongo');
var IndexedDb = minimongo.IndexedDb;
/*
* Executes deleteRemovedSeries, storeSchemaFlag, createFolderHierarchyFlag
*/
var restoreState = function (cbRestoreState) {
new IndexedDb({namespace: 'mydb'}, function (db) { // eslint-disable-line no-new
db.addCollection('tciaSchema', function () {
async.parallel({
// Adds 'toRemove' class to seriesArray elements and deletes them
deleteRemovedSeries: function (callback) {
db.tciaSchema.findOne({'_id': 'removedSeries'}, {}, function (doc) {
if (doc && doc.seriesArray.length) {
async.each(doc.seriesArray, function (item, cbItem) {
$("[id='row_" + item + "']").addClass('toRemove');
cbItem();
}, function (err) { // eslint-disable-line handle-callback-err
dTable.rows('.toRemove').remove().draw();
callback(null, null);
});
} else {
callback(null, null);
}
});
},
// returns storeSchemaFlag if schemaExist
storeSchemaFlag: function (callback) {
db.tciaSchema.findOne({'_id': 'storeSchemaInfo'}, {}, function (schemaExist) {
if (!schemaExist) {
callback(null, 0);
} else {
callback(null, 1);
}
});
},
// returns createFolderHierarchyFlag if folderHierarchyExist
createFolderHierarchyFlag: function (callback) {
db.tciaSchema.findOne({'_id': 'createFolderHierarchyInfo'}, {}, function (folderHierarchyExist) {
if (!folderHierarchyExist) {
callback(null, 0);
} else {
callback(null, 1);
}
});
}
},
function (err, results) { // eslint-disable-line handle-callback-err
// results: {storeSchemaFlag: 0/1, createFolderHierarchyFlag: 0/1}
cbRestoreState(results);
});
}, function (err) {
console.log(err);
});
});
};
module.exports.restoreState = restoreState;