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 || {}; var Neeto = Neeto || {};
if(window.crypto.subtle) { if(window.crypto.subtle) {
// console.log("using WebCrypto");
Neeto.crypto = new SNCryptoWeb(); Neeto.crypto = new SNCryptoWeb();
} else { } else {
// console.log("using CryptoJS");
Neeto.crypto = new SNCryptoJS(); Neeto.crypto = new SNCryptoJS();
} }

View File

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

View File

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

View File

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

View File

@@ -43,6 +43,10 @@ class Note extends Item {
return {uuid: this.uuid} return {uuid: this.uuid}
} }
isSharedIndividually() {
return this.presentation_name;
}
isPublic() { isPublic() {
return super.isPublic() || this.hasOnePublicTag; 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"); var request = Restangular.one("users", this.user.uuid).one("items");
request.get(updatedAfter ? {"updated_after" : updatedAfter.toString()} : {}) request.get(updatedAfter ? {"updated_after" : updatedAfter.toString()} : {})
.then(function(response){ .then(function(response){
console.log("refresh response", response.items); var items = this.handleItemsResponse(response.items, null);
var items = this.handleItemsResponse(response.items);
callback(items); callback(items);
}.bind(this)) }.bind(this))
.catch(function(response) { .catch(function(response) {
@@ -261,14 +260,15 @@ angular.module('app.frontend')
}.bind(this)); }.bind(this));
request.post().then(function(response) { request.post().then(function(response) {
// this.handleItemsResponse(response.items); var omitFields = ["content", "enc_item_key", "auth_hash"];
this.handleItemsResponse(response.items, omitFields);
callback(response); callback(response);
}.bind(this)) }.bind(this))
} }
this.handleItemsResponse = function(responseItems) { this.handleItemsResponse = function(responseItems, omitFields) {
this.decryptItems(responseItems); this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModels(responseItems); return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
} }
this.createRequestParamsForItem = function(item) { this.createRequestParamsForItem = function(item) {

View File

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

View File

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

View File

@@ -23,11 +23,11 @@
%li %li
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.toggleMarkdown()"} Toggle Markdown Preview %a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.toggleMarkdown()"} Toggle Markdown Preview
.shortcut Cmd + M .shortcut Cmd + M
%li{"ng-if" => "!ctrl.note.isPublic()"} %li{"ng-if" => "!ctrl.note.isSharedIndividually()"}
%a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.shareNote()"} Share %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 %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 %a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.unshareNote()"} Unshare
%li %li
%a.text{"ng-click" => "ctrl.deleteNote()"} Delete %a.text{"ng-click" => "ctrl.deleteNote()"} Delete
@@ -40,7 +40,7 @@
.public-link{"ng-if" => "ctrl.note.isPublic()"} .public-link{"ng-if" => "ctrl.note.isPublic()"}
%a.url{"ng-if" => "!ctrl.editingUrl", "href" => "{{ctrl.publicUrlForNote(ctrl.note)}}", "target" => "_blank"} %a.url{"ng-if" => "!ctrl.editingUrl", "href" => "{{ctrl.publicUrlForNote(ctrl.note)}}", "target" => "_blank"}
%span.icon-rss.icon %span.icon-rss.icon
{{ctrl.publicUrlForNote(note)}} %span{"ng-if" => "ctrl.note.isSharedIndividually()"}{{ctrl.publicUrlForNote(note)}}
.edit-url{"ng-if" => "ctrl.editingUrl"} .edit-url{"ng-if" => "ctrl.editingUrl"}
{{ctrl.url.base}} {{ctrl.url.base}}
%input.input{"ng-model" => "ctrl.url.token", "ng-keyup" => "$event.keyCode == 13 && ctrl.saveUrl($event)", %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 || {}; var Neeto = Neeto || {};
if (window.crypto.subtle) { if (window.crypto.subtle) {
// console.log("using WebCrypto");
Neeto.crypto = new SNCryptoWeb(); Neeto.crypto = new SNCryptoWeb();
} else { } else {
// console.log("using CryptoJS");
Neeto.crypto = new SNCryptoJS(); Neeto.crypto = new SNCryptoJS();
} }
@@ -506,6 +504,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.setNote = function (note, oldNote) { this.setNote = function (note, oldNote) {
this.editorMode = 'edit'; this.editorMode = 'edit';
if (note.content.text.length == 0 && note.dummy) { if (note.content.text.length == 0 && note.dummy) {
this.focusTitle(100); this.focusTitle(100);
} }
@@ -818,7 +817,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
this.downloadDataArchive = function () { this.downloadDataArchive = function () {
var link = document.createElement('a'); var link = document.createElement('a');
link.setAttribute('download', 'neeto.json'); link.setAttribute('download', 'notes.json');
link.href = apiController.itemsDataFile(); link.href = apiController.itemsDataFile();
link.click(); link.click();
}; };
@@ -1411,6 +1410,11 @@ var Note = function (_Item) {
value: function toJSON() { value: function toJSON() {
return { uuid: this.uuid }; return { uuid: this.uuid };
} }
}, {
key: 'isSharedIndividually',
value: function isSharedIndividually() {
return this.presentation_name;
}
}, { }, {
key: 'isPublic', key: 'isPublic',
value: function isPublic() { value: function isPublic() {
@@ -1744,8 +1748,7 @@ var User = function User(json_obj) {
this.refreshItems = function (updatedAfter, callback) { this.refreshItems = function (updatedAfter, callback) {
var request = Restangular.one("users", this.user.uuid).one("items"); var request = Restangular.one("users", this.user.uuid).one("items");
request.get(updatedAfter ? { "updated_after": updatedAfter.toString() } : {}).then(function (response) { request.get(updatedAfter ? { "updated_after": updatedAfter.toString() } : {}).then(function (response) {
console.log("refresh response", response.items); var items = this.handleItemsResponse(response.items, null);
var items = this.handleItemsResponse(response.items);
callback(items); callback(items);
}.bind(this)).catch(function (response) { }.bind(this)).catch(function (response) {
callback(response.data); callback(response.data);
@@ -1764,14 +1767,15 @@ var User = function User(json_obj) {
}.bind(this)); }.bind(this));
request.post().then(function (response) { request.post().then(function (response) {
// this.handleItemsResponse(response.items); var omitFields = ["content", "enc_item_key", "auth_hash"];
this.handleItemsResponse(response.items, omitFields);
callback(response); callback(response);
}.bind(this)); }.bind(this));
}; };
this.handleItemsResponse = function (responseItems) { this.handleItemsResponse = function (responseItems, omitFields) {
this.decryptItems(responseItems); this.decryptItems(responseItems);
return modelManager.mapResponseItemsToLocalModels(responseItems); return modelManager.mapResponseItemsToLocalModelsOmittingFields(responseItems, omitFields);
}; };
this.createRequestParamsForItem = function (item) { this.createRequestParamsForItem = function (item) {
@@ -2448,6 +2452,11 @@ var ItemManager = function () {
}, { }, {
key: 'mapResponseItemsToLocalModels', key: 'mapResponseItemsToLocalModels',
value: function mapResponseItemsToLocalModels(items) { value: function mapResponseItemsToLocalModels(items) {
return this.mapResponseItemsToLocalModelsOmittingFields(items, null);
}
}, {
key: 'mapResponseItemsToLocalModelsOmittingFields',
value: function mapResponseItemsToLocalModelsOmittingFields(items, omitFields) {
var models = []; var models = [];
var _iteratorNormalCompletion3 = true; var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false; var _didIteratorError3 = false;
@@ -2457,6 +2466,7 @@ var ItemManager = function () {
for (var _iterator3 = items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { for (var _iterator3 = items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var json_obj = _step3.value; var json_obj = _step3.value;
json_obj = _.omit(json_obj, omitFields || []);
var item = this.findItem(json_obj["uuid"]); var item = this.findItem(json_obj["uuid"]);
if (json_obj["deleted"] == true) { if (json_obj["deleted"] == true) {
if (item) { if (item) {
@@ -2601,7 +2611,7 @@ var ModelManager = function (_ItemManager) {
var _this5 = _possibleConstructorReturn(this, (ModelManager.__proto__ || Object.getPrototypeOf(ModelManager)).call(this)); var _this5 = _possibleConstructorReturn(this, (ModelManager.__proto__ || Object.getPrototypeOf(ModelManager)).call(this));
_this5.notes = []; _this5.notes = [];
_this5.groups = []; _this5.tags = [];
_this5.dirtyItems = []; _this5.dirtyItems = [];
return _this5; return _this5;
} }
@@ -2611,12 +2621,12 @@ var ModelManager = function (_ItemManager) {
value: function resolveReferences() { value: function resolveReferences() {
_get(ModelManager.prototype.__proto__ || Object.getPrototypeOf(ModelManager.prototype), 'resolveReferences', this).call(this); _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) { this.notes.forEach(function (note) {
note.updateReferencesLocalMapping(); note.updateReferencesLocalMapping();
}); });
this.tags = this.itemsForContentType("Tag"); this.tags.push.apply(this.tags, _.difference(this.itemsForContentType("Tag"), this.tags));
this.tags.forEach(function (tag) { this.tags.forEach(function (tag) {
tag.updateReferencesLocalMapping(); tag.updateReferencesLocalMapping();
}); });
@@ -2649,6 +2659,7 @@ var ModelManager = function (_ItemManager) {
value: function addTag(tag) { value: function addTag(tag) {
this.tags.unshift(tag); this.tags.unshift(tag);
this.addItem(tag); this.addItem(tag);
console.log("adding tag", tag, "tags", this.tags);
} }
}, { }, {
key: 'addTagToNote', key: 'addTagToNote',

File diff suppressed because one or more lines are too long