Commit 34030808b5c54d75da783983255dc184561f2fdd

More edit article
Delete wiki, delete article
Fixed journal update error

Commit diff

app/controllers/articles_controller.rb

 
3131 def show
3232 end
3333
34 def edit
35 if @project
36 # Project article
37 @article = Article.find_by_id(params[:id], current_user)
38 if @article
39 @title = "Editing: " + @project.title + ": " + @article.title
40 render :action => "ac_project_edit"
41 else
42 flash[:error] = "Article not found."
43 redirect_to project_path(@project)
44 end
45 else
46 # Normal article index page
47 end
48 end
49
50 def update
51 if @project
52 # Project article
53 @article = Article.find_by_id(params[:id], current_user)
54 if @article
55 #FIXME is this correct?, does deep_clone make one? (if not it should)
56 original_article = Article.new
57 original_article = @article.deep_clone
58 if @article.update_attributes(params[:article])
59 @article.save
60 Journal.update(original_article, @article, request.env["REMOTE_ADDR"], @project.id, current_user.id)
61 flash[:notice] = "Article was successfully updated."
62 redirect_to project_articles_path(@project)
63 else
64 @title = "Editing: " + @project.title + ": " + @article.title
65 render :action => "ac_project_edit"
66 end
67 else
68 flash[:error] = "Article not found."
69 redirect_to project_path(@project)
70 end
71 else
72 # Normal Article
73 end
74 end
75
76 def destroy
77 if @is_member
78 flash[:notice] = 'Article deleted.'
79 Article.find(params[:id]).destroy
80 redirect_to project_articles_path(@project)
81 end
82 rescue ActiveRecord::RecordNotFound
83 flash[:error] = 'Article ' + params[:id] + ' does not exist.'
84 redirect_to project_articles_path(@project)
85 end
86
87
88
89
90
3491 # Show all articles /2008 or /2008/11 or /2008/11/1 and render grouped by date
3592 def find_by_date
3693 @articles = Article.find_by_date(current_user, params[:year], params[:month], params[:day])
toggle raw diff

app/controllers/wikis_controller.rb

 
115115 original_wiki = Wiki.new
116116 original_wiki = @wiki.deep_clone
117117 if @wiki.update_attributes(params[:wiki])
118 @wiki.save
118119 Journal.update(original_wiki, @wiki, request.env["REMOTE_ADDR"], @project.id, current_user.id)
119120 flash[:notice] = "Wiki was successfully updated."
120121 @title = @wiki.title
140140 end
141141 end
142142
143 def destroy
144 if @is_member
145 flash[:notice] = 'Wiki deleted.'
146 Wiki.find(params[:id]).destroy
147 redirect_to project_wikis_path(@project)
148 end
149 rescue ActiveRecord::RecordNotFound
150 flash[:error] = 'Wiki ' + params[:id] + ' does not exist.'
151 redirect_to project_wikis_path(@project)
152 end
153
154
143155 #FIXME
144156 def to_slug(s)
145157 s.gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-')
toggle raw diff

