1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# frozen_string_literal: true
module Admin
class BroadcastMessagesController < ApplicationController
include Admin::BroadcastMessagesHelper
before_action :find_broadcast_message, only: [:edit, :update, :destroy]
before_action :find_broadcast_messages, only: [:index, :create]
feature_category :onboarding
urgency :low
def index
@broadcast_message = System::BroadcastMessage.new
end
def edit; end
def create
@broadcast_message = System::BroadcastMessage.new(broadcast_message_params)
success = @broadcast_message.save
respond_to do |format|
format.json do
if success
render json: @broadcast_message, status: :ok
else
render json: { errors: @broadcast_message.errors.full_messages }, status: :bad_request
end
end
format.html do
if success
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully created.')
else
render :index
end
end
end
end
def update
success = @broadcast_message.update(broadcast_message_params)
respond_to do |format|
format.json do
if success
render json: @broadcast_message, status: :ok
else
render json: { errors: @broadcast_message.errors.full_messages }, status: :bad_request
end
end
format.html do
if success
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully updated.')
else
render :edit
end
end
end
end
def destroy
@broadcast_message.destroy
respond_to do |format|
format.html { redirect_back_or_default(default: { action: 'index' }) }
format.js { head :ok }
end
end
def preview
@broadcast_message = System::BroadcastMessage.new(broadcast_message_params)
render plain: render_broadcast_message(@broadcast_message), status: :ok
end
protected
def find_broadcast_message
@broadcast_message = System::BroadcastMessage.find(params[:id])
end
def find_broadcast_messages
@broadcast_messages = System::BroadcastMessage.order(ends_at: :desc).page(params[:page]) # rubocop: disable CodeReuse/ActiveRecord
end
def broadcast_message_params
params.require(:broadcast_message)
.permit(%i[
theme
ends_at
message
starts_at
target_path
broadcast_type
dismissable
show_in_cli
], target_access_levels: []).reverse_merge!(target_access_levels: [])
end
end
end
|