Module: MongoBureau

Includes:
BackendApiAdapter::InstanceMethods, Bureau::Adapter::InstanceMethods, MongoCrushyform::InstanceMethods
Defined in:
lib/mongo_bureau.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BUREAU_CRUSHYFORM_TYPES =
{
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bureau::Adapter::InstanceMethods

#nutshell_backend_columns, #nutshell_header, #nutshell_toolbar, #placeholder_thumb, #preview_on_frontend, #to_nutshell

Methods included from BackendApiAdapter::InstanceMethods

#backend_clone_form, #backend_delete, #backend_delete_form, #backend_fields, #backend_form, #backend_form_title, #backend_put, #backend_save?, #backend_show, #backend_values

Class Method Details

.included(base) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/mongo_bureau.rb', line 73

def self.included(base)
  base.extend(BackendApiAdapter::ClassMethods)
  base.extend(MongoCrushyform::ClassMethods) if defined?(MongoCrushyform)
  base.extend(Bureau::Adapter::ClassMethods)
  base.extend(ClassMethods)
  base.bureau_config = {:nut_tree_class=>'sortable-grid'}
  base.crushyform_types.update(BUREAU_CRUSHYFORM_TYPES)
end

Instance Method Details

#after_stash(col) ⇒ Object



150
151
152
153
# File 'lib/mongo_bureau.rb', line 150

def after_stash(col)
  convert(col, "-resize '100x75^' -gravity center -extent 100x75", 'stash_thumb_gif')
  convert(col, "-resize '184x138^' -gravity center -extent 184x138", 'nutshell_jpg')
end

#bureau_attachment_url_for(obj, col = 'image', size = 'original') ⇒ Object



155
156
157
158
# File 'lib/mongo_bureau.rb', line 155

def bureau_attachment_url_for obj, col='image', size='original'
  return obj.attachment_url(col,size) if obj.respond_to?(:attachment_url)
  "/gridfs/#{obj.doc[col][size]}"
end

#cloning_backend_columnsObject



212
# File 'lib/mongo_bureau.rb', line 212

def cloning_backend_columns; default_backend_columns.reject{|c| model.schema[c][:type]==:attachment}; end

#default_backend_columnsObject



211
# File 'lib/mongo_bureau.rb', line 211

def default_backend_columns; model.schema.keys; end

#generic_thumb(img, size = 'stash_thumb_gif', obj = self) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/mongo_bureau.rb', line 160

def generic_thumb(img , size='stash_thumb_gif', obj=self)
   return placeholder_thumb(size) if obj.nil?
  current = obj.doc[img]
  if !current.nil? && !current[size].nil?
    "<img src='#{bureau_attachment_url_for(obj,img,size)}' onerror=\"this.style.display='none'\" />\n"
  else
    placeholder_thumb(size)
  end
end

#in_nutshellObject



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/mongo_bureau.rb', line 180

def in_nutshell
  o = model.list_options
out = "<div class='in-nutshell'>\n"
out << self.to_bureau_thumb('nutshell_jpg') if self.respond_to?(:to_bureau_thumb)
cols = model.bureau_config[:quick_update_fields] || nutshell_backend_columns.select{|col| 
  [:boolean,:select].include?(model.schema[col][:type]) && !model.schema[col][:multiple] && !model.schema[col][:no_quick_update]
}
cols.each do |c|
  column_label = model.schema[c][:name] || c.to_s.sub(/^id_/, '').tr('_', ' ').capitalize
  out << "<div class='quick-update'><form><span class='column-title'>#{column_label}:</span> #{self.crushyinput(c)}</form></div>\n"
 end
out << "</div>\n"
end

#nutshell_backend_associationsObject



207
208
209
# File 'lib/mongo_bureau.rb', line 207

def nutshell_backend_associations
  model.relationships
end

#nutshell_childrenObject



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/mongo_bureau.rb', line 194

def nutshell_children
  o = model.list_options
  out = ""
  nutshell_backend_associations.each do |k, opts|
    next if opts[:hidden]
    k = Kernel.const_get(k)
    link = "#{o[:path]}/list/#{k}?filter[#{model.foreign_key_name}]=#{self.id}"
    text = opts[:link_text] || "#{k.human_name}(s)"
    out << "<a href='#{link}' class='push-stack sublist-link nutshell-child'>#{text} #{self.children_count(k) unless opts[:hide_count]}</a>\n"
  end
  out
end

#scene_selector_coordinatesObject



178
# File 'lib/mongo_bureau.rb', line 178

def scene_selector_coordinates; @doc['coordinates']; end

#to_thumb(c) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/mongo_bureau.rb', line 170

def to_thumb(c)
  current = @doc[c]
  if current.respond_to?(:[])
    img_url = @doc[c]['stash_thumb_gif'].nil? ? model.list_options&&"#{model.list_options[:path]}/_static/img/file.png" : bureau_attachment_url_for(self,c,'stash_thumb_gif')
    "<img src='#{img_url}' #{"width='100'" unless @doc[c]['stash_thumb_gif'].nil?} onerror=\"this.style.display='none'\" />\n"
  end
end