mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-18 17:11:38 +00:00
refactoring argument handling + added basic paging support...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e0238715ec
commit
dd82f4fa53
@ -2222,6 +2222,10 @@ module.System = {
|
|||||||
<a href="#@var(path)/delete">×</a>
|
<a href="#@var(path)/delete">×</a>
|
||||||
</macro>` },
|
</macro>` },
|
||||||
// XXX this is really slow...
|
// XXX this is really slow...
|
||||||
|
// XXX need to handle count/offset arguments correctly...
|
||||||
|
// ...for this we'll need to be able to either:
|
||||||
|
// - count our own pages or
|
||||||
|
// - keep a global count
|
||||||
tree: {
|
tree: {
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
<slot title/>
|
<slot title/>
|
||||||
|
|||||||
@ -293,9 +293,17 @@ module.BaseStore = {
|
|||||||
// XXX should we have separate indexes for path, text and tags or
|
// XXX should we have separate indexes for path, text and tags or
|
||||||
// cram the three together?
|
// cram the three together?
|
||||||
// XXX need to store this...
|
// XXX need to store this...
|
||||||
|
/* XXX
|
||||||
|
__search_options: {
|
||||||
|
preset: 'match',
|
||||||
|
tokenize: 'full',
|
||||||
|
},
|
||||||
|
//*/
|
||||||
__search: index.makeIndex('search',
|
__search: index.makeIndex('search',
|
||||||
async function(){
|
async function(){
|
||||||
var index = new flexsearch.Index()
|
var index = new flexsearch.Index(
|
||||||
|
this.__search_options
|
||||||
|
?? {})
|
||||||
var update = this.__search.options.update
|
var update = this.__search.options.update
|
||||||
for(var path of (await this.paths)){
|
for(var path of (await this.paths)){
|
||||||
update.call(this, index, path, await this.get(path)) }
|
update.call(this, index, path, await this.get(path)) }
|
||||||
@ -387,6 +395,7 @@ module.BaseStore = {
|
|||||||
: '/'+p
|
: '/'+p
|
||||||
if(pages.has(p)){
|
if(pages.has(p)){
|
||||||
return p+args } } },
|
return p+args } } },
|
||||||
|
|
||||||
//
|
//
|
||||||
// Resolve page for path
|
// Resolve page for path
|
||||||
// .match(<path>)
|
// .match(<path>)
|
||||||
@ -407,6 +416,73 @@ module.BaseStore = {
|
|||||||
// actual existing pages, while in non-strict mode the pattern will
|
// actual existing pages, while in non-strict mode the pattern will
|
||||||
// match all sub-paths.
|
// match all sub-paths.
|
||||||
//
|
//
|
||||||
|
__match_args__: {
|
||||||
|
//
|
||||||
|
// <tag-name>: function(value, args){
|
||||||
|
// // setup state if needed and pre-check...
|
||||||
|
// // ...
|
||||||
|
// return no_check_needed ?
|
||||||
|
// false
|
||||||
|
// // path predicate...
|
||||||
|
// : function(path){
|
||||||
|
// if( path_matches ){
|
||||||
|
// return true } } },
|
||||||
|
//
|
||||||
|
// NOTE: handlers are run in order of definition.
|
||||||
|
//
|
||||||
|
tags: async function(tags){
|
||||||
|
tags = typeof(tags) == 'string' ?
|
||||||
|
this.parseTags(tags)
|
||||||
|
: false
|
||||||
|
tags && await this.tags
|
||||||
|
return tags
|
||||||
|
&& function(path){
|
||||||
|
// tags -> skip untagged pages...
|
||||||
|
var t = this.tags.paths[path]
|
||||||
|
if(!t){
|
||||||
|
return false }
|
||||||
|
for(var tag of tags){
|
||||||
|
if(!t || !t.has(tag)){
|
||||||
|
return false } }
|
||||||
|
return true } },
|
||||||
|
search: async function(search){
|
||||||
|
search = search
|
||||||
|
&& new Set(await this.search(search))
|
||||||
|
return search instanceof Set
|
||||||
|
&& function(path){
|
||||||
|
// nothing found or not in match list...
|
||||||
|
if(search.size == 0
|
||||||
|
|| !search.has(path)){
|
||||||
|
return false }
|
||||||
|
return true } },
|
||||||
|
// XXX EXPERIMENTAL...
|
||||||
|
// XXX add page/page-size???
|
||||||
|
offset: function(offset){
|
||||||
|
offset = parseInt(offset)
|
||||||
|
return !!offset
|
||||||
|
&& function(path){
|
||||||
|
offset--
|
||||||
|
return !(offset >= 0) } },
|
||||||
|
count: function(count){
|
||||||
|
count = parseInt(count)
|
||||||
|
return !!count
|
||||||
|
&& function(path){
|
||||||
|
count--
|
||||||
|
return !!(count >= 0) } },
|
||||||
|
},
|
||||||
|
__match_args: async function(args){
|
||||||
|
var that = this
|
||||||
|
var predicates = []
|
||||||
|
for(var [key, gen] of Object.entries(this.__match_args__ ?? {})){
|
||||||
|
var p = await gen.call(this, args[key], args)
|
||||||
|
p && predicates.push(p) }
|
||||||
|
return predicates.length > 0 ?
|
||||||
|
function(path){
|
||||||
|
for(var p of predicates){
|
||||||
|
if(!p.call(that, path)){
|
||||||
|
return false } }
|
||||||
|
return true }
|
||||||
|
: undefined },
|
||||||
match: async function(path, strict=false){
|
match: async function(path, strict=false){
|
||||||
var that = this
|
var that = this
|
||||||
// pattern match * / **
|
// pattern match * / **
|
||||||
@ -416,11 +492,7 @@ module.BaseStore = {
|
|||||||
|
|
||||||
var {path, args} = pwpath.splitArgs(path)
|
var {path, args} = pwpath.splitArgs(path)
|
||||||
var all = args.all
|
var all = args.all
|
||||||
var tags = args.tags
|
var test = await this.__match_args(args)
|
||||||
tags = typeof(tags) == 'string' ?
|
|
||||||
this.parseTags(tags)
|
|
||||||
: false
|
|
||||||
tags && await this.tags
|
|
||||||
args = pwpath.joinArgs('', args)
|
args = pwpath.joinArgs('', args)
|
||||||
|
|
||||||
// NOTE: we are matching full paths only here so leading and
|
// NOTE: we are matching full paths only here so leading and
|
||||||
@ -444,16 +516,9 @@ module.BaseStore = {
|
|||||||
// skip metadata paths...
|
// skip metadata paths...
|
||||||
if(p.includes('*')){
|
if(p.includes('*')){
|
||||||
return res }
|
return res }
|
||||||
// skip untagged pages...
|
// check path: stage 1
|
||||||
if(tags){
|
|
||||||
var t = that.tags.paths[p]
|
|
||||||
if(!t){
|
|
||||||
return res }
|
|
||||||
for(var tag of tags){
|
|
||||||
if(!t || !t.has(tag)){
|
|
||||||
return res } } }
|
|
||||||
var m = [...p.matchAll(pattern)]
|
var m = [...p.matchAll(pattern)]
|
||||||
m.length > 0
|
var visible = m.length > 0
|
||||||
&& (!all ?
|
&& (!all ?
|
||||||
// test if we need to hide things....
|
// test if we need to hide things....
|
||||||
m.reduce(function(res, m){
|
m.reduce(function(res, m){
|
||||||
@ -462,6 +527,16 @@ module.BaseStore = {
|
|||||||
: !/(^\.|[\\\/]\.)/.test(m[1])
|
: !/(^\.|[\\\/]\.)/.test(m[1])
|
||||||
}, true)
|
}, true)
|
||||||
: true)
|
: true)
|
||||||
|
// args...
|
||||||
|
// NOTE: this needs to be between path checking
|
||||||
|
// stages as we need to skip paths depending
|
||||||
|
// on the all argument...
|
||||||
|
if(visible
|
||||||
|
&& test
|
||||||
|
&& !test(p)){
|
||||||
|
return res }
|
||||||
|
// check path: stage 2
|
||||||
|
visible
|
||||||
&& (m = m[0])
|
&& (m = m[0])
|
||||||
&& (!strict
|
&& (!strict
|
||||||
|| m[0] == p)
|
|| m[0] == p)
|
||||||
|
|||||||
35
pwiki2.js
35
pwiki2.js
@ -12,7 +12,7 @@
|
|||||||
* - pouchdb-couchdb sync -
|
* - pouchdb-couchdb sync -
|
||||||
* - pouchdb-pouchdb sync (p2p via webrtc) - XXX
|
* - pouchdb-pouchdb sync (p2p via webrtc) - XXX
|
||||||
* - tags - DONE
|
* - tags - DONE
|
||||||
* - search -
|
* - search - DONE
|
||||||
* - images - XXX
|
* - images - XXX
|
||||||
* - GUI -
|
* - GUI -
|
||||||
* - CLI -
|
* - CLI -
|
||||||
@ -74,17 +74,6 @@
|
|||||||
* XXX generalize html/dom api...
|
* XXX generalize html/dom api...
|
||||||
* ...see refresh() in pwiki2.html
|
* ...see refresh() in pwiki2.html
|
||||||
* XXX test pouchdb latency at scale in browser...
|
* XXX test pouchdb latency at scale in browser...
|
||||||
* XXX BUG: for some reason deleting and refreshing takes ~2x as long as
|
|
||||||
* refreshing...
|
|
||||||
* to reproduce:
|
|
||||||
* pwiki.path = '/tree' // reports about ~2sec
|
|
||||||
* await pwiki.get('/Test/Subtree/Page2/delete').raw // refresh reports ~4sec (XXX)
|
|
||||||
* while:
|
|
||||||
* pwiki.path = '/tree' // reports about ~2sec
|
|
||||||
* await pwiki.get('/Test/Subtree/Page2').delete() // fast
|
|
||||||
* pwiki.path = '/tree' // reports about ~2sec
|
|
||||||
* XXX test with action...
|
|
||||||
* ...cane we make everything index-related sync?
|
|
||||||
* XXX macros: .depends: need fast path pattern matching...
|
* XXX macros: .depends: need fast path pattern matching...
|
||||||
* XXX macros / CACHE: convert a /path/* dependency to /path/** if a script
|
* XXX macros / CACHE: convert a /path/* dependency to /path/** if a script
|
||||||
* is recursive...
|
* is recursive...
|
||||||
@ -120,23 +109,6 @@
|
|||||||
* ...likely no...
|
* ...likely no...
|
||||||
* ...would depend on where we iterate pages and on whether
|
* ...would depend on where we iterate pages and on whether
|
||||||
* we can/should reach that spot from within the parser...
|
* we can/should reach that spot from within the parser...
|
||||||
* XXX page access mothods (.get(..) / .__get__(..) via path + args)
|
|
||||||
* - path -- DONE
|
|
||||||
* - tags --
|
|
||||||
* - search --
|
|
||||||
* Syntax:
|
|
||||||
* /path/to/*:tags=a,b,c:search=some text
|
|
||||||
* +--------+ . . . . . . . . . . . . . . . . path
|
|
||||||
* +--------+ . . . . . . . . . . . tags
|
|
||||||
* +--------------+ . . search
|
|
||||||
* order is not relevant here...
|
|
||||||
* each of the methods narrows down the previous' results
|
|
||||||
* XXX FEATURE list macro paging...
|
|
||||||
* ...should this be macro level or handled in .each()
|
|
||||||
* what mode?
|
|
||||||
* - count + block-offset (preferred)
|
|
||||||
* - count + elem-offset
|
|
||||||
* - from + to
|
|
||||||
* XXX revise/update sort...
|
* XXX revise/update sort...
|
||||||
* XXX FEATURE images...
|
* XXX FEATURE images...
|
||||||
* XXX async/live render...
|
* XXX async/live render...
|
||||||
@ -252,7 +224,6 @@
|
|||||||
* XXX add action to reset overloaded (bootstrap/.next) pages...
|
* XXX add action to reset overloaded (bootstrap/.next) pages...
|
||||||
* - per page
|
* - per page
|
||||||
* - global
|
* - global
|
||||||
* XXX TEST @macro(..) and @slot(..) must overload in the same way...
|
|
||||||
* XXX should render templates (_view and the like) be a special case
|
* XXX should render templates (_view and the like) be a special case
|
||||||
* or render as any other page???
|
* or render as any other page???
|
||||||
* ...currently they are rendered in the context of the page and
|
* ...currently they are rendered in the context of the page and
|
||||||
@ -322,8 +293,8 @@
|
|||||||
* - get tags from page -- DONE
|
* - get tags from page -- DONE
|
||||||
* - show tagged pages -- DONE
|
* - show tagged pages -- DONE
|
||||||
* - search
|
* - search
|
||||||
* - paths --
|
* - paths -- ???
|
||||||
* - text --
|
* - text -- DONE
|
||||||
* - markdown -- DONE
|
* - markdown -- DONE
|
||||||
* - WikiWord -- DONE
|
* - WikiWord -- DONE
|
||||||
* - dom filter mechanics -- DONE
|
* - dom filter mechanics -- DONE
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user