Wiki: base implemetation logic
This commit is contained in:
parent
eacea15a21
commit
4c1b8558df
8 changed files with 35 additions and 68 deletions
|
@ -1,61 +1,42 @@
|
||||||
class WikisController < ApplicationController
|
class WikisController < ApplicationController
|
||||||
before_filter :project
|
before_filter :project
|
||||||
layout "project"
|
layout "project"
|
||||||
respond_to :html
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@wiki = @project.wikis.find_by_slug(params[:id])
|
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
|
||||||
respond_with(@wiki)
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
|
||||||
@wiki = Wiki.new
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
if @wiki
|
||||||
format.json { render json: @wiki }
|
format.html
|
||||||
|
else
|
||||||
|
@wiki = @project.wikis.new(:slug => params[:id])
|
||||||
|
format.html { render "edit" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@wiki = Wiki.find(params[:id])
|
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
|
||||||
|
@wiki = Wiki.regenerate_from @wiki
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@wiki = Wiki.new(params[:wiki])
|
@wiki = @project.wikis.new(params[:wiki])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @wiki.save
|
if @wiki.save
|
||||||
format.html { redirect_to @wiki, notice: 'Wiki was successfully created.' }
|
format.html { redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.' }
|
||||||
format.json { render json: @wiki, status: :created, location: @wiki }
|
|
||||||
else
|
|
||||||
format.html { render action: "new" }
|
|
||||||
format.json { render json: @wiki.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@wiki = Wiki.find(params[:id])
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @wiki.update_attributes(params[:wiki])
|
|
||||||
format.html { redirect_to @wiki, notice: 'Wiki was successfully updated.' }
|
|
||||||
format.json { head :no_content }
|
|
||||||
else
|
else
|
||||||
format.html { render action: "edit" }
|
format.html { render action: "edit" }
|
||||||
format.json { render json: @wiki.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@wiki = Wiki.find(params[:id])
|
@wiki = @project.wikis.find(params[:id])
|
||||||
@wiki.destroy
|
@wiki.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to wikis_url }
|
format.html { redirect_to wikis_url }
|
||||||
format.json { head :no_content }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,10 +2,9 @@ class Wiki < ActiveRecord::Base
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
validates :content, :title, :presence => true
|
validates :content, :title, :presence => true
|
||||||
validates :title, :length => 1..250,
|
validates :title, :length => 1..250
|
||||||
:uniqueness => {:scope => :project_id, :case_sensitive => false}
|
|
||||||
|
|
||||||
before_save :set_slug
|
before_update :set_slug
|
||||||
|
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
|
@ -17,4 +16,17 @@ class Wiki < ActiveRecord::Base
|
||||||
def set_slug
|
def set_slug
|
||||||
self.slug = self.title.parameterize
|
self.slug = self.title.parameterize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def regenerate_from wiki
|
||||||
|
regenerated_field = [:slug, :content, :title]
|
||||||
|
|
||||||
|
new_wiki = Wiki.new
|
||||||
|
regenerated_field.each do |field|
|
||||||
|
new_wiki.send("#{field}=", wiki.send(field))
|
||||||
|
end
|
||||||
|
new_wiki
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,5 +21,5 @@
|
||||||
Wall
|
Wall
|
||||||
|
|
||||||
- if @project.wiki_enabled
|
- if @project.wiki_enabled
|
||||||
-#= link_to project_wikis_path(@project), :class => current_page?(:controller => "projects", :action => "wiki", :id => @project) ? "current" : nil do
|
= link_to project_wiki_path(@project, :index), :class => current_page?(:controller => "projects", :action => "wiki", :id => @project) ? "current" : nil do
|
||||||
Wiki
|
Wiki
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form_for @wiki do |f|
|
= form_for [@project, @wiki] do |f|
|
||||||
-if @wiki.errors.any?
|
-if @wiki.errors.any?
|
||||||
#error_explanation
|
#error_explanation
|
||||||
%h2= "#{pluralize(@wiki.errors.count, "error")} prohibited this wiki from being saved:"
|
%h2= "#{pluralize(@wiki.errors.count, "error")} prohibited this wiki from being saved:"
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
.field
|
.field
|
||||||
= f.label :title
|
= f.label :title
|
||||||
= f.text_field :title
|
= f.text_field :title
|
||||||
|
= f.hidden_field :slug
|
||||||
.field
|
.field
|
||||||
= f.label :content
|
= f.label :content
|
||||||
= f.text_area :content
|
= f.text_area :content
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
%h1 Editing wiki
|
%h1 Editing page
|
||||||
|
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
|
||||||
= link_to 'Show', @wiki
|
= link_to 'Show', [@project, @wiki]
|
||||||
\|
|
|
||||||
= link_to 'Back', wikis_path
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
%h1 Listing wikis
|
|
||||||
|
|
||||||
%table
|
|
||||||
%tr
|
|
||||||
%th Title
|
|
||||||
%th Content
|
|
||||||
%th
|
|
||||||
%th
|
|
||||||
%th
|
|
||||||
|
|
||||||
- @wikis.each do |wiki|
|
|
||||||
%tr
|
|
||||||
%td= wiki.title
|
|
||||||
%td= wiki.content
|
|
||||||
%td= link_to 'Show', wiki
|
|
||||||
%td= link_to 'Edit', edit_wiki_path(wiki)
|
|
||||||
%td= link_to 'Destroy', wiki, :confirm => 'Are you sure?', :method => :delete
|
|
||||||
|
|
||||||
%br
|
|
||||||
|
|
||||||
= link_to 'New Wiki', new_wiki_path
|
|
|
@ -1,5 +0,0 @@
|
||||||
%h1 New wiki
|
|
||||||
|
|
||||||
= render 'form'
|
|
||||||
|
|
||||||
= link_to 'Back', wikis_path
|
|
|
@ -56,7 +56,8 @@ Gitlab::Application.routes.draw do
|
||||||
get "files"
|
get "files"
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :wikis, :only => [:show, :edit, :destroy]
|
resources :wikis, :only => [:show, :edit, :destroy, :create]
|
||||||
|
|
||||||
resource :repository do
|
resource :repository do
|
||||||
member do
|
member do
|
||||||
get "branches"
|
get "branches"
|
||||||
|
|
Loading…
Add table
Reference in a new issue