System smart tags

This commit is contained in:
Mo Bitar
2019-01-10 16:03:16 -06:00
parent ffc636ca48
commit e05580d597
9 changed files with 3515 additions and 86 deletions

View File

@@ -40,10 +40,6 @@ angular.module('app')
openDatabase();
// Retrieve local data and begin sycing timer
initiateSync();
// Configure "All" psuedo-tag
loadAllTag();
// Configure "Archived" psuedo-tag
loadArchivedTag();
}
if(passcodeManager.isLocked()) {
@@ -94,7 +90,6 @@ angular.module('app')
syncManager.loadLocalItems().then(() => {
$timeout(() => {
$scope.allTag.didLoad = true;
$rootScope.$broadcast("initial-data-loaded"); // This needs to be processed first before sync is called so that singletonManager observers function properly.
syncManager.sync();
// refresh every 30s
@@ -113,25 +108,6 @@ angular.module('app')
})
}
function loadAllTag() {
var allTag = new SNTag({content: {title: "All"}});
allTag.all = true;
allTag.needsLoad = true;
$scope.allTag = allTag;
$scope.tags = modelManager.tags;
$scope.allTag.notes = modelManager.notes;
}
function loadArchivedTag() {
var archiveTag = new SNSmartTag({content: {title: "Archived", predicate: ["archived", "=", true]}});
Object.defineProperty(archiveTag, "notes", {
get: () => {
return modelManager.notesMatchingPredicate(archiveTag.content.predicate);
}
});
$scope.archiveTag = archiveTag;
}
/*
Editor Callbacks
*/
@@ -220,7 +196,7 @@ angular.module('app')
$scope.notesAddNew = function(note) {
modelManager.addItem(note);
if(!$scope.selectedTag.all && !$scope.selectedTag.isSmartTag()) {
if(!$scope.selectedTag.isSmartTag()) {
$scope.selectedTag.addItemAsRelationship(note);
$scope.selectedTag.setDirty(true);
}

View File

@@ -136,7 +136,7 @@ angular.module('app')
if(this.isFiltering()) {
return `${this.tag.notes.filter((i) => {return i.visible;}).length} search results`;
} else if(this.tag) {
return `${this.tag.title} notes`;
return `${this.tag.title}`;
}
}
@@ -390,7 +390,7 @@ angular.module('app')
return false;
}
if(this.tag.all) {
if(this.tag.content.isAllTag) {
return note.tags && note.tags.length > 0;
}

View File

@@ -7,8 +7,6 @@ angular.module('app')
selectionMade: "&",
save: "&",
tags: "=",
allTag: "=",
archiveTag: "=",
updateNoteTag: "&",
removeTag: "&"
},
@@ -17,25 +15,22 @@ angular.module('app')
controller: 'TagsCtrl',
controllerAs: 'ctrl',
bindToController: true,
link:function(scope, elem, attrs, ctrl) {
scope.$watch('ctrl.tags', function(newTags){
if(newTags) {
ctrl.setTags(newTags);
}
});
scope.$watch('ctrl.allTag', function(allTag){
if(allTag) {
ctrl.setAllTag(allTag);
}
});
}
}
})
.controller('TagsCtrl', function ($rootScope, modelManager, $timeout, componentManager, authManager) {
.controller('TagsCtrl', function ($rootScope, modelManager, syncManager, $timeout, componentManager, authManager) {
let initialLoad = true;
var initialLoad = true;
syncManager.addEventHandler((syncEvent, data) => {
if(syncEvent == "initial-data-loaded" || syncEvent == "sync:completed") {
this.tags = modelManager.tags;
this.smartTags = modelManager.getSmartTags();
if(initialLoad) {
initialLoad = false;
this.selectTag(this.smartTags[0]);
}
}
});
this.panelController = {};
@@ -69,40 +64,27 @@ angular.module('app')
}.bind(this), actionHandler: function(component, action, data){
if(action === "select-item") {
if(data.item.content_type == "Tag") {
var tag = modelManager.findItem(data.item.uuid);
let tag = modelManager.findItem(data.item.uuid);
if(tag) {
this.selectTag(tag);
}
} else if(data.item.content_type == "SN|SmartTag") {
var tag = new SNSmartTag(data.item);
Object.defineProperty(tag, "notes", {
get: () => {
return modelManager.notesMatchingPredicate(tag.content.predicate);
}
});
this.selectTag(tag);
let smartTag = new SNSmartTag(data.item);
this.selectTag(smartTag);
}
} else if(action === "clear-selection") {
this.selectTag(this.allTag);
this.selectTag(this.smartTags[0]);
}
}.bind(this)});
this.setAllTag = function(allTag) {
this.selectTag(this.allTag);
}
this.setTags = function(tags) {
if(initialLoad) {
initialLoad = false;
this.selectTag(this.allTag);
} else {
if(tags && tags.length > 0) {
this.selectTag(tags[0]);
}
}
}
this.selectTag = function(tag) {
if(tag.isSmartTag()) {
Object.defineProperty(tag, "notes", {
get: () => {
return modelManager.notesMatchingPredicate(tag.content.predicate);
}
});
}
this.selectedTag = tag;
tag.conflict_of = null; // clear conflict
this.selectionMade()(tag);
@@ -161,12 +143,12 @@ angular.module('app')
this.selectedDeleteTag = function(tag) {
this.removeTag()(tag);
this.selectTag(this.allTag);
this.selectTag(this.smartTags[0]);
}
this.noteCount = function(tag) {
var validNotes = SNNote.filterDummyNotes(tag.notes).filter(function(note){
return !note.archived;
return !note.archived && !note.content.trashed;
});
return validNotes.length;
}

View File

@@ -22,6 +22,8 @@ class ModelManager extends SFModelManager {
this.components = [];
this.storageManager = storageManager;
this.buildSystemSmartTags();
}
handleSignout() {
@@ -119,6 +121,21 @@ class ModelManager extends SFModelManager {
return this.itemsMatchingPredicates([contentTypePredicate, predicate]);
}
buildSystemSmartTags() {
this.systemSmartTags = SNSmartTag.systemSmartTags();
}
getSmartTagWithId(id) {
return this.getSmartTags().find((candidate) => candidate.uuid == id);
}
getSmartTags() {
let userTags = this.validItemsForContentType("SN|SmartTag").sort((a, b) => {
return a.content.title < b.content.title ? -1 : 1;
});
return this.systemSmartTags.concat(userTags);
}
/*
Misc
*/