Commit 799d815b

mo khan <mo@mokhan.ca>
2014-07-08 04:04:48
remove jquery file upload and old photo upload pages.
1 parent d31db3e
app/assets/javascripts/application.js
@@ -16,7 +16,6 @@
 //= require jquery.ui.all
 //= require jquery.validate
 //= require jquery.masonry
-//= require jquery-fileupload
 //= require jquery.embedly
 //= require tag-it
 //= require bootstrap
app/assets/stylesheets/application.css.scss
@@ -8,7 +8,6 @@
  * You're free to add application-wide styles to this file and they'll appear at the top of the
  * compiled file, but it's generally better to create a new file per style scope.
  *
- *= require jquery.fileupload-ui
  *= require_self
  *= require jquery.tagit
  *= require jquery.ui.all
app/controllers/my/photos_controller.rb
@@ -1,44 +0,0 @@
-module My
-  class PhotosController < BaseController
-    before_filter :find_creation
-
-    def initialize(mapper = PhotoToJQJsonMapper.new)
-      @mapper = mapper
-      super()
-    end
-
-    def index
-      @photos = @cake.photos
-      render json: { files: @photos.map { |photo| @mapper.map_from(photo) } }
-    end
-
-    def new
-      @photo = Photo.new
-    end
-
-    def create
-      render json: { files: [UploadPhoto.new.run(params[:cake_id], photo_params)] }
-    end
-
-    def destroy
-      @photo = @cake.photos.find(params[:id])
-      if @photo.destroy
-        @cake.touch
-        render json: { files: [@mapper.map_from(@photo)] }
-      else
-        render json: [ { error: "could not remove the photo" } ], status: 304
-      end
-    end
-
-    private
-
-    def find_creation
-      @cake = current_user.creations.find(params[:cake_id])
-      raise ActiveRecord::RecordNotFound unless @cake
-    end
-
-    def photo_params
-      params.require(:photo).permit(:image)
-    end
-  end
-end
app/models/comment.rb
@@ -1,7 +1,7 @@
 class Comment < ActiveRecord::Base
   belongs_to :user
   belongs_to :creation
-  has_many :activities, as: :subject
+  has_many :activities, as: :subject, dependent: :destroy
   after_create :create_activity
 
   private
app/services/application/photo_to_jq_json_mapper.rb
@@ -1,11 +0,0 @@
-class PhotoToJQJsonMapper
-  def map_from(photo)
-    {
-      name: photo.image,
-      url: photo.url_for(:large),
-      thumbnail_url: photo.url_for(:thumb),
-      delete_url: photo.id,
-      delete_type: "DELETE"
-    }
-  end
-end
app/services/application/upload_photo.rb
@@ -7,22 +7,11 @@ class UploadPhoto
   def run(cake_id, params)
     photo = @cakes.find(cake_id).photos.create!(image_processing: true, watermark: params[:watermark])
     @message_bus.publish(:upload_photo, create_message_from(cake_id, params, photo))
-    map_from(photo.id, params[:image].original_filename)
     photo
   end
 
   private
 
-  def map_from(photo_id, name)
-    {
-      name: name,
-      url: "/_default.png",
-      thumbnail_url: "/assets/thumb_default.png",
-      delete_url: photo_id,
-      delete_type: "DELETE"
-    }
-  end
-
   def move_to_temporary_storage(temp_file_path, original_filename)
     new_path = "#{create_tmp_dir}/#{original_filename}"
     FileUtils.mv(temp_file_path, new_path)
