import fix

This commit is contained in:
Mo Bitar
2016-12-30 12:59:45 -06:00
parent 68df05c159
commit 25b5ce16aa
3 changed files with 29 additions and 27 deletions

View File

@@ -92,7 +92,6 @@ angular.module('app.frontend')
Neeto.crypto.computeEncryptionKeysForUser(_.merge({email: email, password: password}, authParams), function(keys){ Neeto.crypto.computeEncryptionKeysForUser(_.merge({email: email, password: password}, authParams), function(keys){
this.setMk(keys.mk); this.setMk(keys.mk);
var request = Restangular.one("auth/sign_in"); var request = Restangular.one("auth/sign_in");
console.log("sending pw", keys.pw);
var params = {password: keys.pw, email: email}; var params = {password: keys.pw, email: email};
_.merge(request, params); _.merge(request, params);
request.post().then(function(response){ request.post().then(function(response){
@@ -100,7 +99,6 @@ angular.module('app.frontend')
callback(response); callback(response);
}) })
.catch(function(response){ .catch(function(response){
console.log(response.data);
callback(response.data); callback(response.data);
}) })
}.bind(this)); }.bind(this));
@@ -119,7 +117,6 @@ angular.module('app.frontend')
callback(response); callback(response);
}) })
.catch(function(response){ .catch(function(response){
console.log(response.data);
callback(response.data); callback(response.data);
}) })
}.bind(this)); }.bind(this));
@@ -219,7 +216,7 @@ angular.module('app.frontend')
Items Items
*/ */
this.sync = function(callback) { this.syncWithOptions = function(callback, options = {}) {
if(!this.user.uuid) { if(!this.user.uuid) {
this.writeItemsToLocalStorage(); this.writeItemsToLocalStorage();
callback(); callback();
@@ -229,7 +226,7 @@ angular.module('app.frontend')
var dirtyItems = modelManager.dirtyItems; var dirtyItems = modelManager.dirtyItems;
var request = Restangular.one("items/sync"); var request = Restangular.one("items/sync");
request.items = _.map(dirtyItems, function(item){ request.items = _.map(dirtyItems, function(item){
return this.createRequestParamsForItem(item); return this.createRequestParamsForItem(item, options.additionalFields);
}.bind(this)); }.bind(this));
if(this.syncToken) { if(this.syncToken) {
@@ -253,13 +250,17 @@ angular.module('app.frontend')
}) })
} }
this.sync = function(callback) {
this.syncWithOptions(callback, undefined);
}
this.handleItemsResponse = function(responseItems, omitFields) { this.handleItemsResponse = function(responseItems, omitFields) {
this.decryptItems(responseItems); this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields); return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
} }
this.createRequestParamsForItem = function(item) { this.createRequestParamsForItem = function(item, additionalFields) {
return this.paramsForItem(item, !item.isPublic(), null, false); return this.paramsForItem(item, !item.isPublic(), additionalFields, false);
} }
this.paramsForItem = function(item, encrypted, additionalFields, forExportFile) { this.paramsForItem = function(item, encrypted, additionalFields, forExportFile) {
@@ -295,7 +296,6 @@ angular.module('app.frontend')
this.deleteItem = function(item, callback) { this.deleteItem = function(item, callback) {
item.deleted = true; item.deleted = true;
console.log("adding dirty item", item);
modelManager.addDirtyItems([item]); modelManager.addDirtyItems([item]);
this.sync(callback); this.sync(callback);
} }
@@ -344,11 +344,11 @@ angular.module('app.frontend')
this.importJSONData = function(jsonString, callback) { this.importJSONData = function(jsonString, callback) {
var data = JSON.parse(jsonString); var data = JSON.parse(jsonString);
var customModelManager = new ModelManager(); // var customModelManager = new ModelManager();
customModelManager.mapResponseItemsToLocalModels(data.items); modelManager.mapResponseItemsToLocalModels(data.items);
console.log("Importing data", JSON.parse(jsonString)); console.log("Importing data", JSON.parse(jsonString));
modelManager.addDirtyItems(customModelManager.items); modelManager.addDirtyItems(modelManager.items);
this.sync(callback); this.syncWithOptions(callback, {additionalFields: ["created_at", "updated_at"]});
} }
/* /*
@@ -373,7 +373,7 @@ angular.module('app.frontend')
}.bind(this); }.bind(this);
var items = _.map(modelManager.items, function(item){ var items = _.map(modelManager.items, function(item){
return this.paramsForItem(item, false, ["created_at", "updated_at"], true) return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]);
}.bind(this)); }.bind(this));
var data = { var data = {

View File

@@ -1626,14 +1626,12 @@ var User = function User(json_obj) {
Neeto.crypto.computeEncryptionKeysForUser(_.merge({ email: email, password: password }, authParams), function (keys) { Neeto.crypto.computeEncryptionKeysForUser(_.merge({ email: email, password: password }, authParams), function (keys) {
this.setMk(keys.mk); this.setMk(keys.mk);
var request = Restangular.one("auth/sign_in"); var request = Restangular.one("auth/sign_in");
console.log("sending pw", keys.pw);
var params = { password: keys.pw, email: email }; var params = { password: keys.pw, email: email };
_.merge(request, params); _.merge(request, params);
request.post().then(function (response) { request.post().then(function (response) {
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
callback(response); callback(response);
}).catch(function (response) { }).catch(function (response) {
console.log(response.data);
callback(response.data); callback(response.data);
}); });
}.bind(this)); }.bind(this));
@@ -1651,7 +1649,6 @@ var User = function User(json_obj) {
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
callback(response); callback(response);
}).catch(function (response) { }).catch(function (response) {
console.log(response.data);
callback(response.data); callback(response.data);
}); });
}.bind(this)); }.bind(this));
@@ -1748,7 +1745,9 @@ var User = function User(json_obj) {
Items Items
*/ */
this.sync = function (callback) { this.syncWithOptions = function (callback) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!this.user.uuid) { if (!this.user.uuid) {
this.writeItemsToLocalStorage(); this.writeItemsToLocalStorage();
callback(); callback();
@@ -1758,7 +1757,7 @@ var User = function User(json_obj) {
var dirtyItems = modelManager.dirtyItems; var dirtyItems = modelManager.dirtyItems;
var request = Restangular.one("items/sync"); var request = Restangular.one("items/sync");
request.items = _.map(dirtyItems, function (item) { request.items = _.map(dirtyItems, function (item) {
return this.createRequestParamsForItem(item); return this.createRequestParamsForItem(item, options.additionalFields);
}.bind(this)); }.bind(this));
if (this.syncToken) { if (this.syncToken) {
@@ -1781,13 +1780,17 @@ var User = function User(json_obj) {
}); });
}; };
this.sync = function (callback) {
this.syncWithOptions(callback, undefined);
};
this.handleItemsResponse = function (responseItems, omitFields) { this.handleItemsResponse = function (responseItems, omitFields) {
this.decryptItems(responseItems); this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields); return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
}; };
this.createRequestParamsForItem = function (item) { this.createRequestParamsForItem = function (item, additionalFields) {
return this.paramsForItem(item, !item.isPublic(), null, false); return this.paramsForItem(item, !item.isPublic(), additionalFields, false);
}; };
this.paramsForItem = function (item, encrypted, additionalFields, forExportFile) { this.paramsForItem = function (item, encrypted, additionalFields, forExportFile) {
@@ -1821,7 +1824,6 @@ var User = function User(json_obj) {
this.deleteItem = function (item, callback) { this.deleteItem = function (item, callback) {
item.deleted = true; item.deleted = true;
console.log("adding dirty item", item);
modelManager.addDirtyItems([item]); modelManager.addDirtyItems([item]);
this.sync(callback); this.sync(callback);
}; };
@@ -1872,11 +1874,11 @@ var User = function User(json_obj) {
this.importJSONData = function (jsonString, callback) { this.importJSONData = function (jsonString, callback) {
var data = JSON.parse(jsonString); var data = JSON.parse(jsonString);
var customModelManager = new ModelManager(); // var customModelManager = new ModelManager();
customModelManager.mapResponseItemsToLocalModels(data.items); modelManager.mapResponseItemsToLocalModels(data.items);
console.log("Importing data", JSON.parse(jsonString)); console.log("Importing data", JSON.parse(jsonString));
modelManager.addDirtyItems(customModelManager.items); modelManager.addDirtyItems(modelManager.items);
this.sync(callback); this.syncWithOptions(callback, { additionalFields: ["created_at", "updated_at"] });
}; };
/* /*
@@ -1901,7 +1903,7 @@ var User = function User(json_obj) {
}.bind(this); }.bind(this);
var items = _.map(modelManager.items, function (item) { var items = _.map(modelManager.items, function (item) {
return this.paramsForItem(item, false, ["created_at", "updated_at"], true); return _.omit(this.paramsForItem(item, false, ["created_at", "updated_at"], true), ["deleted"]);
}.bind(this)); }.bind(this));
var data = { var data = {

File diff suppressed because one or more lines are too long