mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-22 23:16:53 +00:00
Add 'missing' and 'orphan' tabs
This commit is contained in:
parent
43001d58d1
commit
7cb65a3816
@ -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";
|
||||
}
|
||||
|
@ -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() {
|
||||
|
16
core/templates/MoreSideBar.tid
Normal file
16
core/templates/MoreSideBar.tid
Normal file
@ -0,0 +1,16 @@
|
||||
title: $:/templates/MoreSideBar
|
||||
|
||||
<div class="tw-tab-set">
|
||||
<div class="tw-tab-buttons"><$button type="set" set="$:/state/moreSideBarTabSet" setTo="missingTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Missing</$button><$button type="set" set="$:/state/moreSideBarTabSet" setTo="orphanTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Orphans</$button><$button type="set" set="$:/state/moreSideBarTabSet" setTo="systemTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">System</$button></div>
|
||||
<div class="tw-tab-contents">
|
||||
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="missingTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[is[missing]sort[title]]" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="orphanTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[is[orphan]sort[title]]" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="systemTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[is[system]sort[title]]" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
</div>
|
||||
</div>
|
@ -2,19 +2,20 @@ title: $:/templates/SideBar
|
||||
|
||||
<!-- The implementation of tabs here is currently a bit unreadable -->
|
||||
<div class="tw-tab-set">
|
||||
<div class="tw-tab-buttons"><$button type="set" set="myTabset" setTo="openTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Open</$button><$button type="set" set="myTabset" setTo="allTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">All</$button><$button type="set" set="myTabset" setTo="systemTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">System</$button><$button type="set" set="myTabset" setTo="toolsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Tools</$button></div>
|
||||
<div class="tw-tab-buttons"><$button type="set" set="$:/state/sideBarTabSet" setTo="openTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Open</$button><$button type="set" set="$:/state/sideBarTabSet" setTo="allTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">All</$button><$button type="set" set="$:/state/sideBarTabSet" setTo="toolsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Tools</$button><$button type="set" set="$:/state/sideBarTabSet" setTo="moreTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">More</$button></div>
|
||||
<div class="tw-tab-contents">
|
||||
<$reveal type="match" state="myTabset" text="openTab" qualifyTiddlerTitles="yes">
|
||||
<$reveal type="match" state="$:/state/sideBarTabSet" text="openTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[list[$:/StoryList]]" history="$:/HistoryList" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
<$reveal type="match" state="myTabset" text="allTab" qualifyTiddlerTitles="yes">
|
||||
<$reveal type="match" state="$:/state/sideBarTabSet" text="allTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[!is[system]sort[title]]" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
<$reveal type="match" state="myTabset" text="systemTab" qualifyTiddlerTitles="yes">
|
||||
<$list filter="[is[system]sort[title]]" itemClass="tw-menu-list-item"/>
|
||||
</$reveal>
|
||||
<$reveal type="match" state="myTabset" text="toolsTab" qualifyTiddlerTitles="yes">
|
||||
<$reveal type="match" state="$:/state/sideBarTabSet" text="toolsTab" qualifyTiddlerTitles="yes">
|
||||
{{$:/templates/ControlPanel}}
|
||||
</$reveal>
|
||||
</div>
|
||||
<$reveal type="match" state="$:/state/sideBarTabSet" text="moreTab" qualifyTiddlerTitles="yes">
|
||||
{{$:/templates/MoreSideBar}}
|
||||
</$reveal>
|
||||
</div>
|
||||
|
||||
|
3
core/wiki/moreSideBarTabSet.tid
Normal file
3
core/wiki/moreSideBarTabSet.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/state/moreSideBarTabSet-tiddlerTitle:$:/templates/MoreSideBar;templateTitle:$:/templates/MoreSideBar;-tiddlerTitle:$:/templates/SideBar;templateTitle:$:/templates/SideBar;-tiddlerTitle:$:/templates/PageTemplate;-
|
||||
|
||||
missingTab
|
@ -1,3 +0,0 @@
|
||||
title: myTabset-tiddlerTitle:$:/templates/SideBar;templateTitle:$:/templates/SideBar;-tiddlerTitle:$:/templates/PageTemplate;-
|
||||
|
||||
openTab
|
3
core/wiki/sideBarTabSet.tid
Normal file
3
core/wiki/sideBarTabSet.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/state/sideBarTabSet-tiddlerTitle:$:/templates/SideBar;templateTitle:$:/templates/SideBar;-tiddlerTitle:$:/templates/PageTemplate;-
|
||||
|
||||
openTab
|
Loading…
Reference in New Issue
Block a user