demarches-normaliennes/app/models/label.rb

36 lines
1 KiB
Ruby
Raw Normal View History

2024-09-25 15:05:09 +02:00
# frozen_string_literal: true
2024-10-29 14:52:14 +01:00
class Label < ApplicationRecord
2024-09-25 15:05:09 +02:00
belongs_to :procedure
2024-09-25 16:03:58 +02:00
has_many :dossier_labels, dependent: :destroy
2024-09-25 15:05:09 +02:00
2024-10-16 14:31:08 +02:00
NAME_MAX_LENGTH = 30
GENERIC_LABELS = [
{ name: 'À examiner', color: 'purple_glycine' },
{ name: 'À relancer', color: 'green_tilleul_verveine' },
{ name: 'Complet', color: 'green_emeraude' },
{ name: 'À signer', color: 'blue_ecume' },
{ name: 'Urgent', color: 'pink_macaron' }
]
2024-10-16 14:31:08 +02:00
enum color: {
green_tilleul_verveine: "green-tilleul-verveine",
green_bourgeon: "green-bourgeon",
green_emeraude: "green-emeraude",
green_menthe: "green-menthe",
blue_ecume: "blue-ecume",
purple_glycine: "purple-glycine",
pink_macaron: "pink-macaron",
yellow_tournesol: "yellow-tournesol",
brown_cafe_creme: "brown-cafe-creme",
beige_gris_galet: "beige-gris-galet"
}
2024-09-25 15:05:09 +02:00
validates :name, :color, presence: true
2024-10-16 14:31:08 +02:00
validates :name, length: { maximum: NAME_MAX_LENGTH }
def self.class_name(color)
2024-10-29 15:39:58 +01:00
Label.colors.fetch(color.underscore)
end
2024-09-25 15:05:09 +02:00
end