Skip to content
Snippets Groups Projects
Commit 79b79b75 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

website pages draft

parent 64ae3950
No related branches found
No related tags found
No related merge requests found
Showing
with 226 additions and 15 deletions
class Admin::Communication::Website::ApplicationController < Admin::Communication::ApplicationController
load_and_authorize_resource :website, class: Communication::Website
protected
def breadcrumb
super
add_breadcrumb Communication::Website.model_name.human(count: 2), admin_communication_websites_path(journal_id: nil)
breadcrumb_for @website, website_id: nil
end
def default_url_options
return {} unless params.has_key? :website_id
{
website_id: params[:website_id]
}
end
end
class Admin::Communication::Website::PagesController < Admin::Communication::Website::ApplicationController
load_and_authorize_resource class: Communication::Website::Page
def index
@pages = @website.pages
breadcrumb
end
def show
breadcrumb
end
def new
@page.website = @website
breadcrumb
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def create
@page.university = current_university
if @page.save
redirect_to admin_communication_website_page_path(@page), notice: "Page was successfully created."
else
breadcrumb
render :new, status: :unprocessable_entity
end
end
def update
if @page.update(page_params)
redirect_to admin_communication_website_page_path(@page), notice: "Page was successfully updated."
else
breadcrumb
render :edit, status: :unprocessable_entity
end
end
def destroy
redirect_to admin_communication_website_url, notice: "Page was successfully destroyed."
end
protected
def breadcrumb
super
add_breadcrumb Communication::Website::Page.model_name.human(count: 2), admin_communication_website_pages_path
breadcrumb_for @page
end
def page_params
params.require(:communication_website_page)
.permit(:university_id, :communication_website_id, :title,
:description, :about_type, :about_id, :slug, :published_at,
:parent_id)
end
end
class Communication::Website::PagesController < ApplicationController
def index
redirect_to '/admin' if is_university?
@page = current_website.pages.find_by path: request.path
if @page
render :show
else
@pages = current_website.pages
end
end
def show
end
end
class HomeController < ApplicationController
def index
redirect_to '/admin' if is_university?
end
end
......@@ -19,6 +19,7 @@
#
class Communication::Website < ApplicationRecord
belongs_to :university
has_many :pages, foreign_key: :communication_website_id
def self.with_host(host)
find_by domain: extract_domain_from(host)
......
# == Schema Information
#
# Table name: communication_website_pages
#
# id :uuid not null, primary key
# about_type :string
# description :text
# path :text
# position :integer default(0), not null
# published_at :datetime
# slug :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid
# communication_website_id :uuid not null
# parent_id :uuid
# university_id :uuid not null
#
# Indexes
#
# index_communication_website_pages_on_about (about_type,about_id)
# index_communication_website_pages_on_communication_website_id (communication_website_id)
# index_communication_website_pages_on_parent_id (parent_id)
# index_communication_website_pages_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_... (communication_website_id => communication_websites.id)
# fk_rails_... (parent_id => communication_website_pages.id)
# fk_rails_... (university_id => universities.id)
#
class Communication::Website::Page < ApplicationRecord
belongs_to :university
belongs_to :website, foreign_key: :communication_website_id
belongs_to :parent, class_name: 'Communication::Website::Page', optional: true
belongs_to :about, polymorphic: true, optional: true
validates :title, presence: true
before_save :make_path
def to_s
"#{ title }"
end
protected
def make_path
self.path = "#{parent&.path}/#{slug}"
end
end
<%= simple_form_for [:admin, page] do |f| %>
<div class="row">
<div class="col-md-8">
<%= f.input :title %>
<%= f.input :slug %>
<%= f.input :description %>
</div>
<div class="col-md-4">
<%= f.input :published_at, html5: true %>
<%= f.association :parent, collection: page.website.pages.where.not(id: page) %>
<%= f.association :website, include_blank: false %>
</div>
</div>
<% content_for :buttons do %>
<%= submit f %>
<% end %>
<% end %>
<% content_for :title, @page %>
<%= render 'form', page: @page %>
<% content_for :title, Communication::Website::Page.model_name.human(count: 2) %>
<table class="table">
<thead>
<tr>
<th><%= Communication::Website::Page.human_attribute_name('title') %></th>
<th><%= Communication::Website::Page.human_attribute_name('parent') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr>
<td><%= link_to page, [:admin, page] %></td>
<td><%= link_to page.parent, [:admin, page.parent] if page.parent %></td>
<td class="text-end">
<%= edit_link page %>
<%= destroy_link page %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% content_for :buttons do %>
<%= create_link Communication::Website::Page %>
<% end %>
<% content_for :title, Research::Journal::Article.model_name.human %>
<%= render 'form', page: @page %>
<% content_for :title, @page %>
<p>
<strong>Description</strong>
<%= @page.description %>
</p>
<p>
<strong>Slug</strong>
<%= @page.slug %>
</p>
<p>
<strong>Path</strong>
<%= @page.path %>
</p>
<% content_for :buttons do %>
<%= edit_link @page %>
<% end %>
json.extract! features_websites_site, :id, :name, :domain, :created_at, :updated_at
json.url features_websites_site_url(features_websites_site, format: :json)
......@@ -5,6 +5,7 @@
<tr>
<th><%= Communication::Website.human_attribute_name('name') %></th>
<th><%= Communication::Website.human_attribute_name('domain') %></th>
<th><%= Communication::Website.human_attribute_name('pages') %></th>
<th></th>
</tr>
</thead>
......@@ -13,6 +14,7 @@
<tr>
<td><%= link_to website, [:admin, website] %></td>
<td><%= link_to website.domain_url, website.domain_url, target: :_blank %></td>
<td><%= website.pages.count %></td>
<td class="text-end">
<%= edit_link website %>
<%= destroy_link website %>
......
json.array! @sites, partial: "admin/features/websites/sites/site", as: :site
......@@ -7,3 +7,12 @@
<% content_for :buttons do %>
<%= edit_link @website %>
<% end %>
<h2 class="mt-5"><%= Communication::Website::Page.model_name.human(count: 2) %></h2>
<%= link_to t('create'),
new_admin_communication_website_page_path(website_id: @website),
class: button_classes %>
<%= link_to 'Toutes les pages',
admin_communication_website_pages_path(website_id: @website) %>
json.partial! "features_websites_sites/features_websites_site", features_websites_site: @features_websites_site
json.extract! program, :id, :university_id, :name, :level, :capacity, :ects, :continuing, :prerequisites, :objectives, :duration, :registration, :pedagogy, :evaluation, :accessibility, :created_at, :updated_at
json.url program_url(program, format: :json)
json.array! @programs, partial: "admin/features/education/programs/program", as: :program
json.partial! "programs/program", program: @program
json.extract! university, :id, :name, :address, :zipcode, :city, :country, :private, :created_at, :updated_at
json.url university_url(university, format: :json)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment