diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 163b0d3c9..d4295c999 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -271,13 +271,25 @@ div#c-posts { .prev { position: absolute; - left: 1em; + left: 2em; top: 0px; } .next { position: absolute; - right: 1em; + right: 2em; + top: 0px; + } + + .first { + position: absolute; + left: 0.5em; + top: 0px; + } + + .last { + position: absolute; + right: 0.5em; top: 0px; } diff --git a/app/models/note.rb b/app/models/note.rb index cf7c31b65..80c0a1ec4 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -7,7 +7,8 @@ class Note < ActiveRecord::Base before_validation :initialize_updater before_validation :blank_body validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height - validate :coordinates_in_range, :message => "must be inside the image" + validate :post_must_exist + validate :note_within_image, :message => "must be inside the image" has_many :versions, :class_name => "NoteVersion", :order => "note_versions.id ASC" after_save :update_post after_save :create_version @@ -96,9 +97,9 @@ class Note < ActiveRecord::Base self.updater_ip_addr = CurrentUser.ip_addr end - def coordinates_in_range - if x < 0 || y < 0 || (x > post.image_width) || (y > post.image_height) - self.errors.add(:coordinates, "must be inside the image") + def post_must_exist + if !Post.exists?(post_id) + errors.add :post, "must exist" return false end end @@ -110,6 +111,14 @@ class Note < ActiveRecord::Base end end + def note_within_image + return false unless post.present? + if x < 0 || y < 0 || (x > post.image_width) || (y > post.image_height) || width < 0 || height < 0 || (x + width > post.image_width) || (y + height > post.image_height) + self.errors.add(:note, "must be inside the image") + return false + end + end + def is_locked? Post.exists?(["id = ? AND is_note_locked = ?", post_id, true]) end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index f78b94c58..8c50b20cc 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -194,11 +194,13 @@ class PostPresenter < Presenter klass = "" end + pool_html << template.link_to("«".html_safe, template.post_path(pool.post_id_array.first, :pool_id => pool.id), :class => "#{klass} first") + if pool.neighbors(@post).previous - pool_html << template.link_to("«prev".html_safe, template.post_path(pool.neighbors(@post).previous, :pool_id => pool.id), :rel => prev_rel, :class => "#{klass} prev") + pool_html << template.link_to("‹ prev".html_safe, template.post_path(pool.neighbors(@post).previous, :pool_id => pool.id), :rel => prev_rel, :class => "#{klass} prev") match_found = true else - pool_html << '«prev' + pool_html << '‹ prev' end pool_html << ' ' @@ -206,12 +208,14 @@ class PostPresenter < Presenter pool_html << ' ' if pool.neighbors(@post).next - pool_html << template.link_to("next»".html_safe, template.post_path(pool.neighbors(@post).next, :pool_id => pool.id), :rel => next_rel, :class => "#{klass} next") + pool_html << template.link_to("next ›".html_safe, template.post_path(pool.neighbors(@post).next, :pool_id => pool.id), :rel => next_rel, :class => "#{klass} next") match_found = true else - pool_html << 'next»' + pool_html << 'next ›' end + pool_html << template.link_to("»".html_safe, template.post_path(pool.post_id_array.last, :pool_id => pool.id), :class => "#{klass} last") + pool_html << "" pool_html end diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index db0aad375..12b6b57ed 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -40,7 +40,19 @@ class NoteTest < ActiveSupport::TestCase should "not validate if the note is outside the image" do @note = FactoryGirl.build(:note, :x => 1001, :y => 500, :post => @post) @note.save - assert_equal(["Coordinates must be inside the image"], @note.errors.full_messages) + assert_equal(["Note must be inside the image"], @note.errors.full_messages) + end + + should "not validate if the note is larger than the image" do + @note = FactoryGirl.build(:note, :x => 500, :y => 500, :height => 501, :width => 500, :post => @post) + @note.save + assert_equal(["Note must be inside the image"], @note.errors.full_messages) + end + + should "not validate if the post does not exist" do + @note = FactoryGirl.build(:note, :x => 500, :y => 500, :post_id => -1) + @note.save + assert_equal(["Post must exist"], @note.errors.full_messages) end should "create a version" do