From 0bc55bec74f2d62d2053d09d9041b3022245f258 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 3 Jul 2017 22:05:53 -0500 Subject: [PATCH 1/5] notes: redirect /notes/123 to /posts/456#note-123. --- app/controllers/notes_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index bed70f667..06e78a77b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -17,7 +17,9 @@ class NotesController < ApplicationController def show @note = Note.find(params[:id]) - respond_with(@note) + respond_with(@note) do |format| + format.html { redirect_to(post_path(@note.post, anchor: "note-#{@note.id}")) } + end end def create From c2e62b77fa82e38f6dafe66b1bb7db973f498f8f Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 3 Jul 2017 22:07:11 -0500 Subject: [PATCH 2/5] notes: move js initialization into `initialize_all` function. --- app/assets/javascripts/notes.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index a5763bef7..a5b55902f 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -778,17 +778,29 @@ Danbooru.Note = { Danbooru.Note.Box.resize_inner_border($(note_box)); }); } - } -} + }, -$(function() { - if ($("#c-posts").length && $("#a-show").length && $("#image").length && !$("video#image").length) { + initialize_all: function() { + if ($("#c-posts #a-show #image").length == 0 || $("video#image").length) { + return; + } + + Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true"); + Danbooru.Note.load_all(); + + this.initialize_shortcuts(); + }, + + initialize_shortcuts: function() { if ($("#note-locked-notice").length == 0) { $("#translate").click(Danbooru.Note.TranslationMode.toggle); Danbooru.keydown("n", "translation_mode", Danbooru.Note.TranslationMode.toggle); } - Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true"); - Danbooru.Note.load_all(); + $("#image").click(Danbooru.Note.Box.toggle_all); - } + }, +} + +$(function() { + Danbooru.Note.initialize_all(); }); From ab0b4b4c679507e97fef03ee12b89d257ef83281 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 3 Jul 2017 22:13:08 -0500 Subject: [PATCH 3/5] notes: highlight notes linked via /posts/456#note-123. --- app/assets/javascripts/notes.js | 18 ++++++++++++++++++ app/assets/stylesheets/common/000_vars.scss | 2 ++ app/assets/stylesheets/specific/notes.scss | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index a5b55902f..9412b31f7 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -137,6 +137,14 @@ Danbooru.Note = { return $("#note-container div.note-box[data-id=" + id + "]"); }, + show_highlighted: function($note_box) { + var note_id = $note_box.data("id"); + + Danbooru.Note.Body.show(note_id); + $note_box.addClass("note-box-highlighted"); + Danbooru.scroll_to($note_box); + }, + resize_inner_border: function($note_box) { var $inner_border = $note_box.find("div.note-box-inner-border"); $inner_border.css({ @@ -789,6 +797,7 @@ Danbooru.Note = { Danbooru.Note.load_all(); this.initialize_shortcuts(); + this.initialize_highlight(); }, initialize_shortcuts: function() { @@ -799,6 +808,15 @@ Danbooru.Note = { $("#image").click(Danbooru.Note.Box.toggle_all); }, + + initialize_highlight: function() { + var matches = window.location.hash.match(/^#note-(\d+)$/); + + if (matches) { + var $note_box = Danbooru.Note.Box.find(matches[1]); + Danbooru.Note.Box.show_highlighted($note_box); + } + }, } $(function() { diff --git a/app/assets/stylesheets/common/000_vars.scss b/app/assets/stylesheets/common/000_vars.scss index b0cb036f9..4ad0d4c10 100644 --- a/app/assets/stylesheets/common/000_vars.scss +++ b/app/assets/stylesheets/common/000_vars.scss @@ -27,6 +27,8 @@ $preview_flagged_color: #F00; $preview_sample_warning_color: hsl(0, 100%, 90%); // light red $preview_quality_warning_color: hsl(50, 100%, 90%); // light yellow +$note_highlight_color: $preview_pending_color; + $error_color: hsl(0, 100%, 95%); // light red $success_color: hsl(120, 100%, 95%); // light green diff --git a/app/assets/stylesheets/specific/notes.scss b/app/assets/stylesheets/specific/notes.scss index 9b7fd61d1..02120fd52 100644 --- a/app/assets/stylesheets/specific/notes.scss +++ b/app/assets/stylesheets/specific/notes.scss @@ -92,6 +92,10 @@ div#note-container { vertical-align: middle; } } + + &.note-box-highlighted { + outline: 2px solid $note_highlight_color; + } } } From c13000a41e39c8b09a7f9571ccc3cb8e242db20b Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 3 Jul 2017 22:08:23 -0500 Subject: [PATCH 4/5] notes: show note id in note edit dialog title. --- app/assets/javascripts/notes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 9412b31f7..a4c023f5d 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -369,6 +369,8 @@ Danbooru.Note = { Edit: { show: function($note_body) { + var id = $note_body.data("id"); + if (Danbooru.Note.editing) { return; } @@ -393,7 +395,7 @@ Danbooru.Note = { $dialog = $('
'); $dialog.append($textarea); - $dialog.data("id", $note_body.data("id")); + $dialog.data("id", id); $dialog.dialog({ width: 360, height: 210, @@ -415,7 +417,7 @@ Danbooru.Note = { $dialog.data("uiDialog")._title = function(title) { title.html(this.options.title); // Allow unescaped html in dialog title } - $dialog.dialog("option", "title", 'Edit note (view help)'); + $dialog.dialog("option", "title", 'Edit note #' + id + ' (view help)'); $dialog.on("dialogclose", function() { Danbooru.Note.editing = false; From e875f2973a33134168cb76b0b37d634b29cc42b5 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 7 Jul 2017 16:22:44 -0500 Subject: [PATCH 5/5] /notes, /note_versions: link directly to note within post. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also adds a "»" link, linking to the note's history. --- app/views/note_versions/index.html.erb | 7 +++++-- app/views/notes/index.html.erb | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index 7423a0927..2d5513774 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -2,7 +2,7 @@

Note Changes

- +
@@ -25,8 +25,11 @@ - +
<%= link_to note_version.post_id, post_path(note_version.post_id) %><%= link_to "#{note_version.note_id}.#{note_version.version}", note_versions_path(:search => {:note_id => note_version.note_id}) %> + <%= link_to "#{note_version.note_id}.#{note_version.version}", post_path(note_version.post_id, anchor: "note-#{note_version.note_id}") %> + <%= link_to "»", note_versions_path(search: {note_id: note_version.note_id}) %> + <%= h(note_version.body) %> <% unless note_version.is_active? %> (deleted) diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index c588ca160..a9140c815 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -2,10 +2,11 @@

Notes

- +
+ @@ -15,9 +16,13 @@ <% @notes.each do |note| %> + -
PostNote Created by Created at Body
<%= link_to note.post_id, post_path(note.post_id) %> + <%= link_to "#{note.id}.#{note.version}", post_path(note.post_id, anchor: "note-#{note.id}") %> + <%= link_to "»", note_versions_path(search: {note_id: note.id}) %> + <%= link_to_user note.creator %> <%= compact_time(note.created_at) %> + <%= h(note.body) %> <% unless note.is_active? %> (deleted)