2024-09-23 10:35:00 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SortedColumn
|
2024-10-11 15:29:52 +02:00
|
|
|
# include validations to enable procedure_presentation.validate_associate,
|
|
|
|
# which enforces the deserialization of columns in the sorted_column attribute
|
|
|
|
# and raises an error if a column is not found
|
|
|
|
include ActiveModel::Validations
|
|
|
|
|
2024-09-26 17:18:43 +02:00
|
|
|
attr_reader :column, :order
|
2024-09-23 10:35:00 +02:00
|
|
|
|
|
|
|
def initialize(column:, order:)
|
|
|
|
@column = column
|
|
|
|
@order = order
|
|
|
|
end
|
|
|
|
|
|
|
|
def ascending? = @order == 'asc'
|
|
|
|
|
2024-09-24 15:06:12 +02:00
|
|
|
def opposite_order = ascending? ? 'desc' : 'asc'
|
|
|
|
|
2024-09-23 10:35:00 +02:00
|
|
|
def ==(other)
|
|
|
|
other&.column == column && other.order == order
|
|
|
|
end
|
2024-10-08 19:40:19 +02:00
|
|
|
|
|
|
|
def sort_by_notifications?
|
|
|
|
@column.notifications? && @order == 'desc'
|
|
|
|
end
|
2024-09-23 10:35:00 +02:00
|
|
|
end
|