Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Admin: Improve Posts management (#12678)

Damian Legawiec918839ab7cf7
diff --git a/admin/app/controllers/spree/admin/posts_controller.rb b/admin/app/controllers/spree/admin/posts_controller.rb
index 1e714e78da..32fef7f091 100644
--- a/admin/app/controllers/spree/admin/posts_controller.rb
+++ b/admin/app/controllers/spree/admin/posts_controller.rb
@@ -1,6 +1,8 @@
module Spree
module Admin
class PostsController < ResourceController
+ before_action :load_post_categories
+
def select_options
render json: current_store.posts.published.to_tom_select_json
end
@@ -18,6 +20,10 @@ module Spree
@search = @collection.ransack(params[:q])
@collection = @search.result.page(params[:page]).per(params[:per_page])
end
+
+ def load_post_categories
+ @post_categories = current_store.post_categories.accessible_by(current_ability).order(:title)
+ end
end
end
end
diff --git a/admin/app/views/spree/admin/pages/_page.erb b/admin/app/views/spree/admin/pages/_page.erb
deleted file mode 100644
index 946f98fc9a..0000000000
--- a/admin/app/views/spree/admin/pages/_page.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<tr id="<%= dom_id page %>" data-controller="row-link" class="cursor-pointer">
- <td scope="row" data-action="click->row-link#openLink">
- <%= link_to page.name, spree.edit_admin_theme_path(current_store.default_theme, page_id: page.id), data: { row_link_target: :link } %>
- </td>
- <td data-action="click->row-link#openLink">
- <%= local_time_ago(page.updated_at, class: 'with-tip') %>
- </td>
-</tr>
diff --git a/admin/app/views/spree/admin/pages/_page.html.erb b/admin/app/views/spree/admin/pages/_page.html.erb
new file mode 100644
index 0000000000..f793afae4d
--- /dev/null
+++ b/admin/app/views/spree/admin/pages/_page.html.erb
@@ -0,0 +1,26 @@
+<tr id="<%= dom_id page %>" data-controller="row-link" class="cursor-pointer">
+ <td scope="row" data-action="click->row-link#openLink" class="w-60">
+ <%= link_to page.name, spree.edit_admin_theme_path(current_store.default_theme, page_id: page.id), data: { row_link_target: :link } %>
+ </td>
+ <td data-action="click->row-link#openLink" class="w-15">
+ <%= local_time_ago(page.created_at, class: 'with-tip') %>
+ </td>
+ <td data-action="click->row-link#openLink" class="w-15">
+ <%= local_time_ago(page.updated_at, class: 'with-tip') %>
+ </td>
+ <td class="w-10 text-right">
+ <div class="dropdown">
+ <button class="btn btn-sm btn-light" type="button" data-toggle="dropdown" aria-expanded="false">
+ <%= icon('dots-vertical', class: 'mr-0') %>
+ </button>
+ <ul class="dropdown-menu">
+ <li>
+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_theme_path(current_store.default_theme, page_id: page.id), class: 'dropdown-item' %>
+ </li>
+ <li>
+ <%= link_to_delete(page, class: 'dropdown-item btn-danger', icon: 'trash') %>
+ </li>
+ </ul>
+ </div>
+ </td>
+</tr>
diff --git a/admin/app/views/spree/admin/pages/index.html.erb b/admin/app/views/spree/admin/pages/index.html.erb
index 04cedf2c6a..eff30b78de 100644
--- a/admin/app/views/spree/admin/pages/index.html.erb
+++ b/admin/app/views/spree/admin/pages/index.html.erb
@@ -12,8 +12,10 @@
<table class="table">
<thead>
<tr>
- <th><%= Spree.t(:name) %></th>
- <th><%= Spree.t(:updated_at) %></th>
+ <th><%= sort_link @search, :name, Spree.t(:name) %></th>
+ <th><%= sort_link @search, :created_at, Spree.t(:created_at) %></th>
+ <th><%= sort_link @search, :updated_at, Spree.t(:updated_at) %></th>
+ <th></th>
</tr>
</thead>
<tbody>
diff --git a/admin/app/views/spree/admin/post_categories/_post_category.html.erb b/admin/app/views/spree/admin/post_categories/_post_category.html.erb
index a58851a3ca..b9df18cd8c 100644
--- a/admin/app/views/spree/admin/post_categories/_post_category.html.erb
+++ b/admin/app/views/spree/admin/post_categories/_post_category.html.erb
@@ -1,6 +1,9 @@
<tr data-controller="row-link" id="<%= dom_id(post_category) %>">
- <td><%= link_to post_category.title, spree.edit_admin_post_category_path(post_category), class: 'd-flex', data: { row_link_target: :link } %></td>
- <td class="actions cursor-pointer" data-action="click->row-link#openLink">
+ <td class="w-60 p-0">
+ <%= link_to post_category.title, spree.edit_admin_post_category_path(post_category), class: 'd-block w-100 h-100 px-3 py-2', data: { row_link_target: :link } %>
+ </td>
+ <td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= post_category.posts.count %></td>
+ <td class="w-10 cursor-pointer text-right" data-action="click->row-link#openLink">
<%= link_to_edit(post_category, class: 'btn btn-light btn-sm') if can? :edit, post_category %>
</td>
</tr>
diff --git a/admin/app/views/spree/admin/post_categories/index.html.erb b/admin/app/views/spree/admin/post_categories/index.html.erb
index c74356301b..1a24c68906 100644
--- a/admin/app/views/spree/admin/post_categories/index.html.erb
+++ b/admin/app/views/spree/admin/post_categories/index.html.erb
@@ -10,7 +10,8 @@
<table class="table">
<thead>
<tr>
- <th class="w-90"><%= Spree.t(:title) %></th>
+ <th><%= Spree.t(:title) %></th>
+ <th><%= Spree.t(:posts) %></th>
<th></th>
</tr>
</thead>
diff --git a/admin/app/views/spree/admin/posts/_filters.html.erb b/admin/app/views/spree/admin/posts/_filters.html.erb
index 7c56a5d547..f526edbf4f 100644
--- a/admin/app/views/spree/admin/posts/_filters.html.erb
+++ b/admin/app/views/spree/admin/posts/_filters.html.erb
@@ -20,9 +20,9 @@
<div class="form-group">
<%= f.label :post_category_id_eq, Spree.t(:category) %>
<%= f.select :post_category_id_eq,
- options_for_select(Spree::PostCategory.all.pluck(:title, :id), params.dig(:q, :post_category_id_eq)),
+ options_for_select(@post_categories.pluck(:title, :id), params.dig(:q, :post_category_id_eq)),
{ include_blank: true },
- { class: "custom-select", data: { filters_target: :input } } %>
+ { data: { filters_target: :input, controller: 'autocomplete-select' } } %>
</div>
</div>
</div>
diff --git a/admin/app/views/spree/admin/posts/_form.html.erb b/admin/app/views/spree/admin/posts/_form.html.erb
index b3bfaeec05..4c98cd2dd4 100644
--- a/admin/app/views/spree/admin/posts/_form.html.erb
+++ b/admin/app/views/spree/admin/posts/_form.html.erb
@@ -48,12 +48,12 @@
<div class="card-body">
<div class="form-group">
<%= f.label :author_id, Spree.t(:author) %>
- <%= f.select :author_id, options_for_select(post_authors_select_options, @post.author_id || try_spree_current_user.id), {}, { class: 'custom-select' } %>
+ <%= f.select :author_id, options_for_select(post_authors_select_options, @post.author_id || try_spree_current_user.id), {}, { data: { controller: 'autocomplete-select' } } %>
</div>
<div class="form-group">
<%= f.label :post_category_id, Spree.t(:category) %>
- <%= f.select :post_category_id, options_for_select(current_store.post_categories.pluck(:title, :id), @post.post_category_id), { include_blank: true }, { class: 'custom-select' } %>
+ <%= f.select :post_category_id, options_for_select(@post_categories.pluck(:title, :id), @post.post_category_id), { include_blank: true }, { data: { controller: 'autocomplete-select' } } %>
</div>
<div class="form-group">
diff --git a/admin/app/views/spree/admin/posts/index.html.erb b/admin/app/views/spree/admin/posts/index.html.erb
index faea725e0e..ee948b2775 100644
--- a/admin/app/views/spree/admin/posts/index.html.erb
+++ b/admin/app/views/spree/admin/posts/index.html.erb
@@ -13,10 +13,10 @@
<table class="table">
<thead>
<tr>
- <th><%= Spree.t(:title) %></th>
+ <th><%= sort_link @search, :title, Spree.t(:title) %></th>
<th><%= Spree.t(:category) %></th>
<th><%= Spree.t(:author) %></th>
- <th><%= Spree.t(:published_at) %></th>
+ <th><%= sort_link @search, :published_at, Spree.t(:published_at) %></th>
<th></th>
</tr>
</thead>