Skip to content

Commit

Permalink
Merge pull request #482 from godunno/bugfix/reload-after-delete-media
Browse files Browse the repository at this point in the history
Re-fetch medias after deleting one
  • Loading branch information
oddlyfunctional committed Mar 10, 2015
2 parents 30c5ccc + 8d48515 commit 13c20e3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ MediasIndexCtrl = ($scope, Media, Utils, MediaSearcher)->
$scope.removeMedia = (media)->
if confirm("Deseja remover este anexo? Ele também será removida dos diários. Esta operação não poderá ser desfeita.")
media.remove().then ->
Utils.remove($scope.medias, media)
last = $scope.medias.length == 1
page = if last then $scope.previous_page else $scope.current_page
$scope.fetch(page: page)

MediasIndexCtrl.$inject = ['$scope', 'Media', 'Utils', 'MediaSearcher']
DunnoApp.controller 'MediasIndexCtrl', MediasIndexCtrl
5 changes: 3 additions & 2 deletions app/behaviors/has_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module HasFile
extend ActiveSupport::Concern

included do
before_destroy :delete_file
after_commit :delete_file, on: [:destroy], if: :file?

def file
AwsFile.new(file_url) if file?
end
Expand All @@ -20,6 +21,6 @@ def file?
private

def delete_file
file.try(:delete)
DeleteAwsFileWorker.perform_async(:delete, file_url)
end
end
6 changes: 5 additions & 1 deletion app/controllers/api/v1/teacher/medias_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Api::V1::Teacher::MediasController < Api::V1::TeacherApplicationController
respond_to :json

def index
@result = Media.search(params.merge(
@result = Media.search(media_search_params.merge(
filter: {
teacher_id: current_teacher.id
}
Expand Down Expand Up @@ -58,6 +58,10 @@ def media_params
params.require(:media).permit(:title, :tag_list, tag_list: [])
end

def media_search_params
params.permit(:page, :q)
end

def media_create_params
params.require(:media).permit(:url, :file_url, :original_filename)
end
Expand Down
9 changes: 9 additions & 0 deletions app/workers/delete_aws_file_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DeleteAwsFileWorker
include Sidekiq::Worker
sidekiq_options queue: 's3'

def perform(file_url)
logger.debug ["deleting aws file", "File URL: #{file_url}"]
AwsFile.new(file_url).delete
end
end
1 change: 1 addition & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
:queues:
- default
- elasticsearch
- s3

0 comments on commit 13c20e3

Please sign in to comment.