app/helpers/articles_helper.rb

 
55
66 include ProjectsHelper
77
8 #
9 # article - object
10 # short - false to show full body text, true to show summary
11 # use_permalink - makes title in to an anchor to permalink url
12 #
813 def render_article (article, short, use_permalink)
914 # render the coloured tab
1015 out = %Q{<div class='article_left_tab'><a href='/archives/type/}
toggle raw diff

app/helpers/projects_helper.rb

 
108108 out << actionbox_complex(:allow_shortcuts => true, :new_project_wiki => true)
109109 else
110110 out << actionbox_complex(:allow_shortcuts => true, :edit_project_wiki => true, :new_project_wiki => true, :list_project_wikis => true)
111 out << render_right_project_extrainfo
112 out << render_right_project_contributors
111113 end
112 out << render_right_project_extrainfo
113 out << render_right_project_contributors
114114 when PRJ_TAB_ACTIVITIES
115115 out << actionbox_basic(:allow_shortcuts => true)
116116 out << render(:partial => "ac_right_actionbox_post_message") if @is_member
138138 out << actionbox_complex(:allow_shortcuts => true, :new_ticket => true)
139139 out << render(:partial => "ac_right_ticket_filter")
140140 when PRJ_TAB_ARTICLES
141 out << actionbox_complex(:allow_shortcuts => true, :new_article => true)
141 case subtab
142 when PRJ_TAB_ARTICLES_EDIT, PRJ_TAB_ARTICLES_NEW
143 out << actionbox_basic(:allow_shortcuts => true)
144 else
145 out << actionbox_complex(:allow_shortcuts => true, :new_article => true)
146 end
142147 when PRJ_TAB_FORUM
143148 out << actionbox_basic(:allow_shortcuts => true)
144149 when PRJ_TAB_LOG
toggle raw diff

app/models/article.rb

 
2828 return at.to_s.capitalize
2929 end
3030 end
31
31
32 def deep_clone
33 Marshal::load(Marshal.dump(self))
34 end
35
3236protected
3337
3438
8181 @projects = Project.list_for_user(curruser)
8282 find(:all, :conditions => ["status = '#{:published}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC", :limit => 3)
8383 end
84
85 # finds articles for a user based on the user slug e.g. /profiles/test-user/articles
86 def self.find_by_id (id, curruser)
87 @projects = Project.list_for_user(curruser)
88 find(:first, :conditions => ["status = '#{:published}' AND id = '#{id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"])
89 end
8490
8591 # finds articles for a user based on the user slug e.g. /profiles/test-user/articles
8692 def self.find_by_user (user_id, curruser)
toggle raw diff

app/models/journal.rb

 
8585 # record that something has happened
8686 journal = Journal.new
8787 journal.action = :update
88 journal.model_type = updated_model.type.to_s
88 journal.model_type = updated_model.class.to_s
8989 journal.row_id = updated_model.id
9090 journal.ip = ip
9191 journal.user_id = user_id
92 journal.summary = "Updated " << model.class.to_s
92 journal.summary = "Updated " << updated_model.class.to_s
9393 #TODO check saves okay
9494 journal.save
9595 #
toggle raw diff

app/views/articles/_ac_form.html.erb

 
0<p>
1 <%= form.label :title -%><br />
2 <%= form.text_field :title, :class => "text" -%>
3</p>
4<% unless ["edit", "update"].include?(controller.action_name) -%>
5 <p>
6 <%= form.label :slug, "Slug (for urls etc)" -%><br />
7 <%= form.text_field :slug, :class => "text" -%>
8 </p>
9 <script type="text/javascript" charset="utf-8">
10 var slugger = new ProjectSluggorizer("project_title", "project_slug");
11 </script>
12<% end -%>
13<p>
14 <%= form.label :tag_list, "Categories (space seperated)" -%><br />
15 <%= form.text_field :tag_list, :class => "text" -%>
16</p>
17<p>
18 <%= form.label :license -%><br />
19 <%= form.select :license, Project::LICENSES -%>
20</p>
21<p>
22 <%= form.label :home_url, "Home URL (eg Rubyforge etc)" -%><br />
23 <%= form.text_field :home_url, :class => "text" -%>
24</p>
25<p>
26 <%= form.label :mailinglist_url, "Mailinglist URL (if any)" -%><br />
27 <%= form.text_field :mailinglist_url, :class => "text" -%>
28</p>
29<p>
30 <%= form.label :bugtracker_url, "Bugtracker URL (if any)" -%><br />
31 <%= form.text_field :bugtracker_url, :class => "text" -%>
32</p>
33<p>
34 <%= form.label :description -%><br />
35 <small class="hint">
36 <a href="http://daringfireball.net/projects/markdown/">Markdown</a> and
37 basic html is allowed
38 </small><br />
39 <%= form.text_area :description, :class => "text wide tall" -%>
40</p>
toggle raw diff

app/views/articles/ac_project_edit.html.erb

 
55
66<%= div_formattedtext_open %>
77
8<%= error_messages_for :wiki %>
8<%= error_messages_for :article %>
99
10<% form_for :wiki, :url => project_wiki_path(@project.slug, @wiki.slug), :html => {:method => :put, :name => 'editwiki', :id => 'input'} do |f| -%>
10<% form_for :article, :url => project_article_path(@project.slug, @article.id), :html => {:method => :put, :name => 'editarticle', :id => 'input'} do |f| -%>
1111
1212 <h2><%= @title %></h2>
1313
1414 <p>The wiki title is automatically prefixed with the project title when the wiki is displayed.</p>
1515
16 <%= render :partial => "ac_form", :locals => { :f => f } %>
16 <%= render :partial => "ac_form" %>
1717
1818 <p>
19 <%= f.label :slug -%><br/>
20 <%= f.text_field :slug -%>
19 <%= f.label :title -%><br/>
20 <%= f.text_field :title -%>
2121 </p>
2222
2323 <p>
24 <%= link_to "Cancel", project_wiki_path(@project.slug, @wiki.slug) %>
25 <a href="javascript:document.editwiki.submit();">Preview</a>
26 <a href="javascript:document.editwiki.submit();">Update</a>
24 <%= f.label :body -%><br/>
25 <%= f.text_area :body, :rows => 20 -%>
26 </p>
27
28 <p>
29 <%= f.label :body_summary -%><br/>
30 <%= f.text_area :body_summary, :rows => 10 -%>
31 </p>
32
33 <p>
34 <%= f.label :permalink -%><br/>
35 <%= f.text_field :permalink -%>
36 </p>
37
38 <p>
39 <%= link_to "Cancel", project_articles_path(@project.slug) %>
40 <a href="javascript:document.editarticle.submit();">Preview</a>
41 <a href="javascript:document.editarticle.submit();">Update</a>
2742 </p>
2843
2944<% end -%>
4646<br />
4747<br />
4848
49<%= render_wiki %>
49<%= render_article(@article, false, false) %>
5050<%= div_formattedtext_close %>
5151
5252<%= render :partial => "projects/ac_project_footer" %>
toggle raw diff

app/views/shared/_ac_article_list.html.erb

 
3535 <td align=center><%= 0 %></td>
3636 <td align=center><%= article.views %></td>
3737 <td width=<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT %>><%= link_to("Edit", edit_project_article_path(@project.slug, article.id)) %></td>
38 <td width=<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT %>><%= link_to("Del.", project_article_path(@project.slug, article.id), :action => "destroy") %></td>
38 <td width=<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT %>><%= link_to("Del.", project_article_path(@project.slug, article.id), :method => :delete) %></td>
3939<% end %>
4040</tr>
4141<% end %>
toggle raw diff

app/views/wikis/ac_project_index.html.erb

 
3434 <td><%= wiki.format.to_s.capitalize %></td>
3535 <td><%= format_datetime_ddmmyyhhmm(wiki.created_at) %></td>
3636 <% if @is_member %>
37 <td>Edit</td>
38 <td>Del</td>
37 <td width=<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT %>><%= link_to("Edit", edit_project_wiki_path(@project.slug, wiki.slug)) %></td>
38 <td width=<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT %>><%= link_to("Del.", project_wiki_path(@project.slug, wiki.id), :method => :delete) %></td>
3939 <% end %>
4040</tr>
4141<% end %>
toggle raw diff

db/migrate/014_create_articles.rb

 
44# also it's 7 because there are 6 migrations before it on the project being merged in, the order
55# of the migrations is importand for foreign_key_migrations plugin
66#
7# Some fields have an _jid this is an identifier for journaling system that tracks changes
8#
97
108class CreateArticles < ActiveRecord::Migration
119
2222
2323 create_table :articles do |t|
2424 t.string :title, :default => "Empty", :null => false
25 t.integer :title_jid
26 #
2725 t.text :body
28 t.integer :body_jid
29 #
3026 t.text :body_summary
31 t.integer :body_summary_jid
3227 #also need to change the article_type table/fixtures
3328 t.column :article_type, :enum, :limit => [:news, :code, :release, :howto, :issue, :other], :default => :other, :null => true
34 t.integer :article_type_jid
35 #
3629 t.column :status, :enum, :limit => [:draft, :published, :test, :deleted], :default => :draft
37 t.integer :status_jid
38 # who is allowed to post comments
3930 t.column :comment_status, :enum, :limit => [:open, :closed, :users, :administrators], :default => :open
40 t.integer :comment_status_jid
41 # slug friendly name e.g. sample-title
4231 t.string :permalink, :null => false
43 t.integer :permalink_jid
44 # who is allowed to view (members = project members)
4532 t.column :audience, :enum, :limit => [:public, :members], :default => :public
46 t.integer :audience_jid
47 #
4833 t.integer :views, :default => 0
4934 #t.boolean :members_only, :default => false, :null => false
5035 t.timestamps
5136 #foreign keys
5237 t.integer :user_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
53 t.integer :user_id_jid
54 #
5538 t.integer :category_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
56 t.integer :category_id_jid
57 #
5839 #FIXME allow project|version|release polymorphic (maybe, it would help the project filter on the article tab)
5940 t.integer :project_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
60 t.integer :project_id_jid
6141 end
6242 add_index :articles, [:id]
6343 add_index :articles, [:status, :audience]
toggle raw diff

db/migrate/015_create_tickets.rb

 
4848 t.timestamps
4949 #
5050 t.integer :component_id
51 t.integer :component_jid
5251 t.integer :milestone_id
5352 t.integer :assignee_id, :references => nil #foreign key to user table
5453 t.integer :submitter_id, :references => nil #foreign key to user table
toggle raw diff

test/fixtures/tickets.yml

 
77<% fixtures :users, :milestones %>
88
99#
10# Fixup edit article and wiki preview button
11#
12# Change articles bodies and project descriptions to use markdown
13#
14# Update wiki and article should have the .save error checked
15#
16# Add delete journals for wiki, article (they shouldn't physically delete anyway)
17#
18
19
20#
1021# Possible filtering
1122#
1223# * Summary
toggle raw diff