Commit 85974948e778f5261cc24a2911bd652a91e950da

Authored by Valery Sizov
1 parent b565cd19

Wiki: history

app/controllers/wikis_controller.rb
... ... @@ -4,7 +4,11 @@ class WikisController < ApplicationController
4 4 layout "project"
5 5  
6 6 def show
7   - @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
  7 + if params[:old_page_id]
  8 + @wiki = @project.wikis.find(params[:old_page_id])
  9 + else
  10 + @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
  11 + end
8 12 respond_to do |format|
9 13 if @wiki
10 14 format.html
... ... @@ -22,6 +26,7 @@ class WikisController < ApplicationController
22 26  
23 27 def create
24 28 @wiki = @project.wikis.new(params[:wiki])
  29 + @wiki.user = current_user
25 30  
26 31 respond_to do |format|
27 32 if @wiki.save
... ... @@ -31,6 +36,10 @@ class WikisController < ApplicationController
31 36 end
32 37 end
33 38 end
  39 +
  40 + def history
  41 + @wikis = @project.wikis.where(:slug => params[:id]).order("created_at")
  42 + end
34 43  
35 44 def destroy
36 45 @wiki = @project.wikis.find(params[:id])
... ...
app/models/wiki.rb
1 1 class Wiki < ActiveRecord::Base
2 2 belongs_to :project
  3 + belongs_to :user
3 4  
4   - validates :content, :title, :presence => true
  5 + validates :content, :title, :user_id, :presence => true
5 6 validates :title, :length => 1..250
6 7  
7 8 before_update :set_slug
... ...
app/views/wikis/history.html.haml 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +%h2 Versions
  2 +%table
  3 + %thead
  4 + %tr
  5 + %th #
  6 + %th last edit
  7 + %th created by
  8 + %tbody
  9 + - @wikis.each_with_index do |wiki_page, i|
  10 + %tr
  11 + %td= i + 1
  12 + %td= link_to wiki_page.created_at.to_s(:short), project_wiki_path(@project, wiki_page, :old_page_id => wiki_page.id)
  13 + %td= wiki_page.user.name
  14 +
... ...
app/views/wikis/show.html.haml
1 1 %h3
2 2 = @wiki.title
3 3 - if can? current_user, :write_wiki, @project
  4 + = link_to history_project_wiki_path(@project, @wiki), :class => "right btn small" do
  5 + History
4 6 = link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do
5 7 Edit
6 8  
... ...
config/routes.rb
... ... @@ -56,7 +56,11 @@ Gitlab::Application.routes.draw do
56 56 get "files"
57 57 end
58 58  
59   - resources :wikis, :only => [:show, :edit, :destroy, :create]
  59 + resources :wikis, :only => [:show, :edit, :destroy, :create] do
  60 + member do
  61 + get "history"
  62 + end
  63 + end
60 64  
61 65 resource :repository do
62 66 member do
... ...
db/migrate/20120219193300_add_user_to_wiki.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class AddUserToWiki < ActiveRecord::Migration
  2 + def change
  3 + add_column :wikis, :user_id, :integer
  4 +
  5 + end
  6 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20120219140810) do
  14 +ActiveRecord::Schema.define(:version => 20120219193300) do
15 15  
16 16 create_table "issues", :force => true do |t|
17 17 t.string "title"
... ... @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120219140810) do
166 166 t.datetime "created_at", :null => false
167 167 t.datetime "updated_at", :null => false
168 168 t.string "slug"
  169 + t.integer "user_id"
169 170 end
170 171  
171 172 end
... ...