mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-09 03:19:13 +00:00
Add 'missing' and 'orphan' tabs
This commit is contained in:
@@ -107,6 +107,18 @@ exports.operators = {
|
||||
break;
|
||||
case "system":
|
||||
return "for(title in source) {if(" + op + "this.getTiddler(title).isSystem()) {$tw.utils.pushTop(subResults,title);}}";
|
||||
case "missing":
|
||||
if(operator.prefix === "!") {
|
||||
return "for(title in source) {$tw.utils.pushTop(subResults,title);}";
|
||||
} else {
|
||||
return "var m = this.getMissingTitles(); for(t=0; t<m.length; t++) {$tw.utils.pushTop(subResults,m[t]);}";
|
||||
}
|
||||
case "orphan":
|
||||
if(operator.prefix === "!") {
|
||||
return "var m = this.getOrphanTitles(); for(title in source) {if(m.indexOf(title) === -1) {$tw.utils.pushTop(subResults,title);}}";
|
||||
} else {
|
||||
return "var m = this.getOrphanTitles(); for(t=0; t<m.length; t++) {$tw.utils.pushTop(subResults,m[t]);}";
|
||||
}
|
||||
default:
|
||||
throw "Unknown operand for 'is' filter operator";
|
||||
}
|
||||
@@ -123,6 +135,14 @@ exports.operators = {
|
||||
break;
|
||||
case "system":
|
||||
return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isSystem()) {subResults.splice(r,1);}}";
|
||||
case "missing":
|
||||
return "t = this.getMissingTitles(); for(r=subResults.length-1; r>=0; r--) {if(" + op + "!$tw.utils.hop(t,subResults[r])) {subResults.splice(r,1);}}";
|
||||
case "orphan":
|
||||
if(operator.prefix === "!") {
|
||||
return "t = this.getOrphanTitles(); for(r=subResults.length-1; r>=0; r--) {if(t.indexOf(subResults[r]) === -1) {subResults.splice(r,1);}}";
|
||||
} else {
|
||||
return "t = this.getOrphanTitles(); for(r=subResults.length-1; r>=0; r--) {if(t.indexOf(subResults[r]) !== -1) {subResults.splice(r,1);}}";
|
||||
}
|
||||
default:
|
||||
throw "Unknown operand for 'is' filter operator";
|
||||
}
|
||||
|
||||
+59
-2
@@ -256,12 +256,69 @@ exports.forEachTiddler = function(/* [sortField,[excludeTag,]]callback */) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Return an array of tiddler titles that are directly linked from the specified tiddler
|
||||
*/
|
||||
exports.getTiddlerLinks = function(title) {
|
||||
var self = this;
|
||||
// We'll cache the links so they only get computed if the tiddler changes
|
||||
return this.getCacheForTiddler(title,"links",function() {
|
||||
// Parse the tiddler
|
||||
var parser = self.parseTiddler(title);
|
||||
// Count up the links
|
||||
var links = [],
|
||||
checkParseTree = function(parseTree) {
|
||||
for(var t=0; t<parseTree.length; t++) {
|
||||
var parseTreeNode = parseTree[t];
|
||||
if(parseTreeNode.type === "element" && parseTreeNode.tag === "$link" && parseTreeNode.attributes.to.type === "string") {
|
||||
var value = parseTreeNode.attributes.to.value;
|
||||
if(links.indexOf(value) === -1) {
|
||||
links.push(value);
|
||||
}
|
||||
}
|
||||
if(parseTreeNode.children) {
|
||||
checkParseTree(parseTreeNode.children);
|
||||
}
|
||||
}
|
||||
};
|
||||
if(parser) {
|
||||
checkParseTree(parser.tree)
|
||||
}
|
||||
return links;
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Return a hashmap of tiddler titles that are referenced but not defined. Each value is the number of times the missing tiddler is referenced
|
||||
*/
|
||||
exports.getMissingTitles = function() {
|
||||
return []; // Todo
|
||||
var self = this,
|
||||
missing = [];
|
||||
// We should cache the missing tiddler list, even if we recreate it every time any tiddler is modified
|
||||
this.forEachTiddler(function(title,tiddler) {
|
||||
var links = self.getTiddlerLinks(title);
|
||||
$tw.utils.each(links,function(link) {
|
||||
if(!self.tiddlerExists(link) && missing.indexOf(link) === -1) {
|
||||
missing.push(link);
|
||||
}
|
||||
});
|
||||
});
|
||||
return missing;
|
||||
};
|
||||
|
||||
exports.getOrphanTitles = function() {
|
||||
return []; // Todo
|
||||
var self = this,
|
||||
orphans = this.getTiddlers();
|
||||
this.forEachTiddler(function(title,tiddler) {
|
||||
var links = self.getTiddlerLinks(title);
|
||||
$tw.utils.each(links,function(link) {
|
||||
var p = orphans.indexOf(link);
|
||||
if(p !== -1) {
|
||||
orphans.splice(p,1);
|
||||
}
|
||||
});
|
||||
});
|
||||
return orphans; // Todo
|
||||
};
|
||||
|
||||
exports.getSystemTitles = function() {
|
||||
|
||||
Reference in New Issue
Block a user