Skip to content

Commit

Permalink
article merging works - comments not started yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Samvit Ramadurgam committed Mar 10, 2012
1 parent f1de5dd commit 2993e71
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bundle/config
@@ -1,2 +1,2 @@
---
BUNDLE_WITHOUT: adapters
BUNDLE_WITHOUT: production
21 changes: 21 additions & 0 deletions app/controllers/admin/content_controller.rb
Expand Up @@ -24,10 +24,12 @@ def index
end

def new
@status="new"
new_or_edit
end

def edit
@status="edit"
@article = Article.find(params[:id])
unless @article.access_by? current_user
redirect_to :action => 'index'
Expand Down Expand Up @@ -162,6 +164,12 @@ def new_or_edit

@article.published_at = DateTime.strptime(params[:article][:published_at], "%B %e, %Y %I:%M %p GMT%z").utc rescue Time.parse(params[:article][:published_at]).utc rescue nil

if params.include? :id_to_merge
@article = @article.merge_with(params[:id_to_merge])
params[:id] = @article.id
end


if request.post?
set_article_author
save_attachments
Expand All @@ -171,6 +179,7 @@ def new_or_edit
else
@article.permalink = @article.stripped_title if @article.permalink.nil? or @article.permalink.empty?
end


if @article.save
destroy_the_draft unless @article.draft
Expand All @@ -188,6 +197,18 @@ def new_or_edit
render 'new'
end

# def merge_articles(merge_id)
# @article_to_be_merged = Article.find(merge_id)
#
# @article_to_be_merged.permalink=@article.permalink
# @article.title = @article.title + ", "+ @article_to_be_merged.title
# @article.body = @article.body + @article_to_be_merged.body
#
# @article.save!
# @article_to_be_merged.save!
# end


def set_the_flash
case params[:action]
when 'new'
Expand Down
24 changes: 16 additions & 8 deletions app/models/article.rb
Expand Up @@ -48,7 +48,7 @@ def spam

before_create :set_defaults, :create_guid
after_create :add_notifications
before_save :set_published_at, :ensure_settings_type
before_save :set_published_at
after_save :post_trigger
after_save :keywords_to_tags

Expand Down Expand Up @@ -424,13 +424,6 @@ def set_published_at
end
end

def ensure_settings_type
if settings.is_a?(String)
# Any dump access forcing de-serialization
password.blank?
end
end

def set_defaults
if self.attributes.include?("permalink") and
(self.permalink.blank? or
Expand Down Expand Up @@ -466,4 +459,19 @@ def self.time_delta(year = nil, month = nil, day = nil)
to = to - 1 # pull off 1 second so we don't overlap onto the next day
return from..to
end

public
def merge_with(other_article_id)
other = Article.find(other_article_id)
fusion = self.clone
fusion.comments = self.comments + other.comments

fusion.title = self.title + ", "+ other.title
fusion.body = self.body + other.body

other.destroy
self.destroy
fusion.save!
return fusion
end
end
7 changes: 7 additions & 0 deletions app/views/admin/content/new.html.erb
@@ -1,3 +1,10 @@
<% @page_heading = _('New article') %>
<% if @status=="edit" %>
<form>
ID of Article to be merged: <input type="text" name="id_to_merge" /><br />
<input type="submit" value="Merge With This Article" />
</form>
<% end %>
<%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>

0 comments on commit 2993e71

Please sign in to comment.