-
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.
- Loading branch information
1 parent
d328077
commit e49280a
Showing
24 changed files
with
298 additions
and
220 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class Base < Katalyst::Tables::BodyCellComponent | ||
def before_render | ||
# fallback if no content block is given | ||
with_content(attribute_value) unless content? | ||
end | ||
|
||
def attribute_value | ||
value.to_s | ||
end | ||
|
||
def inspect | ||
"#<#{self.class.name} #{@attribute.inspect}>" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/components/koi/tables/body/columns/boolean_component.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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class BooleanComponent < Base | ||
def attribute_value | ||
value ? "Yes" : "No" | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class DateComponent < Base | ||
def initialize(table, record, attribute, format: :admin, **options) | ||
super(table, record, attribute, **options) | ||
|
||
@format = format | ||
end | ||
|
||
def attribute_value | ||
l(value.to_date, format: @format) if value.present? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
app/components/koi/tables/body/columns/datetime_component.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class DatetimeComponent < Base | ||
def initialize(table, record, attribute, format: :admin, **options) | ||
super(table, record, attribute, **options) | ||
|
||
@format = format | ||
end | ||
|
||
def attribute_value | ||
l(value.to_datetime, format: @format) if value.present? | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class MoneyComponent < Base | ||
def attribute_value | ||
number_to_currency(value / 100.0) if value.present? | ||
end | ||
|
||
def default_html_attributes | ||
{ class: "number" } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
app/components/koi/tables/body/columns/number_component.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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class NumberComponent < Base | ||
def attribute_value | ||
number_to_human(value) if value.present? | ||
end | ||
|
||
def default_html_attributes | ||
{ class: "number" } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/components/koi/tables/body/columns/rich_text_component.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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
module Columns | ||
class RichTextComponent < Base | ||
def attribute_value | ||
value.to_plain_text | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Body | ||
class RowComponent < Katalyst::Tables::BodyRowComponent | ||
# can't name this `columns` because it conflicts with the Katalyst::Tables::BodyRowComponent columns slots | ||
renders_many :cells, types: { | ||
boolean: { | ||
renders: lambda do |attribute, **options, &block| | ||
with_column(Columns::BooleanComponent.new(@table, @record, attribute, **options), &block) | ||
end, | ||
as: :boolean_column, | ||
}, | ||
date: { | ||
renders: lambda do |attribute, format: :admin, **options, &block| | ||
with_column(Columns::DateComponent.new(@table, @record, attribute, format:, **options), &block) | ||
end, | ||
as: :date_column, | ||
}, | ||
datetime: { | ||
renders: lambda do |attribute, format: :admin, **options, &block| | ||
with_column(Columns::DatetimeComponent.new(@table, @record, attribute, format:, **options), &block) | ||
end, | ||
as: :datetime_column, | ||
}, | ||
number: { | ||
renders: lambda do |attribute, **options, &block| | ||
with_column(Columns::NumberComponent.new(@table, @record, attribute, **options), &block) | ||
end, | ||
as: :number_column, | ||
}, | ||
money: { | ||
renders: lambda do |attribute, **options, &block| | ||
with_column(Columns::MoneyComponent.new(@table, @record, attribute, **options), &block) | ||
end, | ||
as: :money_column, | ||
}, | ||
rich_text: { | ||
renders: lambda do |attribute, **options, &block| | ||
with_column(Columns::RichTextComponent.new(@table, @record, attribute, **options), &block) | ||
end, | ||
as: :rich_text_column, | ||
}, | ||
text: { | ||
renders: lambda do |attribute, **options, &block| | ||
with_column(Columns::Base.new(@table, @record, attribute, **options), &block) | ||
end, | ||
as: :text_column, | ||
}, | ||
} | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Tables | ||
module Header | ||
module Columns | ||
class Base < Katalyst::Tables::HeaderCellComponent | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.