auteur article

This commit is contained in:
Nicolas Bally 2014-12-09 23:26:33 +01:00
parent 1f443d1704
commit 17e668413d
24 changed files with 225 additions and 19 deletions

View File

@ -567,3 +567,8 @@ h1{
line-height:24px; line-height:24px;
font-family:$header_font; font-family:$header_font;
} }
.article_date{
text-align:left;
margin-bottom:10px;
}

View File

@ -113,7 +113,7 @@ class Admin::ArticlesController < ApplicationController
private private
def article_params def article_params
params.require(:article).permit(:category_id, :enabled, :published_at, :title, :slug, :tags_cache, :description, :image_file_id, :title_cached) params.require(:article).permit(:author_id, :category_id, :enabled, :published_at, :title, :slug, :tags_cache, :description, :image_file_id, :title_cached)

View File

@ -0,0 +1,67 @@
class Admin::AuthorsController < ApplicationController
layout "admin"
before_filter :auth_admin
def index
@authors = Author.all
end
def show
@author = Author.find(params[:id])
end
def new
@author = Author.new
end
def edit
@author = Author.find(params[:id])
end
def create
@author = Author.new(author_params)
if @author.save
@authors = Author.all
else
render :action => "new"
end
end
def update
@author = Author.find(params[:id])
if @author.update_attributes(author_params)
else
render :action => "edit"
end
end
def destroy
@author = Author.find(params[:id])
@author.destroy if @author != @current_author
end
private
def author_params
params.require(:author).permit(:name, :firstname, :username, :password, :password_confirmation, :email, :avatar)
end
end

View File

@ -6,7 +6,7 @@ class Article < ActiveRecord::Base
validates :title, :presence => true validates :title, :presence => true
validates :slug, :presence => true, :uniqueness => true validates :slug, :presence => true, :uniqueness => true
has_one :block, :as => :blockable has_one :block, :as => :blockable
belongs_to :author
belongs_to :category belongs_to :category
has_many :enabled_comments,-> {where(:enabled => true)}, :source => :comments, :as => :commentable has_many :enabled_comments,-> {where(:enabled => true)}, :source => :comments, :as => :commentable
after_create :after_creation after_create :after_creation

5
app/models/author.rb Normal file
View File

@ -0,0 +1,5 @@
class Author < ActiveRecord::Base
belongs_to :image_file
validates :name, :presence => true
end

View File

@ -2,6 +2,7 @@
.content .content
= form.inputs do = form.inputs do
=form.input :image_file_id, :as => :qi_image_select =form.input :image_file_id, :as => :qi_image_select
=form.input :author_id, :as => :select, :collection => Author.order(:name), :include_blank => false
=form.input :category_id, :as => :select, :collection => Category.order(:name) =form.input :category_id, :as => :select, :collection => Category.order(:name)
= form.input :enabled,:as => :boolean , :label => "Actif" = form.input :enabled,:as => :boolean , :label => "Actif"
= form.input :published_at, :label => "Date de publication : ",:as => :qi_date_picker = form.input :published_at, :label => "Date de publication : ",:as => :qi_date_picker

View File

@ -0,0 +1,11 @@
%tr#author_row{:id => author.id}
%td=author.name
%td.actions
= link_to i(:"trash-o"), [:admin, author], :confirm => 'Voulez-vous vraiment supprimer cet author ?', :method => :delete, :remote => true
= link_to i(:pencil), edit_admin_author_path(author), :remote => true

View File

