diff --git a/app/assets/stylesheets/public.scss b/app/assets/stylesheets/public.scss index ee1c12b..968522a 100644 --- a/app/assets/stylesheets/public.scss +++ b/app/assets/stylesheets/public.scss @@ -566,4 +566,9 @@ h1{ font-size:22px; line-height:24px; font-family:$header_font; +} + +.article_date{ + text-align:left; + margin-bottom:10px; } \ No newline at end of file diff --git a/app/controllers/admin/articles_controller.rb b/app/controllers/admin/articles_controller.rb index 1c57b9f..095e5a1 100644 --- a/app/controllers/admin/articles_controller.rb +++ b/app/controllers/admin/articles_controller.rb @@ -113,7 +113,7 @@ class Admin::ArticlesController < ApplicationController private 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) diff --git a/app/controllers/admin/authors_controller.rb b/app/controllers/admin/authors_controller.rb new file mode 100644 index 0000000..ea1f883 --- /dev/null +++ b/app/controllers/admin/authors_controller.rb @@ -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 diff --git a/app/models/article.rb b/app/models/article.rb index 918a232..0bb72e7 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -6,7 +6,7 @@ class Article < ActiveRecord::Base validates :title, :presence => true validates :slug, :presence => true, :uniqueness => true has_one :block, :as => :blockable - + belongs_to :author belongs_to :category has_many :enabled_comments,-> {where(:enabled => true)}, :source => :comments, :as => :commentable after_create :after_creation diff --git a/app/models/author.rb b/app/models/author.rb new file mode 100644 index 0000000..c95904d --- /dev/null +++ b/app/models/author.rb @@ -0,0 +1,5 @@ +class Author < ActiveRecord::Base + belongs_to :image_file + + validates :name, :presence => true +end diff --git a/app/views/admin/articles/_form.html.haml b/app/views/admin/articles/_form.html.haml index 9c9a439..489f3d1 100644 --- a/app/views/admin/articles/_form.html.haml +++ b/app/views/admin/articles/_form.html.haml @@ -2,6 +2,7 @@ .content = form.inputs do =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 :enabled,:as => :boolean , :label => "Actif" = form.input :published_at, :label => "Date de publication : ",:as => :qi_date_picker diff --git a/app/views/admin/authors/_author.html.haml b/app/views/admin/authors/_author.html.haml new file mode 100644 index 0000000..1254a3e --- /dev/null +++ b/app/views/admin/authors/_author.html.haml @@ -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 + + + + \ No newline at end of file diff --git a/app/views/admin/authors/_form.html.haml b/app/views/admin/authors/_form.html.haml new file mode 100644 index 0000000..a9d3bdd --- /dev/null +++ b/app/views/admin/authors/_form.html.haml @@ -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" + diff --git a/app/views/admin/authors/create.js.erb b/app/views/admin/authors/create.js.erb new file mode 100644 index 0000000..d517d17 --- /dev/null +++ b/app/views/admin/authors/create.js.erb @@ -0,0 +1,2 @@ +$('#author_rows').html("<%= escape_javascript(render(@authors))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/authors/destroy.js.erb b/app/views/admin/authors/destroy.js.erb new file mode 100644 index 0000000..5d44b59 --- /dev/null +++ b/app/views/admin/authors/destroy.js.erb @@ -0,0 +1 @@ +$('#author_row_<%= @author.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/authors/edit.js.erb b/app/views/admin/authors/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/authors/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/authors/index.html.haml b/app/views/admin/authors/index.html.haml new file mode 100644 index 0000000..0f2665b --- /dev/null +++ b/app/views/admin/authors/index.html.haml @@ -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"} +   + + + + + %tbody#author_rows.rows + + =render @authors + + + + + + + + + + + + + diff --git a/app/views/admin/authors/index.js.erb b/app/views/admin/authors/index.js.erb new file mode 100644 index 0000000..6a4e08d --- /dev/null +++ b/app/views/admin/authors/index.js.erb @@ -0,0 +1,2 @@ + +$('#Admin_index_block').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>"); \ No newline at end of file diff --git a/app/views/admin/authors/new.js.erb b/app/views/admin/authors/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/authors/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/authors/update.js.erb b/app/views/admin/authors/update.js.erb new file mode 100644 index 0000000..fb6db49 --- /dev/null +++ b/app/views/admin/authors/update.js.erb @@ -0,0 +1,3 @@ +$('#author_row_<%= @author.id %>').replaceWith("<%= escape_javascript(render(@author))%>"); + +close_pane_hover(); \ No newline at end of file diff --git a/app/views/layouts/public.html.haml b/app/views/layouts/public.html.haml index 57441f3..8e42b8b 100644 --- a/app/views/layouts/public.html.haml +++ b/app/views/layouts/public.html.haml @@ -85,12 +85,13 @@ -if articles .articles -articles.each do |article| - .article - .image=image_tag article.image_file.file.large.medium.url if article.image_file + %a{:href => public_article_path(:id => article.slug)} + .article + .image=image_tag article.image_file.file.large.medium.url if article.image_file - .description - %h2=article.title + .description + %h2=article.title .clear diff --git a/app/views/public/articles/show.html.haml b/app/views/public/articles/show.html.haml index e1b1dbe..be35aa2 100644 --- a/app/views/public/articles/show.html.haml +++ b/app/views/public/articles/show.html.haml @@ -1,6 +1,12 @@ %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 %hr =render @article.block diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f41f997..faafece 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -31,7 +31,7 @@ fr: long: "%e %B %Y" only_month: "%B %Y" 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] 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] @@ -48,7 +48,7 @@ fr: short: "%d %b %H:%M" long: "%A %d %B %Y %H:%M" human: "le %A %d %B %Y à %Hh%M" - human_date: "%A %d %B %Y" + human_date: "%A %-d %B %Y" am: 'am' pm: 'pm' diff --git a/config/routes.rb b/config/routes.rb index f6601bb..480b258 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,7 @@ Survey::Application.routes.draw do #admin namespace :admin do - + resources :authors resources :password_resets resources :admin_auths do diff --git a/db/migrate/20141209215300_add_author_to_articles.rb b/db/migrate/20141209215300_add_author_to_articles.rb new file mode 100644 index 0000000..7c71117 --- /dev/null +++ b/db/migrate/20141209215300_add_author_to_articles.rb @@ -0,0 +1,5 @@ +class AddAuthorToArticles < ActiveRecord::Migration + def change + add_reference :articles, :author, index: true + end +end diff --git a/db/migrate/20141209215455_create_authors.rb b/db/migrate/20141209215455_create_authors.rb new file mode 100644 index 0000000..d9a9341 --- /dev/null +++ b/db/migrate/20141209215455_create_authors.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index e610566..f48d234 100644 --- a/db/schema.rb +++ b/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: 20141208202946) do +ActiveRecord::Schema.define(version: 20141209215455) do create_table "admins", force: true do |t| t.string "email", default: "", null: false @@ -24,20 +24,14 @@ ActiveRecord::Schema.define(version: 20141208202946) do t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "username" t.string "name" t.string "firstname" t.string "file" - t.string "avatar" - t.string "password_digest", default: "", null: false - t.string "remember_token" 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| t.string "name" t.boolean "super_admin" @@ -84,8 +78,22 @@ ActiveRecord::Schema.define(version: 20141208202946) do t.integer "category_id" t.datetime "created_at" t.datetime "updated_at" + t.integer "author_id" 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| t.integer "style" t.integer "nbr_columns" diff --git a/test/fixtures/authors.yml b/test/fixtures/authors.yml new file mode 100644 index 0000000..4bbde36 --- /dev/null +++ b/test/fixtures/authors.yml @@ -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 diff --git a/test/models/author_test.rb b/test/models/author_test.rb new file mode 100644 index 0000000..92b5e1f --- /dev/null +++ b/test/models/author_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AuthorTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end