diff --git a/Gemfile.lock b/Gemfile.lock
index c6a9b74..fd3a4c1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -4,7 +4,7 @@ PATH
fassets_resources (0.1.0)
carrierwave
fancybox-rails
- fassets_core (~> 0.3.1)
+ fassets_core (~> 0.4.0)
haml
jquery-rails
mime-types
@@ -63,7 +63,7 @@ GEM
erubis (2.7.0)
fancybox-rails (0.1.4)
railties (>= 3.1.0)
- fassets_core (0.3.1)
+ fassets_core (0.4.0)
best_in_place
fancybox-rails
haml
@@ -153,10 +153,10 @@ GEM
sys-proctable (0.9.1)
thor (0.14.6)
tilt (1.3.3)
- treetop (1.4.11)
+ treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.34)
+ tzinfo (0.3.35)
warden (1.0.5)
rack (>= 1.0)
wikipedia-client (1.0.0)
diff --git a/app/assets/javascripts/fassets_resources/index.js b/app/assets/javascripts/fassets_resources/index.js
index 6bbd557..a4e53fd 100644
--- a/app/assets/javascripts/fassets_resources/index.js
+++ b/app/assets/javascripts/fassets_resources/index.js
@@ -1,6 +1,5 @@
//= require fassets_core
//= require flowplayer
-//= require jquery.fileupload
-//= require jquery.fileupload-ui
//= require_self
//= require ./add_asset_box
+//= require ./wikipedia_search
diff --git a/app/assets/javascripts/fassets_resources/wikipedia_search.js b/app/assets/javascripts/fassets_resources/wikipedia_search.js
new file mode 100644
index 0000000..427b655
--- /dev/null
+++ b/app/assets/javascripts/fassets_resources/wikipedia_search.js
@@ -0,0 +1,19 @@
+$(document).ready(function(){
+ var performWikiSearch = function() {
+ var wiki_qry_path = $("input.wiki_submit").data("wiki-qry-path");
+ var search_key = $("input#file_asset_search_key").val();
+ $("#wiki_search_result").load(wiki_qry_path,{'search_key': search_key});
+ };
+ $(document).ajaxComplete(function() {
+ $("input.wiki_submit").one("click", function(event){
+ event.preventDefault();
+ performWikiSearch();
+ });
+ $("input#file_asset_search_key").one("keydown", function(event){
+ if (event.which == 13) {
+ event.preventDefault();
+ performWikiSearch();
+ };
+ });
+ });
+});
diff --git a/app/assets/stylesheets/fassets_resources/file_assets.css.scss b/app/assets/stylesheets/fassets_resources/file_assets.css.scss
new file mode 100644
index 0000000..66cd0ea
--- /dev/null
+++ b/app/assets/stylesheets/fassets_resources/file_assets.css.scss
@@ -0,0 +1,3 @@
+#file_asset_form {
+ float: none;
+}
\ No newline at end of file
diff --git a/app/assets/stylesheets/fassets_resources/index.css b/app/assets/stylesheets/fassets_resources/index.css
index aa4d1d5..25cf624 100644
--- a/app/assets/stylesheets/fassets_resources/index.css
+++ b/app/assets/stylesheets/fassets_resources/index.css
@@ -2,4 +2,6 @@
*= require fancybox
*= require_self
*= require fassets_core
+ *= require ./file_assets
+ *= require ./wikipedia
*/
diff --git a/app/controllers/fassets_resources/file_assets_controller.rb b/app/controllers/fassets_resources/file_assets_controller.rb
index 27148d2..38ef9f7 100644
--- a/app/controllers/fassets_resources/file_assets_controller.rb
+++ b/app/controllers/fassets_resources/file_assets_controller.rb
@@ -3,6 +3,7 @@
module FassetsResources
class FileAssetsController < AssetsController
skip_before_filter :authenticate_user!, :only => [:thumb, :preview, :original]
+ skip_before_filter :find_content, :only => [:wikipedia_images]
def thumb
redirect_to "/public/uploads/#{@content.id}/thumb.#{params[:format]}"
@@ -20,24 +21,17 @@ def original
def content_model
return FileAsset
end
- def new_remote_file
- @content = FileAsset.new
- render :template => 'file_assets/new_remote_file'
- end
- def search_wiki_imgs
+ def wikipedia_images
@content = FileAsset.new
Wikipedia.Configure {
domain 'en.wikipedia.org'
#domain 'commons.wikimedia.org'
path 'w/api.php'
}
- page = Wikipedia.find(params[:search_key])
- image_urls = page.image_urls
- render :partial => 'file_assets/search_wiki_imgs', :locals => {:search_key => params[:search_key], :image_urls => image_urls}
- end
- def get_wiki_imgs
- @content = FileAsset.new
- render :template => "file_assets/new_wiki_img"
+ page = Wikipedia.find(params[:search_key]) unless params[:search_key] == ""
+ @image_urls = page.image_urls unless page.nil?
+ @image_urls ||= []
+ render :partial => 'wikipedia_images', :locals => {:search_key => params[:search_key], :image_urls => @image_urls}
end
end
end
diff --git a/app/views/fassets_resources/file_assets/_fileupload_widget.html.erb b/app/views/fassets_resources/file_assets/_fileupload_widget.html.erb
deleted file mode 100644
index 09cd08b..0000000
--- a/app/views/fassets_resources/file_assets/_fileupload_widget.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
diff --git a/app/views/fassets_resources/file_assets/_form.html.haml b/app/views/fassets_resources/file_assets/_form.html.haml
index 9b9816f..d7993cb 100644
--- a/app/views/fassets_resources/file_assets/_form.html.haml
+++ b/app/views/fassets_resources/file_assets/_form.html.haml
@@ -1,6 +1,6 @@
- if controller.action_name == "new"
- #file_asset_form
- = render :partial => FassetsResources::FileAssetsHelper::partial_for_type(@selected_type)
+ %p#file_asset_form
+ = render :partial => FassetsResources::FileAssetsHelper::partial_for_type(@selected_type), :object => form
- if controller.action_name == "edit"
#edit_asset_content
diff --git a/app/views/fassets_resources/file_assets/_local_file_form.html.haml b/app/views/fassets_resources/file_assets/_local_file_form.html.haml
index 0861b71..aa24abd 100644
--- a/app/views/fassets_resources/file_assets/_local_file_form.html.haml
+++ b/app/views/fassets_resources/file_assets/_local_file_form.html.haml
@@ -1,18 +1,5 @@
-#fileupload
- =form_for :file_asset, :html => { :multipart => true } do |f|
- .fileupload-buttonbar
- %label.fileinput-button
- %span
- Add files...
- =f.file_field :file
- %br
- %button{:type=>"submit",:class=>"start"}Start upload
- %button{:type=>"reset",:class=>"cancel"}Cancel upload
- %button{:type=>"button",:class=>"delete"}Delete files
- .fileupload-content
- %table{:class=>"files"}
- .fileupload-progressbar
+-local_file_form.multipart = true # set multipart for the form builder to true to allow file uploads
- =render :partial => "fassets_resources/file_assets/template-upload"
- =render :partial => "fassets_resources/file_assets/template-download"
- =render :partial => "fassets_resources/file_assets/fileupload_widget"
+=fields_for :fassets_resources_file_asset do |f|
+ =f.label :file
+ =f.file_field :file
diff --git a/app/views/fassets_resources/file_assets/_remote_file_form.html.haml b/app/views/fassets_resources/file_assets/_remote_file_form.html.haml
index 59969b5..c65ccda 100644
--- a/app/views/fassets_resources/file_assets/_remote_file_form.html.haml
+++ b/app/views/fassets_resources/file_assets/_remote_file_form.html.haml
@@ -1,12 +1,3 @@
--content_for :h1 do
- #type
- =@content.class.to_s
- #name
- New
-
-#main.fassets_core
- =fields_for "fassets_resources_file_asset" do |a|
- %p
- =a.label :remote_url, "Remote File Url:"
- =a.text_field :remote_file_url
- =submit_tag "Add", :class => "add_remote_file"
+=fields_for "fassets_resources_file_asset" do |a|
+ =a.label :remote_url, "Remote File Url:"
+ =a.text_field :remote_file_url
diff --git a/app/views/fassets_resources/file_assets/_template-download.html.erb b/app/views/fassets_resources/file_assets/_template-download.html.erb
deleted file mode 100644
index 72adeef..0000000
--- a/app/views/fassets_resources/file_assets/_template-download.html.erb
+++ /dev/null
@@ -1,40 +0,0 @@
-
diff --git a/app/views/fassets_resources/file_assets/_template-upload.html.erb b/app/views/fassets_resources/file_assets/_template-upload.html.erb
deleted file mode 100644
index 1a97956..0000000
--- a/app/views/fassets_resources/file_assets/_template-upload.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
\ No newline at end of file
diff --git a/app/views/fassets_resources/file_assets/_wiki_img_form.html.haml b/app/views/fassets_resources/file_assets/_wiki_img_form.html.haml
index c4a9951..94baa41 100644
--- a/app/views/fassets_resources/file_assets/_wiki_img_form.html.haml
+++ b/app/views/fassets_resources/file_assets/_wiki_img_form.html.haml
@@ -4,11 +4,10 @@
#name
New
-#main.fassets_core
- =form_for @content, :url => "/search_wiki_imgs",:html => {:multipart => true} do |f|
- =render :partial => "shared/error", :locals => {:target => @content}
- %p
- %label{:for => 'search_key'} Search for Images from:
- =text_field :file_asset, :search_key
- =submit_tag "Search", :class => "wiki_submit"
-
+#search_wiki_images
+ =render :partial => "shared/error", :locals => {:target => @content}
+ %p
+ %label{:for => 'search_key'} Search for Images from:
+ =text_field :file_asset, :search_key
+ =submit_tag "Search", :class => "wiki_submit", :data => {:wiki_qry_path => fassets_resources.wikipedia_search_path}
+ #wiki_search_result
diff --git a/app/views/fassets_resources/file_assets/_search_wiki_imgs.html.haml b/app/views/fassets_resources/file_assets/_wikipedia_images.html.haml
similarity index 100%
rename from app/views/fassets_resources/file_assets/_search_wiki_imgs.html.haml
rename to app/views/fassets_resources/file_assets/_wikipedia_images.html.haml
diff --git a/config/routes.rb b/config/routes.rb
index ca3836b..aa8295d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,10 +9,5 @@
end
end
- match 'file_assets/:id' => 'FileAssets#update'
- match 'urls/:id' => 'Urls#update'
- match 'new_remote_file' => 'FileAssets#new_remote_file'
- match 'get_wiki_imgs' => 'FileAssets#get_wiki_imgs'
- match 'search_wiki_imgs' => 'FileAssets#search_wiki_imgs'
- match 'add_wiki_img' => 'FileAssets#add_wiki_image'
+ post '/wikipedia_search', :as => 'wikipedia_search', :action => 'wikipedia_images', :controller => "file_assets"
end
diff --git a/fassets_resources.gemspec b/fassets_resources.gemspec
index 23763a2..03d65ff 100644
--- a/fassets_resources.gemspec
+++ b/fassets_resources.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 3.1.1"
- s.add_dependency "fassets_core", "~> 0.3.1"
+ s.add_dependency "fassets_core", "~> 0.4.0"
s.add_dependency "jquery-rails"
s.add_dependency "haml"
s.add_dependency "sqlite3"
diff --git a/spec/controllers/fassets_resources/file_assets_controller_spec.rb b/spec/controllers/fassets_resources/file_assets_controller_spec.rb
index 0262b5d..0162505 100644
--- a/spec/controllers/fassets_resources/file_assets_controller_spec.rb
+++ b/spec/controllers/fassets_resources/file_assets_controller_spec.rb
@@ -46,5 +46,35 @@ module FassetsResources
response.should render_template("assets/show")
end
end
+
+ context "GET wikipedia_images" do
+ it "should get a list of images" do
+ page = double("Wikipedia::Page")
+ test_urls = ['http://test.host/test1.png','http://test.host/test2.png']
+ page.should_receive(:image_urls) { test_urls }
+ Wikipedia.should_receive(:find).with("test search") { page }
+ get 'wikipedia_images', :use_route => :fassets_resources, :search_key => "test search"
+ response.should be_success
+ response.should render_template "wikipedia_images"
+ response.should_not render_template "layouts/fassets_core/application"
+ assigns(:image_urls).should == test_urls
+ end
+
+ it "should not assign nil as image list" do
+ page = double("Wikipedia::Page")
+ # image_urls returns nil if no images are found
+ page.should_receive(:image_urls) { nil }
+ Wikipedia.should_receive(:find).with("test search") { page }
+ get 'wikipedia_images', :use_route => :fassets_resources, :search_key => "test search"
+ assigns(:image_urls).should_not be_nil
+ assigns(:image_urls).should be_empty
+ end
+
+ it "should not fail with empty search string" do
+ # find with empty string will raise a type error
+ Wikipedia.should_not_receive(:find).with("")
+ get 'wikipedia_images', :use_route => :fassets_resources, :search_key => ""
+ end
+ end
end
end