Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7347 from vishalzambre/tagging
Adds Tagging module
- Loading branch information
Showing
19 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
backend/app/assets/javascripts/spree/backend/tag_picker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
$.fn.tagAutocomplete = function () { | ||
'use strict'; | ||
|
||
function formatTag(tag) { | ||
return Select2.util.escapeMarkup(tag.name); | ||
} | ||
|
||
this.select2({ | ||
placeholder: Spree.translations.tags_placeholder, | ||
minimumInputLength: 1, | ||
tokenSeparators: [','], | ||
multiple: true, | ||
tags: true, | ||
initSelection: function (element, callback) { | ||
var data = $(element.val().split(',')).map(function() { | ||
return { name: this, id: this }; | ||
}); | ||
callback(data); | ||
}, | ||
ajax: { | ||
url: Spree.routes.tags_search, | ||
datatype: 'json', | ||
data: function (term) { | ||
return { | ||
q: term, | ||
token: Spree.api_key | ||
}; | ||
}, | ||
results: function (data) { | ||
return { | ||
results: data.tags.map(function(tag) { | ||
return { name: tag.name, id: tag.name }; | ||
}) | ||
}; | ||
} | ||
}, | ||
createSearchChoice: function(term, data) { | ||
if ($(data).filter(function() { | ||
return this.name.localeCompare(term)===0; | ||
}).length===0) { | ||
return { id: term, name: term }; | ||
} | ||
}, | ||
formatResult: formatTag, | ||
formatSelection: formatTag | ||
}); | ||
}; | ||
|
||
$(document).ready(function () { | ||
$('.tag_picker').tagAutocomplete(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
collection(@tags => :tags) | ||
attributes :name, :id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Spree | ||
module ActsAsTaggable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
acts_as_taggable | ||
Spree::PermittedAttributes.send("#{model_name.param_key}_attributes") << | ||
[:tag_list] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Spree | ||
class Tag < ActsAsTaggableOn::Tag | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "acts-as-taggable-on" | ||
if ActsAsTaggableOn::Utils.using_mysql? | ||
ActsAsTaggableOn.force_binary_collation = true | ||
end | ||
|
||
ActsAsTaggableOn::Tag.class_eval do | ||
self.table_name_prefix = "spree_" | ||
end | ||
|
||
ActsAsTaggableOn::Tagging.class_eval do | ||
self.table_name_prefix = "spree_" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/db/migrate/20160511071954_acts_as_taggable_on_migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class ActsAsTaggableOnMigration < ActiveRecord::Migration | ||
def self.up | ||
create_table :spree_tags do |t| | ||
t.string :name | ||
t.integer :taggings_count, default: 0 | ||
end | ||
|
||
create_table :spree_taggings do |t| | ||
t.references :tag | ||
|
||
# You should make sure that the column created is | ||
# long enough to store the required class names. | ||
t.references :taggable, polymorphic: true | ||
t.references :tagger, polymorphic: true | ||
|
||
# Limit is created to prevent MySQL error on index | ||
# length for MyISAM table type: http://bit.ly/vgW2Ql | ||
t.string :context, limit: 128 | ||
|
||
t.datetime :created_at | ||
end | ||
|
||
add_index :spree_tags, :name, unique: true | ||
add_index :spree_taggings, | ||
[ | ||
:tag_id, | ||
:taggable_id, | ||
:taggable_type, | ||
:context, | ||
:tagger_id, | ||
:tagger_type | ||
], | ||
unique: true, name: "spree_taggings_idx" | ||
end | ||
|
||
def self.down | ||
drop_table :spree_taggings | ||
drop_table :spree_tags | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
core/db/migrate/20160511072249_change_collation_for_tag_names.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This migration is added to circumvent issue #623 and have special characters | ||
# work properly | ||
class ChangeCollationForTagNames < ActiveRecord::Migration | ||
def up | ||
if ActsAsTaggableOn::Utils.using_mysql? | ||
execute("ALTER TABLE spree_tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AddMissingIndexes < ActiveRecord::Migration | ||
def change | ||
add_index :spree_taggings, :tag_id | ||
add_index :spree_taggings, :taggable_id | ||
add_index :spree_taggings, :taggable_type | ||
add_index :spree_taggings, :tagger_id | ||
add_index :spree_taggings, :context | ||
|
||
add_index :spree_taggings, [:tagger_id, :tagger_type] | ||
add_index :spree_taggings, | ||
[:taggable_id, :taggable_type, :tagger_id, :context], | ||
name: "spree_taggings_idy" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryGirl.define do | ||
factory :tag, class: Spree::Tag do | ||
name "awesome" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters