How would you manage SCHEDULE data?


(Priit Pärna) #1

Hey, I might have a tricky task in my hands, but I’m building a simple conference signup page inside my website driven by push_type. I’m currently thinking how would you guys store the SCHEDULE data so it’s manageable via admin?

Events can have 1 or more days, every day has a timeline what’s going to happen at what time, in what (fields/nodes) structure would you use for that data?

Adding just a sample what I’m talking about, thats not the exact design I’m working on.

Thanks,
Priit


(Aaron Russell) #2

Hi @chemic, with this kind of thing there’s no right or wrong way. I think they key decision to make is whether to try and include all the data in a single monolithic Event node, or split the event sessions into serperate nodes. Whichever route you take will have different tradeoffs to balance in terms of how intuitive and easy it is for the admin to manage.

For example, a monolithic approach using the matrix field:

class Event < PushType::Node

  has_child_nodes false

  field :start_on, :date
  field :end_on, :date

  field :sessions, :matrix, grid: false do
    field :title, :string
    field :date, :date
    field :time, :time
  end

end

Alternatively, the event session could be child node:

class Event < PushType::Node

  has_child_nodes :event_session

  field :start_on, :date
  field :end_on, :date

  def sessions
    children.where(type: 'EventSession')
  end

end

class EventSession < PushType::Node

  has_child_nodes false

  field :date, :date
  field :time, :time

end

# in config/initializers/push_type.rb
config.unexposed_nodes = [:event_session]

In terms of presenting the events on the front end, whatever approach you go for from above, I’d use a helper or something to take your array of sessions, and group them and order them according to their date and time.

Hope this helps point you in the right direction :)


(Priit Pärna) #3

Hey @aaron ! I was thinking the same way.

One question regarding to :time field type… that timepicker gives me only ability to set times with 30min cycles… but I need to use smaller amounts like 10, 15min etc… how would you suggest to do that then?

Thanks for supporting!
Priit


(Aaron Russell) #4

I’m afraid there isn’t actually an exposed way to change the options of the date/time picker fields. This is something that needs improving.

If you need more freestyle time formatting then I think the simplest option is just use a string field and allow admins to enter the time freehand (or you could validate it to coerce a 24hr format so you know you have a consistent format to work with).