Class: Postnhost::PageVariantsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Postnhost::PageVariantsController
- Defined in:
- app/controllers/postnhost/page_variants_controller.rb
Constant Summary collapse
- PAGE_SIZE =
15
Instance Method Summary collapse
- #bulk_destroy ⇒ Object
- #bulk_publish ⇒ Object
- #bulk_unpublish ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#bulk_destroy ⇒ Object
103 104 105 106 107 108 109 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 103 def bulk_destroy variants = @page.page_variants.where(id: params[:ids]).where.not(generating: true) count = variants.count variants.destroy_all redirect_to page_variants_path(@page), notice: "#{count} translation(s) deleted successfully." end |
#bulk_publish ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 87 def bulk_publish result = Postnhost::Publishing::PageVariants::PublishMany.call(page: @page, ids: params[:ids]) error = result.errors.to_sentence unless result.success? error = "#{result.value[:failures].count} translation(s) failed." if result.success? && result.value[:failures].any? redirect_to page_variants_path(@page), **(error.present? ? { alert: error } : {}) end |
#bulk_unpublish ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 95 def bulk_unpublish result = Postnhost::Publishing::PageVariants::UnpublishMany.call(page: @page, ids: params[:ids]) error = result.errors.to_sentence unless result.success? error = "#{result.value[:failures].count} translation(s) failed." if result.success? && result.value[:failures].any? redirect_to page_variants_path(@page), **(error.present? ? { alert: error } : {}) end |
#destroy ⇒ Object
82 83 84 85 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 82 def destroy @page_variant.destroy redirect_to page_variants_path(@page), notice: "Translation was successfully deleted." end |
#edit ⇒ Object
33 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 33 def edit; end |
#index ⇒ Object
12 13 14 15 16 17 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 12 def index variants = @page.page_variants.includes(:language, :page_variant_snapshot).order(:created_at) @pagy, @variants = pagy(:offset, variants, limit: PAGE_SIZE) @available_languages = Postnhost::Language.where.not(id: @page.page_variants.select(:language_id)) @available_languages = @available_languages.where.not(id: @page.language_id) if @page.language_id.present? end |
#new ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 19 def new @page_variant = @page.page_variants.new @page_variant.language = Postnhost::Language.find_by(id: params[:language_id]) if params[:language_id] @page_variant.title = @page.title @page_variant.title_tag = @page.title_tag @page_variant.og_title = @page.og_title @page_variant. = @page. @page_variant.content = @page.content @page_variant.save! redirect_to edit_page_variant_path(@page, @page_variant), notice: "Page variant was successfully created." end |
#publish ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 50 def publish result = Postnhost::Publishing::PageVariants::Publish.call(page_variant: @page_variant) @page_variant.reload error = result.errors.to_sentence unless result.success? respond_to do |format| format.html do redirect_to edit_page_variant_path(@page, @page_variant), **(error.present? ? { alert: error } : {}) end format.turbo_stream do flash.now[:alert] = error if error.present? render :publish, status: result.status end end end |
#unpublish ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 66 def unpublish result = Postnhost::Publishing::PageVariants::Unpublish.call(page_variant: @page_variant) @page_variant.reload error = result.errors.to_sentence unless result.success? respond_to do |format| format.html do redirect_to edit_page_variant_path(@page, @page_variant), **(error.present? ? { alert: error } : {}) end format.turbo_stream do flash.now[:alert] = error if error.present? render :unpublish, status: result.status end end end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/postnhost/page_variants_controller.rb', line 35 def update if @page_variant.update(variant_params) respond_to do |format| format.html do redirect_to edit_page_variant_path(@page, @page_variant), notice: "Translation was successfully updated." end format.json { head :no_content } format.turbo_stream end else render :edit, status: :unprocessable_content end end |