Make bookmarks sortable by clicks

This commit is contained in:
Arthur Schiwon 2011-08-25 12:55:13 +02:00
parent 55a8ee34bd
commit e0a69bbeac
4 changed files with 53 additions and 3 deletions

View File

@ -50,6 +50,13 @@ if($filterTag){
$offset = isset($_GET['page']) ? intval($_GET['page']) * 10 : 0;
$params[] = $offset;
$sort = isset($_GET['sort']) ? ($_GET['sort']) : 'bookmarks_sorting_recent';
if($sort == 'bookmarks_sorting_clicks') {
$sqlSort = 'clickcount DESC';
} else {
$sqlSort = 'id DESC';
}
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
$_gc_separator = ', \' \'';
} else {
@ -72,7 +79,7 @@ $query = OC_DB::prepare('
AND *PREFIX*bookmarks.user_id = ?
GROUP BY url
'.$sqlFilterTag.'
ORDER BY *PREFIX*bookmarks.id DESC
ORDER BY *PREFIX*bookmarks.'.$sqlSort.'
LIMIT ?, 10');
$bookmarks = $query->execute($params)->fetchAll();

View File

@ -23,6 +23,21 @@
text-decoration: underline;
}
.bookmarks_sorting {
float: left;
margin-left: 2em;
}
.bookmarks_sorting li {
padding: 1ex 1em;
border: 1px solid gray;
-moz-border-radius:1em; -webkit-border-radius:1em; border-radius:1em;
}
.bookmarks_sorting_active {
font-weight: bold;
}
.bookmarks_add {
display: none;
}
@ -65,3 +80,7 @@
.bookmark_tags {
color: #ff3333;
}
.clear {
clear:both;
}

View File

@ -1,6 +1,8 @@
var bookmarks_page = 0;
var bookmarks_loading = false;
var bookmarks_sorting = 'bookmarks_sorting_recent';
$(document).ready(function() {
$('.bookmarks_addBtn').click(function(event){
$('.bookmarks_add').slideToggle();
@ -10,6 +12,9 @@ $(document).ready(function() {
$(window).scroll(updateOnBottom);
$('#bookmark_add_url').focusout(getMetadata);
$('.' + bookmarks_sorting).addClass('bookmarks_sorting_active');
$('.bookmarks_sorting li').click(function(event){changeSorting(this)});
$('.bookmarks_list').empty();
getBookmarks();
@ -20,9 +25,10 @@ function getBookmarks() {
//have patience :)
return;
}
$.ajax({
url: 'ajax/updateList.php',
data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page,
data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
success: function(bookmarks){
bookmarks_page += 1;
$('.bookmark_link').unbind('click', recordClick);
@ -50,6 +56,17 @@ function getMetadata() {
});
}
function changeSorting(sortEl) {
$('.' + bookmarks_sorting).removeClass('bookmarks_sorting_active');
bookmarks_sorting = sortEl.className;
$('.' + bookmarks_sorting).addClass('bookmarks_sorting_active');
$('.bookmarks_list').empty();
bookmarks_page = 0;
bookmarks_loading = false;
getBookmarks();
}
function addBookmark(event) {
var url = encodeEntities($('#bookmark_add_url').val())
var title = encodeEntities($('#bookmark_add_title').val())

View File

@ -12,6 +12,13 @@
<p><label class="bookmarks_label"> </label><label class="bookmarks_hint">Hint: Use space to separate tags.</label></p>
<p><label class="bookmarks_label"></label><input type="submit" id="bookmark_add_submit" /></p>
</div>
<div class="bookmarks_sorting pager">
<ul>
<li class="bookmarks_sorting_recent">Recent Bookmarks</li>
<li class="bookmarks_sorting_clicks">Most clicks</li>
</ul>
</div>
<div class="clear"></div>
<div class="bookmarks_list">
<noscript>
JavaScript is needed to display your Bookmarks