Merge pull request #4000 from r888888888/tag-counts
add dynamic tag counts on upload form
This commit is contained in:
@@ -39,6 +39,10 @@ Post.initialize_all = function() {
|
|||||||
this.initialize_edit_dialog();
|
this.initialize_edit_dialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var $fields_multiple = $('[data-autocomplete="tag-edit"]');
|
||||||
|
$fields_multiple.on("keypress.danbooru", Post.update_tag_count);
|
||||||
|
Post.update_tag_count();
|
||||||
|
|
||||||
$(window).on('danbooru:initialize_saved_seraches', () => {
|
$(window).on('danbooru:initialize_saved_seraches', () => {
|
||||||
Post.initialize_saved_searches();
|
Post.initialize_saved_searches();
|
||||||
});
|
});
|
||||||
@@ -78,7 +82,7 @@ Post.initialize_gestures = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Post.initialize_edit_dialog = function() {
|
Post.initialize_edit_dialog = function() {
|
||||||
$("#open-edit-dialog").button().show().on("click.danbooru", function(e) {
|
$("#open-edit-dialog").show().on("click.danbooru", function(e) {
|
||||||
Post.open_edit_dialog();
|
Post.open_edit_dialog();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
@@ -598,6 +602,27 @@ Post.initialize_saved_searches = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Post.update_tag_count = function(event) {
|
||||||
|
let string = "0 tags";
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
let tags = $(event.target).val().match(/\S+/g);
|
||||||
|
if (tags) {
|
||||||
|
count = tags.length;
|
||||||
|
string = (count == 1) ? (count + " tag") : (count + " tags")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$("#tags-container .count").html(string);
|
||||||
|
let klass = "smile";
|
||||||
|
if (count < 25) {
|
||||||
|
klass = "frown";
|
||||||
|
} else if (count < 35) {
|
||||||
|
klass = "meh";
|
||||||
|
}
|
||||||
|
$("#tags-container .options #face").removeClass().addClass(`far fa-${klass}`);
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
Post.initialize_all();
|
Post.initialize_all();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,10 +44,6 @@ article.post-preview {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#open-edit-dialog {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#edit-dialog textarea {
|
#edit-dialog textarea {
|
||||||
margin-bottom: 0.25em;
|
margin-bottom: 0.25em;
|
||||||
}
|
}
|
||||||
@@ -57,7 +53,6 @@ article.post-preview {
|
|||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
&.post-status-has-children img {
|
&.post-status-has-children img {
|
||||||
border-color: $preview_has_children_color;
|
border-color: $preview_has_children_color;
|
||||||
}
|
}
|
||||||
@@ -348,6 +343,7 @@ div#c-posts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
width: 100%;
|
||||||
margin-bottom: 0.25em;
|
margin-bottom: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,47 @@ div#c-tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tags-container {
|
||||||
|
max-width: 70em;
|
||||||
|
|
||||||
|
div.header {
|
||||||
|
margin: 0;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 50% 50%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
label {
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.options {
|
||||||
|
grid-column: 2;
|
||||||
|
justify-self: end;
|
||||||
|
|
||||||
|
.count {
|
||||||
|
color: gray;
|
||||||
|
text-decoration: italic;
|
||||||
|
margin-left: 0.25em;
|
||||||
|
padding-bottom: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
i {
|
||||||
|
margin-left: 0.25em;
|
||||||
|
font-size: 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-frown {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-meh {
|
||||||
|
color: darkkhaki;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-smile {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ div#c-uploads {
|
|||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
margin-bottom: 0.25em;
|
margin-bottom: 0.25em;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hint {
|
.hint {
|
||||||
|
|||||||
@@ -75,16 +75,25 @@
|
|||||||
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="input">
|
|
||||||
<div>
|
|
||||||
|
<div class="input" id="tags-container">
|
||||||
|
<div class="header">
|
||||||
<%= f.label :tag_string, "Tags" %>
|
<%= f.label :tag_string, "Tags" %>
|
||||||
<%= f.text_area :tag_string, :size => "50x5", :value => post.presenter.split_tag_list_text + " ", :data => { :autocomplete => "tag-edit" } %>
|
|
||||||
<span id="open-edit-dialog" class="ui-icon ui-icon-arrow-1-ne" title="detach" style="display: none;" data-shortcut="shift+e"/>
|
<span class="options">
|
||||||
|
<i id="face" class="fas"></i>
|
||||||
|
<span class="count"></span>
|
||||||
|
<a href="#"><i id="open-edit-dialog" class="fas fa-arrows-alt" title="detach" data-shortcut="shift+e"></i></a>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= f.text_area :tag_string, :size => "60x5", :spellcheck => false, :"data-autocomplete" => "tag-edit", :"data-shortcut" => "e", :value => params[:tag_string] %>
|
||||||
|
</div>
|
||||||
<%= render "related_tags/buttons" %>
|
<%= render "related_tags/buttons" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<%= submit_tag "Submit", :class => "ui-button ui-widget ui-corner-all" %>
|
<%= submit_tag "Submit", :class => "ui-button ui-widget ui-corner-all" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -90,18 +90,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input" id="tags-container">
|
||||||
<div>
|
<div class="header">
|
||||||
<%= f.label :tag_string, "Tags" %>
|
<%= f.label :tag_string, "Tags" %>
|
||||||
<%= f.text_area :tag_string, :size => "60x5", :spellcheck => false, :"data-autocomplete" => "tag-edit", :"data-shortcut" => "e", :value => params[:tag_string] %>
|
|
||||||
<span id="open-edit-dialog" class="ui-icon ui-icon-arrow-1-ne" title="detach" style="display: none;" data-shortcut="shift+e"/>
|
<span class="options">
|
||||||
|
<i id="face" class="fas"></i>
|
||||||
|
<span class="count"></span>
|
||||||
|
<a href="#"><i id="open-edit-dialog" class="fas fa-arrows-alt" title="detach" data-shortcut="shift+e"></i></a>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= f.text_area :tag_string, :size => "60x5", :spellcheck => false, :"data-autocomplete" => "tag-edit", :"data-shortcut" => "e", :value => params[:tag_string] %>
|
||||||
|
</div>
|
||||||
<%= render "related_tags/buttons" %>
|
<%= render "related_tags/buttons" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<%= submit_tag "Submit", :id => "submit-button", :class => "large ui-button ui-widget ui-corner-all gradient", data: {disable_with: false} %>
|
<%= submit_tag "Submit", :id => "submit-button", :class => "large ui-button ui-widget ui-corner-all gradient", data: { disable_with: false } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render "related_tags/container" %>
|
<%= render "related_tags/container" %>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
class ChangeDescendantNamesToArrayOnTagImplications < ActiveRecord::Migration[5.2]
|
class ChangeDescendantNamesToArrayOnTagImplications < ActiveRecord::Migration[5.2]
|
||||||
def up
|
def up
|
||||||
TagImplication.without_timeout do
|
TagImplication.without_timeout do
|
||||||
change_column_default :tag_implications, :descendant_names, from: '', to: nil
|
add_column :tag_implications, :descendant_names_array, "text[]", default: "{}"
|
||||||
change_column :tag_implications, :descendant_names, "text[]", using: "string_to_array(descendant_names, ' ')::text[]", default: "{}"
|
execute "update tag_implications set descendant_names_array = string_to_array(descendant_names, ' ')::text[]"
|
||||||
|
remove_column :tag_implications, :descendant_names
|
||||||
|
rename_column :tag_implications, :descendant_names_array, :descendant_names
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
class ChangeStringsToArraysOnArtistVersions < ActiveRecord::Migration[5.2]
|
class ChangeStringsToArraysOnArtistVersions < ActiveRecord::Migration[5.2]
|
||||||
def up
|
def up
|
||||||
ArtistVersion.without_timeout do
|
ArtistVersion.without_timeout do
|
||||||
change_column_default :artist_versions, :other_names, from: '', to: nil
|
add_column :artist_versions, :other_names_array, "text[]", default: "{}"
|
||||||
change_column :artist_versions, :other_names, "text[]", using: "array_remove(regexp_split_to_array(other_names, '\\s+'), '')", default: "{}"
|
execute "update artist_versions set other_names_array = array_remove(regexp_split_to_array(other_names, '\\s+'), '')"
|
||||||
|
remove_column :artist_versions, :other_names
|
||||||
|
rename_column :artist_versions, :other_names_array, :other_names
|
||||||
|
|
||||||
change_column :artist_versions, :url_string, "text[]", using: "array_remove(regexp_split_to_array(url_string, '\\s+'), '')", default: "{}"
|
add_column :artist_versions, :urls, "text[]", default: "{}"
|
||||||
rename_column :artist_versions, :url_string, :urls
|
execute "update artist_versions set urls = array_remove(regexp_split_to_array(url_string, '\\s+'), '')"
|
||||||
|
remove_column :artist_versions, :url_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
|||||||
setup do
|
setup do
|
||||||
@urls = [
|
@urls = [
|
||||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/koyorin"),
|
FactoryBot.create(:artist_url, url: "https://www.artstation.com/koyorin"),
|
||||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artist/koyorin"),
|
|
||||||
FactoryBot.create(:artist_url, url: "https://koyorin.artstation.com"),
|
FactoryBot.create(:artist_url, url: "https://koyorin.artstation.com"),
|
||||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artwork/04XA4")
|
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artwork/04XA4")
|
||||||
]
|
]
|
||||||
@@ -74,8 +73,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
|||||||
should "normalize" do
|
should "normalize" do
|
||||||
assert_equal("http://www.artstation.com/koyorin/", @urls[0].normalized_url)
|
assert_equal("http://www.artstation.com/koyorin/", @urls[0].normalized_url)
|
||||||
assert_equal("http://www.artstation.com/koyorin/", @urls[1].normalized_url)
|
assert_equal("http://www.artstation.com/koyorin/", @urls[1].normalized_url)
|
||||||
assert_equal("http://www.artstation.com/koyorin/", @urls[2].normalized_url)
|
assert_equal("http://www.artstation.com/jeyrain/", @urls[2].normalized_url)
|
||||||
assert_equal("http://www.artstation.com/jeyrain/", @urls[3].normalized_url)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user