-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version adds support for drag-and-drop. Styling needs more work.
- Loading branch information
Showing
14 changed files
with
387 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/assets/stylesheets/koi/components/index-table/_ordinal.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
$width: 2rem !default; | ||
|
||
.index-table { | ||
th.ordinal { | ||
width: $width; | ||
padding-left: 0; | ||
a { | ||
width: $width; | ||
height: 3rem; | ||
} | ||
a::after { | ||
right: 0; | ||
} | ||
} | ||
|
||
td.ordinal { | ||
width: $width; | ||
padding-left: 0; | ||
cursor: grab; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
class OrdinalTableComponent < Katalyst::Turbo::TableComponent | ||
include Katalyst::Tables::Orderable | ||
|
||
def initialize(collection:, | ||
id: "index-table", | ||
url: [:order, :admin, collection], | ||
scope: "order[#{collection.model_name.plural}]", | ||
**options) | ||
super(collection:, id:, class: "index-table", caption: true, **options) | ||
|
||
@url = url | ||
@scope = scope | ||
end | ||
|
||
def before_render | ||
with_orderable(url: @url, scope: @scope) unless orderable? | ||
end | ||
|
||
def call | ||
concat(render_parent) | ||
concat(orderable) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
VERSION = "4.0.3" | ||
VERSION = "4.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
spec/support/templates/app/controllers/admin/banners_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class BannersController < ApplicationController | ||
before_action :set_banner, only: %i[show edit update destroy] | ||
|
||
def index | ||
collection = Collection.new.with_params(params).apply(::Banner.strict_loading) | ||
table = Koi::OrdinalTableComponent.new(collection:) | ||
|
||
respond_to do |format| | ||
format.turbo_stream { render table } if self_referred? | ||
format.html { render :index, locals: { table:, collection: } } | ||
end | ||
end | ||
|
||
def show | ||
render locals: { banner: @banner } | ||
end | ||
|
||
def new | ||
render locals: { banner: ::Banner.new } | ||
end | ||
|
||
def edit | ||
render locals: { banner: @banner } | ||
end | ||
|
||
def create | ||
@banner = ::Banner.new(banner_params) | ||
|
||
if @banner.save | ||
redirect_to [:admin, @banner] | ||
else | ||
render :new, locals: { banner: @banner }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @banner.update(banner_params) | ||
redirect_to action: :show | ||
else | ||
render :edit, locals: { banner: @banner }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@banner.destroy | ||
|
||
redirect_to action: :index | ||
end | ||
|
||
def order | ||
order_params[:banners].each do |id, attrs| | ||
Banner.find(id).update(attrs) | ||
end | ||
|
||
redirect_back(fallback_location: admin_banners_path, status: :see_other) | ||
end | ||
|
||
private | ||
|
||
# Only allow a list of trusted parameters through. | ||
def banner_params | ||
params.require(:banner).permit(:name, :image, :ordinal) | ||
end | ||
|
||
def order_params | ||
params.require(:order).permit(banners: [:ordinal]) | ||
end | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_banner | ||
@banner = ::Banner.find(params[:id]) | ||
end | ||
|
||
class Collection < Katalyst::Tables::Collection::Base | ||
attribute :search, :string | ||
|
||
def filter | ||
self.items = items.admin_search(search) if search.present? | ||
end | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
spec/support/templates/app/views/admin/banners/_banner.html+row.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% row.ordinal %> | ||
<% row.cell :name do |cell| %> | ||
<%= link_to cell.value, url_for([:admin, banner]) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :banner do | ||
name { Faker::Kpop.solo } | ||
sequence(:ordinal) | ||
end | ||
end |
Oops, something went wrong.