Eval search on server, use hash, and only add once
This commit is contained in:
parent
4cb98ac8df
commit
ecfc9dc968
|
@ -23,6 +23,8 @@
|
||||||
n]
|
n]
|
||||||
[#f
|
[#f
|
||||||
#f]
|
#f]
|
||||||
|
[#t
|
||||||
|
#t]
|
||||||
[(? symbol? s)
|
[(? symbol? s)
|
||||||
(symbol->string s)]
|
(symbol->string s)]
|
||||||
[(? keyword? s)
|
[(? keyword? s)
|
||||||
|
@ -48,10 +50,27 @@
|
||||||
(pkg-index/basic
|
(pkg-index/basic
|
||||||
(λ () pkg-list)
|
(λ () pkg-list)
|
||||||
(λ (pkg-name)
|
(λ (pkg-name)
|
||||||
(define ht (file->value (build-path pkgs-path pkg-name)))
|
(define ht (file->value (build-path pkgs-path pkg-name)))
|
||||||
|
|
||||||
(hash-set* ht
|
(hash-set* ht
|
||||||
'name pkg-name
|
'name pkg-name
|
||||||
'tags (hash-ref ht 'tags empty)
|
'tags (hash-ref ht 'tags empty)
|
||||||
|
'search-terms
|
||||||
|
(let* ([st (hasheq)]
|
||||||
|
[st (for/fold ([st st])
|
||||||
|
([t (in-list (hash-ref ht 'tags empty))])
|
||||||
|
(hash-set st (string->symbol t) #t))]
|
||||||
|
[st (hash-set st (string->symbol (format "ring:~a" (hash-ref ht 'ring 2))) #t)]
|
||||||
|
[st (for/fold ([st st])
|
||||||
|
([a (in-list (author->list (hash-ref ht 'author "")))])
|
||||||
|
(hash-set st (string->symbol (format "author:~a" a)) #t))]
|
||||||
|
[st (if (empty? (hash-ref ht 'tags empty))
|
||||||
|
(hash-set st ':no-tag: #t)
|
||||||
|
st)]
|
||||||
|
[st (if (hash-ref ht 'checksum-error #f)
|
||||||
|
(hash-set st ':error: #t)
|
||||||
|
st)])
|
||||||
|
st)
|
||||||
'authors (author->list (hash-ref ht 'author ""))))))
|
'authors (author->list (hash-ref ht 'author ""))))))
|
||||||
|
|
||||||
(define (url->request u)
|
(define (url->request u)
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
// xxx manage packages
|
// xxx manage packages
|
||||||
|
|
||||||
$( document ).ready(function() {
|
$( document ).ready(function() {
|
||||||
var search_terms = [ "!main-tests", "!main-distribution" ];
|
var search_terms = { "!main-tests": true, "!main-distribution": true };
|
||||||
|
|
||||||
function addfilterlink ( text, term ) {
|
function addfilterlink ( text, term ) {
|
||||||
return [$('<a>', { text: text,
|
return [$('<a>', { text: text,
|
||||||
href: "javascript:void(0)",
|
href: "javascript:void(0)",
|
||||||
click: function () {
|
click: function () {
|
||||||
search_terms.push(term);
|
search_terms[term] = true;
|
||||||
evaluate_search();
|
evaluate_search();
|
||||||
} } ),
|
} } ),
|
||||||
" "
|
" "
|
||||||
|
@ -22,16 +22,59 @@ $( document ).ready(function() {
|
||||||
return [$('<a>', { text: text,
|
return [$('<a>', { text: text,
|
||||||
href: "javascript:void(0)",
|
href: "javascript:void(0)",
|
||||||
click: function () {
|
click: function () {
|
||||||
search_terms = $.grep( search_terms, function (v) { return v != term } );
|
delete search_terms[term];
|
||||||
evaluate_search();
|
evaluate_search();
|
||||||
} } ),
|
} } ),
|
||||||
" "
|
" "
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
$.getJSON( "/pkgs-all.json", function( resp ) {
|
function evaluate_search () {
|
||||||
|
$.each( $('#packages_table tr'), function (key, dom) {
|
||||||
|
var value = $(dom).data("obj");
|
||||||
|
var show = true;
|
||||||
|
var vterms = value['search-terms'];
|
||||||
|
|
||||||
|
$.each(search_terms,
|
||||||
|
function ( term, termv ) {
|
||||||
|
if ( term.charAt(0) == "!" ) {
|
||||||
|
if ( vterms[term.substring(1)] ) {
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( ! vterms[term] ) {
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( show ) {
|
||||||
|
$(dom).show();
|
||||||
|
} else {
|
||||||
|
$(dom).hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// xxx handle search button
|
||||||
|
|
||||||
|
// xxx update menu available
|
||||||
|
$("#search_menu").html("").append( $.map( search_terms, function ( term, i ) {
|
||||||
|
return removefilterlink ( i, i );
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
$("#packages_table tr:visible:even").removeClass("even");
|
||||||
|
$("#packages_table tr:visible:odd").addClass("even");
|
||||||
|
};
|
||||||
|
|
||||||
|
function object_keys ( o ) {
|
||||||
var names = [];
|
var names = [];
|
||||||
$.each(resp, function(key, value) { names.push(key) });
|
$.each(o, function(key, value) { names.push(key) });
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.getJSON( "/pkgs-all.json", function( resp ) {
|
||||||
|
var names = object_keys(resp);
|
||||||
var snames = names.sort(function(a,b) {
|
var snames = names.sort(function(a,b) {
|
||||||
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
||||||
})
|
})
|
||||||
|
@ -63,54 +106,4 @@ $( document ).ready(function() {
|
||||||
|
|
||||||
evaluate_search();
|
evaluate_search();
|
||||||
});
|
});
|
||||||
|
|
||||||
function evaluate_search_term( value, term ) {
|
|
||||||
if ( term == ":error:") {
|
|
||||||
return value['checksum-error'];
|
|
||||||
} else if ( term == ":no-tag:") {
|
|
||||||
return value['tags'].length == 0;
|
|
||||||
} else if ( term.substring(0, 5) == "ring:") {
|
|
||||||
return value['ring'] == term.substring(5);
|
|
||||||
} else if ( term.substring(0, 7) == "author:") {
|
|
||||||
return ($.inArray( term.substring(7), value['authors'] ) != -1);
|
|
||||||
} else if ( term.charAt(0) == "!" ) {
|
|
||||||
return ! evaluate_search_term( value, term.substring(1) );
|
|
||||||
} else if ( $.inArray( term, value['tags']) != -1 ) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function evaluate_search () {
|
|
||||||
$.each( $('#packages_table tr'), function (key, dom) {
|
|
||||||
var value = $(dom).data("obj");
|
|
||||||
var show = true;
|
|
||||||
|
|
||||||
for (termi in search_terms) {
|
|
||||||
var term = search_terms[termi];
|
|
||||||
if ( ! evaluate_search_term( value, term ) ) {
|
|
||||||
show = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( show ) {
|
|
||||||
$(dom).show();
|
|
||||||
} else {
|
|
||||||
$(dom).hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// xxx handle search button
|
|
||||||
|
|
||||||
// xxx update menu available
|
|
||||||
$("#search_menu").html("").append( $.map( search_terms, function ( term, i ) {
|
|
||||||
return removefilterlink ( term, term );
|
|
||||||
} ) );
|
|
||||||
|
|
||||||
$("#packages_table tr:visible:even").removeClass("even");
|
|
||||||
$("#packages_table tr:visible:odd").addClass("even");
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user