sync wip
This commit is contained in:
@@ -207,8 +207,9 @@ angular.module('app.frontend')
|
|||||||
|
|
||||||
var original = this.note.presentation_name;
|
var original = this.note.presentation_name;
|
||||||
this.note.presentation_name = this.url.token;
|
this.note.presentation_name = this.url.token;
|
||||||
|
modelManager.addDirtyItems([this.note]);
|
||||||
|
|
||||||
apiController.saveItems([this.note], function(response){
|
apiController.sync(function(response){
|
||||||
if(!response) {
|
if(!response) {
|
||||||
this.note.presentation_name = original;
|
this.note.presentation_name = original;
|
||||||
this.url.token = original;
|
this.url.token = original;
|
||||||
|
|||||||
@@ -74,9 +74,7 @@ angular.module('app.frontend')
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.refreshData = function() {
|
this.refreshData = function() {
|
||||||
apiController.refreshItems(function(items){
|
apiController.sync(null);
|
||||||
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loginSubmitPressed = function() {
|
this.loginSubmitPressed = function() {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ angular.module('app.frontend')
|
|||||||
$scope.tags = modelManager.tags;
|
$scope.tags = modelManager.tags;
|
||||||
$scope.allTag.notes = modelManager.notes;
|
$scope.allTag.notes = modelManager.notes;
|
||||||
|
|
||||||
// setInterval(function () {
|
setInterval(function () {
|
||||||
// apiController.refreshItems(null);
|
apiController.sync(null);
|
||||||
// }, 1000);
|
}, 1000);
|
||||||
|
|
||||||
// apiController.verifyEncryptionStatusOfAllItems($scope.defaultUser, function(success){});
|
// apiController.verifyEncryptionStatusOfAllItems($scope.defaultUser, function(success){});
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,8 @@ angular.module('app.frontend')
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.tagsSave = function(tag, callback) {
|
$scope.tagsSave = function(tag, callback) {
|
||||||
apiController.saveItems([tag], callback);
|
modelManager.addDirtyItems([tag]);
|
||||||
|
apiController.sync(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -65,7 +66,7 @@ angular.module('app.frontend')
|
|||||||
modelManager.addTagToNote(newTag, originalNote);
|
modelManager.addTagToNote(newTag, originalNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
apiController.saveDirtyItems(function(){});
|
apiController.sync(function(){});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -109,7 +110,7 @@ angular.module('app.frontend')
|
|||||||
$scope.saveNote = function(note, callback) {
|
$scope.saveNote = function(note, callback) {
|
||||||
modelManager.addDirtyItems(note);
|
modelManager.addDirtyItems(note);
|
||||||
|
|
||||||
apiController.saveDirtyItems(function(){
|
apiController.sync(function(){
|
||||||
note.hasChanges = false;
|
note.hasChanges = false;
|
||||||
|
|
||||||
if(callback) {
|
if(callback) {
|
||||||
@@ -133,7 +134,7 @@ angular.module('app.frontend')
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiController.deleteItem(note, function(success){})
|
apiController.deleteItem(note, function(success){})
|
||||||
apiController.saveDirtyItems(function(){});
|
apiController.sync(function(){});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -223,47 +223,31 @@ angular.module('app.frontend')
|
|||||||
Items
|
Items
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.saveDirtyItems = function(callback) {
|
this.sync = function(callback) {
|
||||||
var dirtyItems = modelManager.dirtyItems;
|
|
||||||
if(dirtyItems.length == 0) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.saveItems(dirtyItems, function(response){
|
|
||||||
modelManager.clearDirtyItems();
|
|
||||||
callback();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.refreshItems = function(callback) {
|
|
||||||
var request = Restangular.one("users", this.user.uuid).one("items");
|
|
||||||
request.get(this.lastRefreshDate ? {"updated_after" : this.lastRefreshDate.toString()} : {})
|
|
||||||
.then(function(response){
|
|
||||||
this.lastRefreshDate = new Date();
|
|
||||||
var items = this.handleItemsResponse(response.items, null);
|
|
||||||
callback(items);
|
|
||||||
}.bind(this))
|
|
||||||
.catch(function(response) {
|
|
||||||
callback(response.data);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.saveItems = function(items, callback) {
|
|
||||||
if(!this.user.uuid) {
|
if(!this.user.uuid) {
|
||||||
this.writeItemsToLocalStorage();
|
this.writeItemsToLocalStorage();
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var request = Restangular.one("users", this.user.uuid).one("items");
|
|
||||||
request.items = _.map(items, function(item){
|
var dirtyItems = modelManager.dirtyItems;
|
||||||
|
var request = Restangular.one("users", this.user.uuid).one("items/sync");
|
||||||
|
request.items = _.map(dirtyItems, function(item){
|
||||||
return this.createRequestParamsForItem(item);
|
return this.createRequestParamsForItem(item);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
if(this.lastRefreshDate) {
|
||||||
|
request.updated_after = this.lastRefreshDate.toString();
|
||||||
|
}
|
||||||
|
|
||||||
request.post().then(function(response) {
|
request.post().then(function(response) {
|
||||||
var omitFields = ["content", "enc_item_key", "auth_hash"];
|
modelManager.clearDirtyItems();
|
||||||
this.handleItemsResponse(response.items, omitFields);
|
var lastUpdated = new Date(response.last_updated);
|
||||||
callback(response);
|
this.lastRefreshDate = lastUpdated;
|
||||||
|
this.handleItemsResponse(response.retrieved_items, null);
|
||||||
|
if(callback) {
|
||||||
|
callback(response);
|
||||||
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +312,8 @@ angular.module('app.frontend')
|
|||||||
var shareFn = function() {
|
var shareFn = function() {
|
||||||
item.presentation_name = "_auto_";
|
item.presentation_name = "_auto_";
|
||||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||||
this.saveItems(needsUpdate, function(success){})
|
modelManager.addDirtyItems(needsUpdate);
|
||||||
|
this.sync();
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
if(!this.user.username) {
|
if(!this.user.username) {
|
||||||
@@ -352,7 +337,8 @@ angular.module('app.frontend')
|
|||||||
this.unshareItem = function(item, callback) {
|
this.unshareItem = function(item, callback) {
|
||||||
item.presentation_name = null;
|
item.presentation_name = null;
|
||||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||||
this.saveItems(needsUpdate, function(success){})
|
modelManager.addDirtyItems(needsUpdate);
|
||||||
|
this.sync(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -364,9 +350,8 @@ angular.module('app.frontend')
|
|||||||
var customModelManager = new ModelManager();
|
var customModelManager = new ModelManager();
|
||||||
customModelManager.mapResponseItemsToLocalModels(data.items);
|
customModelManager.mapResponseItemsToLocalModels(data.items);
|
||||||
console.log("Importing data", JSON.parse(jsonString));
|
console.log("Importing data", JSON.parse(jsonString));
|
||||||
this.saveItems(customModelManager.items, function(response){
|
modelManager.addDirtyItems(customModelManager.items);
|
||||||
callback(response);
|
this.sync(callback);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
77
vendor/assets/javascripts/transpiled.js
vendored
77
vendor/assets/javascripts/transpiled.js
vendored
@@ -641,8 +641,9 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
|
|
||||||
var original = this.note.presentation_name;
|
var original = this.note.presentation_name;
|
||||||
this.note.presentation_name = this.url.token;
|
this.note.presentation_name = this.url.token;
|
||||||
|
modelManager.addDirtyItems([this.note]);
|
||||||
|
|
||||||
apiController.saveItems([this.note], function (response) {
|
apiController.sync(function (response) {
|
||||||
if (!response) {
|
if (!response) {
|
||||||
this.note.presentation_name = original;
|
this.note.presentation_name = original;
|
||||||
this.url.token = original;
|
this.url.token = original;
|
||||||
@@ -765,7 +766,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.refreshData = function () {
|
this.refreshData = function () {
|
||||||
apiController.refreshItems(function (items) {});
|
apiController.sync(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.loginSubmitPressed = function () {
|
this.loginSubmitPressed = function () {
|
||||||
@@ -871,9 +872,9 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
$scope.tags = modelManager.tags;
|
$scope.tags = modelManager.tags;
|
||||||
$scope.allTag.notes = modelManager.notes;
|
$scope.allTag.notes = modelManager.notes;
|
||||||
|
|
||||||
// setInterval(function () {
|
setInterval(function () {
|
||||||
// apiController.refreshItems(null);
|
apiController.sync(null);
|
||||||
// }, 1000);
|
}, 1000);
|
||||||
|
|
||||||
// apiController.verifyEncryptionStatusOfAllItems($scope.defaultUser, function(success){});
|
// apiController.verifyEncryptionStatusOfAllItems($scope.defaultUser, function(success){});
|
||||||
};
|
};
|
||||||
@@ -913,7 +914,8 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.tagsSave = function (tag, callback) {
|
$scope.tagsSave = function (tag, callback) {
|
||||||
apiController.saveItems([tag], callback);
|
modelManager.addDirtyItems([tag]);
|
||||||
|
apiController.sync(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -927,7 +929,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
modelManager.addTagToNote(newTag, originalNote);
|
modelManager.addTagToNote(newTag, originalNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
apiController.saveDirtyItems(function () {});
|
apiController.sync(function () {});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -971,7 +973,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
$scope.saveNote = function (note, callback) {
|
$scope.saveNote = function (note, callback) {
|
||||||
modelManager.addDirtyItems(note);
|
modelManager.addDirtyItems(note);
|
||||||
|
|
||||||
apiController.saveDirtyItems(function () {
|
apiController.sync(function () {
|
||||||
note.hasChanges = false;
|
note.hasChanges = false;
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@@ -995,7 +997,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiController.deleteItem(note, function (success) {});
|
apiController.deleteItem(note, function (success) {});
|
||||||
apiController.saveDirtyItems(function () {});
|
apiController.sync(function () {});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1742,45 +1744,31 @@ var User = function User(json_obj) {
|
|||||||
Items
|
Items
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.saveDirtyItems = function (callback) {
|
this.sync = function (callback) {
|
||||||
var dirtyItems = modelManager.dirtyItems;
|
|
||||||
if (dirtyItems.length == 0) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.saveItems(dirtyItems, function (response) {
|
|
||||||
modelManager.clearDirtyItems();
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
this.refreshItems = function (callback) {
|
|
||||||
var request = Restangular.one("users", this.user.uuid).one("items");
|
|
||||||
request.get(this.lastRefreshDate ? { "updated_after": this.lastRefreshDate.toString() } : {}).then(function (response) {
|
|
||||||
this.lastRefreshDate = new Date();
|
|
||||||
var items = this.handleItemsResponse(response.items, null);
|
|
||||||
callback(items);
|
|
||||||
}.bind(this)).catch(function (response) {
|
|
||||||
callback(response.data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
this.saveItems = function (items, callback) {
|
|
||||||
if (!this.user.uuid) {
|
if (!this.user.uuid) {
|
||||||
this.writeItemsToLocalStorage();
|
this.writeItemsToLocalStorage();
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var request = Restangular.one("users", this.user.uuid).one("items");
|
|
||||||
request.items = _.map(items, function (item) {
|
var dirtyItems = modelManager.dirtyItems;
|
||||||
|
var request = Restangular.one("users", this.user.uuid).one("items/sync");
|
||||||
|
request.items = _.map(dirtyItems, function (item) {
|
||||||
return this.createRequestParamsForItem(item);
|
return this.createRequestParamsForItem(item);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
if (this.lastRefreshDate) {
|
||||||
|
request.updated_after = this.lastRefreshDate.toString();
|
||||||
|
}
|
||||||
|
|
||||||
request.post().then(function (response) {
|
request.post().then(function (response) {
|
||||||
var omitFields = ["content", "enc_item_key", "auth_hash"];
|
modelManager.clearDirtyItems();
|
||||||
this.handleItemsResponse(response.items, omitFields);
|
var lastUpdated = new Date(response.last_updated);
|
||||||
callback(response);
|
this.lastRefreshDate = lastUpdated;
|
||||||
|
this.handleItemsResponse(response.retrieved_items, null);
|
||||||
|
if (callback) {
|
||||||
|
callback(response);
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1842,7 +1830,8 @@ var User = function User(json_obj) {
|
|||||||
var shareFn = function () {
|
var shareFn = function () {
|
||||||
item.presentation_name = "_auto_";
|
item.presentation_name = "_auto_";
|
||||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||||
this.saveItems(needsUpdate, function (success) {});
|
modelManager.addDirtyItems(needsUpdate);
|
||||||
|
this.sync();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
if (!this.user.username) {
|
if (!this.user.username) {
|
||||||
@@ -1868,7 +1857,8 @@ var User = function User(json_obj) {
|
|||||||
this.unshareItem = function (item, callback) {
|
this.unshareItem = function (item, callback) {
|
||||||
item.presentation_name = null;
|
item.presentation_name = null;
|
||||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||||
this.saveItems(needsUpdate, function (success) {});
|
modelManager.addDirtyItems(needsUpdate);
|
||||||
|
this.sync(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1880,9 +1870,8 @@ var User = function User(json_obj) {
|
|||||||
var customModelManager = new ModelManager();
|
var customModelManager = new ModelManager();
|
||||||
customModelManager.mapResponseItemsToLocalModels(data.items);
|
customModelManager.mapResponseItemsToLocalModels(data.items);
|
||||||
console.log("Importing data", JSON.parse(jsonString));
|
console.log("Importing data", JSON.parse(jsonString));
|
||||||
this.saveItems(customModelManager.items, function (response) {
|
modelManager.addDirtyItems(customModelManager.items);
|
||||||
callback(response);
|
this.sync(callback);
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
2
vendor/assets/javascripts/transpiled.js.map
vendored
2
vendor/assets/javascripts/transpiled.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user