require 'fiona7/recursive_object_finder' module Fiona7 class ReleaseCollector def initialize(obj_id) @obj = Fiona7::WriteObj.find(obj_id) @finder = Fiona7::RecursiveObjectFinder.new(@obj) end def call [ images, downloads, referenced, linked ].compact end def self.call(obj_id) self.new(obj_id).call end protected def images objs = @finder.images.select {|o| o.really_edited? } if objs.any? group = { title: t(:"fiona7.release.images"), objs: objs_to_items(objs, true) } end end def downloads objs = @finder.downloads.select {|o| o.really_edited? } if objs.any? group = { title: t(:"fiona7.release.downloads"), objs: objs_to_items(objs, true) } end end def referenced objs = @finder.referenced.select {|o| o.really_edited? } if objs.any? group = { title: t(:"fiona7.release.referenced"), objs: objs_to_items(objs, true) } end end def linked objs = @finder.linked.select {|o| o.really_edited? } if objs.any? group = { title: t(:"fiona7.release.linked"), objs: objs_to_items(objs, false) } end end def objs_to_items(objs, checked=true) items = objs.map do |obj| { id: obj.id, title: (obj.title.presence || obj.path), description: obj.obj_class, checked: checked } end end def t(key, options={}) I18n.t(key, {locale: (Scrivito::Configuration.ui_locale || I18n.locale)}.merge(options)) end end end