Skip to content
Browse files

Basic support for uploading file (probably broken)

  • Loading branch information...
1 parent 7678b67 commit 2258edc4e5161796f57b230fc66cf9463a69d532 @jbbarth jbbarth committed
View
21 app/controllers/admin/assets_controller.rb
@@ -0,0 +1,21 @@
+class Admin::AssetsController < Admin::BaseController
+ def index
+ @sorter = SortingHelper::Sorter.new self, %w(filename), params[:sort], params[:order], 'filename', 'ASC'
+ @assets = Asset.find(:all)
+ end
+
+ def create
+ @asset = Asset.new(params[:asset])
+ if @asset.save
+ flash[:notice] = 'Asset was successfully created.'
+ redirect_to Site.full_url + '/admin/assets'
+ else
+ render :action => :new
+ end
+ end
+
+ def upload
+ post = Asset.save(params[:asset])
+ render :text => "File has been uploaded successfully"
+ end
+end
View
2 app/controllers/admin/base_controller.rb
@@ -67,7 +67,7 @@ def user_authorize
unless valid
# we didn't find a author... send them to the login page
session[:came_from] = nil
- session[:came_from] = request.parameters if !$no_session_actions.index(params[:action])
+ #session[:came_from] = request.parameters if !$no_session_actions.index(params[:action])
flash[:notice] = 'Please log in'
redirect_to Site.full_url + '/login' and return false
end
View
2 app/helpers/assets_helper.rb
@@ -0,0 +1,2 @@
+module AssetsHelper
+end
View
7 app/models/asset.rb
@@ -0,0 +1,7 @@
+class Asset < ActiveRecord::Base
+ def self.save(upload)
+ directory = "public/files"
+ path = File.join(directory, upload['file'].original_filename)
+ File.open(path, "wb") { |f| f.write(upload['file'].read) }
+ end
+end
View
16 app/views/admin/assets/_form.html.erb
@@ -0,0 +1,16 @@
+<%= error_messages_for 'asset' %>
+
+<table class="form" cellpadding="0" cellspacing="0">
+<!--[form:tag]-->
+<tr class="breaker btop"><td colspan="2">File Details</td></tr>
+
+<tr>
+ <td class="labels">
+ <label for="asset"><b>File</b></label>
+ </td>
+ <td class="fields">
+ <%= file_field "asset", "file" %>
+ </td>
+</tr>
+<!--[eoform:tag]-->
+</table>
View
12 app/views/admin/assets/_subnav.html.erb
@@ -0,0 +1,12 @@
+<div id="admin_sub_nav">
+ <div class="sn_left">
+ <% if na %>
+ New asset!
+ <% else %>
+ <% form_tag(Site.full_url + '/admin/posts/search', :id => 'post_search_form') do %>
+ <%= link_to '<b>Upload a new file</b>', Site.full_url + '/admin/assets/new' %> or search...
+ <% end -%>
+ <% end %>
+ </div>
+ <br/>
+</div>
View
29 app/views/admin/assets/index.html.erb
@@ -0,0 +1,29 @@
+<%= render :partial => 'admin/assets/subnav', :locals => {:na => false} %>
+
+<div id="header">
+ <h1>Your assets</h1>
+ <% if flash[:notice] %><div class="green flash"><b>Success:</b> <%= flash[:notice] %></div><% end %>
+</div>
+
+<table class="list" cellspacing="0" cellpadding="0">
+
+ <tr>
+ <th class="first_col">Filename</th>
+ <th>Uploaded at</th>
+ <th class="del_col">X</th>
+ </tr>
+
+ <% f = 1 -%>
+ <% for asset in @assets -%>
+ <tr class="<%= cycle('alt_row ','') %><%= (f == 1 ? 'first_row' : '') %>">
+ <td class="first_col"><%= link_to asset.filename, Site.full_url + '/admin/assets/edit/' + asset.id.to_s %></td>
+ <td><%= asset.created_at %></td>
+ <td class="del_col"><%= link_to 'X', Site.full_url + '/admin/assets/destroy/' + asset.id.to_s, :confirm => "You are about to delete this asset. This is permanent.\n\nAre you ABSOLUTELY sure?" %></td>
+ </tr>
+ <% f += 1 -%>
+ <% end -%>
+ <% unless @assets.length > 0 -%>
+ <tr class="first_row"><td class="first_col" colspan="3"><span class="gray">There are no assets at this time.</span></td></tr>
+ <% end -%>
+</table>
+<br/>
View
16 app/views/admin/assets/new.html.erb
@@ -0,0 +1,16 @@
+<%= render :partial => 'admin/assets/subnav', :locals => {:na => true} %>
+
+<div id="header">
+ <h1>New file</h1>
+ <br/>
+</div>
+
+<% form_tag(Site.full_url + '/admin/assets/upload', :multipart => true) do %>
+ <%= render :partial => 'admin/assets/form' %>
+ <div class="submit_area">
+ <%= submit_tag 'Upload the file', :class => 'submit' %> or
+ <%= link_to 'cancel and return to file list', Site.full_url + '/admin/assets' %>
+ </div>
+<% end -%>
+
+<br/>
View
14 app/views/layouts/admin.html.erb
@@ -51,15 +51,17 @@
<%
comments_sys_on = get_pref('COMMENTING_ON')
cb = (comments_sys_on == 'yes')
+a = 0
%>
<div id="admin_nav">
<ul class="navlist">
- <li><a accesskey="1" href="<%= Site.full_url %>/admin/posts" title="Posts"<%= ' class="current"' if params[:action][0..3] == 'post' %>>Posts</a>&nbsp;<a accesskey="n" href="<%= Site.full_url %>/admin/posts/new" title="Create a new post"><img src="<%= Site.full_url %>/images/admin/new_button.png" id="new_post_button" alt="Create a new post" border="0"/></a></li>
- <li><a accesskey="2" href="<%= Site.full_url %>/admin/pages" title="Pages"<%= ' class="current"' if params[:action][0..3] == 'page' %>>Pages</a></li>
- <% if cb %><li><a accesskey="3" href="<%= Site.full_url %>/admin/comments" title="Comments"<%= ' class="current"' if (params[:action][0..6] == 'comment' or params[:action][0..8] == 'blacklist') %>>Comments</a></li><% end %>
- <li><a accesskey="<%= (cb ? '4' : '3') %>" href="<%= Site.full_url %>/admin/tags" title="Tags"<%= ' class="current"' if params[:action][0..2] == 'tag' %>>Tags</a></li>
- <li><a accesskey="<%= (cb ? '5' : '4') %>" href="<%= Site.full_url %>/admin/authors" title="Authors"<%= ' class="current"' if params[:action][0..5] == 'author' %>>Authors</a></li>
- <li class="end"><a accesskey="<%= (cb ? '6' : '5') %>" id="ping_obj" href="<%= Site.full_url %>/admin/ping" title="Ping"<%= ' class="current"' if params[:action][0..3] == 'ping' %> onclick="showPingPanel(); return false;">Ping</a></li>
+ <li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/posts" title="Posts"<%= ' class="current"' if params[:action][0..3] == 'post' %>>Posts</a>&nbsp;<a accesskey="n" href="<%= Site.full_url %>/admin/posts/new" title="Create a new post"><img src="<%= Site.full_url %>/images/admin/new_button.png" id="new_post_button" alt="Create a new post" border="0"/></a></li>
+ <li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/pages" title="Pages"<%= ' class="current"' if params[:action][0..3] == 'page' %>>Pages</a></li>
+ <li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/assets" title="Assets"<%= ' class="current"' if params[:controller].include?('asset') %>>Assets</a></li>
+ <% if cb %><li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/comments" title="Comments"<%= ' class="current"' if (params[:action][0..6] == 'comment' or params[:action][0..8] == 'blacklist') %>>Comments</a></li><% end %>
+ <li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/tags" title="Tags"<%= ' class="current"' if params[:action][0..2] == 'tag' %>>Tags</a></li>
+ <li><a accesskey="<%=a += 1%>" href="<%= Site.full_url %>/admin/authors" title="Authors"<%= ' class="current"' if params[:action][0..5] == 'author' %>>Authors</a></li>
+ <li class="end"><a accesskey="<%=a += 1%>" id="ping_obj" href="<%= Site.full_url %>/admin/ping" title="Ping"<%= ' class="current"' if params[:action][0..3] == 'ping' %> onclick="showPingPanel(); return false;">Ping</a></li>
</ul>
<ul class="navlist right">
<li><a accesskey="p" href="<%= Site.full_url %>/admin/prefs" title="Preferences"<%= ' class="current"' if params[:action][0..4] == 'prefs' %>>Preferences</a></li>
View
5 config/routes.rb
@@ -20,6 +20,11 @@
#++
ActionController::Routing::Routes.draw do |map|
+
+ # assets
+ # map.resources :assets
+ map.connect 'admin/assets', :controller => 'admin/assets', :action => 'index'
+ map.connect 'admin/assets/:action', :controller => 'admin/assets'
tokens = /archives|older|past/
View
18 db/migrate/030_create_assets.rb
@@ -0,0 +1,18 @@
+class CreateAssets < ActiveRecord::Migration
+ def self.up
+# create_table :assets do |t|
+# t.integer :parent_id
+# t.string :content_type
+# t.string :filename
+# t.string :thumbnail
+# t.integer :size
+# t.integer :width
+# t.integer :height
+# t.timestamps
+# end
+ end
+
+ def self.down
+# drop_table :assets
+ end
+end
View
2 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 29) do
+ActiveRecord::Schema.define(:version => 30) do
create_table "authors", :force => true do |t|
t.datetime "created_at", :null => false
View
BIN public/files/earthy.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
19 test/fixtures/assets.yml
@@ -0,0 +1,19 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ parent_id: 1
+ content_type: MyString
+ filename: MyString
+ thumbnail: MyString
+ size: 1
+ width: 1
+ height: 1
+
+two:
+ parent_id: 1
+ content_type: MyString
+ filename: MyString
+ thumbnail: MyString
+ size: 1
+ width: 1
+ height: 1
View
8 test/functional/assets_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class Admin::AssetsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
View
8 test/unit/asset_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class AssetTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end

0 comments on commit 2258edc

Please sign in to comment.
Something went wrong with that request. Please try again.