5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 17:46:21 +00:00
panel/app/views/posts/index.haml
2020-12-24 16:25:45 -03:00

128 lines
5.9 KiB
Text

= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
@site.name,
link_to(t('posts.index'),
site_posts_path(@site)),
@category_name]
%main.row
%aside.menu.col-md-3
%h1= link_to @site.title, @site.url
%p.lead= @site.description
%h3= t('posts.new')
%table.mb-3
- @site.layouts.each do |layout|
- next if layout.hidden?
- filter = params[:layout] == layout.value
%tr
%th= layout.humanized_name
%td.pl-3= link_to t('posts.add'),
new_site_post_path(@site, layout: layout.name),
class: 'badge badge-secondary'
%td= link_to t(filter ? 'posts.remove_filter' : 'posts.filter'),
site_posts_path(@site, layout: (filter ? nil : layout.value)),
class: 'badge badge-' + (filter ? 'primary' : 'secondary')
- if policy(@site).edit?
= link_to t('sites.edit.btn', site: @site.title), edit_site_path(@site), class: 'btn'
- if policy(@site).private?
= link_to t('sites.private'), '../private/' + @site.name, class: 'btn', target: '_blank', rel: 'noopener'
- if policy(SiteUsuarie.new(@site, current_usuarie)).index?
= render 'layouts/btn_with_tooltip',
tooltip: t('usuaries.index.help.self'),
text: t('usuaries.index.title'),
type: 'info',
link: site_usuaries_path(@site)
= render 'sites/build', site: @site
- if @site.design.credits
.alert.alert-primary{ role: 'alert' }
= sanitize_markdown @site.design.credits
= link_to t('sites.donations.text'), t('sites.donations.url'), class: 'btn'
- if @site.design.designer_url
= link_to t('sites.designer_url'), @site.design.designer_url, class: 'btn'
%section.col
= render 'layouts/flash'
- if @posts.empty?
%h2= t('posts.none')
- else
= form_tag site_posts_reorder_path, method: :post do
.d-flex.justify-content-between.align-items-center
-#
TODO: Pensar una interfaz mejor para cuando haya más de tres
idiomas
- unless @site.locales.length == 1
.locales
- @site.locales.each do |locale|
= link_to t("locales.#{locale}.name"), site_posts_path(@site, locale: locale),
class: "mr-2 mt-2 mb-2#{locale == @locale ? 'active font-weight-bold' : ''}"
%table.table{ data: { controller: 'reorder' } }
%caption.sr-only= t('posts.caption')
%thead
%tr
%th.border-0.background-white.position-sticky{ style: 'top: 0; z-index: 2', colspan: '4' }
= submit_tag t('posts.reorder.submit'), class: 'btn'
%button.btn{ data: { action: 'reorder#unselect' } }
= t('posts.reorder.unselect')
%span.badge{ data: { target: 'reorder.counter' } } 0
%button.btn{ data: { action: 'reorder#up' } }= t('posts.reorder.up')
%button.btn{ data: { action: 'reorder#down' } }= t('posts.reorder.down')
%button.btn{ data: { action: 'reorder#top' } }= t('posts.reorder.top')
%button.btn{ data: { action: 'reorder#bottom' } }= t('posts.reorder.bottom')
%tbody
- dir = t("locales.#{@locale}.dir")
- @posts.each_with_index do |post, i|
-#
TODO: Solo les usuaries cachean porque tenemos que separar
les botones por permisos.
TODO: Verificar qué pasa cuando se gestiona el sitio en
distintos idiomas a la vez
- cache_if @usuarie, post do
- checkbox_id = "checkbox-#{post.uuid.value}"
%tr{ id: post.uuid.value, data: { target: 'reorder.row' } }
%td
.custom-control.custom-checkbox
%input.custom-control-input{ id: checkbox_id, type: 'checkbox', autocomplete: 'off', data: { action: 'reorder#select' } }
%label.custom-control-label{ for: checkbox_id }
%span.sr-only= t('posts.reorder.select')
-# Orden más alto es mayor prioridad
= hidden_field 'post[reorder]', post.uuid.value,
value: @posts.length - i,
data: { reorder: true }
%td.w-100{ class: dir }
= link_to site_post_path(@site, post.id) do
%span{ lang: post.lang.value, dir: dir }= post.title.value
- if post.attributes.include? :draft
- if post.draft.value
%span.badge.badge-primary
= post_label_t(:draft, post: post)
- if post.attributes.include? :categories
- unless post.categories.value.empty?
%br
%small
- (post.categories.respond_to?(:belongs_to) ? post.categories.belongs_to : post.categories.value).each do |c|
= link_to site_posts_path(@site, category: (c.respond_to?(:uuid) ? c.uuid.value : c)) do
%span{ lang: post.lang.value, dir: dir }= (c.respond_to?(:title) ? c.title.value : c)
%td
= post.date.value.strftime('%F')
%br/
- if post.attribute? :order
= post.order.value
%td
- if @usuarie || policy(post).edit?
= link_to t('posts.edit'),
edit_site_post_path(@site, post.id),
class: 'btn btn-block'
- if @usuarie || policy(post).destroy?
= link_to t('posts.destroy'),
site_post_path(@site, post.id),
class: 'btn btn-block',
method: :delete,
data: { confirm: t('posts.confirm_destroy') }