app/views/my/photos/_form.html.erb
@@ -1,89 +0,0 @@
-<% content_for :javascript do %>
-<script type="text/javascript" charset="utf-8">
-  $(function () {
-    $('#fileupload').fileupload({autoUpload:true, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i });
-    $('#fileupload').fileupload( 'option', 'redirect', window.location.href.replace( /\/[^\/]*$/, '/cors/result.html?%s'));
-    $('#fileupload').each(function () {
-      var that = this;
-      $.getJSON(this.action, function (result) {
-        if (result) {
-          $(that).fileupload('option', 'done').call(that, null, {result: result});
-        }
-      });
-    });
-  });
-</script>
-<% end %>
-  <%= form_for [@cake, @photo], url: my_cake_photos_path, :html => { :multipart => true, :id => "fileupload"  } do |f| %>
-    <div class="row fileupload-buttonbar">
-      <div class="span10">&nbsp;</div>
-      <div class="span2">
-        <span class="btn btn-success fileinput-button"><i class="icon-plus icon-white"></i><span> Browse... </span><%= f.file_field :image %></span>
-        <%= link_to "NEXT", my_dashboard_path, :class => "btn btn-primary" %>
-      </div>
-    </div>
-    <div class="fileupload-loading"></div>
-    <br>
-    <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
-  <% end %>
-</div>
-
-<!-- The template to display files available for upload -->
-<script id="template-upload" type="text/x-tmpl">
-{% for (var i=0, file; file=o.files[i]; i++) { %}
-    <tr class="template-upload fade">
-        <td class="preview"><span class="fade"></span></td>
-        <td class="name"><span>{%=file.name%}</span></td>
-        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
-        {% if (file.error) { %}
-            <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
-        {% } else if (o.files.valid && !i) { %}
-            <td>
-                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
-            </td>
-            <td class="start">{% if (!o.options.autoUpload) { %}
-                <button class="btn btn-primary">
-                    <i class="icon-upload icon-white"></i>
-                    <span>Start</span>
-                </button>
-            {% } %}</td>
-        {% } else { %}
-            <td colspan="2"></td>
-        {% } %}
-        <td class="cancel">{% if (!i) { %}
-            <button class="btn btn-warning">
-                <i class="icon-ban-circle icon-white"></i>
-                <span>Cancel</span>
-            </button>
-        {% } %}</td>
-    </tr>
-{% } %}
-</script>
-<!-- The template to display files available for download -->
-<script id="template-download" type="text/x-tmpl">
-{% for (var i=0, file; file=o.files[i]; i++) { %}
-    <tr class="template-download fade">
-        {% if (file.error) { %}
-            <td></td>
-            <td class="name"><span>{%=file.name%}</span></td>
-            <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
-            <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
-        {% } else { %}
-            <td class="preview">{% if (file.thumbnail_url) { %}
-                <img src="{%=file.thumbnail_url%}" style="width:260px;height:180px;">
-            {% } %}</td>
-            <td class="name">
-                <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
-            </td>
-            <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
-            <td colspan="2"></td>
-        {% } %}
-        <td class="delete">
-            <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
-                <i class="icon-trash icon-white"></i>
-                <span>Remove</span>
-            </button>
-        </td>
-    </tr>
-{% } %}
-</script>
app/views/my/photos/new.html.erb
@@ -1,8 +0,0 @@
-<% provide(:title, "Upload images for this cake") -%>
-<div class="row">
-  <div class="span12">
-    <h1><small>Upload images of </small> <%= @cake.name %> <small> (Step 2 of 2)</small></h1>
-    <hr>
-    <%= render 'form' %>
-  </div>
-</div>
spec/controllers/my/photos_controller_spec.rb
@@ -1,64 +0,0 @@
-require 'rails_helper'
-
-module My
-  describe PhotosController do
-    let(:user){ create(:user) }
-    let(:cake){ create(:creation) }
-
-    before(:each) do
-      user.creations << cake
-      http_login(user)
-    end
-
-    describe "#create" do
-      let(:image) { Rack::Test::UploadedFile.new("spec/fixtures/images/gorilla.jpg", "image/jpeg") }
-
-      before :each do
-        xhr :post, :create, cake_id: cake.id, photo: { image: image }
-      end
-
-      it "returns http success" do
-        response.should be_success
-      end
-
-      it "should upload a new photo" do
-        json = JSON.parse(response.body)
-        json["files"].first["name"].should_not be_nil
-        json["files"].first["url"].should_not be_nil
-        json["files"].first["thumbnail_url"].should_not be_nil
-        json["files"].first["delete_url"].should_not be_nil
-        json["files"].first["delete_type"].should == "DELETE"
-      end
-    end
-
-    describe "#delete" do
-      let!(:photo) { create(:photo, creation_id: cake.id, image_processing: nil) }
-      let(:asset_host) { ENV['ASSET_HOST'] }
-
-      before :each do
-        delete :destroy, cake_id: cake.id, id: photo.id
-      end
-
-      it "returns http success" do
-        response.should be_success
-      end
-
-      it "should destroy the photo" do
-        Photo.exists?(photo.id).should be_falsey
-      end
-
-      it "should respond with the proper json" do
-        response.body.should ==
-        {
-          files: [{
-              name: "example.png",
-              url: "#{asset_host}/uploads/photo/image/#{photo.id}/large_example.png",
-              thumbnail_url: "#{asset_host}/uploads/photo/image/#{photo.id}/thumb_example.png",
-              delete_url: photo.id,
-              delete_type: "DELETE"
-            }]
-        }.to_json
-      end
-    end
-  end
-end
spec/controllers/creations_controller_spec.rb
@@ -50,7 +50,6 @@ describe CreationsController do
         before :each do
           post :create, creation: {
             name: 'stone',
-            story: 'morning glory',
             category_id: category.id
           }, creation_tags: 'cake'
         end
@@ -58,7 +57,6 @@ describe CreationsController do
         it "assigns a newly created creation" do
           assigns(:creation).should_not be_nil
           assigns(:creation).name.should == 'stone'
-          assigns(:creation).story.should == 'morning glory'
         end
 
         it "redirects to the created creation" do
Gemfile
@@ -22,7 +22,6 @@ gem 'acts-as-taggable-on', '~> 2.4.1'
 gem 'delayed_job', "~> 4.0.0"
 gem 'delayed_job_active_record', "~> 4.0.0"
 gem 'daemons', '~> 1.1.9'
-gem 'jquery-fileupload-rails', '~> 0.4.1'
 gem 'dotenv-rails'
 gem 'pg'
 gem 'asset_sync', '~> 1.0.0'
Gemfile.lock
@@ -158,9 +158,6 @@ GEM
     jbuilder (1.5.3)
       activesupport (>= 3.0.0)
       multi_json (>= 1.2.0)
-    jquery-fileupload-rails (0.4.1)
-      actionpack (>= 3.1)
-      railties (>= 3.1)
     jquery-rails (3.1.1)
       railties (>= 3.0, < 5.0)
       thor (>= 0.14, < 2.0)
@@ -351,7 +348,6 @@ DEPENDENCIES
   foreman
   gibbon (~> 1.1.2)
   jbuilder (~> 1.2)
-  jquery-fileupload-rails (~> 0.4.1)
   jquery-rails
   jquery-ui-rails (~> 4.0.0)
   js-routes (~> 0.9.8)