@ -0,0 +1,19 @@
=semantic_form_for [:admin, @author], :remote => true, :html => { :multipart => true } do |f|
.content
%h3
Auteur
= f.inputs do
=#f.input :avatar, :label => "Avatar :"
= f.input :name, :label => "Nom :"
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,2 @@
$('#author_rows').html("<%= escape_javascript(render(@authors))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#author_row_<%= @author.id %>').remove();

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,36 @@
= link_to 'Ajouter un auteur', new_admin_author_path, :remote => true, :class => "btn btn-primary", :style => "float:right;"
%h1 Liste des auteurs
%table.table.table-hover.table-striped
%thead#Admin_rows_header.rows_header
%tr
%td
Nom
%td{:style => "width:100px"}
&nbsp;
%tbody#author_rows.rows
=render @authors

View File

@ -0,0 +1,2 @@
$('#Admin_index_block').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>");

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,3 @@
$('#author_row_<%= @author.id %>').replaceWith("<%= escape_javascript(render(@author))%>");
close_pane_hover();

View File

@ -85,12 +85,13 @@
-if articles -if articles
.articles .articles
-articles.each do |article| -articles.each do |article|
.article %a{:href => public_article_path(:id => article.slug)}
.image=image_tag article.image_file.file.large.medium.url if article.image_file .article
.image=image_tag article.image_file.file.large.medium.url if article.image_file
.description .description
%h2=article.title %h2=article.title
.clear .clear

View File

@ -1,6 +1,12 @@
%h1=@article.title %h1=@article.title
=image_tag @article.image_file.file.large.medium.url .article_date
le
=l @article.published_at, :format => :human_date
-if @article.author
par
=@article.author.name
=image_tag @article.image_file.file.large.medium.url if @article.image_file
.description=simple_format @article.description .description=simple_format @article.description
%hr %hr
=render @article.block =render @article.block

View File

@ -31,7 +31,7 @@ fr:
long: "%e %B %Y" long: "%e %B %Y"
only_month: "%B %Y" only_month: "%B %Y"
only_month_name: "%B" only_month_name: "%B"
human_date: "%A %d %B %Y" human_date: "%A %-d %B %Y"
day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi] day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam] abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]
month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre] month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
@ -48,7 +48,7 @@ fr:
short: "%d %b %H:%M" short: "%d %b %H:%M"
long: "%A %d %B %Y %H:%M" long: "%A %d %B %Y %H:%M"
human: "le %A %d %B %Y à %Hh%M" human: "le %A %d %B %Y à %Hh%M"
human_date: "%A %d %B %Y" human_date: "%A %-d %B %Y"
am: 'am' am: 'am'
pm: 'pm' pm: 'pm'

View File

@ -51,7 +51,7 @@ Survey::Application.routes.draw do
#admin #admin
namespace :admin do namespace :admin do
resources :authors
resources :password_resets resources :password_resets
resources :admin_auths do resources :admin_auths do

View File

@ -0,0 +1,5 @@
class AddAuthorToArticles < ActiveRecord::Migration
def change
add_reference :articles, :author, index: true
end
end

View File

@ -0,0 +1,12 @@
class CreateAuthors < ActiveRecord::Migration
def change
create_table :authors do |t|
t.string :name
t.text :bio
t.references :image_file, index: true
t.string :slug
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141208202946) do ActiveRecord::Schema.define(version: 20141209215455) do
create_table "admins", force: true do |t| create_table "admins", force: true do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
@ -24,20 +24,14 @@ ActiveRecord::Schema.define(version: 20141208202946) do
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at", null: false t.datetime "created_at"
t.datetime "updated_at", null: false t.datetime "updated_at"
t.string "username" t.string "username"
t.string "name" t.string "name"
t.string "firstname" t.string "firstname"
t.string "file" t.string "file"
t.string "avatar"
t.string "password_digest", default: "", null: false
t.string "remember_token"
end end
add_index "admins", ["email"], name: "index_admins_on_email", unique: true, using: :btree
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true, using: :btree
create_table "albums", force: true do |t| create_table "albums", force: true do |t|
t.string "name" t.string "name"
t.boolean "super_admin" t.boolean "super_admin"
@ -84,8 +78,22 @@ ActiveRecord::Schema.define(version: 20141208202946) do
t.integer "category_id" t.integer "category_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "author_id"
end end
add_index "articles", ["author_id"], name: "index_articles_on_author_id", using: :btree
create_table "authors", force: true do |t|
t.string "name"
t.text "bio"
t.integer "image_file_id"
t.string "slug"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "authors", ["image_file_id"], name: "index_authors_on_image_file_id", using: :btree
create_table "block_contents", force: true do |t| create_table "block_contents", force: true do |t|
t.integer "style" t.integer "style"
t.integer "nbr_columns" t.integer "nbr_columns"

13
test/fixtures/authors.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
bio:
image_file_id:
slug: MyString
two:
name: MyString
bio:
image_file_id:
slug: MyString

View File

@ -0,0 +1,7 @@
require 'test_helper'
class AuthorTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end