Add cards to custom pages
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
class Admin::SiteCustomization::CardsController < Admin::SiteCustomization::BaseController
|
||||
skip_authorization_check
|
||||
|
||||
def index
|
||||
@cards = ::Widget::Card.page(params[:page_id])
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,14 +2,24 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
include Translatable
|
||||
|
||||
def new
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
if header_card?
|
||||
@card = ::Widget::Card.new(header: header_card?)
|
||||
elsif params[:page_id] != 0
|
||||
@card = ::Widget::Card.new(site_customization_page_id: params[:page_id])
|
||||
else
|
||||
@card = ::Widget::Card.new
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@card = ::Widget::Card.new(card_params)
|
||||
if @card.save
|
||||
notice = "Success"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -23,7 +33,11 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
@card = ::Widget::Card.find(params[:id])
|
||||
if @card.update(card_params)
|
||||
notice = "Updated"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -34,7 +48,11 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
@card.destroy
|
||||
|
||||
notice = "Removed"
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
if params[:page_id] != 0
|
||||
redirect_to admin_site_customization_page_cards_path(page), notice: notice
|
||||
else
|
||||
redirect_to admin_homepage_url, notice: notice
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@@ -43,7 +61,7 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
|
||||
|
||||
params.require(:widget_card).permit(
|
||||
:link_url, :button_text, :button_url, :alignment, :header,
|
||||
:link_url, :button_text, :button_url, :alignment, :header, :site_customization_page_id,
|
||||
translation_params(Widget::Card),
|
||||
image_attributes: image_attributes
|
||||
)
|
||||
@@ -52,6 +70,9 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
def header_card?
|
||||
params[:header_card].present?
|
||||
end
|
||||
def page
|
||||
::SiteCustomization::Page.find(@card.site_customization_page_id)
|
||||
end
|
||||
|
||||
def resource
|
||||
Widget::Card.find(params[:id])
|
||||
|
||||
@@ -9,6 +9,7 @@ class PagesController < ApplicationController
|
||||
@banners = Banner.in_section('help_page').with_active
|
||||
|
||||
if @custom_page.present?
|
||||
@cards = Widget::Card.page(@custom_page.id)
|
||||
render action: :custom_page
|
||||
else
|
||||
render action: params[:id]
|
||||
|
||||
@@ -15,6 +15,12 @@ class Widget::Card < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.body
|
||||
where(header: false).order(:created_at)
|
||||
where(header: false, site_customization_page_id: 0).order(:created_at)
|
||||
end
|
||||
|
||||
#add widget cards to custom pages
|
||||
def self.page(page_id)
|
||||
where(site_customization_page_id: page_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
30
app/views/admin/site_customization/cards/_card.html.erb
Normal file
30
app/views/admin/site_customization/cards/_card.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<tr id="<%= dom_id(card) %>" class="homepage-card">
|
||||
<td>
|
||||
<%= card.label %><br>
|
||||
<%= card.title %>
|
||||
</td>
|
||||
<td><%= card.description %></td>
|
||||
<td>
|
||||
<%= card.link_text %><br>
|
||||
<%= card.link_url %>
|
||||
</td>
|
||||
|
||||
<!-- remove conditional once specs have image validations -->
|
||||
<td>
|
||||
<% if card.image.present? %>
|
||||
<%= link_to t("admin.shared.show_image"), card.image_url(:large),
|
||||
title: card.image.title, target: "_blank" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.actions.edit"),
|
||||
edit_admin_widget_card_path(card, page_id: params[:page_id]),
|
||||
class: "button hollow" %>
|
||||
|
||||
<%= link_to t("admin.actions.delete"),
|
||||
admin_widget_card_path(card, page_id: params[:page_id]),
|
||||
method: :delete,
|
||||
data: { confirm: t('admin.actions.confirm') },
|
||||
class: "button hollow alert" %>
|
||||
</td>
|
||||
</tr>
|
||||
16
app/views/admin/site_customization/cards/_cards.html.erb
Normal file
16
app/views/admin/site_customization/cards/_cards.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.homepage.cards.title") %></th>
|
||||
<th class="small-4"><%= t("admin.homepage.cards.description") %></th>
|
||||
<th><%= t("admin.homepage.cards.link_text") %> / <%= t("admin.homepage.cards.link_url") %></th>
|
||||
<th><%= t("admin.shared.image") %></th>
|
||||
<th class="small-2"><%= t("admin.shared.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% cards.each do |card| %>
|
||||
<%= render "card", card: card %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
16
app/views/admin/site_customization/cards/index.html.erb
Normal file
16
app/views/admin/site_customization/cards/index.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<%= back_link_to admin_site_customization_pages_path %>
|
||||
<div id="cards">
|
||||
<h3 class="inline-block"><%= t("admin.homepage.cards_title") %></h3>
|
||||
|
||||
<div class="float-right">
|
||||
<%= link_to t("admin.homepage.create_card"), new_admin_widget_card_path(page_id: params[:page_id]), class: "button" %>
|
||||
</div>
|
||||
|
||||
<% if @cards.present? %>
|
||||
<%= render "cards", cards: @cards %>
|
||||
<% else %>
|
||||
<div class="callout primary clear">
|
||||
<%= t("admin.homepage.no_cards") %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -13,6 +13,7 @@
|
||||
<tr>
|
||||
<th><%= t("admin.site_customization.pages.page.title") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.slug") %></th>
|
||||
<th><%= t("admin.homepage.cards_title") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.created_at") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.updated_at") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.status") %></th>
|
||||
@@ -26,6 +27,10 @@
|
||||
<%= link_to page.title, edit_admin_site_customization_page_path(page) %>
|
||||
</td>
|
||||
<td><%= page.slug %></td>
|
||||
<td>
|
||||
<%= link_to "Cards", admin_site_customization_page_cards_path(page),
|
||||
class: "button hollow expanded" %>
|
||||
</td>
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
</div>
|
||||
|
||||
<%= f.hidden_field :header, value: @card.header? %>
|
||||
<%= f.hidden_field :site_customization_page_id, value: @card.site_customization_page_id %>
|
||||
|
||||
<div class="image-form">
|
||||
<div class="image small-12 column">
|
||||
|
||||
16
app/views/pages/_card.html.erb
Normal file
16
app/views/pages/_card.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div id="<%= dom_id(card) %>" class="card small-12 medium-6 column margin-bottom end large-4" data-equalizer-watch>
|
||||
<%= link_to card.link_url do %>
|
||||
<figure class="figure-card">
|
||||
<div class="gradient"></div>
|
||||
<% if card.image.present? %>
|
||||
<%= image_tag(card.image_url(:large), alt: card.image.title) %>
|
||||
<% end %>
|
||||
<figcaption>
|
||||
<span><%= card.label %></span><br>
|
||||
<h3><%= card.title %></h3>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<p class="description"><%= card.description %></p>
|
||||
<p><%= card.link_text %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
7
app/views/pages/_cards.html.erb
Normal file
7
app/views/pages/_cards.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<h3 class="title"><%= t("welcome.cards.title") %></h3>
|
||||
|
||||
<div class="row" data-equalizer data-equalizer-on="medium">
|
||||
<% @cards.find_each do |card| %>
|
||||
<%= render "card", card: card %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,3 +1,4 @@
|
||||
<%= content_for :body_class, "home-page" %>
|
||||
<% provide :title do %><%= @custom_page.title %><% end %>
|
||||
|
||||
<div class="row margin-top">
|
||||
@@ -16,4 +17,11 @@
|
||||
<%= render '/shared/print' %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @cards.any? %>
|
||||
<div class="small-12 column">
|
||||
<%= render "cards" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -214,7 +214,9 @@ namespace :admin do
|
||||
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
|
||||
namespace :site_customization do
|
||||
resources :pages, except: [:show]
|
||||
resources :pages, except: [:show] do
|
||||
resources :cards, only: [:index]
|
||||
end
|
||||
resources :images, only: [:index, :update, :destroy]
|
||||
resources :content_blocks, except: [:show]
|
||||
delete '/heading_content_blocks/:id', to: 'content_blocks#delete_heading_content_block', as: 'delete_heading_content_block'
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSiteCustomizationPageToWidgetCards < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :widget_cards, :site_customization_page, index: true, default: 0
|
||||
end
|
||||
end
|
||||
138
db/schema.rb
138
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
ActiveRecord::Schema.define(version: 20181218164126) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -504,6 +504,46 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
add_index "geozones_polls", ["geozone_id"], name: "index_geozones_polls_on_geozone_id", using: :btree
|
||||
add_index "geozones_polls", ["poll_id"], name: "index_geozones_polls_on_poll_id", using: :btree
|
||||
|
||||
create_table "house_images", force: :cascade do |t|
|
||||
t.integer "house_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "house_news", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "photo"
|
||||
t.string "link"
|
||||
t.string "house_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "houses", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "schedule"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
t.string "photo"
|
||||
t.boolean "disability_access"
|
||||
t.integer "zonal_administration_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "houses_administrators", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "houses_age_ranges", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "i18n_content_translations", force: :cascade do |t|
|
||||
t.integer "i18n_content_id", null: false
|
||||
t.string "locale", null: false
|
||||
@@ -792,6 +832,7 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
t.integer "zoom"
|
||||
t.integer "proposal_id"
|
||||
t.integer "investment_id"
|
||||
t.integer "house_id"
|
||||
end
|
||||
|
||||
add_index "map_locations", ["investment_id"], name: "index_map_locations_on_investment_id", using: :btree
|
||||
@@ -838,6 +879,13 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
|
||||
add_index "moderators", ["user_id"], name: "index_moderators_on_user_id", using: :btree
|
||||
|
||||
create_table "neighborhoods", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "id_parish"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "newsletters", force: :cascade do |t|
|
||||
t.string "subject"
|
||||
t.string "segment_recipient", null: false
|
||||
@@ -870,6 +918,12 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
|
||||
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
|
||||
|
||||
create_table "parishes", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "poll_answers", force: :cascade do |t|
|
||||
t.integer "question_id"
|
||||
t.integer "author_id"
|
||||
@@ -1379,6 +1433,11 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
t.integer "failed_email_digests_count", default: 0
|
||||
t.text "former_users_data_log", default: ""
|
||||
t.boolean "public_interests", default: false
|
||||
t.string "userlastname"
|
||||
t.integer "user_parish"
|
||||
t.integer "user_neighborhood"
|
||||
t.string "ethnic_group"
|
||||
t.string "studies_level"
|
||||
t.boolean "recommended_debates", default: true
|
||||
t.boolean "recommended_proposals", default: true
|
||||
end
|
||||
@@ -1457,6 +1516,39 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
add_index "visits", ["started_at"], name: "index_visits_on_started_at", using: :btree
|
||||
add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree
|
||||
|
||||
create_table "volunt_categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "volunt_programs", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "photo"
|
||||
t.string "schedule"
|
||||
t.integer "quota"
|
||||
t.string "short_description"
|
||||
t.text "long_description"
|
||||
t.integer "volunt_category_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
end
|
||||
|
||||
create_table "volunt_users", force: :cascade do |t|
|
||||
t.integer "id_user"
|
||||
t.integer "volunt_program_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "volunteerings_administrators", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "votes", force: :cascade do |t|
|
||||
t.integer "votable_id"
|
||||
t.string "votable_type"
|
||||
@@ -1500,11 +1592,14 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
t.string "link_text"
|
||||
t.string "link_url"
|
||||
t.string "label"
|
||||
t.boolean "header", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "header", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "site_customization_page_id", default: 0
|
||||
end
|
||||
|
||||
add_index "widget_cards", ["site_customization_page_id"], name: "index_widget_cards_on_site_customization_page_id", using: :btree
|
||||
|
||||
create_table "widget_feeds", force: :cascade do |t|
|
||||
t.string "kind"
|
||||
t.integer "limit", default: 3
|
||||
@@ -1512,6 +1607,41 @@ ActiveRecord::Schema.define(version: 20181206153510) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "workshop_images", force: :cascade do |t|
|
||||
t.integer "workshop_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "workshop_users", force: :cascade do |t|
|
||||
t.integer "id_user"
|
||||
t.integer "workshop_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "status"
|
||||
end
|
||||
|
||||
create_table "workshops", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "teacher"
|
||||
t.string "schedule"
|
||||
t.integer "quota"
|
||||
t.string "short_description"
|
||||
t.text "long_description"
|
||||
t.string "photo"
|
||||
t.integer "house_id"
|
||||
t.integer "id_age_range"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "status"
|
||||
end
|
||||
|
||||
create_table "zonal_administrations", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_foreign_key "administrators", "users"
|
||||
add_foreign_key "annotations", "legacy_legislations"
|
||||
add_foreign_key "annotations", "users"
|
||||
|
||||
Reference in New Issue
Block a user