From 7d9b96980ad6c96bc0d7d48345a9ca0af4cf46c5 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 17 Apr 2023 18:29:01 -0300 Subject: [PATCH 1/3] fix: establecer el color por defecto de los botones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit si lo establecemos después de bootstrap, pisamos los colores de los botones --- app/assets/stylesheets/application.scss | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index bba48558..0f848946 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -29,6 +29,11 @@ $sizes: ( "70ch": 70ch, ); +.btn { + background-color: var(--foreground); + color: var(--background); +} + @import "bootstrap"; @import "editor"; @@ -204,8 +209,6 @@ svg { } .btn { - background-color: var(--foreground); - color: var(--background); border: none; border-radius: 0; margin-right: 0.3rem; From 35b79ed9b463cdf555be626c49895e795b39509f Mon Sep 17 00:00:00 2001 From: f Date: Mon, 17 Apr 2023 18:30:21 -0300 Subject: [PATCH 2/3] feat: organizar layouts #13072 --- app/models/layout.rb | 7 ++++++ app/models/site.rb | 1 + app/models/site/layout_ordering.rb | 38 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 app/models/site/layout_ordering.rb diff --git a/app/models/layout.rb b/app/models/layout.rb index c70829fa..efca66ee 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -9,6 +9,13 @@ Layout = Struct.new(:site, :name, :meta, :metadata, keyword_init: true) do name.to_s end + # Obtiene todos los layouts (schemas) dependientes de este. + # + # @return [Array] + def schemas + @schemas ||= site.layouts.to_h.slice(*site.schema_organization[name]).values + end + def attributes @attributes ||= metadata.keys.map(&:to_sym) end diff --git a/app/models/site.rb b/app/models/site.rb index 3f2aa34e..521f298d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -9,6 +9,7 @@ class Site < ApplicationRecord include Site::Api include Site::DeployDependencies include Site::BuildStats + include Site::LayoutOrdering include Tienda # Cifrar la llave privada que cifra y decifra campos ocultos. Sutty diff --git a/app/models/site/layout_ordering.rb b/app/models/site/layout_ordering.rb new file mode 100644 index 00000000..9fecbf21 --- /dev/null +++ b/app/models/site/layout_ordering.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class Site + # Obtiene un listado de layouts (schemas) + module LayoutOrdering + extend ActiveSupport::Concern + + included do + + # Obtiene o genera un listado de layouts (schemas) con sus + # dependencias, para poder generar un árbol. + # + # Por defecto, si el sitio no lo soporta, se obtienen los layouts + # ordenados alfabéticamente por traducción. + # + # @return [Hash] + def schema_organization + @schema_organization ||= + begin + schema_organization = data.dig('schema', 'organization') + schema_organization&.symbolize_keys! + schema_organization&.transform_values! do |ary| + ary.map(&:to_sym) + end + + schema_organization || + begin + layouts = self.layouts.sort_by(&:humanized_name).map(&:name) + Hash[layouts.zip([].fill([], 0, layouts.size))] + end + end + end + + # TODO: Deprecar cuando renombremos layouts a schemas + alias layout_organization schema_organization + end + end +end From 5c976377387d62bf515bb6d4cbf103029984b780 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 17 Apr 2023 18:31:51 -0300 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20mostrar=20la=20lista=20de=20art?= =?UTF-8?q?=C3=ADculos=20organizada=20#13072?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/posts/index.haml | 16 ++++++---------- app/views/schemas/_add.haml | 1 + app/views/schemas/_filter.haml | 4 ++++ app/views/schemas/_row.haml | 12 ++++++++++++ config/locales/en.yml | 8 +++++--- config/locales/es.yml | 9 ++++++--- 6 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 app/views/schemas/_add.haml create mode 100644 app/views/schemas/_filter.haml create mode 100644 app/views/schemas/_row.haml diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 4f814cda..cbc67a60 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -6,16 +6,12 @@ = render 'sites/status', site: @site %h3= t('posts.new') - %table.mb-3 - - @site.layouts.sort_by(&:humanized_name).each do |layout| - - next if layout.hidden? - %tr - %th= layout.humanized_name - %td.pl-3= link_to t('posts.add'), new_site_post_path(@site, layout: layout.value), class: 'btn btn-secondary btn-sm' - - if @filter_params[:layout] == layout.name.to_s - %td= link_to t('posts.remove_filter'), site_posts_path(@site, **@filter_params.merge(layout: nil)), class: 'btn btn-primary btn-sm' - - else - %td= link_to t('posts.filter'), site_posts_path(@site, **@filter_params.merge(layout: layout.value)), class: 'btn btn-secondary btn-sm' + %table.table.table-sm.mb-3 + %tbody + - @site.schema_organization.each do |schema, _| + - schema = @site.layouts[schema] + - next if schema.hidden? + = render 'schemas/row', site: @site, schema: schema, filter: @filter_params - if policy(@site_stat).index? = link_to t('stats.index.title'), site_stats_path(@site), class: 'btn' diff --git a/app/views/schemas/_add.haml b/app/views/schemas/_add.haml new file mode 100644 index 00000000..0131a6bb --- /dev/null +++ b/app/views/schemas/_add.haml @@ -0,0 +1 @@ += link_to t('.add'), new_site_post_path(site, layout: schema.value), class: 'btn btn-secondary btn-sm m-0' diff --git a/app/views/schemas/_filter.haml b/app/views/schemas/_filter.haml new file mode 100644 index 00000000..c422c5b8 --- /dev/null +++ b/app/views/schemas/_filter.haml @@ -0,0 +1,4 @@ +- if filter[:layout] == schema.name.to_s + = link_to t('.remove'), site_posts_path(site, **filter.merge(layout: nil)), class: 'btn btn-primary btn-sm m-0' +- else + = link_to t('.filter'), site_posts_path(site, **filter.merge(layout: schema.value)), class: 'btn btn-secondary btn-sm m-0' diff --git a/app/views/schemas/_row.haml b/app/views/schemas/_row.haml new file mode 100644 index 00000000..9a759fd9 --- /dev/null +++ b/app/views/schemas/_row.haml @@ -0,0 +1,12 @@ +%tr + %th{ scope: 'row' } + - if local_assigns[:parent_schema] + %span.text-muted — + = schema.humanized_name + %td.px-0= render 'schemas/add', **local_assigns + %td.px-0= render 'schemas/filter', **local_assigns + +-# XXX: Solo un nivel de recursividad +- unless local_assigns[:parent_schema] + - schema.schemas.each do |s| + = render 'schemas/row', schema: s, site: site, filter: filter, parent_schema: schema diff --git a/config/locales/en.yml b/config/locales/en.yml index 3ddf681d..5da5fe4f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -539,9 +539,6 @@ en: order: 'Order' content: 'Text' new: 'Post types' - add: 'Add' - filter: 'Filter' - remove_filter: 'Back' remove_filter_help: 'Remove the filter: %{filter}' categories: 'Everything' index: 'Posts' @@ -697,3 +694,8 @@ en: queries: show: empty: '(empty)' + schemas: + add: 'Add' + filter: + filter: 'Filter' + remove: 'Back' diff --git a/config/locales/es.yml b/config/locales/es.yml index 01f1085c..829e0ccc 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -548,9 +548,6 @@ es: content: 'Cuerpo del artículo' categories: 'Todos' new: 'Tipos de artículos' - add: 'Agregar' - filter: 'Filtrar' - remove_filter: 'Volver' remove_filter_help: 'Quitar este filtro: %{filter}' index: 'Artículos' edit: 'Editar' @@ -705,3 +702,9 @@ es: queries: show: empty: '(vacío)' + schemas: + add: + add: 'Agregar' + filter: + filter: 'Filtrar' + remove: 'Volver'