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) {
// Al soltar, reordenamos toda la tabla
$('.post_order').val(function(i,v) { return i; });
$('.reorder-posts-panel')
.addClass('d-block')
.removeClass('d-none');
// Mostramos el nuevo orden también
$('.order.is').text(function(i,v) { return i; });
// 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

View file

@ -6,6 +6,12 @@ class PostsController < ApplicationController
@site = find_site
@category = session[:category] = params.dig(:category)
@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
def show

View file

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

View file

@ -20,6 +20,16 @@
.col
= render 'layouts/flash'
- 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
= hidden_field 'posts', 'lang', value: @lang
.reorder-posts-panel.alert.alert-info.alert-dismissible.fade.show{role: 'alert'}
@ -38,10 +48,15 @@
- next unless post.categories.include?(@category)
-# establecer la direccion del texto
- direction = post.get_front_matter(:dir)
- order = post.order || i
%tr
%td
= 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}
= link_to post.title, site_post_path(@site, post, lang: @lang)

View file

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

View file

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