Organize media


(Erlingur) #1

Hi there! Just found Pushtype and it’s awesome!

I was wondering if there was some way of organizing the uploaded media? I have a site that would like to upload multiple photos in album style so having everything in one place might get messy.

Has anyone created a photo album node? Any recommendations on how to do that intelligently? Thanks!


(Aaron Russell) #2

Hi @erlingur, thanks for giving PushType a try.

Unfortunately the answer to both parts of your question is kinda unsatisfactory. No :slight_smile: … although, both are on the roadmap.

In terms of organising uploaded media, right now it’s just one reverse-chronologically ordered bucket of stuff. I realise this isn’t ideal. At some point you will be able to tag uploaded files, and then also be able to search and filter according to tags, names, descriptions, file types etc. But not right now I’m afraid.

As for galleries, right now it’s probably best to use a Repeater or Matrix field, eg:

field :gallery, :repeater, repeats: :asset

# or ...

field :gallery, :matrix, grid: false do
  field :image_id, :asset
  field :caption, :string
end

The above will work, but in terms of UX I think it’s a solution that can be improved. Really we need a dedicated gallery field.


(Erlingur) #3

Alright, thanks for your answer. I might be interested in taking a stab at making a gallery field. Should I ping you back if I have something?


(Aaron Russell) #4

That would be superb. I’m probably some way off being able to tackle the gallery field myself.

I can help point you in the right direction, as none of this stuff is documented yet…

Probably the best way to start is build off an existing field and just create your own UI by using the :template option:

field :gallery, :matrix, template: 'my_gallery' do
  field :image_id, :asset
  field :caption, :string
end

This way the underlying data structure that the field would expect is an array of hashes, just like how the existing matrix field works, but now you can focus on creating a better UI for a gallery. Later on you can work out whether this needs to be it’s own field type (a class inheriting from PushType::FieldType).

If you need to load your own js/css assets, there is a way of doing this. Somewhere in your application initialisation:

# We can add custom assets to the admin asset pipeline
PushType.admin_assets.javascripts << 'my_gallery'
PushType.admin_assets.stylesheets << 'my_gallery'
# Or do the same in one line...
PushType.admin_assets.register 'my_gallery'

In terms of JavaScript, the admin UI is a bit of a bastardisation. It’s not a real SPA (uses Turbolinks), uses Foundation for a bunch of built-in components, and any custom components have been built with Vue.js. None of these things play particularly nicely with each other :stuck_out_tongue: So expect to have a bit of fun. I’d encourage you to use Vue.js - that way you can make use of some of the existing components - eg the AssetModal component.

Give me a shout if you need any help or pointers :slight_smile:


(Erlingur) #5

Awesome, thanks for this!

I’ll be taking a look at this in the coming weeks :slight_smile: I’ll send you a link to whatever I come up with, we’ll see if it’s something you think could fit the project :slight_smile: