2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
class WizardStepSerializer < ApplicationSerializer
|
2023-09-25 22:34:38 -04:00
|
|
|
attributes :id, :next, :previous, :description, :title, :index, :emoji
|
2016-08-25 13:14:56 -04:00
|
|
|
has_many :fields, serializer: WizardFieldSerializer, embed: :objects
|
|
|
|
|
|
|
|
def id
|
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
object.index
|
|
|
|
end
|
|
|
|
|
|
|
|
def next
|
|
|
|
object.next.id if object.next.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_next?
|
|
|
|
object.next.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous
|
|
|
|
object.previous.id if object.previous.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_previous?
|
|
|
|
object.previous.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def i18n_key
|
|
|
|
@i18n_key ||= "wizard.step.#{object.id}".underscore
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:59:42 -05:00
|
|
|
def translate(sub_key, vars = nil)
|
|
|
|
key = "#{i18n_key}.#{sub_key}"
|
|
|
|
return nil unless I18n.exists?(key)
|
|
|
|
|
|
|
|
vars.nil? ? I18n.t(key) : I18n.t(key, vars)
|
|
|
|
end
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
def description
|
2018-12-05 12:05:37 -05:00
|
|
|
key = object.disabled ? "disabled" : "description"
|
|
|
|
translate(key, object.description_vars)
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2018-11-07 11:59:42 -05:00
|
|
|
translate("title")
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_title?
|
|
|
|
title.present?
|
|
|
|
end
|
|
|
|
|
2022-12-19 19:24:09 -05:00
|
|
|
def emoji
|
|
|
|
object.emoji
|
|
|
|
end
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|