Add widget cards to homepage

This commit is contained in:
rgarcia
2018-05-22 19:56:40 +02:00
committed by decabeza
parent 85c08da7a6
commit 664e77305c
21 changed files with 412 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
class Admin::HomepageController < Admin::BaseController
def show
load_cards
end
private
@@ -9,4 +10,9 @@ class Admin::HomepageController < Admin::BaseController
settings = /feature.homepage.widgets/
@settings = Setting.select {|setting| setting.key =~ /#{settings}/ }
end
def load_cards
@cards = ::Widget::Card.body
end
end

View File

@@ -0,0 +1,51 @@
class Admin::Widget::CardsController < Admin::BaseController
def new
@card = ::Widget::Card.new(header: header_card?)
end
def create
@card = ::Widget::Card.new(card_params)
if @card.save
notice = "Success"
redirect_to admin_homepage_url, notice: notice
else
render :new
end
end
def edit
@card = ::Widget::Card.find(params[:id])
end
def update
@card = ::Widget::Card.find(params[:id])
if @card.update(card_params)
notice = "Updated"
redirect_to admin_homepage_url, notice: notice
else
render :edit
end
end
def destroy
@card = ::Widget::Card.find(params[:id])
@card.destroy
notice = "Removed"
redirect_to admin_homepage_url, notice: notice
end
private
def card_params
params.require(:widget_card).permit(:title, :description, :link_text, :link_url,
:button_text, :button_url, :alignment, :header,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end
def header_card?
params[:header_card].present?
end
end

View File

@@ -5,6 +5,7 @@ class WelcomeController < ApplicationController
layout "devise", only: [:welcome, :verification]
def index
@cards = Widget::Card.body
end
def welcome