summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-07-07 22:04:48 -0600
committermo khan <mo@mokhan.ca>2014-07-07 22:04:48 -0600
commit799d815b99f0c844d5bdf2292035b43fda993bcb (patch)
tree8312373a690a6a1d9b63081670b7512f767ec03a
parentd31db3e0300e8c075cd7cebe44076aeac808fd89 (diff)
remove jquery file upload and old photo upload pages.
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock4
-rw-r--r--app/assets/javascripts/application.js1
-rw-r--r--app/assets/stylesheets/application.css.scss1
-rw-r--r--app/controllers/my/photos_controller.rb44
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/services/application/photo_to_jq_json_mapper.rb11
-rw-r--r--app/services/application/upload_photo.rb11
-rw-r--r--app/views/my/photos/_form.html.erb89
-rw-r--r--app/views/my/photos/new.html.erb8
-rw-r--r--spec/controllers/creations_controller_spec.rb2
-rw-r--r--spec/controllers/my/photos_controller_spec.rb64
12 files changed, 1 insertions, 237 deletions
diff --git a/Gemfile b/Gemfile
index d0d7cf5a..124f6afb 100644
--- a/Gemfile
+++ b/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'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9a5713c2..de3a7253 100644
--- a/Gemfile.lock
+++ b/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)
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 1bee516a..2d87213c 100644
--- a/app/assets/javascripts/application.js
+++ b/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
diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
index da34f861..8f19b2a4 100644
--- a/app/assets/stylesheets/application.css.scss
+++ b/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
diff --git a/app/controllers/my/photos_controller.rb b/app/controllers/my/photos_controller.rb
deleted file mode 100644
index d67a17be..00000000
--- a/app/controllers/my/photos_controller.rb
+++ /dev/null
@@ -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
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 72b4dc5c..464d05f9 100644
--- a/app/models/comment.rb
+++ b/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
diff --git a/app/services/application/photo_to_jq_json_mapper.rb b/app/services/application/photo_to_jq_json_mapper.rb
deleted file mode 100644
index f85235f4..00000000
--- a/app/services/application/photo_to_jq_json_mapper.rb
+++ /dev/null
@@ -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
diff --git a/app/services/application/upload_photo.rb b/app/services/application/upload_photo.rb
index cba399c8..16b2c381 100644
--- a/app/services/application/upload_photo.rb
+++ b/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)
diff --git a/app/views/my/photos/_form.html.erb b/app/views/my/photos/_form.html.erb
deleted file mode 100644
index 01601017..00000000
--- a/app/views/my/photos/_form.html.erb
+++ /dev/null
@@ -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>
diff --git a/app/views/my/photos/new.html.erb b/app/views/my/photos/new.html.erb
deleted file mode 100644
index 5ee789a4..00000000
--- a/app/views/my/photos/new.html.erb
+++ /dev/null
@@ -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>
diff --git a/spec/controllers/creations_controller_spec.rb b/spec/controllers/creations_controller_spec.rb
index b52cac83..3e5620af 100644
--- a/spec/controllers/creations_controller_spec.rb
+++ b/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
diff --git a/spec/controllers/my/photos_controller_spec.rb b/spec/controllers/my/photos_controller_spec.rb
deleted file mode 100644
index 401bca25..00000000
--- a/spec/controllers/my/photos_controller_spec.rb
+++ /dev/null
@@ -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