This commit is contained in:
Mo Bitar
2016-12-28 15:22:53 -06:00
parent 195d219e88
commit 96006e3dca
11 changed files with 48 additions and 28 deletions

View File

@@ -3,10 +3,8 @@
var Neeto = Neeto || {};
if(window.crypto.subtle) {
// console.log("using WebCrypto");
Neeto.crypto = new SNCryptoWeb();
} else {
// console.log("using CryptoJS");
Neeto.crypto = new SNCryptoJS();
}

View File

@@ -67,6 +67,7 @@ angular.module('app.frontend')
this.setNote = function(note, oldNote) {
this.editorMode = 'edit';
if(note.content.text.length == 0 && note.dummy) {
this.focusTitle(100);
}

View File

@@ -126,7 +126,7 @@ angular.module('app.frontend')
this.downloadDataArchive = function() {
var link = document.createElement('a');
link.setAttribute('download', 'neeto.json');
link.setAttribute('download', 'notes.json');
link.href = apiController.itemsDataFile();
link.click();
}

View File

@@ -62,7 +62,7 @@ angular.module('app.frontend')
if(this.editingTag) {
return;
}
this.newTag = new Tag();
this.selectedTag = this.newTag;
this.editingTag = this.newTag;

View File

@@ -43,6 +43,10 @@ class Note extends Item {
return {uuid: this.uuid}
}
isSharedIndividually() {
return this.presentation_name;
}
isPublic() {
return super.isPublic() || this.hasOnePublicTag;
}

View File

@@ -240,8 +240,7 @@ angular.module('app.frontend')
var request = Restangular.one("users", this.user.uuid).one("items");
request.get(updatedAfter ? {"updated_after" : updatedAfter.toString()} : {})
.then(function(response){
console.log("refresh response", response.items);
var items = this.handleItemsResponse(response.items);
var items = this.handleItemsResponse(response.items, null);
callback(items);
}.bind(this))
.catch(function(response) {
@@ -261,14 +260,15 @@ angular.module('app.frontend')
}.bind(this));
request.post().then(function(response) {
// this.handleItemsResponse(response.items);
var omitFields = ["content", "enc_item_key", "auth_hash"];
this.handleItemsResponse(response.items, omitFields);
callback(response);
}.bind(this))
}
this.handleItemsResponse = function(responseItems) {
this.handleItemsResponse = function(responseItems, omitFields) {
this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModels(responseItems);
return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
}
this.createRequestParamsForItem = function(item) {

View File

@@ -17,8 +17,13 @@ class ItemManager {
}
mapResponseItemsToLocalModels(items) {
return this.mapResponseItemsToLocalModelsOmittingFields(items, null)
}
mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
var models = []
for (var json_obj of items) {
json_obj = _.omit(json_obj, omitFields || [])
var item = this.findItem(json_obj["uuid"]);
if(json_obj["deleted"] == true) {
if(item) {

View File

@@ -3,19 +3,19 @@ class ModelManager extends ItemManager {
constructor() {
super();
this.notes = [];
this.groups = [];
this.tags = [];
this.dirtyItems = [];
}
resolveReferences() {
super.resolveReferences()
this.notes = this.itemsForContentType("Note");
this.notes.push.apply(this.notes, _.difference(this.itemsForContentType("Note"), this.notes));
this.notes.forEach(function(note){
note.updateReferencesLocalMapping();
})
this.tags = this.itemsForContentType("Tag");
this.tags.push.apply(this.tags, _.difference(this.itemsForContentType("Tag"), this.tags));
this.tags.forEach(function(tag){
tag.updateReferencesLocalMapping();
})
@@ -48,6 +48,7 @@ class ModelManager extends ItemManager {
addTag(tag) {
this.tags.unshift(tag);
this.addItem(tag);
console.log("adding tag", tag, "tags", this.tags);
}
addTagToNote(tag, note) {

View File

@@ -23,11 +23,11 @@
%li
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.toggleMarkdown()"} Toggle Markdown Preview
.shortcut Cmd + M
%li{"ng-if" => "!ctrl.note.isPublic()"}
%li{"ng-if" => "!ctrl.note.isSharedIndividually()"}
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.shareNote()"} Share
%li{"ng-if" => "ctrl.note.isPublic()"}
%li{"ng-if" => "ctrl.note.isSharedIndividually()"}
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.editUrlPressed()"} Edit URL
%li{"ng-if" => "ctrl.note.isPublic()"}
%li{"ng-if" => "ctrl.note.isSharedIndividually()"}
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.unshareNote()"} Unshare
%li
%a.text{"ng-click" => "ctrl.deleteNote()"} Delete
@@ -40,7 +40,7 @@
.public-link{"ng-if" => "ctrl.note.isPublic()"}
%a.url{"ng-if" => "!ctrl.editingUrl", "href" => "{{ctrl.publicUrlForNote(ctrl.note)}}", "target" => "_blank"}
%span.icon-rss.icon
{{ctrl.publicUrlForNote(note)}}
%span{"ng-if" => "ctrl.note.isSharedIndividually()"}{{ctrl.publicUrlForNote(note)}}
.edit-url{"ng-if" => "ctrl.editingUrl"}
{{ctrl.url.base}}
%input.input{"ng-model" => "ctrl.url.token", "ng-keyup" => "$event.keyCode == 13 && ctrl.saveUrl($event)",

View File

@@ -360,10 +360,8 @@ exports.SNCryptoWeb = SNCryptoWeb;
var Neeto = Neeto || {};
if (window.crypto.subtle) {
// console.log("using WebCrypto");
Neeto.crypto = new SNCryptoWeb();
} else {
// console.log("using CryptoJS");
Neeto.crypto = new SNCryptoJS();
}
@@ -506,6 +504,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.setNote = function (note, oldNote) {
this.editorMode = 'edit';
if (note.content.text.length == 0 && note.dummy) {
this.focusTitle(100);
}
@@ -818,7 +817,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.downloadDataArchive = function () {
var link = document.createElement('a');
link.setAttribute('download', 'neeto.json');
link.setAttribute('download', 'notes.json');
link.href = apiController.itemsDataFile();
link.click();
};
@@ -1411,6 +1410,11 @@ var Note = function (_Item) {
value: function toJSON() {
return { uuid: this.uuid };
}
}, {
key: 'isSharedIndividually',
value: function isSharedIndividually() {
return this.presentation_name;
}
}, {
key: 'isPublic',
value: function isPublic() {
@@ -1744,8 +1748,7 @@ var User = function User(json_obj) {
this.refreshItems = function (updatedAfter, callback) {
var request = Restangular.one("users", this.user.uuid).one("items");
request.get(updatedAfter ? { "updated_after": updatedAfter.toString() } : {}).then(function (response) {
console.log("refresh response", response.items);
var items = this.handleItemsResponse(response.items);
var items = this.handleItemsResponse(response.items, null);
callback(items);
}.bind(this)).catch(function (response) {
callback(response.data);
@@ -1764,14 +1767,15 @@ var User = function User(json_obj) {
}.bind(this));
request.post().then(function (response) {
// this.handleItemsResponse(response.items);
var omitFields = ["content", "enc_item_key", "auth_hash"];
this.handleItemsResponse(response.items, omitFields);
callback(response);
}.bind(this));
};
this.handleItemsResponse = function (responseItems) {
this.handleItemsResponse = function (responseItems, omitFields) {
this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModels(responseItems);
return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
};
this.createRequestParamsForItem = function (item) {
@@ -2448,6 +2452,11 @@ var ItemManager = function () {
}, {
key: 'mapResponseItemsToLocalModels',
value: function mapResponseItemsToLocalModels(items) {
return this.mapResponseItemsToLocalModelsOmittingFields(items, null);
}
}, {
key: 'mapResponseItemsToLocalModelsOmittingFields',
value: function mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
var models = [];
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
@@ -2457,6 +2466,7 @@ var ItemManager = function () {
for (var _iterator3 = items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var json_obj = _step3.value;
json_obj = _.omit(json_obj, omitFields || []);
var item = this.findItem(json_obj["uuid"]);
if (json_obj["deleted"] == true) {
if (item) {
@@ -2601,7 +2611,7 @@ var ModelManager = function (_ItemManager) {
var _this5 = _possibleConstructorReturn(this, (ModelManager.__proto__ || Object.getPrototypeOf(ModelManager)).call(this));
_this5.notes = [];
_this5.groups = [];
_this5.tags = [];
_this5.dirtyItems = [];
return _this5;
}
@@ -2611,12 +2621,12 @@ var ModelManager = function (_ItemManager) {
value: function resolveReferences() {
_get(ModelManager.prototype.__proto__ || Object.getPrototypeOf(ModelManager.prototype), 'resolveReferences', this).call(this);
this.notes = this.itemsForContentType("Note");
this.notes.push.apply(this.notes, _.difference(this.itemsForContentType("Note"), this.notes));
this.notes.forEach(function (note) {
note.updateReferencesLocalMapping();
});
this.tags = this.itemsForContentType("Tag");
this.tags.push.apply(this.tags, _.difference(this.itemsForContentType("Tag"), this.tags));
this.tags.forEach(function (tag) {
tag.updateReferencesLocalMapping();
});
@@ -2649,6 +2659,7 @@ var ModelManager = function (_ItemManager) {
value: function addTag(tag) {
this.tags.unshift(tag);
this.addItem(tag);
console.log("adding tag", tag, "tags", this.tags);
}
}, {
key: 'addTagToNote',

File diff suppressed because one or more lines are too long