cloudhdr_rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/cloudhdr/updater.js +115 -0
- data/app/assets/stylesheets/cloudhdr/updater.css +8 -0
- data/app/controllers/cloudhdr_controller.rb +64 -0
- data/app/helpers/cloudhdr_helper.rb +245 -0
- data/app/models/cloudhdr_job.rb +189 -0
- data/app/views/cloudhdr/_thumbnail_update.html.erb +3 -0
- data/app/views/cloudhdr/multi_thumbnail_update.json.erb +7 -0
- data/app/views/cloudhdr/thumbnail_update.js.erb +1 -0
- data/config/routes.rb +8 -0
- data/lib/cloudhdr_rails/acts_as_cloudhdr.rb +1020 -0
- data/lib/cloudhdr_rails/engine.rb +4 -0
- data/lib/cloudhdr_rails/errors.rb +46 -0
- data/lib/cloudhdr_rails/version.rb +3 -0
- data/lib/cloudhdr_rails.rb +7 -0
- data/lib/generators/cloudhdr_rails/model_update_generator.rb +52 -0
- data/lib/generators/cloudhdr_rails/scaffold_generator.rb +94 -0
- data/lib/generators/cloudhdr_rails/setup_generator.rb +33 -0
- data/lib/generators/cloudhdr_rails/templates/cloudhdr.yml +19 -0
- data/lib/generators/cloudhdr_rails/templates/controller.rb +71 -0
- data/lib/generators/cloudhdr_rails/templates/helper.rb +5 -0
- data/lib/generators/cloudhdr_rails/templates/migration.rb +21 -0
- data/lib/generators/cloudhdr_rails/templates/model.rb +15 -0
- data/lib/generators/cloudhdr_rails/templates/model_migration.rb +56 -0
- data/lib/generators/cloudhdr_rails/templates/model_thumbnail.rb +5 -0
- data/lib/generators/cloudhdr_rails/templates/model_update_migration.rb +64 -0
- data/lib/generators/cloudhdr_rails/templates/views/_form.html.erb.tt +23 -0
- data/lib/generators/cloudhdr_rails/templates/views/index.html.erb.tt +26 -0
- data/lib/generators/cloudhdr_rails/templates/views/new.html.erb.tt +5 -0
- data/lib/generators/cloudhdr_rails/templates/views/show.html.erb.tt +12 -0
- data/lib/tasks/cloudhdr_rails_tasks.rake +19 -0
- metadata +212 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'CloudhdrRails'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
var Cloudhdr = {};
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Cloudhdr.JQueryUpdater = function(){
|
6
|
+
_self = this;
|
7
|
+
this.img_selector = "img[data-cloudhdr-waiting]";
|
8
|
+
|
9
|
+
this.init = function(options){
|
10
|
+
//console.log("Cloudhdr.Updater.init()");
|
11
|
+
if(options == null){ options = {}; }
|
12
|
+
this.jslib = options.jslib || "jquery";
|
13
|
+
setTimeout(this.update,200);
|
14
|
+
};
|
15
|
+
|
16
|
+
this.update = function(){
|
17
|
+
//console.log("starting update!!");
|
18
|
+
params = _self.build_update_params();
|
19
|
+
//console.debug(params);
|
20
|
+
if(params.length == 0){
|
21
|
+
//console.debug("ending because params are blank")
|
22
|
+
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
$.ajax({ type: 'POST',
|
26
|
+
url : '/cloudhdr/multi_thumbnail_update.json',
|
27
|
+
dataType : 'json',
|
28
|
+
data : { images : params },
|
29
|
+
error : function(jqXHR, textStatus, errorThrown) {
|
30
|
+
//console.log(jqXHR); console.log(textStatus); console.log(errorThrown);
|
31
|
+
},
|
32
|
+
success : _self.update_response
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
this.update_response = function(data, textStatus, jqXHR){
|
37
|
+
//console.log("starting update_response");
|
38
|
+
$.each(data,function(key,value){
|
39
|
+
$("#"+key).replaceWith(value);
|
40
|
+
});
|
41
|
+
setTimeout(_self.update,15000);
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
this.build_update_params = function(){
|
46
|
+
params = [];
|
47
|
+
elements = _self.select_elements();
|
48
|
+
$.each(elements,function(index,elem){
|
49
|
+
// Format is : Image_1_medium_db0ce8ba5d55c25eee7c767220d654fe
|
50
|
+
// Format is : class_id_thumbnail_random
|
51
|
+
//match = $(elem).attr("id").match(/^(.*)_(.*)_(.*)_(.*)$/)
|
52
|
+
//hash = {
|
53
|
+
// class_name : match[1],
|
54
|
+
// id : match[2],
|
55
|
+
// thumbnail : match[3],
|
56
|
+
// random : match[4]
|
57
|
+
//}
|
58
|
+
params.push( $(elem).attr("id") );
|
59
|
+
});
|
60
|
+
return params;
|
61
|
+
}
|
62
|
+
|
63
|
+
this.select_elements = function(){
|
64
|
+
return $(this.img_selector);
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
}; // Cloudhdr.JQueryUpdater
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
Cloudhdr.Updater = function(){
|
75
|
+
_self = this;
|
76
|
+
this.img_selector = "img[data-cloudhdr-waiting]";
|
77
|
+
|
78
|
+
this.init = function(options){
|
79
|
+
//console.log("Cloudhdr.Updater.init()");
|
80
|
+
if(options == null){ options = {}; }
|
81
|
+
this.jslib = options.jslib || "jquery";
|
82
|
+
setTimeout(this.update,2000);
|
83
|
+
};
|
84
|
+
|
85
|
+
this.update = function(){
|
86
|
+
params = _self.build_update_params();
|
87
|
+
//console.debug(params);
|
88
|
+
}
|
89
|
+
|
90
|
+
this.build_update_params = function(){
|
91
|
+
params = {};
|
92
|
+
elements = _self.select_elements();
|
93
|
+
|
94
|
+
return params;
|
95
|
+
}
|
96
|
+
|
97
|
+
this.select_elements = function(){
|
98
|
+
if(this.jslib == "jquery"){
|
99
|
+
return this.select_elements_jquery();
|
100
|
+
}else if(this.jslib == "prototype"){
|
101
|
+
return this.select_elements_prototype();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
this.select_elements_jquery = function(){
|
106
|
+
return $(this.img_selector);
|
107
|
+
};
|
108
|
+
|
109
|
+
this.select_elements_prototype = function(){
|
110
|
+
return $$(this.img_selector);
|
111
|
+
};
|
112
|
+
|
113
|
+
}; // Cloudhdr.PrototypeUpdater
|
114
|
+
|
115
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class CloudhdrController < ApplicationController
|
2
|
+
|
3
|
+
protect_from_forgery :except=>[:cloudhdr_notification_update,:zencoder_notification_update,:thumbnail_update,:multi_thumbnail_update]
|
4
|
+
|
5
|
+
def cloudhdr_notification_update
|
6
|
+
full_params = params
|
7
|
+
CloudhdrJob.update_from_cloudhdr(full_params)
|
8
|
+
respond_to do |format|
|
9
|
+
format.json { render :json => {} }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def thumbnail_update
|
14
|
+
@img = Kernel.const_get(params[:class]).find params[:id]
|
15
|
+
@random = params[:random]
|
16
|
+
@live_vide = params[:live_video]
|
17
|
+
respond_to do |format|
|
18
|
+
format.js {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def multi_thumbnail_update
|
23
|
+
@outputs = []
|
24
|
+
params[:images].each do |image|
|
25
|
+
# Format ex : Image_1_medium_db0ce8ba5d55c25eee7c767220d654fe
|
26
|
+
# Format is : class_id_thumbnail_random
|
27
|
+
match = image.match(/^(.*)_(.*)_(.*)_(.*)$/)
|
28
|
+
hash = {
|
29
|
+
:elem_id => image,
|
30
|
+
:class_name => match[1],
|
31
|
+
:id => match[2],
|
32
|
+
:thumbnail => match[3],
|
33
|
+
:random => match[4],
|
34
|
+
:image => Kernel.const_get(match[1]).find(match[2])
|
35
|
+
}
|
36
|
+
@outputs << hash
|
37
|
+
end
|
38
|
+
respond_to do |format|
|
39
|
+
format.json {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# thanks to http://avdi.org/devblog/2009/07/14/recursively-symbolize-keys/
|
45
|
+
#def symbolize_keys(hash)
|
46
|
+
#puts "the hash = #{hash.class} : #{hash}"
|
47
|
+
#return hash if !hash.is_a?(Hash)
|
48
|
+
#hash.inject({}){|result, (key, value)|
|
49
|
+
#new_key = case key
|
50
|
+
#when String then key.to_sym
|
51
|
+
#else key
|
52
|
+
#end
|
53
|
+
#new_value = case value
|
54
|
+
#when Hash then symbolize_keys(value)
|
55
|
+
#else value
|
56
|
+
#end
|
57
|
+
#result[new_key] = new_value
|
58
|
+
#result
|
59
|
+
#}
|
60
|
+
#end
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
module CloudhdrHelper
|
2
|
+
|
3
|
+
def preview_reload_timeout
|
4
|
+
#time in ms between preview reloading
|
5
|
+
10000
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
#def cloudhdr_includes
|
10
|
+
#tag = javascript_include_tag 'cloudhdr.js'
|
11
|
+
#tag += "\n"
|
12
|
+
#tag += stylesheet_link_tag 'cloudhdr.css'
|
13
|
+
#end
|
14
|
+
|
15
|
+
|
16
|
+
def cloudhdr_link(text,file)
|
17
|
+
if file.cloudhdr_status == "ready" or file.cloudhdr_status == "s3"
|
18
|
+
link_to text, file.public_filename
|
19
|
+
else
|
20
|
+
text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# for now we'll assume that a thumbnail is needed
|
26
|
+
# some files aren't displayable in a native way (NEF etc...)
|
27
|
+
#
|
28
|
+
def cloudhdr_thumbnail(image,thumbnail="small",options={})
|
29
|
+
if image.image?
|
30
|
+
return cloudhdr_image_thumbnail(image,thumbnail,options)
|
31
|
+
else
|
32
|
+
return error_div("This #{image.class} is not an image.")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Passing a thumbnail is STRONGLY ADVISED
|
38
|
+
# Unless you are abosultely sure that you are only accepting web safe image formats you'll want to supply a thumbnail arg
|
39
|
+
#
|
40
|
+
def cloudhdr_image_thumbnail(image_upload,thumbnail="small",options={})
|
41
|
+
if ActsAsCloudhdr.storeage_mode == "offline"
|
42
|
+
cloudhdr_image_offline(image_upload,thumbnail,options)
|
43
|
+
else
|
44
|
+
cloudhdr_image_online(image_upload,thumbnail,options)
|
45
|
+
end
|
46
|
+
#return display_image(image_upload,options) if thumbnail.blank?
|
47
|
+
#thumbnail = find_or_create_thumbnail(image_upload,thumbnail,options)
|
48
|
+
#return display_image_thumbnail(image_upload,thumbnail,options) if thumbnail
|
49
|
+
#return error_div "Could not find a thumbnail for: class=#{image_upload.class} thumbnail=#{thumbnail.to_json}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def cloudhdr_image_offline(image_upload,thumbnail="small",options={})
|
53
|
+
if !image_upload.web_safe?
|
54
|
+
error_div "#{image_upload.filename} can not be displayed directly because it is not web safe. Content type = #{image_upload.content_type}"
|
55
|
+
elsif thumbnail.blank?
|
56
|
+
image_tag(image_upload.public_url,options)
|
57
|
+
else
|
58
|
+
begin
|
59
|
+
# since we're in offline mode here we don't actually have files created for the thumbnail
|
60
|
+
# so we return an image with the path to the original, we don't care about cloudhdr_status
|
61
|
+
thumbnail = find_thumbnail_attributes(image_upload,thumbnail,options)
|
62
|
+
image_tag image_upload.public_url, {:width => thumbnail[:width],:height => thumbnail[:height]}.merge(options)
|
63
|
+
rescue ActsAsCloudhdr::ThumbnailAttributesNotFoundError
|
64
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def cloudhdr_image_online(image_upload,thumbnail="small",options={})
|
70
|
+
if thumbnail.blank? and !image_upload.web_safe?
|
71
|
+
error_div "#{image_upload.filename} can not be displayed directly because it is not web safe. Content type = #{image_upload.content_type}"
|
72
|
+
elsif thumbnail.blank? and !image_upload.ready?
|
73
|
+
# don't know width and height yet
|
74
|
+
image_tag(image_upload.public_url,options)
|
75
|
+
elsif thumbnail.blank?
|
76
|
+
# now we have width and height
|
77
|
+
image_tag(image_upload.public_url,options.merge(:width => image_upload.width, :height => image_upload.height))
|
78
|
+
elsif !image_upload.ready?
|
79
|
+
begin
|
80
|
+
# We can only look for attributes now to show a pending message with the correct dimensions
|
81
|
+
thumb_atts = find_thumbnail_attributes(image_upload,thumbnail,options)
|
82
|
+
pending_cloudhdr_thumbnail(image_upload,thumb_atts,options)
|
83
|
+
rescue ActsAsCloudhdr::ThumbnailAttributesNotFoundError
|
84
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
85
|
+
end
|
86
|
+
else
|
87
|
+
begin
|
88
|
+
thumb = find_or_create_thumbnail(image_upload,thumbnail,options)
|
89
|
+
if thumb.ready?
|
90
|
+
image_tag thumb.public_url, {:width => thumb[:width],:height => thumb[:height]}.merge(options)
|
91
|
+
else
|
92
|
+
pending_cloudhdr_thumbnail(image_upload,thumb,options)
|
93
|
+
end
|
94
|
+
rescue ActsAsCloudhdr::ThumbnailNotFoundError
|
95
|
+
error_div "'#{thumbnail}' is not a valid thumbnail name or size string."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# def display_image(image_upload,options={})
|
101
|
+
# if ActsAsCloudhdr.storeage_mode == "offline"
|
102
|
+
# offline_cloudhdr_image_thumbnail(image_upload,image_upload,options)
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
def find_thumbnail_attributes(image_upload,thumbnail,options)
|
106
|
+
if thumbnail.is_a? String
|
107
|
+
thumb_atts = image_upload.thumbnail_attributes_for(thumbnail)
|
108
|
+
elsif thumbnail.is_a? Hash
|
109
|
+
thumb_atts = thumbnail
|
110
|
+
end
|
111
|
+
thumb_atts
|
112
|
+
end
|
113
|
+
|
114
|
+
def find_or_create_thumbnail(image_upload,thumbnail="small",options={})
|
115
|
+
if thumbnail.is_a? String
|
116
|
+
thumb = image_upload.thumbnail_for(thumbnail)
|
117
|
+
end
|
118
|
+
thumb
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# # image = the original upload
|
124
|
+
# # thumbnail = a record representing the dimensions of the thumbnail
|
125
|
+
# # options = some other stuff
|
126
|
+
# def display_image_thumbnail(image_upload,thumbnail,options)
|
127
|
+
# puts "Thumbnail = #{thumbnail.to_json}"
|
128
|
+
# if ActsAsCloudhdr.storeage_mode == "offline"
|
129
|
+
# offline_cloudhdr_image_thumbnail(image_upload,thumbnail,options)
|
130
|
+
# elsif thumbnail.cloudhdr_status != "ready"
|
131
|
+
# pending_cloudhdr_thumbnail(image_upload,thumbnail,false,options)
|
132
|
+
# else
|
133
|
+
# image_tag thumbnail.public_url, {:width => thumbnail[:width],:height => thumbnail[:height]}.merge(options)
|
134
|
+
# end
|
135
|
+
# end
|
136
|
+
|
137
|
+
# # A special handler when the mode is 'offline'
|
138
|
+
# # The thumbnail record will contain the proper dimensions, but the path will be no good.
|
139
|
+
# # This combines the path of the original with the dimensions of the original and serves from the local store.
|
140
|
+
# def offline_cloudhdr_image_thumbnail(photo,thumbnail_atts,options={})
|
141
|
+
# image_tag photo.local_url, {:width => thumbnail_atts[:width],:height => thumbnail_atts[:height]}.merge(options)
|
142
|
+
# #if thumbnail_atts.blank?
|
143
|
+
# # image_tag photo.local_url, options
|
144
|
+
# #elsif thumbnail_atts[:aspect_mode] == "stretch"
|
145
|
+
# #
|
146
|
+
# #else
|
147
|
+
# # "<div style='overflow:hidden;background:#ccc;width:#{thumbnail_atts[:width]}px;height:#{thumbnail_atts[:height]}px'>#{image_tag(photo.local_url,{:width => thumbnail_atts[:width]}.merge(options))}</div>".html_safe
|
148
|
+
# #end
|
149
|
+
# end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# Thumbnail should either be an ActiveRecord or a Hash
|
154
|
+
def pending_cloudhdr_thumbnail(photo,thumbnail,options,spinner='waiting')
|
155
|
+
random = SecureRandom.hex(16)
|
156
|
+
Rails.logger.debug "======================================================"
|
157
|
+
Rails.logger.debug "building pending thumbnail for #{thumbnail.class} #{thumbnail.to_json}"
|
158
|
+
if thumbnail.is_a? Hash
|
159
|
+
thumb_name = thumbnail[:label]
|
160
|
+
else
|
161
|
+
thumb_name = thumbnail.thumbnail
|
162
|
+
end
|
163
|
+
width = thumbnail[:width]
|
164
|
+
height = thumbnail[:height]
|
165
|
+
|
166
|
+
elemId = "#{photo.class.to_s}_#{photo.id.to_s}_#{thumb_name}_#{random}"
|
167
|
+
|
168
|
+
tag = image_tag "#{spinner}.gif", :size=>"#{width}x#{height}", :id => elemId, "data-cloudhdr-waiting" => true
|
169
|
+
end
|
170
|
+
|
171
|
+
# def error_cloudhdr_thumbnail(photo,thumbnail,options,spinner='error')
|
172
|
+
# width = thumbnail.try :width
|
173
|
+
# height = thumbnail.try :height
|
174
|
+
# tag = image_tag "#{spinner}.gif", :size=>"#{width}x#{height}"
|
175
|
+
# end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
# # for now we'll assume that a thumbnail is needed
|
180
|
+
# # some files aren't displayable in a native way (NEF etc...)
|
181
|
+
# #
|
182
|
+
# def old_cloudhdr_image_thumbnail(image_upload,thumbnail="small",options={})
|
183
|
+
# puts "thumbnail = #{thumbnail}"
|
184
|
+
# thumbnail_atts = image_upload.class.thumbnail_attributes_for thumbnail
|
185
|
+
# if ActsAsCloudhdr.storeage_mode == "offline" and (thumbnail.blank? or !thumbnail_atts.blank?)
|
186
|
+
# return offline_cloudhdr_thumbnail(image_upload,thumbnail_atts,options)
|
187
|
+
# elsif thumbnail.nil? and (image_upload.cloudhdr_status == "ready")
|
188
|
+
# return image_tag image_upload.public_url, {:size=>"#{image_upload.width}x#{image_upload.height}"}.merge(options)
|
189
|
+
# elsif thumbnail_atts.blank?
|
190
|
+
# return error_div("'#{thumbnail}' is not a valid thumbnail size for #{image_upload.class}")
|
191
|
+
# elsif image_upload.cloudhdr_status != "ready" #and image_upload.zencoder_status != "ready"
|
192
|
+
# puts "image_upload is not ready!!!!!!!!!!!!!!!!!!!!!!!!"
|
193
|
+
# return pending_cloudhdr_thumbnail(image_upload,thumbnail,false,thumbnail_atts)
|
194
|
+
# #else
|
195
|
+
# # return "<div class='notice'>Online mode is coming soon!</div>"
|
196
|
+
# end
|
197
|
+
#
|
198
|
+
# thumb = image_upload.thumbnail_for(thumbnail)
|
199
|
+
# if thumb.blank? or thumb.cloudhdr_status != "ready"
|
200
|
+
# puts "thumb (#{thumb.to_json}) is not ready!!!!!!!!!!!!!!!!!!!!!!!!"
|
201
|
+
# #this happens if the main image has been notified, but not this thumbnail
|
202
|
+
# return pending_cloudhdr_thumbnail(image_upload,thumbnail,false,thumbnail_atts)
|
203
|
+
# end
|
204
|
+
# image_tag thumb.public_url, {:size=>"#{thumb.width}x#{thumb.height}"}.merge(options)
|
205
|
+
# end
|
206
|
+
|
207
|
+
|
208
|
+
def error_div(msg)
|
209
|
+
%[<div class="cloudhdr_error">#{msg}</div>].html_safe
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
#def jquery_updater(photo,thumbnail,random)
|
216
|
+
# %[
|
217
|
+
# <script type="text/javascript">
|
218
|
+
# setTimeout(function() {
|
219
|
+
# $.ajax({ type: 'POST',
|
220
|
+
# url : '/cloudhdr/thumbnail_update.js',
|
221
|
+
# dataType : 'script',
|
222
|
+
# data : { class:'#{photo.class.to_s}', id:#{photo.id.to_s},thumbnail:'#{thumbnail}',random:'#{random}' }
|
223
|
+
# });
|
224
|
+
# },#{preview_reload_timeout});
|
225
|
+
# </script>
|
226
|
+
# ]
|
227
|
+
#end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
#def prototype_updater(photo,thumbnail,random)
|
232
|
+
# %[
|
233
|
+
# <script type="text/javascript">
|
234
|
+
# setTimeout(function() {
|
235
|
+
# new Ajax.Request( '/cloudhdr/thumbnail_update', {
|
236
|
+
# evalScripts:true,
|
237
|
+
# parameters: { class:'#{photo.class.to_s}', id:#{photo.id.to_s},thumbnail:'#{thumbnail}',random:'#{random}' }
|
238
|
+
# });
|
239
|
+
# },#{preview_reload_timeout});
|
240
|
+
# </script>
|
241
|
+
# ]
|
242
|
+
#end
|
243
|
+
|
244
|
+
|
245
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
class CloudhdrJob < ActiveRecord::Base
|
2
|
+
|
3
|
+
belongs_to :image, :polymorphic=>true
|
4
|
+
|
5
|
+
scope :pending, :conditions => "cloudhdr_status != 'ready'"
|
6
|
+
#scope :for_components, :conditions => "tracking_mode = 'component'"
|
7
|
+
#scope :for_jobs, :conditions => "tracking_mode = 'job'"
|
8
|
+
|
9
|
+
def initialize(params = {}, options={})
|
10
|
+
super
|
11
|
+
#self.tracking_mode = "component" unless self.tracking_mode
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_status
|
15
|
+
job_data = Cloudhdr::Job.details(cloudhdr_job_id).body
|
16
|
+
#puts job_data.to_json
|
17
|
+
puts " CloudhdrJob #{id} = #{job_data["aasm_state"]}"
|
18
|
+
puts "job_data = #{job_data}"
|
19
|
+
puts "*" * 50
|
20
|
+
puts "cloudhdr_input_id = #{cloudhdr_input_id}"
|
21
|
+
if cloudhdr_input_id
|
22
|
+
job_data["inputs"].each do |input|
|
23
|
+
#puts "input = #{input.to_json}"
|
24
|
+
puts "input id = #{input["id"]} my cloudhdr_input_id = #{cloudhdr_input_id}"
|
25
|
+
if input["id"] == cloudhdr_input_id
|
26
|
+
input.symbolize_keys!
|
27
|
+
params = {
|
28
|
+
:class => image_type,
|
29
|
+
:id => image_id,
|
30
|
+
:job => { :id => job_data["id"] },
|
31
|
+
:input => input
|
32
|
+
}
|
33
|
+
CloudhdrJob.update_from_cloudhdr(params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
elsif cloudhdr_output_id
|
37
|
+
outputs = (job_data["thumbnails"] || []) +
|
38
|
+
(job_data["hdrs"] || []) +
|
39
|
+
(job_data["tone_mappings"] || []) +
|
40
|
+
(job_data["composites"] || []) +
|
41
|
+
(job_data["hdr_htmls"] || [])
|
42
|
+
outputs.each do |output|
|
43
|
+
if output["id"] == cloudhdr_output_id
|
44
|
+
output.symbolize_keys!
|
45
|
+
output[:url] = output[:base_url] + output[:filename]
|
46
|
+
params = {
|
47
|
+
:class => image_type,
|
48
|
+
:id => image_id,
|
49
|
+
:job => { :id => job_data["id"] },
|
50
|
+
:output => output
|
51
|
+
}
|
52
|
+
CloudhdrJob.update_from_cloudhdr(params)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
puts "+++++++++++++++"
|
57
|
+
#if job_data["aasm_state"] == "complete"
|
58
|
+
# self.cloudhdr_status = "ready"
|
59
|
+
# self.image.cloudhdr_status = "ready"
|
60
|
+
# self.image.thumbnails.each do |t|
|
61
|
+
# t.cloudhdr_status = "ready"
|
62
|
+
# end
|
63
|
+
# self.save
|
64
|
+
# #self.image.save
|
65
|
+
#end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.update_pending_jobs
|
69
|
+
CloudhdrJob.pending.find_each do |e|
|
70
|
+
e.update_status
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def self.update_from_cloudhdr(params)
|
76
|
+
#if params.keys.include?("inputs") && params.keys.include?("outputs")
|
77
|
+
update_from_cloudhdr_job_style(params)
|
78
|
+
#else
|
79
|
+
# update_from_cloudhdr_component_style(params)
|
80
|
+
#end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.update_from_cloudhdr_job_style(params)
|
84
|
+
if params[:job][:type] == 'ThumbnailJob'
|
85
|
+
update_from_cloudhdr_thumbnail_job(params)
|
86
|
+
elsif params[:job][:type] == 'CompositeJob' || params[:job][:type] == 'ToneMappingJob'
|
87
|
+
update_from_cloudhdr_generic_job_with_thumbnails(params)
|
88
|
+
else
|
89
|
+
update_from_cloudhdr_generic_job(params)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.update_from_cloudhdr_thumbnail_job(params)
|
94
|
+
#debugger
|
95
|
+
job = self.find_by_cloudhdr_job_id params[:job][:id]
|
96
|
+
image = job.image
|
97
|
+
|
98
|
+
img_params = params[:inputs].first
|
99
|
+
update_image_and_job_from_img_params(image,job,img_params)
|
100
|
+
|
101
|
+
params[:outputs].each do |thumb_params|
|
102
|
+
thumbnail = image.thumbnail_for(thumb_params[:label])
|
103
|
+
update_image_and_job_from_img_params(thumbnail,job,thumb_params)
|
104
|
+
thumbnail.cloudhdr_status = "ready" if thumbnail.respond_to?(:cloudhdr_status=)
|
105
|
+
thumbnail.cloudhdr_status = "ready" if thumbnail.respond_to?(:cloudhdr_status=)
|
106
|
+
thumbnail.save!
|
107
|
+
end
|
108
|
+
|
109
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
110
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
111
|
+
image.save!
|
112
|
+
image.fire_ready_callback
|
113
|
+
|
114
|
+
job.cloudhdr_status = "ready"
|
115
|
+
job.save
|
116
|
+
job
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.update_from_cloudhdr_generic_job(params)
|
120
|
+
#debugger
|
121
|
+
job = self.find_by_cloudhdr_job_id params[:job][:id]
|
122
|
+
image = job.image
|
123
|
+
|
124
|
+
img_params = params[:outputs].first
|
125
|
+
update_image_and_job_from_img_params(image,job,img_params)
|
126
|
+
|
127
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
128
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
129
|
+
image.save!
|
130
|
+
image.fire_ready_callback
|
131
|
+
|
132
|
+
job.cloudhdr_status = "ready"
|
133
|
+
job.save
|
134
|
+
job
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.update_from_cloudhdr_generic_job_with_thumbnails(params)
|
138
|
+
#debugger
|
139
|
+
job = self.for_jobs.find_by_cloudhdr_job_id params[:job][:id]
|
140
|
+
image = job.image
|
141
|
+
|
142
|
+
img_params = {}
|
143
|
+
|
144
|
+
|
145
|
+
params[:outputs].each do |thumb_params|
|
146
|
+
if thumb_params[:label].blank?
|
147
|
+
img_params = thumb_params
|
148
|
+
next
|
149
|
+
end
|
150
|
+
thumbnail = image.thumbnail_for(thumb_params[:label])
|
151
|
+
update_image_and_job_from_img_params(thumbnail,job,thumb_params)
|
152
|
+
thumbnail.cloudhdr_status = "ready" if thumbnail.respond_to?(:cloudhdr_status=)
|
153
|
+
thumbnail.cloudhdr_status = "ready" if thumbnail.respond_to?(:cloudhdr_status=)
|
154
|
+
thumbnail.save!
|
155
|
+
end
|
156
|
+
|
157
|
+
update_image_and_job_from_img_params(image,job,img_params)
|
158
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
159
|
+
image.cloudhdr_status = "ready" if image.respond_to?(:cloudhdr_status=)
|
160
|
+
image.save!
|
161
|
+
image.fire_ready_callback
|
162
|
+
|
163
|
+
job.cloudhdr_status = "ready"
|
164
|
+
job.save
|
165
|
+
job
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
def self.update_image_and_job_from_img_params(image,job,img_params)
|
172
|
+
[ :file_size,:width,:height,:taken_at,:lat,:lng,:saturated_pixels,:gauss,:bits_per_pixel,:camera_make,
|
173
|
+
:camera_model, :orientation, :exposure_time, :f_number, :iso_speed_rating, :exposure_bias_value,
|
174
|
+
:focal_length, :focal_length_in_35mm_film, :subsec_time, :pixels, :processing_time].each do |att|
|
175
|
+
setter = att.to_s + "="
|
176
|
+
if image.respond_to? setter and !img_params[att].blank?
|
177
|
+
image.send setter, img_params[att]
|
178
|
+
end
|
179
|
+
if job.respond_to? setter and !img_params[att].blank?
|
180
|
+
job.send setter, img_params[att]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
<% @outputs.each_with_index do |output,i| %>
|
3
|
+
<% @img = output[:image] %>
|
4
|
+
<% @random = output[:random] %>
|
5
|
+
"<%= output[:elem_id] %>" : "<%= escape_javascript(render(:partial=>"thumbnail_update.html.erb", :locals => {:params => output} )) %>" <%= "," if (i+1) != @outputs.size %>
|
6
|
+
<% end %>
|
7
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
$('#<%= @img.class.to_s %>_<%= @img.id.to_s %>_<%= @random %>').replaceWith("<%= escape_javascript(render(:partial=>"thumbnail_update")) %>")
|