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, // 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 // such as alternating uuids during sign in. Otherwise, we only want to make interface updates if it's a
// remote retrieved source. // remote retrieved source.
if(this.note.deleted) { if(this.note.deleted || this.note.content.trashed) {
$rootScope.notifyDelete(); $rootScope.notifyDelete();
return; return;
} }
@@ -381,7 +381,7 @@ angular.module('app')
} }
} }
this.deleteNote = async function() { this.deleteNote = async function(permanently) {
let run = () => { let run = () => {
$timeout(() => { $timeout(() => {
if(this.note.locked) { if(this.note.locked) {
@@ -390,8 +390,15 @@ angular.module('app')
} }
let title = this.note.safeTitle().length ? `'${this.note.title}'` : "this note"; let title = this.note.safeTitle().length ? `'${this.note.title}'` : "this note";
if(confirm(`Are you sure you want to delete ${title}?`)) { let message = permanently ? `Are you sure you want to permanently delete ${title}?`
this.remove()(this.note); : `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; 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.togglePin = function() {
this.note.setAppDataItem("pinned", !this.note.pinned); this.note.setAppDataItem("pinned", !this.note.pinned);
this.changesMade({dontUpdatePreviews: true}); 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; note.flags = flags;
return flags; return flags;
@@ -301,10 +308,17 @@ angular.module('app')
this.noteFilter = {text : ''}; this.noteFilter = {text : ''};
this.filterNotes = function(note) { 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(); var isSmartTag = this.tag.isSmartTag();
if(isSmartTag) { if(isSmartTag) {
canShowArchived = this.tag.isReferencingArchivedNotes(); canShowArchived = this.tag.content.isArchiveTag || isTrash;
} else { } else {
canShowArchived = this.showArchived; canShowArchived = this.showArchived;
canShowPinned = !this.hidePinned; canShowPinned = !this.hidePinned;

View File

@@ -81,7 +81,7 @@ angular.module('app')
if(tag.isSmartTag()) { if(tag.isSmartTag()) {
Object.defineProperty(tag, "notes", { Object.defineProperty(tag, "notes", {
get: () => { 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"); 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() { buildSystemSmartTags() {

View File

@@ -38,7 +38,14 @@
%menu-row{"label" => "ctrl.note.locked ? 'Unlock' : 'Lock'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleLockNote()", "desc" => "'Locking notes prevents unintentional editing'"} %menu-row{"label" => "ctrl.note.locked ? 'Unlock' : 'Lock'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleLockNote()", "desc" => "'Locking notes prevents unintentional editing'"}
%menu-row{"label" => "ctrl.note.content.protected ? 'Unprotect' : 'Protect'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleProtectNote()", "desc" => "'Protecting a note will require credentials to view it (Manage Privileges via Account menu)'"} %menu-row{"label" => "ctrl.note.content.protected ? 'Unprotect' : 'Protect'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleProtectNote()", "desc" => "'Protecting a note will require credentials to view it (Manage Privileges via Account menu)'"}
%menu-row{"label" => "'Preview'", "circle" => "ctrl.note.content.hidePreview ? 'danger' : 'success'", "circle-align" => "'right'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleNotePreview()", "desc" => "'Hide or unhide the note preview from the list of notes'"} %menu-row{"label" => "'Preview'", "circle" => "ctrl.note.content.hidePreview ? 'danger' : 'success'", "circle-align" => "'right'", "action" => "ctrl.selectedMenuItem(true); ctrl.toggleNotePreview()", "desc" => "'Hide or unhide the note preview from the list of notes'"}
%menu-row{"label" => "'Delete'", "action" => "ctrl.selectedMenuItem(); ctrl.deleteNote()", "desc" => "'Delete this note permanently from all your devices'"} %menu-row{"ng-show" => "!ctrl.note.content.trashed", "label" => "'Move to Trash'", "action" => "ctrl.selectedMenuItem(); ctrl.deleteNote()", "desc" => "'Send this note to the trash'"}
.sk-menu-panel-section{"ng-if" => "ctrl.note.content.trashed"}
.sk-menu-panel-header
.sk-menu-panel-header-title Trash
%menu-row{"label" => "'Restore Note'", "action" => "ctrl.selectedMenuItem(true); ctrl.restoreTrashedNote()", "desc" => "'Undelete this note and restore it back into your notes'"}
%menu-row{"label" => "'Delete Forever'", "action" => "ctrl.selectedMenuItem(true); ctrl.deleteNotePermanantely()", "desc" => "'Delete this note permanently from all your devices'"}
%menu-row{"label" => "'Empty Trash'", "subtitle" => "ctrl.getTrashCount() + ' notes in trash'", "action" => "ctrl.selectedMenuItem(true); ctrl.emptyTrash()", "desc" => "'Permanently delete all notes in the trash'"}
.sk-menu-panel-section .sk-menu-panel-section
.sk-menu-panel-header .sk-menu-panel-header

View File

@@ -13,7 +13,8 @@
.scrollable .scrollable
.infinite-scroll .infinite-scroll
.tag{"ng-repeat" => "tag in ctrl.smartTags", "ng-click" => "ctrl.selectTag(tag)", "ng-class" => "{'selected' : ctrl.selectedTag == tag}"} .tag{"ng-repeat" => "tag in ctrl.smartTags", "ng-click" => "ctrl.selectTag(tag)",
"ng-class" => "{'selected' : ctrl.selectedTag == tag, 'faded' : !tag.content.isAllTag}"}
.info .info
%input.title{"ng-disabled" => "true", "ng-model" => "tag.title"} %input.title{"ng-disabled" => "true", "ng-model" => "tag.title"}