Add order to Boards

This commit is contained in:
riggraz
2019-09-18 21:00:38 +02:00
parent 876f77e000
commit 109381e791
9 changed files with 57 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ class BoardDashboard < Administrate::BaseDashboard
id: Field::Number,
name: Field::String,
description: Field::Text,
order: Field::Number,
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
@@ -23,6 +24,7 @@ class BoardDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = %i[
name
description
order
].freeze
# SHOW_PAGE_ATTRIBUTES
@@ -31,6 +33,7 @@ class BoardDashboard < Administrate::BaseDashboard
id
name
description
order
created_at
updated_at
].freeze
@@ -41,6 +44,7 @@ class BoardDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = %i[
name
description
order
].freeze
# COLLECTION_FILTERS

View File

@@ -1,4 +1,14 @@
class Board < ApplicationRecord
after_initialize :set_order_to_last
validates :name, presence: true, uniqueness: true
validates :description, length: { in: 0..1024 }, allow_nil: true
def set_order_to_last
return unless new_record?
return unless order.nil?
order_last = Board.maximum(:order) || 0
self.order = order_last + 1
end
end

View File

@@ -1,4 +1,6 @@
class PostStatus < ApplicationRecord
after_initialize :set_order_to_last
validates :name, presence: true, uniqueness: true
validates :color, format: { with: /\A#(?:[0-9a-fA-F]{3}){1,2}\z/ }
validates :order, numericality: { only_integer: true, greater_than: 0 }
@@ -9,4 +11,12 @@ class PostStatus < ApplicationRecord
.order(order: :asc)
end
end
def set_order_to_last
return unless new_record?
return unless order.nil?
order_last = PostStatus.maximum(:order) || 0
self.order = order_last + 1
end
end