Add AdminNotification management at admin panel

In the same fashion Newsletters is managed, with the only difference that
the preview is using the notification partial in the same way the index
of notifications.
This commit is contained in:
Bertocq
2018-02-28 21:03:24 +01:00
committed by decabeza
parent 4a5235f96f
commit f695a7faf3
10 changed files with 243 additions and 8 deletions

View File

@@ -0,0 +1,67 @@
class Admin::AdminNotificationsController < Admin::BaseController
def index
@admin_notifications = AdminNotification.all
end
def show
@admin_notification = AdminNotification.find(params[:id])
end
def new
@admin_notification = AdminNotification.new
end
def create
@admin_notification = AdminNotification.new(admin_notification_params)
if @admin_notification.save
notice = t("admin.admin_notifications.create_success")
redirect_to [:admin, @admin_notification], notice: notice
else
render :new
end
end
def edit
@admin_notification = AdminNotification.find(params[:id])
end
def update
@admin_notification = AdminNotification.find(params[:id])
if @admin_notification.update(admin_notification_params)
notice = t("admin.admin_notifications.update_success")
redirect_to [:admin, @admin_notification], notice: notice
else
render :edit
end
end
def destroy
@admin_notification = AdminNotification.find(params[:id])
@admin_notification.destroy
notice = t("admin.admin_notifications.delete_success")
redirect_to admin_admin_notifications_path, notice: notice
end
def deliver
@admin_notification = AdminNotification.find(params[:id])
if @admin_notification.valid?
@admin_notification.deliver
flash[:notice] = t("admin.admin_notifications.send_success")
else
flash[:error] = t("admin.segment_recipient.invalid_recipients_segment")
end
redirect_to [:admin, @admin_notification]
end
private
def admin_notification_params
params.require(:admin_notification).permit(:title, :body, :link, :segment_recipient)
end
end