Admin for custom pages
This commit is contained in:
10
app/controllers/admin/site_customization/base_controller.rb
Normal file
10
app/controllers/admin/site_customization/base_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Admin::SiteCustomization::BaseController < Admin::BaseController
|
||||
helper_method :namespace
|
||||
|
||||
private
|
||||
|
||||
def namespace
|
||||
"admin"
|
||||
end
|
||||
|
||||
end
|
||||
44
app/controllers/admin/site_customization/pages_controller.rb
Normal file
44
app/controllers/admin/site_customization/pages_controller.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::BaseController
|
||||
load_and_authorize_resource :page, class: "SiteCustomization::Page"
|
||||
|
||||
def index
|
||||
@pages = SiteCustomization::Page.order('slug').page(params[:page])
|
||||
end
|
||||
|
||||
def create
|
||||
if @page.save
|
||||
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.create.notice', link: @page.slug.html_safe)
|
||||
else
|
||||
flash.now[:error] = t('admin.site_customization.pages.create.error')
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @page.update(page_params)
|
||||
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.update.notice', link: @page.slug.html_safe)
|
||||
else
|
||||
flash.now[:error] = t('admin.site_customization.pages.update.error')
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@page.destroy
|
||||
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.destroy.notice')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def page_params
|
||||
params.require(:site_customization_page).permit(
|
||||
:slug,
|
||||
:title,
|
||||
:subtitle,
|
||||
:content,
|
||||
:more_info_flag,
|
||||
:print_content_flag,
|
||||
:status
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -51,6 +51,8 @@ module Abilities
|
||||
|
||||
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
||||
can [:index, :create, :edit, :update, :destroy], Geozone
|
||||
|
||||
can :manage, SiteCustomization::Page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
app/models/site_customization.rb
Normal file
5
app/models/site_customization.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module SiteCustomization
|
||||
def self.table_name_prefix
|
||||
'site_customization_'
|
||||
end
|
||||
end
|
||||
14
app/models/site_customization/page.rb
Normal file
14
app/models/site_customization/page.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class SiteCustomization::Page < ActiveRecord::Base
|
||||
VALID_STATUSES = %w(draft published)
|
||||
|
||||
validates :slug, uniqueness: { case_sensitive: false },
|
||||
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
|
||||
validates :title, presence: true
|
||||
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||
|
||||
scope :published, -> { where(status: 'published').order('id DESC') }
|
||||
|
||||
def url
|
||||
"/#{slug}"
|
||||
end
|
||||
end
|
||||
@@ -122,5 +122,11 @@
|
||||
<span class="icon-stats"></span><%= t("admin.menu.stats") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "pages" %>>
|
||||
<%= link_to admin_site_customization_pages_path do %>
|
||||
<span class="icon-settings"></span><%= t("admin.menu.site_customization.pages") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
52
app/views/admin/site_customization/pages/_form.html.erb
Normal file
52
app/views/admin/site_customization/pages/_form.html.erb
Normal file
@@ -0,0 +1,52 @@
|
||||
<%= form_for [:admin, @page], html: {class: "edit_page", data: {watch_changes: true}} do |f| %>
|
||||
|
||||
<% if @page.errors.any? %>
|
||||
|
||||
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
||||
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
||||
<strong>
|
||||
<%= @page.errors.count %>
|
||||
<%= t("admin.site_customization.pages.errors.form.error", count: @page.errors.count) %>
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
|
||||
<%= f.label :title %>
|
||||
<%= f.text_field :title, label: false %>
|
||||
|
||||
<%= f.label :subtitle %>
|
||||
<%= f.text_field :subtitle, label: false, size: 80, maxlength: 80 %>
|
||||
|
||||
<%= f.label :slug %>
|
||||
<%= f.text_field :slug, label: false, size: 80, maxlength: 80 %>
|
||||
|
||||
<div class="ckeditor margin-top">
|
||||
<%= f.label :content %>
|
||||
<%= f.cktext_area :content, label: false, cols: 80, rows: 10, ckeditor: { language: I18n.locale } %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<div class="page_edit">
|
||||
<h4><%= t("admin.site_customization.pages.form.options") %></h4>
|
||||
<%= f.check_box :more_info_flag %>
|
||||
<%= f.check_box :print_content_flag %>
|
||||
<hr>
|
||||
|
||||
<h4><%= f.label :status %></h4>
|
||||
<% ::SiteCustomization::Page::VALID_STATUSES.each do |status| %>
|
||||
<%= f.radio_button :status, status, label: false %>
|
||||
<%= f.label "status_#{status}", t("admin.site_customization.pages.status_#{status}") %>
|
||||
<br/>
|
||||
<% end %>
|
||||
|
||||
<%= f.submit class: "button success" %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
15
app/views/admin/site_customization/pages/edit.html.erb
Normal file
15
app/views/admin/site_customization/pages/edit.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.pages") %> - <%= @page.title %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to admin_site_customization_pages_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.site_customization.pages.edit.back") %>
|
||||
<% end %>
|
||||
|
||||
<%= button_to t("admin.site_customization.pages.index.delete"), admin_site_customization_page_path(@page), method: :delete, class: "button hollow alert float-right margin-right" %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<h2><%= t("admin.site_customization.pages.edit.title", page_title: @page.title) %></h2>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
52
app/views/admin/site_customization/pages/index.html.erb
Normal file
52
app/views/admin/site_customization/pages/index.html.erb
Normal file
@@ -0,0 +1,52 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.pages") %>
|
||||
<% end %>
|
||||
|
||||
<div class="legislation-admin legislation-process-index">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h2 class="inline-block"><%= t("admin.site_customization.pages.index.title") %></h2>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column legislation-process-new">
|
||||
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3><%= page_entries_info @pages %></h3>
|
||||
|
||||
<table class="stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.site_customization.pages.page.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>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @pages.each do |page| %>
|
||||
<tr id="<%= dom_id(page) %>">
|
||||
<td>
|
||||
<%= link_to page.title, edit_admin_site_customization_page_path(page) %>
|
||||
</td>
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= t("admin.legislation.processes.process.status_#{page.status}") %></td>
|
||||
<td class="small">
|
||||
<span class="icon-eye"></span>
|
||||
<%= link_to t("admin.site_customization.pages.index.see_page"), page.url %>
|
||||
</td>
|
||||
<td class="small">
|
||||
<span class="icon-x"></span>
|
||||
<%= link_to t("admin.site_customization.pages.index.delete"), admin_site_customization_page_path(page), method: :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= paginate @pages %>
|
||||
|
||||
</div>
|
||||
14
app/views/admin/site_customization/pages/new.html.erb
Normal file
14
app/views/admin/site_customization/pages/new.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.pages") %> - <%= t("admin.site_customization.pages.new.title") %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to admin_site_customization_pages_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.site_customization.pages.new.back") %>
|
||||
<% end %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<h2><%= t("admin.site_customization.pages.new.title") %></h2>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user