Skip to content

Commit

Permalink
asset admin ui sharded
Browse files Browse the repository at this point in the history
  • Loading branch information
will-r committed Mar 14, 2009
1 parent cc96888 commit e20a79d
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 94 deletions.
3 changes: 3 additions & 0 deletions README
Expand Up @@ -3,6 +3,9 @@ Paperclipped

Paperclip is a new file management plugin from Thoughtbot which has a few advantages over attachment_fu: it doesn't use RMagick, which uses a lot of RAM and is a bit of overkill for just making thumbnails. Instead it directly uses ImageMagick, making it much easier to install.

###(Forked)

This version of paperclipped adds UI regions to the admin interface for the benefit of eg. multisite and other admin extensions.

###Installation

Expand Down
32 changes: 18 additions & 14 deletions app/views/assets/_form.html.haml
@@ -1,15 +1,19 @@
%p.title
%label{ :for => "asset_title" } Title
= form.text_field :title, :class => 'textbox', :maxlength => 100
#extended-metadata{ :class => "row", :style => "display: none" }
%table.fieldset{ :cellpadding => "0", :cellspacing => "0", :border => "0" }
%tr
%td.label
%label{ :for => "asset_caption" } Caption
%td.field
= form.text_field :caption, :class => 'textbox', :maxlength => 255
%p
%small
%a{ :id => "more-extended-metadata", :href => "#", :onclick => "#{toggle_javascript_for('extended-metadata')}; return false;" } More
%a{ :id => "less-extended-metadata", :href => "#", :onclick => "#{toggle_javascript_for('extended-metadata')}; return false;", :style => "display: none" } Less
= render_region :form_top
- render_region :form do |form|
- form.edit_title do
%p.title
%label{ :for => "asset_title" } Title
= f.text_field :title, :class => 'textbox', :maxlength => 100
- form.edit_metadata do
#extended-metadata{ :class => "row", :style => "display: none" }
%table.fieldset{ :cellpadding => "0", :cellspacing => "0", :border => "0" }
%tr
%td.label
%label{ :for => "asset_caption" } Caption
%td.field
= f.text_field :caption, :class => 'textbox', :maxlength => 255
%p
%small
%a{ :id => "more-extended-metadata", :href => "#", :onclick => "#{toggle_javascript_for('extended-metadata')}; return false;" } More
%a{ :id => "less-extended-metadata", :href => "#", :onclick => "#{toggle_javascript_for('extended-metadata')}; return false;", :style => "display: none" } Less

63 changes: 35 additions & 28 deletions app/views/assets/edit.html.haml
@@ -1,36 +1,43 @@
- include_stylesheet 'admin/assets'
= render_region :top

%h1= "Edit Asset"
- form_for :asset, :url => asset_path(@asset), :html => { :method => "put", :multipart => true } do |form|
.form-area
= render :partial => "form", :locals => { :form => form }
- render_region :main do |main|
- main.edit_header do
%h1= "Edit Asset"

%p.content
%label.filename
= "Filename: #{@asset.asset_file_name unless @asset.new_record?}"
.asset
- if @asset.image?
= image_tag @asset.thumbnail(Radiant::Config['assets.display_size'].to_sym)
- else
= link_to image_tag(@asset.thumbnail(:thumbnail)), @asset.asset.url
= updated_stamp @asset

%p.upload
%label.upload Replace File
= form.file_field :asset, :class => "", :style => "width: 100%"
- main.edit_form do
- form_for :asset, :url => asset_path(@asset), :html => { :method => "put", :multipart => true } do |f|
.form-area
= render :partial => "form", :locals => { :f => f }

%p.content
%label.filename
= "Filename: #{@asset.asset_file_name unless @asset.new_record?}"
.asset
- if @asset.image?
= image_tag @asset.thumbnail(Radiant::Config['assets.display_size'].to_sym)
- else
= link_to image_tag(@asset.thumbnail(:thumbnail)), @asset.asset.url
= updated_stamp @asset

%p.buttons
= save_model_button(@asset)
= save_model_and_continue_editing_button(@asset)
or
= link_to "Cancel", assets_url
- if current_user.admin? or current_user.developer?
%p
You can regenerate the asset thumbnails here. Beware that this will take a while and consume considerable resources on your server.
%p.upload
%label.upload Replace File
= f.file_field :asset, :class => "", :style => "width: 100%"

