-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #7 Adds new model Page. Replaces Page Modules page by Pages (Pag…
…es & Modules) page and show here a tab pane including pages, module collections and modules.
- Loading branch information
1 parent
c98dfe0
commit 76a4097
Showing
25 changed files
with
415 additions
and
50 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class PagesController < ApplicationController | ||
respond_to :html, :js | ||
|
||
before_filter :authenticate_user!, except: [:show] | ||
before_filter :show_breadcrumbs | ||
|
||
def index | ||
@pages = Page.paginate(page: params[:page], per_page: 10) | ||
|
||
if params[:page].blank? | ||
@page_module_collection_slug_stubs = PageModuleCollection.pluck(:slug_stub).uniq.sort | ||
slug_stub = @page_module_collection_slug_stubs.first | ||
@page_module_collections = PageModuleCollection.where(slug_stub: slug_stub).paginate(page: params[:page], per_page: 10) | ||
@page_module_slug_stubs = PageModule.pluck(:slug_stub).uniq.sort | ||
@page_modules = PageModule.where(slug_stub: @page_module_slug_stubs.first).paginate(page: params[:module_page], per_page: 10) | ||
else | ||
render partial: 'pages/collection', layout: false | ||
end | ||
end | ||
|
||
def new | ||
@page = Page.new(params[:page]) | ||
end | ||
|
||
def create | ||
@page = Page.create(params[:page]) | ||
|
||
if @page.persisted? | ||
@path = pages_path(page: 1) | ||
|
||
if request.xhr? | ||
@target = '#pages_container' | ||
@close_modal = true | ||
end | ||
else | ||
@template = :new | ||
|
||
if request.xhr? | ||
@target = '.modal-content' | ||
@target_needs_modal_layout = false | ||
end | ||
end | ||
|
||
render_or_redirect_by_request_type | ||
end | ||
|
||
def show | ||
@page = Page.friendly.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@page = Page.friendly.find(params[:id]) | ||
end | ||
|
||
def update | ||
@page = Page.friendly.find(params[:id]) | ||
|
||
if @page.update_attributes(params[:page]) | ||
flash[:notice] = t('general.form.successfully_updated') | ||
|
||
if request.xhr? | ||
@template_format = 'js' | ||
else | ||
@path = edit_page_path(@page_module) | ||
end | ||
else | ||
@template = :edit | ||
@target = '.modal-content' if request.xhr? | ||
end | ||
|
||
render_or_redirect_by_request_type | ||
end | ||
|
||
def destroy | ||
@page = Page.friendly.find(params[:id]).destroy | ||
|
||
if @page.persisted? | ||
flash[:alert] = I18n.t('general.form.destroy_failed') | ||
else | ||
flash[:notice] = I18n.t('general.form.destroyed') | ||
end | ||
|
||
redirect_to pages_path unless request.xhr? | ||
end | ||
|
||
def resource | ||
@page | ||
end | ||
|
||
protected | ||
|
||
def show_breadcrumbs | ||
@show_breadcrumbs = true if user_signed_in? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Page < ActiveRecord::Base | ||
serialize :data, Hash | ||
|
||
validates :title, presence: true, uniqueness: true | ||
validates :content, presence: true | ||
|
||
validate :valid_liquid_syntax | ||
|
||
attr_accessible :title, :content, :data | ||
|
||
extend FriendlyId | ||
|
||
friendly_id :title, use: :slugged | ||
|
||
private | ||
|
||
def valid_liquid_syntax | ||
Liquid::Template.parse(content) | ||
rescue Liquid::SyntaxError => e | ||
errors.add( | ||
:content, | ||
I18n.t( | ||
'activerecord.errors.models.page_module.attributes.content.liquid_syntax_invalid', message: e.message | ||
) | ||
) | ||
end | ||
|
||
def should_generate_new_friendly_id? | ||
title_changed? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% if @pages.none? %> | ||
<p><%= t('pages.index.empty_collection') %></p> | ||
<% else %> | ||
<table class='table table-striped'> | ||
<thead> | ||
<tr class='<%= cycle('odd', 'even') %>'> | ||
<th style='width: 200px'><%= t('general.attributes.title') %></th> | ||
<th style='width: 200px'><%= t('general.attributes.slug') %></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render partial: 'pages/page', collection: @pages %> | ||
</tbody> | ||
</table> | ||
|
||
<%= will_paginate @pages, renderer: BootstrapPagination::Rails %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= devise_error_messages! %> | ||
|
||
<%= f.input :title %> | ||
<%= f.input :content %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% content_for :modal_footer do %> | ||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('general.close') %></button> | ||
<button type="submit" class="btn btn-primary"><%= t('general.submit') %></button> | ||
<% end %> | ||
|
||
<%= simple_form_for( | ||
resource, url: resource.new_record? ? pages_path : page_path(resource), wrapper: :horizontal_form, | ||
method: resource.new_record? ? :post : :put, remote: request.xhr?, html: { class: 'form-horizontal', autocomplete: 'off' } | ||
) do |f| %> | ||
<% if request.xhr? %> | ||
<% content_for :modal_body do %> | ||
<%= render partial: 'pages/fields', locals: { f: f } %> | ||
<% end %> | ||
|
||
<%= render partial: 'shared/layouts/modal' %> | ||
<% else %> | ||
<%= render partial: 'pages/fields', locals: { f: f } %> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-offset-3 col-sm-9"> | ||
<button type="submit" class="btn btn-primary"><%= t('general.submit') %></button> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<tr class="<%= cycle('odd', 'even') %>" id="pages_row_<%= page.id %>"> | ||
<td> | ||
<%= link_to page.title, page_path(page) %> | ||
</td> | ||
<td> | ||
<%= page.slug %> | ||
</td> | ||
<td> | ||
<div class="dropdown"> | ||
<button | ||
class="btn btn-default dropdown-toggle" type="button" id="page_<%= page.id %>_actions" | ||
data-toggle="dropdown" aria-expanded="true"> | ||
<%= t('general.actions') %> | ||
<span class="caret"></span> | ||
</button> | ||
<ul class="dropdown-menu" role="menu" aria-labelledby="page_<%= page.id %>_actions"> | ||
<li role="presentation"> | ||
<%= link_to( | ||
t('general.destroy'), page_path(page), | ||
id: "page_#{page.id}", method: :delete, data: { confirm: t('general.questions.are_you_sure') }, remote: true | ||
) %> | ||
</li> | ||
<li role="presentation"> | ||
| ||
<button | ||
type="button" class="btn btn-default" data-toggle="modal" data-target="#modal" | ||
data-url="<%= edit_page_path(page) %>" data-title="<%= t('pages.edit.title') %>" data-only-update-body="false" | ||
> | ||
<span class="glyphicon glyphicon-pencil"></span> <%= t('general.edit') %> | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<p> | ||
<% if @page_module_slug_stubs.none? %> | ||
<div class="alert alert-info" role="alert"> | ||
<%= t('page_modules.index.empty_collection') %> | ||
</div> | ||
<% else %> | ||
<div role="tabpanel"> | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<% @page_module_slug_stubs.each_with_index do |slug_stub, index| %> | ||
<li role="presentation"<% if index == 0 %> class="active"<% end %>> | ||
<a | ||
href="<%= page_modules_path(slug_stub: slug_stub) %>" | ||
data-target="#page_modules_slug_stub_<%= slug_stub %>" aria-controls="page_modules_slug_stub_<%= slug_stub %>" | ||
role="tab" data-toggle="tabajax" | ||
> | ||
<%= slug_stub.titleize %> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<div class="tab-content"> | ||
<% @page_module_slug_stubs.each_with_index do |slug_stub, index| %> | ||
<div role="tabpanel" class="tab-pane active" id="page_modules_slug_stub_<%= slug_stub %>"> | ||
<%= render partial: 'page_modules/collection' if index == 0 %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<% end %> | ||
</p> | ||
|
||
<p> | ||
<button | ||
type="button" class="btn btn-default" data-toggle="modal" data-target="#modal" data-url="<%= new_page_module_path %>" | ||
data-title="<%= t('page_modules.new.title') %>" data-only-update-body="false" | ||
> | ||
<span class="glyphicon glyphicon-plus"></span> <%= t('page_modules.new.short_title') %> | ||
</button> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% message = flash[:notice] || flash[:alert] %> | ||
<% flash.delete(:notice); flash.delete(:alert) %> | ||
<% alert = message.present? ? "alert('#{message}');" : '' %> | ||
|
||
<% unless @page.persisted? %> | ||
$("#pages_row_<%= @page.id %>").remove(); | ||
<% end %> | ||
|
||
<%= raw alert %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% content_for :title do %><%= t('pages.edit.title') %><% end %> | ||
|
||
<%= render partial: 'pages/form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% content_for :title do %><%= t('pages.new.title') %><% end %> | ||
|
||
<%= render partial: 'pages/form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% content_for :title do %><%= @page.title %><% end %> | ||
|
||
<%= raw liquidize(@page.content) %> |
Oops, something went wrong.