From 41f0dadf7a8cb2d8f71c6f53b4e8e3e9969da56f Mon Sep 17 00:00:00 2001 From: Lightforger Date: Tue, 30 Apr 2013 11:44:06 +0300 Subject: [PATCH 001/166] Implement click&drag support for creating notes https://github.com/r888888888/danbooru/issues/1051 --- app/views/posts/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 52a39d739..68cdf83f7 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -45,7 +45,7 @@ <%= render_advertisement("horizontal") %>
-
+
<%= @post.presenter.image_html(self) %>
From e1ac5055521f48c54e9e68739efe565023a6a9b1 Mon Sep 17 00:00:00 2001 From: Lightforger Date: Tue, 30 Apr 2013 11:48:14 +0300 Subject: [PATCH 002/166] Implement click&drag support for creating notes #1051 --- app/assets/stylesheets/specific/notes.css.scss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/stylesheets/specific/notes.css.scss b/app/assets/stylesheets/specific/notes.css.scss index 8a1225652..a4219db33 100644 --- a/app/assets/stylesheets/specific/notes.css.scss +++ b/app/assets/stylesheets/specific/notes.css.scss @@ -55,6 +55,14 @@ div#note-container { border: 1px solid red; } } + + div#note-helper { + position: absolute; + border: 1px solid red; + opacity: 0.6; + display: none; + background: white; + } } div.note-edit-dialog { From a2cf238f58f6cd82cf77d413617cfe01dd223a55 Mon Sep 17 00:00:00 2001 From: Lightforger Date: Tue, 30 Apr 2013 11:50:09 +0300 Subject: [PATCH 003/166] Implement click&drag support for creating notes #1051 --- app/assets/javascripts/notes.js | 61 ++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 9d524df13..f96bd0ee9 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -408,22 +408,75 @@ Danbooru.Note = { Danbooru.Note.TranslationMode.active = true; $("#original-file-link").click(); - $("#image").one("click", Danbooru.Note.TranslationMode.create_note); - Danbooru.notice('Click on the image to create a note (shortcut is n)'); + $("#image").one("click", function() { $(".note-box").show() }); /* override the 'hide all note boxes' click event */ + $("#image").one("mousedown", Danbooru.Note.TranslationMode.Drag.start).one("mouseup", Danbooru.Note.TranslationMode.Drag.stop); + Danbooru.notice('Click or drag on the image to create a note (shortcut is n)'); }, stop: function() { Danbooru.Note.TranslationMode.active = false; }, - create_note: function(e) { + create_note: function(e,dragged,x,y,w,h) { Danbooru.Note.TranslationMode.active = false; var offset = $("#image").offset(); - Danbooru.Note.new(e.pageX - offset.left, e.pageY - offset.top); + + if(dragged) { + if(w > 9 && h > 9) { /* minimum note size: 10px */ + Danbooru.Note.new(x-offset.left,y-offset.top,w,h); + } + } else { + Danbooru.Note.new(e.pageX - offset.left, e.pageY - offset.top); + } Danbooru.Note.TranslationMode.stop(); $(".note-box").show(); e.stopPropagation(); e.preventDefault(); + }, + + Drag: { + dragging: false, + dragStartX: 0, + dragStartY: 0, + dragDistanceY: 0, + dragDistanceY: 0, + + start: function (e) { + e.preventDefault(); /* don't drag the image */ + $(window).mousemove(Danbooru.Note.TranslationMode.Drag.drag); + Danbooru.Note.TranslationMode.Drag.dragStartX = e.pageX; + Danbooru.Note.TranslationMode.Drag.dragStartY = e.pageY; + }, + + drag: function (e) { + Danbooru.Note.TranslationMode.Drag.dragDistanceX = e.pageX - Danbooru.Note.TranslationMode.Drag.dragStartX; + Danbooru.Note.TranslationMode.Drag.dragDistanceY = e.pageY - Danbooru.Note.TranslationMode.Drag.dragStartY; + + if(Danbooru.Note.TranslationMode.Drag.dragDistanceX > 9 && Danbooru.Note.TranslationMode.Drag.dragDistanceY > 9) { + Danbooru.Note.TranslationMode.Drag.dragging = true; /* must drag at least 10pixels (minimum note size) in both dimensions. */ + } + if(Danbooru.Note.TranslationMode.Drag.dragging) { + var offset = $("#image").offset(); + $('#note-helper').css({ /* preview of the note you are dragging */ + display: 'block', + left: (Danbooru.Note.TranslationMode.Drag.dragStartX - offset.left + 1), + top: (Danbooru.Note.TranslationMode.Drag.dragStartY - offset.top + 1), + width: (Danbooru.Note.TranslationMode.Drag.dragDistanceX - 3), + height: (Danbooru.Note.TranslationMode.Drag.dragDistanceY - 3) + }); + } + }, + + stop: function (e) { + $(window).unbind("mousemove"); + if(Danbooru.Note.TranslationMode.Drag.dragging) { + $('#note-helper').css({display:'none'}); + Danbooru.Note.TranslationMode.create_note(e, true, Danbooru.Note.TranslationMode.Drag.dragStartX, Danbooru.Note.TranslationMode.Drag.dragStartY, Danbooru.Note.TranslationMode.Drag.dragDistanceX-1, Danbooru.Note.TranslationMode.Drag.dragDistanceY-1); + Danbooru.Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */ + } else { /* no dragging -> create a normal note */ + Danbooru.Note.TranslationMode.create_note(e); + } + } } }, From 6c3aabf2b6d3e1203277b70915953d8fcd83ea0d Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 14:54:40 -0400 Subject: [PATCH 004/166] simplifies parent/child preview code; fixes #1489 --- app/controllers/posts_controller.rb | 9 ++----- app/helpers/posts_helper.rb | 11 +++++---- app/logical/post_sets/post_relationship.rb | 24 +++++++++++++++++++ .../posts/partials/show/_notices.html.erb | 4 ++-- 4 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 app/logical/post_sets/post_relationship.rb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 191ae621f..87df1473c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -22,13 +22,8 @@ class PostsController < ApplicationController @post = Post.find(params[:id]) @post_flag = PostFlag.new(:post_id => @post.id) @post_appeal = PostAppeal.new(:post_id => @post.id) - - @children_post_set = PostSets::Post.new("parent:#{@post.id} -id:#{@post.id}", 1, 200) - @children_post_set.posts.reverse! - @parent_post_set = PostSets::Post.new("id:#{@post.parent_id} status:any") - @siblings_post_set = PostSets::Post.new("parent:#{@post.parent_id} -id:#{@post.parent_id}", 1, 200) - @siblings_post_set.posts.reverse! - + @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => @post.is_deleted?) + @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => @post.is_deleted?) respond_with(@post) end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index b759efbed..7f09d3af9 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -41,16 +41,17 @@ module PostsHelper end end - def has_parent_message(post, parent_post_set, siblings_post_set) + def has_parent_message(post, parent_post_set) html = "" html << "This post belongs to a " html << link_to("parent", post_path(post.parent_id)) - html << " (deleted)" if parent_post_set.posts.first.is_deleted? + html << " (deleted)" if parent_post_set.parent.first.is_deleted? - if siblings_post_set.posts.count > 1 + sibling_count = parent_post_set.children.count - 1 + if sibling_count > 0 html << " and has " - text = siblings_post_set.posts.count > 2 ? "#{siblings_post_set.posts.count - 1} siblings" : "a sibling" + text = sibling_count == 1 ? "a sibling" : "#{sibling_count} siblings" html << link_to(text, posts_path(:tags => "parent:#{post.parent_id}")) end @@ -65,7 +66,7 @@ module PostsHelper html = "" html << "This post has " - text = children_post_set.posts.count == 1 ? "a child" : "#{children_post_set.posts.count} children" + text = children_post_set.children.count == 1 ? "a child" : "#{children_post_set.children.count} children" html << link_to(text, posts_path(:tags => "parent:#{post.id}")) html << " (#{link_to("learn more", wiki_pages_path(:title => "help:post_relationships"))}) " diff --git a/app/logical/post_sets/post_relationship.rb b/app/logical/post_sets/post_relationship.rb new file mode 100644 index 000000000..2cd085590 --- /dev/null +++ b/app/logical/post_sets/post_relationship.rb @@ -0,0 +1,24 @@ +module PostSets + class PostRelationship < PostSets::Post + attr_reader :parent, :children + + def initialize(parent_id, options = {}) + @parent = ::Post.where("id = ?", parent_id) + @children = ::Post.where("parent_id = ?", parent_id).order("id ASC") + if options[:include_deleted] + super("parent:#{parent_id} status:any") + else + @children = @children.where("is_deleted = ?", false) + super("parent:#{parent_id}") + end + end + + def posts + @parent + @children + end + + def presenter + ::PostSetPresenters::Post.new(self) + end + end +end diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index 73e21be68..bdf81b3f5 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -48,8 +48,8 @@ <% if post.parent_id %>
- <%= has_parent_message(post, @parent_post_set, @siblings_post_set) %> -
<%= @parent_post_set.presenter.post_previews_html(self) %><%= @siblings_post_set.presenter.post_previews_html(self) %>
+ <%= has_parent_message(post, @parent_post_set) %> +
<%= @parent_post_set.presenter.post_previews_html(self) %>
<% end %> From 1de2374a60524464fb6099aeaf6d65c619148644 Mon Sep 17 00:00:00 2001 From: Lightforger Date: Wed, 1 May 2013 02:10:15 +0300 Subject: [PATCH 005/166] Update wiki link http://danbooru.donmai.us/forum_posts/87945 --- app/views/posts/partials/show/_notices.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index bdf81b3f5..378515713 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -26,7 +26,7 @@ <% if post.is_pending? %>
- This post is pending approval (<%= link_to "learn more", wiki_pages_path(:title => "help:post_moderation") %>) + This post is pending approval (<%= link_to "learn more", wiki_pages_path(:title => "about:mod_queue") %>) <% if CurrentUser.is_janitor? && !post.disapproved_by?(CurrentUser.user) %>
From 091385f08aa97a7624ca857418e767d03d624dcc Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 19:07:54 -0400 Subject: [PATCH 006/166] remove redundant params in nav links --- app/models/tag.rb | 2 +- app/views/layouts/_main_links.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index 347f4a35a..21797a22b 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -554,7 +554,7 @@ class Tag < ActiveRecord::Base q = q.reorder("name") else - q = q.reorder("post_count desc") + q = q.reorder("id desc") end q diff --git a/app/views/layouts/_main_links.html.erb b/app/views/layouts/_main_links.html.erb index bc42a258b..cfb5e3d22 100644 --- a/app/views/layouts/_main_links.html.erb +++ b/app/views/layouts/_main_links.html.erb @@ -7,8 +7,8 @@ <%= nav_link_to("Posts", posts_path) %> <%= nav_link_to("Comments", comments_path(:group_by => "post")) %> <%= nav_link_to("Notes", notes_path(:group_by => "post")) %> - <%= nav_link_to("Artists", artists_path(:search => {:order => "date"})) %> - <%= nav_link_to("Tags", tags_path(:search => {:order => "date"})) %> + <%= nav_link_to("Artists", artists_path) %> + <%= nav_link_to("Tags", tags_path) %> <% if CurrentUser.is_moderator? %> <%= nav_link_to("Aliases", tag_aliases_path) %> <%= nav_link_to("Implications", tag_implications_path) %> From 7f96169710fb994842957416c0b307b2a1308e97 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 19:12:18 -0400 Subject: [PATCH 007/166] initialize search params to avoid repeated nil checks --- app/controllers/application_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fa1d6f463..989beb816 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base before_filter :set_current_user after_filter :reset_current_user before_filter :set_title + before_filter :normalize_search before_filter :set_started_at_session before_filter :api_check layout "default" @@ -100,4 +101,8 @@ protected def set_title @page_title = Danbooru.config.app_name + "/#{params[:controller]}" end + + def normalize_search + params[:search] ||= {} + end end From 4475902403acb9a909aa39c4747ea7beffdaa444 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 19:14:12 -0400 Subject: [PATCH 008/166] fixes #1492 --- app/models/pool.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/pool.rb b/app/models/pool.rb index 7365d272a..d03b235d0 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -25,9 +25,9 @@ class Pool < ActiveRecord::Base params = {} if params.blank? if params[:name_matches].present? - params[:name_matches] = params[:name_matches].tr(" ", "_") - params[:name_matches] = "*#{params[:name_matches]}*" unless params[:name_matches] =~ /\*/ - q = q.where("name ilike ? escape E'\\\\'", params[:name_matches].to_escaped_for_sql_like) + name_matches = params[:name_matches].tr(" ", "_") + name_matches = "*#{name_matches}*" unless name_matches =~ /\*/ + q = q.where("name ilike ? escape E'\\\\'", name_matches.to_escaped_for_sql_like) end if params[:description_matches].present? From c7e470e329951900379ef96e131d426e1cbd443b Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 19:14:57 -0400 Subject: [PATCH 009/166] preserve tag search params (#1436) --- app/views/tags/_search.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/tags/_search.html.erb b/app/views/tags/_search.html.erb index 6e8810fe4..0e5d919c1 100644 --- a/app/views/tags/_search.html.erb +++ b/app/views/tags/_search.html.erb @@ -5,7 +5,7 @@
- <%= text_field "search", "name_matches" %> + <%= text_field "search", "name_matches", :value => params[:search][:name_matches] %> Use * for wildcard
@@ -15,7 +15,7 @@
- <%= select "search", "category", [""] + Danbooru.config.canonical_tag_category_mapping.to_a %> + <%= select "search", "category", [""] + Danbooru.config.canonical_tag_category_mapping.to_a, :selected => params[:search][:category] %>
@@ -24,7 +24,7 @@
- <%= select "search", "sort", %w(count date name) %> + <%= select "search", "sort", %w(count date name), :selected => params[:search][:sort] %>
@@ -33,7 +33,7 @@
- <%= select "search", "hide_empty", ["yes", "no"] %> + <%= select "search", "hide_empty", ["yes", "no"], :selected => params[:search][:hide_empty] %>
From d83228d9555f893eee210a8e13c8be0e300eb475 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 30 Apr 2013 19:15:40 -0400 Subject: [PATCH 010/166] preserve pool search params (#1436) --- app/views/pools/_search.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/pools/_search.html.erb b/app/views/pools/_search.html.erb index f2de6c63d..f0f2f0ccf 100644 --- a/app/views/pools/_search.html.erb +++ b/app/views/pools/_search.html.erb @@ -5,7 +5,7 @@
- <%= text_field "search", "name_matches" %> + <%= text_field "search", "name_matches", :value => params[:search][:name_matches] %>
@@ -14,7 +14,7 @@
- <%= text_field "search", "description_matches" %> + <%= text_field "search", "description_matches", :value => params[:search][:description_matches] %>
@@ -23,7 +23,7 @@