work on note views

This commit is contained in:
albert
2011-01-19 14:28:22 -05:00
parent 0224c41252
commit a6dfd4f0f5
57 changed files with 104563 additions and 15 deletions

View File

@@ -1,16 +1,39 @@
class NotesController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show]
def index
@search = Note.search(params[:search])
@notes = @search.paginate(:page => params[:page])
respond_with(@notes)
end
def show
@note = Note.find(params[:id])
respond_with(@note)
end
def create
@note = Note.create(params[:note])
respond_with(@note)
end
def update
@note = Note.find(params[:id])
@note.update_attributes(params[:note])
respond_with(@note)
end
def destroy
@note = Note.find(params[:id])
@note.destroy
respond_with(@note)
end
def revert
@note = Note.find(params[:id])
@version = NoteVersion.find(params[:version_id])
@note.revert_to(@version)
respond_with(@note)
end
end

View File

@@ -3,22 +3,29 @@ class Note < ActiveRecord::Base
belongs_to :post
belongs_to :creator, :class_name => "User"
belongs_to :updater, :class_name => "User"
before_save :initialize_creator
before_save :blank_body
has_many :versions, :class_name => "NoteVersion"
before_validation :initialize_creator, :on => :create
before_validation :initialize_updater
before_validation :blank_body
has_many :versions, :class_name => "NoteVersion", :order => "note_versions.id ASC"
after_save :update_post
after_save :create_version
validate :post_must_not_be_note_locked
validates_presence_of :updater_id, :updater_ip_addr
attr_accessible :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active
scope :active, where("is_active = TRUE")
scope :body_matches, lambda {|query| where("text_index @@ plainto_tsquery(?)", query)}
search_method :body_matches
def presenter
@presenter ||= NotePresenter.new(self)
end
def initialize_creator
self.creator_id = updater_id
self.creator_id = CurrentUser.id
end
def initialize_updater
self.updater_id = CurrentUser.id
end
def post_must_not_be_note_locked
@@ -61,30 +68,30 @@ class Note < ActiveRecord::Base
)
end
def revert_to(version, reverter_id, reverter_ip_addr)
def revert_to(version)
self.x = version.x
self.y = version.y
self.body = version.body
self.width = version.width
self.height = version.height
self.is_active = version.is_active
self.updater_id = reverter_id
self.updater_ip_addr = reverter_ip_addr
self.updater_id = CurrentUser.id
self.updater_ip_addr = CurrentUser.ip_addr
end
def revert_to!(version, reverter_id, reverter_ip_addr)
revert_to(version, reverter_id, reverter_ip_addr)
def revert_to!(version)
revert_to(version)
save!
end
def self.undo_changes_by_user(user_id, reverter_id, reverter_ip_addr)
def self.undo_changes_by_user(user_id)
transaction do
notes = Note.joins(:versions).where(["note_versions.updater_id = ?", user_id]).select("DISTINCT notes.*").all
NoteVersion.destroy_all(["updater_id = ?", user_id])
notes.each do |note|
first = note.versions.first
if first
note.revert_to!(first, reverter_id, reverter_ip_addr)
note.revert_to!(first)
end
end
end

View File

View File

View File

View File