Trash bin

This commit is contained in:
Mo Bitar
2019-01-10 17:03:37 -06:00
parent e05580d597
commit 348dd9edb5
6 changed files with 81 additions and 11 deletions

View File

@@ -56,7 +56,7 @@ angular.module('app')
// Before checking if isMappingSourceRetrieved, we check if this item was deleted via a local source,
// such as alternating uuids during sign in. Otherwise, we only want to make interface updates if it's a
// remote retrieved source.
if(this.note.deleted) {
if(this.note.deleted || this.note.content.trashed) {
$rootScope.notifyDelete();
return;
}
@@ -381,7 +381,7 @@ angular.module('app')
}
}
this.deleteNote = async function() {
this.deleteNote = async function(permanently) {
let run = () => {
$timeout(() => {
if(this.note.locked) {
@@ -390,8 +390,15 @@ angular.module('app')
}
let title = this.note.safeTitle().length ? `'${this.note.title}'` : "this note";
if(confirm(`Are you sure you want to delete ${title}?`)) {
this.remove()(this.note);
let message = permanently ? `Are you sure you want to permanently delete ${title}?`
: `Are you sure you want to move ${title} to the trash?`
if(confirm(message)) {
if(permanently) {
this.remove()(this.note);
} else {
this.note.content.trashed = true;
this.changesMade({dontUpdateClientModified: true, dontUpdatePreviews: true});
}
this.showMenu = false;
}
});
@@ -406,6 +413,27 @@ angular.module('app')
}
}
this.restoreTrashedNote = function() {
this.note.content.trashed = false;
this.changesMade({dontUpdateClientModified: true, dontUpdatePreviews: true});
}
this.deleteNotePermanantely = function() {
this.deleteNote(true);
}
this.getTrashCount = function() {
return modelManager.trashedItems().length;
}
this.emptyTrash = function() {
let count = this.getTrashCount();
if(confirm(`Are you sure you want to permanently delete ${count} note(s)?`)) {
modelManager.emptyTrash();
syncManager.sync();
}
}
this.togglePin = function() {
this.note.setAppDataItem("pinned", !this.note.pinned);
this.changesMade({dontUpdatePreviews: true});

View File

@@ -198,6 +198,13 @@ angular.module('app')
})
}
if(note.content.trashed) {
flags.push({
text: "Deleted",
class: "danger"
})
}
note.flags = flags;
return flags;
@@ -301,10 +308,17 @@ angular.module('app')
this.noteFilter = {text : ''};
this.filterNotes = function(note) {
var canShowArchived = false, canShowPinned = true;
let canShowArchived = false, canShowPinned = true;
let isTrash = this.tag.content.isTrashTag;
if(!isTrash && note.content.trashed) {
note.visible = false;
return note.visible;
}
var isSmartTag = this.tag.isSmartTag();
if(isSmartTag) {
canShowArchived = this.tag.isReferencingArchivedNotes();
canShowArchived = this.tag.content.isArchiveTag || isTrash;
} else {
canShowArchived = this.showArchived;
canShowPinned = !this.hidePinned;

View File

@@ -81,7 +81,7 @@ angular.module('app')
if(tag.isSmartTag()) {
Object.defineProperty(tag, "notes", {
get: () => {
return modelManager.notesMatchingPredicate(tag.content.predicate);
return modelManager.notesMatchingSmartTag(tag);
}
});
}

View File

@@ -116,9 +116,29 @@ class ModelManager extends SFModelManager {
}
}
notesMatchingPredicate(predicate) {
notesMatchingSmartTag(tag) {
let contentTypePredicate = new SFPredicate("content_type", "=", "Note");
return this.itemsMatchingPredicates([contentTypePredicate, predicate]);
let predicates = [contentTypePredicate, tag.content.predicate];
if(!tag.content.isTrashTag) {
let notTrashedPredicate = new SFPredicate("content.trashed", "=", false);
predicates.push(notTrashedPredicate);
}
return this.itemsMatchingPredicates(predicates);
}
trashSmartTag() {
return this.systemSmartTags.find((tag) => tag.content.isTrashTag);
}
trashedItems() {
return this.notesMatchingSmartTag(this.trashSmartTag());
}
emptyTrash() {
let notes = this.trashedItems();
for(let note of notes) {
this.setItemToBeDeleted(note);
}
}
buildSystemSmartTags() {