Skip to content

Commit

Permalink
Fixing stuff, taggin room etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Daguaa committed Mar 26, 2011
1 parent a3ee318 commit 98f5964
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 75 deletions.
231 changes: 157 additions & 74 deletions .idea/workspace.xml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions app/controllers/integrity_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class IntegrityController < ApplicationController
def index
@thumb_no_time = Thumbnail.where(:time=>nil).count
end

def time_thumb
Delayed::Job.enqueue ThumbTimeJob.new()
render :nothing=>true
end

def purge_thumb
Delayed::Job.enqueue ThumbPurgeJob.new()
render :nothing=>true
end

end
2 changes: 2 additions & 0 deletions app/helpers/integrity_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module IntegrityHelper
end
7 changes: 7 additions & 0 deletions app/jobs/thumb_purge_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ThumbPurgeJob
def perform
Thumbnail.all.each do |t|
t.destroy
end
end
end
7 changes: 7 additions & 0 deletions app/jobs/thumb_time_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ThumbTimeJob
def perform
Movie.all.each do |m|
m.delay.recalculate_time_of_thumbnails
end
end
end
14 changes: 14 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def process
self.delay.init!
end

def recalculate_time_of_thumbnails
thumbnails.each do |t|
t.time = (t.order*0.1*self.length).to_i;
t.save!
end
end

def check_file_location_and_length
if File.exists?(self.system_file.path)
self.compute_length
Expand All @@ -44,15 +51,22 @@ def check_file_location_and_length

def try_to_make_thumbs
self.generate_thumbnail
end

def thumbs_exist?
thumbs_ok = true
unless self.thumbnails.count != 10
self.thumbnails.each do |t|
unless File.exists?(t.system_files[0].path)
thumbs_ok = false
Log.create(:title=>"Movie with thumbnail object but without files",:controller=>'movie',:action=>"try_to_make_thumbs",:loggable =>self)
end
end
else
thumb_ok = false
Log.create(:title=>"Movie with less than then 10 thumbnails",:controller=>'movie',:action=>"try_to_make_thumbs",:loggable =>self)
end
return thumbs_ok
end

def fancy_length
Expand Down
6 changes: 6 additions & 0 deletions app/views/integrity/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Integrity#index</h1>
There are currently <b><%= @thumb_no_time %></b> thumbnails without a time element.
<%= link_to 'Fix it!', {:controller => 'integrity', :action => 'time_thumb'},:remote=>true %>
<div class="clear"></div>
If the previous fix failed, you can try purging the system of orphaned thumbnails
<%= link_to 'Purge!', {:controller => 'integrity', :action => 'purge_thumb'},:remote=>true %>
3 changes: 2 additions & 1 deletion app/views/tagging_room/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
hoverClass: "ui-state-active",
drop: function(event, ui) {

d = "tag=" + $(this).attr('id') + "&movie=" + ui.draggable.attr('id');
d = "tag=" + $(this).attr('id').replace("_"," ") + "&movie=" + ui.draggable.attr('id');
$.ajax({
type: "POST",
url: "tagging_room/tag",
Expand Down Expand Up @@ -78,6 +78,7 @@
$("#create_tag_button").button();
$("#create_tag_button").click(function() {
tag = $("#tag").attr('value');
tag = tag.replace(" ","_");
$("#tag").val("");
$("#col4").prepend(
'<div class="droppable ui-widget-header" id="' + tag + '">' +
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
MBrowser7::Application.routes.draw do
get "integrity/", :controller => 'integrity', :action => 'index'
get "integrity/time_thumb"
get "integrity/purge_thumb"

post "logs/read_all", :as => 'logs_read_all'
resources :logs

Expand Down
9 changes: 9 additions & 0 deletions test/functional/integrity_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'test_helper'

class IntegrityControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end

end
4 changes: 4 additions & 0 deletions test/unit/helpers/integrity_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class IntegrityHelperTest < ActionView::TestCase
end

0 comments on commit 98f5964

Please sign in to comment.