%p.buttons
= save_model_button(@asset)
= save_model_and_continue_editing_button(@asset)
or
= link_to "Cancel", assets_url

- main.edit_regenerate do
- if current_user.admin? or current_user.developer?
%p
You can regenerate the asset thumbnails here. Beware that this will take a while and consume considerable resources on your server.

- form_tag refresh_assets_path(@asset) do
%p.asset-buttons
%input.button{ :type => "submit", :value => "Regenerate" }
- form_tag refresh_assets_path(@asset) do
%p.asset-buttons
%input.button{ :type => "submit", :value => "Regenerate" }



Expand Down
129 changes: 93 additions & 36 deletions app/views/assets/index.html.haml
@@ -1,42 +1,99 @@
- include_stylesheet 'admin/assets'
= render_region :top

%h1 Assets
- render_region :preamble do |preamble|
- preamble.header do
%h1 Assets

%p
Assets and images can be uploaded and then attached or inserted into pages, snippets and layouts.
Click on a asset name below to edit it or click <code>Remove</code> to delete it.

%p= link_to image_tag('assets/new-asset.png', :alt => 'New Asset'), new_asset_path

%p
- form_tag(assets_url,:id => 'filesearchform', :method => 'get') do
%span
= link_to "Images", "#"
%span
= link_to "Others", "#"
%span
= link_to "Audio", "#"
%span
= link_to "Movies", "#"

#type_boxes{ :style => "display: none" }
= check_box_tag 'filter[audio]', '1', false, :id => 'audio-check'
= check_box_tag 'filter[image]', '1', false, :id => 'images-check'
= check_box_tag 'filter[other]', '1', false, :id => 'others-check'
= check_box_tag 'filter[movie]', '1', false, :id => 'movies-check'

%label Search
%input{ :type => "text", :id => "search", :name => "search" }
= observe_field 'search', :frequency => 1, :update => 'assets_table', :url => { :controller => 'assets', :action=> 'index' }, :method => 'get', :with => "'search=' + escape(value)"
- preamble.explanation do
%p
Assets and images can be uploaded and then attached or inserted into pages, snippets and layouts.
Click on a asset name below to edit it or click <code>Remove</code> to delete it.

- preamble.new_button do
%p= link_to image_tag('assets/new-asset.png', :alt => 'New Asset'), new_asset_path

- preamble.filters do
%p
- form_tag(assets_url,:id => 'filesearchform', :method => 'get') do
%span
= link_to "Images", "#"
%span
= link_to "Others", "#"
%span
= link_to "Audio", "#"
%span
= link_to "Movies", "#"

#type_boxes{ :style => "display: none" }
= check_box_tag 'filter[audio]', '1', false, :id => 'audio-check'
= check_box_tag 'filter[image]', '1', false, :id => 'images-check'
= check_box_tag 'filter[other]', '1', false, :id => 'others-check'
= check_box_tag 'filter[movie]', '1', false, :id => 'movies-check'

%label Search
%input{ :type => "text", :id => "search", :name => "search" }
= observe_field 'search', :frequency => 1, :update => 'assets_table', :url => { :controller => 'assets', :action=> 'index' }, :method => 'get', :with => "'search=' + escape(value)"

#assets_table
= render :partial => 'asset_table'

= render :partial => 'assets_container'

- if current_user.admin?
%p
You can regenerate all thumbnails here. Beware that this will take a while and consume considerable resources on your server.
%table{ :class => "index", :cellpadding => "0", :cellspacing => "0", :border => "0"}
%thead
%tr
- render_region :thead do |thead|
- thead.thumbnail_header do
%th.asset Image
- thead.title_header do
%th.asset-title Title
- thead.content_type_header do
%th.content_type Type
- thead.modify_header do
%th.modify{ :colspan =>"2"} Modify

