This commit is contained in:
Jay McCarthy 2013-10-08 07:13:25 -06:00
parent ecfc9dc968
commit 621feae15b
4 changed files with 74 additions and 58 deletions

View File

@ -21,10 +21,8 @@
(convert-to-json v)))] (convert-to-json v)))]
[(? number? n) [(? number? n)
n] n]
[#f [(? boolean? b)
#f] b]
[#t
#t]
[(? symbol? s) [(? symbol? s)
(symbol->string s)] (symbol->string s)]
[(? keyword? s) [(? keyword? s)

View File

@ -14,9 +14,7 @@
<span id="logout">jay.mccarthy@gmail.com | <a href="/curate">curate</a> | <a href="/rss">rss</a> | <a href="/account/login">re-login</a> | <a href="/account/logout">logout</a></span> <span id="logout">jay.mccarthy@gmail.com | <a href="/curate">curate</a> | <a href="/rss">rss</a> | <a href="/account/login">re-login</a> | <a href="/account/logout">logout</a></span>
</div> </div>
<div id="menu"><form action="/query/search/!main-distribution/!main-tests"> <div id="menu"><span class="menu_option"><a href="/manage">Manage Your Packages</a></span>
<span class="menu_option"><input name="input_0" type="text"><input type="submit" value="Search"></span><span class="menu_option"><a href="/manage">Manage
Your Packages</a></span>
</form></div> </form></div>
<p id="search_menu"></p> <p id="search_menu"></p>
<table class="packages sortable"> <table class="packages sortable">

View File

@ -8,28 +8,30 @@
$( document ).ready(function() { $( document ).ready(function() {
var search_terms = { "!main-tests": true, "!main-distribution": true }; var search_terms = { "!main-tests": true, "!main-distribution": true };
function addfilterlink ( text, term ) { function filterlink ( text, tclass, f ) {
return [$('<a>', { text: text, return [$('<a>', { text: text,
class: tclass,
href: "javascript:void(0)", href: "javascript:void(0)",
click: function () { click: f } ),
" " ]; };
function addfilterlink ( text, term, tclass ) {
return filterlink( text, tclass, function () {
search_terms[term] = true; search_terms[term] = true;
evaluate_search(); evaluate_search(); } ); };
} } ), function removefilterlink ( text, term, tclass ) {
" " return filterlink( text, tclass, function () {
];
};
function removefilterlink ( text, term ) {
return [$('<a>', { text: text,
href: "javascript:void(0)",
click: function () {
delete search_terms[term]; delete search_terms[term];
evaluate_search(); evaluate_search(); } ); };
} } ), function changefilterlink ( text, term, nterm, tclass ) {
" " return filterlink( text, tclass, function () {
]; delete search_terms[term];
}; search_terms["!" + term] = true;
evaluate_search(); } ); };
function evaluate_search () { function evaluate_search () {
var shown_terms = {};
$.each( $('#packages_table tr'), function (key, dom) { $.each( $('#packages_table tr'), function (key, dom) {
var value = $(dom).data("obj"); var value = $(dom).data("obj");
var show = true; var show = true;
@ -39,45 +41,58 @@ $( document ).ready(function() {
function ( term, termv ) { function ( term, termv ) {
if ( term.charAt(0) == "!" ) { if ( term.charAt(0) == "!" ) {
if ( vterms[term.substring(1)] ) { if ( vterms[term.substring(1)] ) {
show = false; show = false; } }
} else {
} else {
if ( ! vterms[term] ) { if ( ! vterms[term] ) {
show = false; show = false; } } });
}
}
});
if ( show ) { if ( show ) {
$(dom).show(); $(dom).show();
} else {
$(dom).hide();
}
}); $.each(vterms, function ( term, termv ) {
if ( term.substring(0,7) != "author:") { shown_terms[term]++; } }); }
else {
$(dom).hide(); } });
$.each(search_terms,
function ( term, termv ) {
if ( term.charAt(0) == "!" ) {
shown_terms[ term.substring(1) ] = -2; }
else {
shown_terms[ term ] = -1; } });
// xxx handle search button // xxx handle search button
// xxx update menu available var shown_terms_keys = object_keys(shown_terms);
$("#search_menu").html("").append( $.map( search_terms, function ( term, i ) { var shown_terms_skeys = shown_terms_keys.sort(function(a,b) {
return removefilterlink ( i, i ); var va = shown_terms[a];
} ) ); var vb = shown_terms[b];
if ( va < 0 && vb < 0 ) { return ((a < b) ? -1 : ((a > b) ? 1 : 0)); }
else if ( va >= 0 && vb >= 0 ) { return ((va < vb) ? -1 : ((va > vb) ? 1 : 0)); }
else if ( va < 0 ) { return -1; }
else if ( vb < 0 ) { return 1; } });
$("#search_menu").html("").append( $.map( shown_terms_skeys, function ( term, i ) {
if ( shown_terms[term] < 0 ) {
if ( shown_terms[term] == -1 ) {
return changefilterlink ( term, term, "!" + term, "active" ); }
else {
return removefilterlink ( term, "!" + term, "inactive" ); } }
else {
return addfilterlink ( term, term, "possible" ); } } ) );
$("#packages_table tr:visible:even").removeClass("even"); $("#packages_table tr:visible:even").removeClass("even");
$("#packages_table tr:visible:odd").addClass("even"); $("#packages_table tr:visible:odd").addClass("even"); };
};
function object_keys ( o ) { function object_keys ( o ) {
var names = []; var names = [];
$.each(o, function(key, value) { names.push(key) }); $.each(o, function(key, value) { names.push(key) });
return names; return names; }
}
$.getJSON( "/pkgs-all.json", function( resp ) { $.getJSON( "/pkgs-all.json", function( resp ) {
var names = object_keys(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)); })
})
var now = new Date().getTime() / 1000; var now = new Date().getTime() / 1000;
@ -87,23 +102,19 @@ $( document ).ready(function() {
var value = resp[name]; var value = resp[name];
$('<tr>', $('<tr>',
{ class: ((now - (60*60*24*2)) < value['last-updated'] ? "recent" : "old") }). { class: ((now - (60*60*24*2)) < value['last-updated'] ? "recent" : "old") })
data( "obj", value).append( .data( "obj", value)
.append(
$('<td>').html( $('<a>', { text: value['name'], $('<td>').html( $('<a>', { text: value['name'],
href: "javascript:void(0)", href: "javascript:void(0)",
click: function () { click: function () {
// XXX open up a subwindow // XXX open up a subwindow
console.log(value); console.log(value); } } ) ),
} } ) ),
$('<td>').append( $.map( value['authors'], function ( author, i ) { $('<td>').append( $.map( value['authors'], function ( author, i ) {
return addfilterlink ( author, "author:" + author ); return addfilterlink ( author, "author:" + author, "possible" ); } ) ),
} ) ),
$('<td>').text( value['description'] ), $('<td>').text( value['description'] ),
$('<td>').append( $.map( value['tags'], function ( tag, i ) { $('<td>').append( $.map( value['tags'], function ( tag, i ) {
return addfilterlink ( tag, tag ); return addfilterlink ( tag, tag, "possible" ); } ) ))
} ) )).appendTo('#packages_table'); .appendTo('#packages_table'); });
});
evaluate_search(); evaluate_search(); }); });
});
});

View File

@ -143,3 +143,12 @@ div.install {
background: rgb(90%, 70%, 70%); background: rgb(90%, 70%, 70%);
} }
a.active {
font-weight: bold;
}
a.inactive {
font-weight: bold;
text-decoration: line-through;
}
a.possible {
}