Class: Wco::NewsvideosController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Wco::NewsvideosController
- Defined in:
- app/controllers/wco/newsvideos_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #generate ⇒ Object
- #generate_illustration ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #split ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 9 def create params[:newsvideo][:tag_ids]&.delete '' @newsvideo = Wco::Newsvideo.new params[:newsvideo].permit! :create, @newsvideo @newsvideo. = current_profile if @newsvideo.save flash_notice "created newsvideo" else flash_alert "Cannot create newsvideo: #{@newsvideo.errors.}" end redirect_to action: 'index' end |
#destroy ⇒ Object
23 24 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 23 def destroy end |
#edit ⇒ Object
26 27 28 29 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 26 def edit @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :edit, @newsvideo end |
#generate ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 31 def generate @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :edit, @newsvideo Rails.env.production? ? Wco::NewsvideoGenerateJob.perform_async(@newsvideo.id.to_s) : Wco::NewsvideoGenerateJob.perform_sync( @newsvideo.id.to_s) render json: { status: :ok, message: 'Scheduled the generation' } end |
#generate_illustration ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 42 def generate_illustration @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :edit, @newsvideo Rails.env.production? ? Wco::NewsvideoIllustrationJob.perform_async(@newsvideo.id.to_s, params[:image_url]) : Wco::NewsvideoIllustrationJob.perform_sync( @newsvideo.id.to_s, params[:image_url]) render json: { status: :ok, message: 'scheduled the run on pc-ai' } # redirect_to action: 'show', newsvideo_id: params[:id] end |
#index ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 54 def index :index, Wco::Newsvideo @newsvideos = Wco::Newsvideo.all.order_by( created_at: :desc ) if params[:deleted] @newsvideos = Wco::Newsvideo.unscoped.where( :deleted_at.ne => nil ) end @newsvideos = @newsvideos.page( params[:newsvideos_page] ).per( current_profile.per_page ) end |
#new ⇒ Object
63 64 65 66 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 63 def new @newsvideo = Wco::Newsvideo.new :create, @newsvideo end |
#show ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 68 def show @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :show, @newsvideo @newspartials = Wco::Newspartial.where( newsvideo_id: @newsvideo.id.to_s).includes(:video) @newsoverlays = @newsvideo. @skip_footer = true end |
#split ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 76 def split @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :edit, @newsvideo if Wco::Newspartial.where( newsvideo: @newsvideo).length > 0 # Wco::Newspartial.where( newsvideo: @newsvideo).each { |n| n.delete } flash_alert 'newspartials already exist for this newsvideo - cannot split.' redirect_to request.referrer return end sentences = PragmaticSegmenter::Segmenter.new(text: @newsvideo.body).segment phrases = sentences_to_phrases(sentences) puts! phrases, 'phrases' phrases.each do |phrase| newspartial = Wco::Newspartial.new body: phrase, newsvideo: @newsvideo newspartial.save! end flash_notice 'Done spliting the video.' redirect_to request.referrer end |
#update ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/wco/newsvideos_controller.rb', line 101 def update params[:newsvideo][:tag_ids]&.delete '' @newsvideo = Wco::Newsvideo.unscoped.find params[:id] :update, @newsvideo if @newsvideo.update params[:newsvideo].permit! flash_notice "updated newsvideo" else flash_alert "Cannot update newsvideo: #{@newsvideo.errors.}" end redirect_to action: 'index' end |