%tbody
- unless @assets.empty?
- for asset in @assets
- render_region :tbody do |tbody|
%tr.node.level-1
- tbody.thumbnail_cell do
%td.asset
- asset_id = "asset_#{asset.id.to_s}"
= link_to image_tag(asset.thumbnail(:icon)), edit_asset_url(:id => asset), :class => 'icon'
- tbody.title_cell do
%td.asset-title
= link_to asset.title, edit_asset_url(:id => asset.id)
&nbsp;
%span.caption
= asset.caption
- tbody.content_type_cell do
%td.content_type
= asset.asset_content_type
- tbody.bucket_cell do
%td.add-to-bucket
= link_to_remote(image_tag('assets/add-to-bucket.png', :alt => 'Add to Bucket'), :url => add_bucket_url(:id => asset))
- tbody.remove_cell do
%td.remove
= link_to image_tag('admin/remove.png', :alt => 'Remove Asset'), remove_asset_url(:id => asset)
- else
- render_region :tbody do |tbody|
%tr
%td.note{ :colspan => "5" }
No Assets

- render_region :pagination do
= will_paginate @assets

%script{ :type => "text/javascript"}
// <! [CDATA[
new RuledTable('assets')
//]

- render_region :assets_container do
= render :partial => 'assets_container'

- form_tag refresh_assets_path do
%input.button{ :type => "submit", :value => "Regenerate" }
- render_region :bottom do |bottom|
- bottom.regenerate do
- if current_user.admin?
%p
You can regenerate all thumbnails here. Beware that this will take a while and consume considerable resources on your server.
- form_tag refresh_assets_path do
%input.button{ :type => "submit", :value => "Regenerate" }
38 changes: 22 additions & 16 deletions app/views/assets/new.html.haml
@@ -1,20 +1,26 @@
- include_stylesheet 'admin/assets'
= render_region :top

%h1= "New Asset"
- render_region :main do |main|
- main.edit_header do
%h1= "New Asset"
%p
Choose an asset to upload here. If the <code>Title</code> field is left blank, the filename (without the file type) will be automatically added.
By clicking on <code>More</code>, you can add a caption as well.

%p
Choose an asset to upload here. If the <code>Title</code> field is left blank, the filename (without the file type) will be automatically added.
By clicking on <code>More</code>, you can add a caption as well.

- form_for :asset, :url => assets_path, :html => { :method => "post", :multipart => true } do |form|
.form-area
= render :partial => "form", :locals => { :form => form }
%p.upload
%label.upload Choose a file to upload
= form.file_field :asset, :class => "", :style => "width: 100%"
- main.edit_form do
- form_for :asset, :url => assets_path, :html => { :method => "post", :multipart => true } do |f|
.form-area
= render :partial => "form", :locals => { :f => f }

%p.upload
%label.upload Choose a file to upload
= f.file_field :asset, :class => "", :style => "width: 100%"

%p.buttons
= save_model_button(@asset)
= save_model_and_continue_editing_button(@asset)
or
= link_to "Cancel", assets_url
%p.buttons
= save_model_button(@asset)
= save_model_and_continue_editing_button(@asset)
or
= link_to "Cancel", assets_url

= main.edit_regenerate
33 changes: 33 additions & 0 deletions lib/assets_admin_ui.rb
@@ -0,0 +1,33 @@
module AssetsAdminUI

def self.included(base)
base.class_eval do

attr_accessor :asset
alias_method :assets, :asset

protected

def load_default_asset_regions
returning OpenStruct.new do |asset|
asset.edit = Radiant::AdminUI::RegionSet.new do |edit|
edit.main.concat %w{edit_header edit_form edit_regenerate}
edit.form.concat %w{edit_title edit_metadata}
end
asset.index = Radiant::AdminUI::RegionSet.new do |index|
index.preamble.concat %w{header explanation new_button filters}
index.thead.concat %w{thumbnail_header title_header content_type_header modify_header}
index.tbody.concat %w{thumbnail_cell title_cell content_type_cell bucket_cell remove_cell}
index.paginate
index.assets_container
index.bottom.concat %w{regenerate}
end
asset.remove = asset.index
asset.new = asset.edit
end
end

end
end
end

5 changes: 5 additions & 0 deletions paperclipped_extension.rb
Expand Up @@ -22,6 +22,11 @@ class PaperclippedExtension < Radiant::Extension

def activate
require_dependency 'application'

unless defined? admin.asset
Radiant::AdminUI.send :include, AssetsAdminUI
admin.asset = Radiant::AdminUI.load_default_asset_regions # UI is a singleton and already loaded
end

%w{page}.each do |view|
admin.send(view).edit.add :main, "/assets/show_bucket_link", :before => "edit_header"
Expand Down

0 comments on commit e20a79d

Please sign in to comment.