Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout parts split in different sections #1307

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/spina/admin/layout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class LayoutController < AdminController
before_action :set_account
before_action :set_locale
before_action :set_breadcrumb
before_action :get_layout_parts

admin_section :content

Expand All @@ -24,6 +25,11 @@ def update
def layout_params
params.require(:account).permit!
end

def get_layout_parts
@layout_parts = Spina::Current.theme.layout_parts
@layout_parts = {parts: @layout_parts} if @layout_parts.is_a?(Array)
end

def set_breadcrumb
add_breadcrumb t("spina.layout.layout")
Expand Down
67 changes: 38 additions & 29 deletions app/views/spina/admin/layout/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
<%= render Spina::UserInterface::HeaderComponent.new do |header| %>
<% header.with_actions do %>
<%= render Spina::UserInterface::TranslationsComponent.new(@account, label: @locale.upcase) %>

<% if Spina::Current.theme.layout_parts.any? %>
<div data-controller="tabs" data-tabs-active="cursor-default text-gray-900 bg-spina-dark bg-opacity-10" data-tabs-inactive="cursor-pointer bg-transparent text-gray-400 border-transparent">
<%= render Spina::UserInterface::HeaderComponent.new do |header| %>
<% header.with_actions do %>
<%= render Spina::UserInterface::TranslationsComponent.new(@account, label: @locale.upcase) %>

<%= button_tag type: :submit, form: dom_id(@account), class: 'btn btn-primary', data: {controller: "button hotkeys", hotkeys: "command+s, ctrl+s", hotkeys_target: "button", action: "button#loading", loading_message: t('spina.ui.saving')} do %>
<%= heroicon('check', style: :mini, class: 'w-5 h-5 -ml-1 mr-1') %>
<%=t 'spina.layout.save' %>
<% end %>
<% end %>

<% header.with_navigation do %>
<nav class="-mb-3 mt-4" <%= 'hidden' unless @layout_parts.keys.many? %>>
<ul class="inline-flex w-auto rounded-md bg-white">
<% @layout_parts.keys.each do |key| %>
<%= render Spina::Pages::TabButtonComponent.new(tab_name: key) do %>
<%=t "spina.layout.sections.#{key}" %>
<% end %>
<% end %>
</ul>
</nav>
<% end %>
<% end %>
<% end %>

<%= form_with model: @account, url: spina.admin_layout_path, id: dom_id(@account) do |f| %>
<%= hidden_field_tag :locale, @locale %>

<div class="py-4 p-8">
<% if Spina::Current.theme.layout_parts.any? %>

<div class="max-w-5xl">
<%= f.fields_for "#{@locale}_content".to_sym, build_parts(f.object, Spina::Current.theme.layout_parts) do |ff| %>
<%= ff.hidden_field :type, value: ff.object.class %>
<%= ff.hidden_field :name %>
<%= ff.hidden_field :title %>

<%= form_with model: @account, url: spina.admin_layout_path, id: dom_id(@account) do |f| %>
<%= hidden_field_tag :locale, @locale %>

<div class="py-4 p-8">
<% @layout_parts.keys.each.with_index do |key, index| %>
<div data-tabs-target="pane" id="<%= key %>">
<div class="max-w-5xl">
<%= f.fields_for "#{@locale}_content".to_sym, build_parts(f.object, @layout_parts[key]) do |ff| %>
<%= ff.hidden_field :type, value: ff.object.class %>
<%= ff.hidden_field :name %>
<%= ff.hidden_field :title %>

<%= render "spina/admin/parts/#{parts_partial_namespace(ff.object.class.to_s)}/form", f: ff %>
<% end %>
</div>
</div>
<% end %>
</div>

<%= render "spina/admin/parts/#{parts_partial_namespace(ff.object.class.to_s)}/form", f: ff %>
<% end %>
</div>
<% else %>
<div class="text-gray-500 italic">
<%=t 'spina.layout.no_layout_parts' %>
</div>
<% end %>
</div>

<% end %>
<% end %>
</div>
6 changes: 4 additions & 2 deletions app/views/spina/admin/shared/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
<%= render Spina::MainNavigation::LinkComponent.new t('spina.website.pages'), spina.admin_pages_path, active: controller_name.in?(%w(pages resources)) %>

<%= render Spina::MainNavigation::LinkComponent.new t('spina.navigations.navigations'), spina.admin_navigations_path, active: controller_name == "navigations" %>

<%= render Spina::MainNavigation::LinkComponent.new t('spina.layout.layout'), spina.edit_admin_layout_path, active: controller_name == "layout" %>

<% if Spina::Current.theme.layout_parts.present? %>
<%= render Spina::MainNavigation::LinkComponent.new t('spina.layout.layout'), spina.edit_admin_layout_path, active: controller_name == "layout" %>
<% end %>

<%= render Spina::MainNavigation::LinkComponent.new t('spina.website.media_library'), spina.admin_images_path, active: controller_name.in?(%w(images media_folders attachments)) %>

Expand Down
Loading