diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index 96c1ac4ac14fae88ea0163cf3ca92b0f7be2a11a..128e30c14c07d7e6f8f9637761edd4bd832fe8ce 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -1,61 +1,42 @@ class WikisController < ApplicationController before_filter :project layout "project" - respond_to :html def show - @wiki = @project.wikis.find_by_slug(params[:id]) - respond_with(@wiki) - end - - def new - @wiki = Wiki.new - + @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last respond_to do |format| - format.html # new.html.erb - format.json { render json: @wiki } + if @wiki + format.html + else + @wiki = @project.wikis.new(:slug => params[:id]) + format.html { render "edit" } + end end end def edit - @wiki = Wiki.find(params[:id]) + @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last + @wiki = Wiki.regenerate_from @wiki end def create - @wiki = Wiki.new(params[:wiki]) + @wiki = @project.wikis.new(params[:wiki]) respond_to do |format| if @wiki.save - format.html { redirect_to @wiki, notice: 'Wiki was successfully created.' } - 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 } + format.html { redirect_to [@project, @wiki], notice: 'Wiki was successfully updated.' } else format.html { render action: "edit" } - format.json { render json: @wiki.errors, status: :unprocessable_entity } end end end - + def destroy - @wiki = Wiki.find(params[:id]) + @wiki = @project.wikis.find(params[:id]) @wiki.destroy respond_to do |format| format.html { redirect_to wikis_url } - format.json { head :no_content } end end end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 7c50446865ecc36d592e38690287d1b0f7f17dcd..b1ecc06e132dd525793b11f232b5bf7dab0df430 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -2,10 +2,9 @@ class Wiki < ActiveRecord::Base belongs_to :project validates :content, :title, :presence => true - validates :title, :length => 1..250, - :uniqueness => {:scope => :project_id, :case_sensitive => false} + validates :title, :length => 1..250 - before_save :set_slug + before_update :set_slug def to_param @@ -17,4 +16,17 @@ class Wiki < ActiveRecord::Base def set_slug self.slug = self.title.parameterize 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 diff --git a/app/views/layouts/_project_menu.html.haml b/app/views/layouts/_project_menu.html.haml index 22439aad29f27eb839e65c38ee188107e883dc80..6a4a3156c0763d955fcbe75276f251cd9c99fe9f 100644 --- a/app/views/layouts/_project_menu.html.haml +++ b/app/views/layouts/_project_menu.html.haml @@ -21,5 +21,5 @@ Wall - 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 diff --git a/app/views/wikis/_form.html.haml b/app/views/wikis/_form.html.haml index 1f2e1d9170020ac1144a298acc8091741952aeda..5c57c2b3179f78e6275f7cd37a88d015fa11a3c2 100644 --- a/app/views/wikis/_form.html.haml +++ b/app/views/wikis/_form.html.haml @@ -1,4 +1,4 @@ -= form_for @wiki do |f| += form_for [@project, @wiki] do |f| -if @wiki.errors.any? #error_explanation %h2= "#{pluralize(@wiki.errors.count, "error")} prohibited this wiki from being saved:" @@ -9,6 +9,7 @@ .field = f.label :title = f.text_field :title + = f.hidden_field :slug .field = f.label :content = f.text_area :content diff --git a/app/views/wikis/edit.html.haml b/app/views/wikis/edit.html.haml index 801ed6400b27c14087678aad18250764a017ee97..f83ff9e1d64647c739f25c564c1f88830d6a0d74 100644 --- a/app/views/wikis/edit.html.haml +++ b/app/views/wikis/edit.html.haml @@ -1,7 +1,5 @@ -%h1 Editing wiki +%h1 Editing page = render 'form' -= link_to 'Show', @wiki -\| -= link_to 'Back', wikis_path += link_to 'Show', [@project, @wiki] diff --git a/app/views/wikis/index.html.haml b/app/views/wikis/index.html.haml deleted file mode 100644 index d19297f82ade71dd9cee561a78412e3e629fa6f9..0000000000000000000000000000000000000000 --- a/app/views/wikis/index.html.haml +++ /dev/null @@ -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 diff --git a/app/views/wikis/new.html.haml b/app/views/wikis/new.html.haml deleted file mode 100644 index c5024d765a1952a65787477b0c312a8b3e9df27a..0000000000000000000000000000000000000000 --- a/app/views/wikis/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%h1 New wiki - -= render 'form' - -= link_to 'Back', wikis_path diff --git a/config/routes.rb b/config/routes.rb index 0a0218a04eff7587f08da92c868329ebf416899f..ef2ff709c9f7fd1b7d8604fc7cdb2a02891b9e0d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,7 +56,8 @@ Gitlab::Application.routes.draw do get "files" end - resources :wikis, :only => [:show, :edit, :destroy] + resources :wikis, :only => [:show, :edit, :destroy, :create] + resource :repository do member do get "branches"