ordenar por fecha o numero de orden

This commit is contained in:
f 2018-04-30 17:50:29 -03:00
parent 7a601a7b31
commit 443807b772
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
6 changed files with 51 additions and 4 deletions

View file

@ -6,9 +6,24 @@ $(document).on('turbolinks:load', function() {
}).on('drop', function(from, to, el, mode) { }).on('drop', function(from, to, el, mode) {
// Al soltar, reordenamos toda la tabla // Al soltar, reordenamos toda la tabla
$('.post_order').val(function(i,v) { return i; }); $('.post_order').val(function(i,v) { return i; });
$('.reorder-posts-panel') // Mostramos el nuevo orden también
.addClass('d-block') $('.order.is').text(function(i,v) { return i; });
.removeClass('d-none'); // Solo mostramos el valor anterior si no coincide con el valor
// actual. Como lo mostramos entre comillas, usamos el atributo
// data-order del <span>
$('.order.was').each(function() {
var el = $(this);
var is = el.parent().find('.order.is');
if (is.text() == el.data('order')) {
el.addClass('d-none');
} else {
el.removeClass('d-none');
}
});
// Muestra el panel
$('.reorder-posts-panel').addClass('d-block').removeClass('d-none');
}); });
// Ocultar el panel de ayuda con botón // Ocultar el panel de ayuda con botón

View file

@ -6,6 +6,12 @@ class PostsController < ApplicationController
@site = find_site @site = find_site
@category = session[:category] = params.dig(:category) @category = session[:category] = params.dig(:category)
@posts = @site.posts_for(@lang) @posts = @site.posts_for(@lang)
if params[:sort_by].present?
@posts.sort_by! do |p|
p.send(params[:sort_by].to_s)
end
end
end end
def show def show

View file

@ -43,4 +43,5 @@ class SitesController < ApplicationController
redirect_to site_posts_path @site redirect_to site_posts_path @site
end end
end end

View file

@ -20,6 +20,16 @@
.col .col
= render 'layouts/flash' = render 'layouts/flash'
- if @posts.present? - if @posts.present?
.row
.col
%small.pull-right
= t('posts.sort.by')
- %w[order date].each do |s|
= link_to t("posts.sort.#{s}"),
site_posts_path(@site,
category: @category,
lang: @lang,
sort_by: s)
= form_tag site_reorder_posts_path, method: :post do = form_tag site_reorder_posts_path, method: :post do
= hidden_field 'posts', 'lang', value: @lang = hidden_field 'posts', 'lang', value: @lang
.reorder-posts-panel.alert.alert-info.alert-dismissible.fade.show{role: 'alert'} .reorder-posts-panel.alert.alert-info.alert-dismissible.fade.show{role: 'alert'}
@ -38,10 +48,15 @@
- next unless post.categories.include?(@category) - next unless post.categories.include?(@category)
-# establecer la direccion del texto -# establecer la direccion del texto
- direction = post.get_front_matter(:dir) - direction = post.get_front_matter(:dir)
- order = post.order || i
%tr %tr
%td %td
= fa_icon 'arrows-v', class: 'handle' = fa_icon 'arrows-v', class: 'handle'
= hidden_field 'posts[order]', i, value: post.order || i, class: 'post_order' = hidden_field 'posts[order]', i, value: order, class: 'post_order'
%small
%br
%span.order.is= order
%span.order.was.d-none{data: { order: order }}= "(#{order})"
%td{class: direction} %td{class: direction}
= link_to post.title, site_post_path(@site, post, lang: @lang) = link_to post.title, site_post_path(@site, post, lang: @lang)

View file

@ -137,6 +137,11 @@ en:
ar: 'Arabic' ar: 'Arabic'
posts: posts:
reorder_posts: 'Reorder posts' reorder_posts: 'Reorder posts'
sort:
by: 'Sort by'
order: 'order'
date: 'date'
order: 'Order'
new: 'New post' new: 'New post'
index: 'Posts' index: 'Posts'
edit: 'Edit' edit: 'Edit'

View file

@ -139,6 +139,11 @@ es:
ar: 'árabe' ar: 'árabe'
posts: posts:
reorder_posts: 'Reordenar artículos' reorder_posts: 'Reordenar artículos'
sort:
by: 'Ordenar por'
order: 'posición'
date: 'fecha'
order: 'Posición'
new: 'Empezar un artículo nuevo' new: 'Empezar un artículo nuevo'
index: 'Artículos' index: 'Artículos'
edit: 'Editar' edit: 'Editar'