mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Allow basic sorting by tag.
This commit is contained in:
@@ -27,6 +27,7 @@ class PinResource(ModelResource): # pylint: disable-msg=R0904
|
||||
|
||||
if 'tag' in filters:
|
||||
orm_filters['tags__name__in'] = filters['tag'].split(',')
|
||||
|
||||
return orm_filters
|
||||
|
||||
def dehydrate_tags(self, bundle):
|
||||
|
||||
@@ -59,6 +59,15 @@ body {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.tags {
|
||||
padding: 13px 0;
|
||||
}
|
||||
|
||||
.tag {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#pins {
|
||||
top: 70px;
|
||||
position: absolute;
|
||||
|
||||
@@ -1,99 +1,112 @@
|
||||
/**
|
||||
* Based on Wookmark's endless scroll.
|
||||
*/
|
||||
$(window).ready(function () {
|
||||
var apiURL = '/api/pin/?format=json&offset='
|
||||
var page = 0;
|
||||
var handler = null;
|
||||
var isLoading = false;
|
||||
var apiURL = '/api/pin/?format=json&offset='
|
||||
var page = 0;
|
||||
var handler = null;
|
||||
var globalTag = null;
|
||||
var isLoading = false;
|
||||
|
||||
/**
|
||||
* When scrolled all the way to the bottom, add more tiles.
|
||||
*/
|
||||
function onScroll(event) {
|
||||
if(!isLoading) {
|
||||
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height() - 100);
|
||||
if(closeToBottom) loadData();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* When scrolled all the way to the bottom, add more tiles.
|
||||
*/
|
||||
function onScroll(event) {
|
||||
if(!isLoading) {
|
||||
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height() - 100);
|
||||
if(closeToBottom) loadData();
|
||||
}
|
||||
};
|
||||
|
||||
function applyLayout() {
|
||||
$('#pins').imagesLoaded(function() {
|
||||
// Clear our previous layout handler.
|
||||
if(handler) handler.wookmarkClear();
|
||||
function applyLayout() {
|
||||
$('#pins').imagesLoaded(function() {
|
||||
// Clear our previous layout handler.
|
||||
if(handler) handler.wookmarkClear();
|
||||
|
||||
// Create a new layout handler.
|
||||
handler = $('#pins .pin');
|
||||
handler.wookmark({
|
||||
autoResize: true,
|
||||
offset: 3,
|
||||
itemWidth: 242
|
||||
});
|
||||
// Create a new layout handler.
|
||||
handler = $('#pins .pin');
|
||||
handler.wookmark({
|
||||
autoResize: true,
|
||||
offset: 3,
|
||||
itemWidth: 242
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads data from the API.
|
||||
*/
|
||||
function loadData() {
|
||||
isLoading = true;
|
||||
$('#loader').show();
|
||||
/**
|
||||
* Loads data from the API.
|
||||
*/
|
||||
function loadData(tag) {
|
||||
isLoading = true;
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
url: apiURL+(page*20),
|
||||
success: onLoadData
|
||||
});
|
||||
};
|
||||
if (tag !== undefined) {
|
||||
globalTag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives data from the API, creates HTML for images and updates the layout
|
||||
*/
|
||||
function onLoadData(data) {
|
||||
data = data.objects;
|
||||
isLoading = false;
|
||||
$('#loader').hide();
|
||||
if (tag !== undefined && page != 0) {
|
||||
$('#pins').html('');
|
||||
page = 0;
|
||||
if (tag != null) $('.tags').html('<span class="label tag" onclick="loadData(null)">' + tag + ' x</span>');
|
||||
else $('.tags').html('');
|
||||
}
|
||||
|
||||
page++;
|
||||
var loadURL = apiURL+(page*20);
|
||||
if (globalTag !== null) loadURL += "&tag=" + tag;
|
||||
|
||||
var html = '';
|
||||
var i=0, length=data.length, image;
|
||||
for(; i<length; i++) {
|
||||
image = data[i];
|
||||
html += '<div class="pin">';
|
||||
html += '<div class="pin-options">';
|
||||
html += '<a href="/pins/delete-pin/'+image.id+'">';
|
||||
html += '<i class="icon-trash"></i>';
|
||||
html += '</a>';
|
||||
html += '</div>';
|
||||
html += '<a class="fancybox" rel="pins" href="'+image.image+'">';
|
||||
html += '<img src="'+image.thumbnail+'" width="200" >';
|
||||
$.ajax({
|
||||
url: loadURL,
|
||||
success: onLoadData
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Receives data from the API, creates HTML for images and updates the layout
|
||||
*/
|
||||
function onLoadData(data) {
|
||||
data = data.objects;
|
||||
isLoading = false;
|
||||
$('#loader').hide();
|
||||
|
||||
page++;
|
||||
|
||||
var html = '';
|
||||
var i=0, length=data.length, image;
|
||||
for(; i<length; i++) {
|
||||
image = data[i];
|
||||
html += '<div class="pin">';
|
||||
html += '<div class="pin-options">';
|
||||
html += '<a href="/pins/delete-pin/'+image.id+'">';
|
||||
html += '<i class="icon-trash"></i>';
|
||||
html += '</a>';
|
||||
if (image.description) html += '<p>'+image.description+'</p>';
|
||||
if (image.tags) {
|
||||
html += '<p>';
|
||||
for (tag in image.tags) {
|
||||
html += image.tags[tag] + ', ';
|
||||
}
|
||||
html += '</p>';
|
||||
}
|
||||
html += '</div>';
|
||||
}
|
||||
html += '<a class="fancybox" rel="pins" href="'+image.image+'">';
|
||||
html += '<img src="'+image.thumbnail+'" width="200" >';
|
||||
html += '</a>';
|
||||
if (image.description) html += '<p>'+image.description+'</p>';
|
||||
if (image.tags) {
|
||||
html += '<p>';
|
||||
for (tag in image.tags) {
|
||||
html += '<span class="label tag" onclick="loadData(\'' + image.tags[tag] + '\')">' + image.tags[tag] + '</span> ';
|
||||
}
|
||||
html += '</p>';
|
||||
}
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
$('#pins').append(html);
|
||||
$('#pins').append(html);
|
||||
|
||||
applyLayout();
|
||||
};
|
||||
applyLayout();
|
||||
};
|
||||
|
||||
$(document).ready(new function() {
|
||||
$(document).bind('scroll', onScroll);
|
||||
loadData();
|
||||
});
|
||||
|
||||
/**
|
||||
* On clicking an image show fancybox original.
|
||||
*/
|
||||
$('.fancybox').fancybox({
|
||||
openEffect: 'none',
|
||||
closeEffect: 'none'
|
||||
});
|
||||
$(document).ready(new function() {
|
||||
$(document).bind('scroll', onScroll);
|
||||
loadData();
|
||||
});
|
||||
|
||||
/**
|
||||
* On clicking an image show fancybox original.
|
||||
*/
|
||||
$('.fancybox').fancybox({
|
||||
openEffect: 'none',
|
||||
closeEffect: 'none'
|
||||
});
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
<body>
|
||||
<div class="navbar navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<a href="{% url core:home %}" class="brand">{{ site_name }}</a>
|
||||
<a href="{% url core:home %}" class="brand pull-left">{{ site_name }}</a>
|
||||
|
||||
<div class="tags pull-left"></div>
|
||||
|
||||
<ul class="nav pull-right">
|
||||
{% if user.is_authenticated %}
|
||||
|
||||
Reference in New Issue
Block a user