From 37fcaf7570b1503b139039113b889f38925f753a Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 1 Sep 2014 11:28:55 -0300 Subject: [PATCH] mergin with master --- Gemfile | 1 - Gemfile.lock | 13 ------------- app/controllers/admin/environment_design_controller.rb | 4 +--- app/controllers/my_profile/cms_controller.rb | 6 ++++++ app/helpers/article_helper.rb | 4 ++++ app/helpers/layout_helper.rb | 1 + app/models/box.rb | 6 ------ app/models/environment.rb | 3 --- app/models/environment_statistics_block.rb | 33 --------------------------------- app/sweepers/profile_sweeper.rb | 10 ---------- app/views/cms/edit.html.erb | 9 +++++++++ app/views/layouts/_javascript.html.erb | 2 +- baseplugins/statistics | 1 + db/migrate/20140827191326_remove_environment_statistics_block.rb | 9 +++++++++ db/schema.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- debian/control | 1 - public/javascripts/inputosaurus.js | 523 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/stylesheets/inputosaurus.css | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ script/noosfero-plugins | 13 ++++--------- script/quick-start | 2 +- test/functional/cms_controller_test.rb | 17 +++++++++++++++++ test/functional/environment_design_controller_test.rb | 16 +--------------- test/unit/box_test.rb | 6 ------ test/unit/environment_statistics_block_test.rb | 99 --------------------------------------------------------------------------------------------------- 24 files changed, 709 insertions(+), 212 deletions(-) delete mode 100644 app/models/environment_statistics_block.rb create mode 120000 baseplugins/statistics create mode 100644 db/migrate/20140827191326_remove_environment_statistics_block.rb create mode 100644 public/javascripts/inputosaurus.js create mode 100644 public/stylesheets/inputosaurus.css delete mode 100644 test/unit/environment_statistics_block_test.rb diff --git a/Gemfile b/Gemfile index 50748b2..dbf3824 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,6 @@ gem 'nokogiri' gem 'rake', :require => false gem 'rest-client' gem 'exception_notification' -gem 'gettext_rails' # FIXME list here all actual dependencies (i.e. the ones in debian/control), # with their GEM names (not the Debian package names) diff --git a/Gemfile.lock b/Gemfile.lock index 79bbfb5..a585c84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,15 +67,6 @@ GEM activesupport (>= 3.0.4) fast_gettext (0.6.8) ffi (1.0.11) - gettext (2.2.1) - locale - gettext_activerecord (2.1.0) - activerecord (>= 2.3.2) - gettext (>= 2.1.0) - gettext_rails (2.1.0) - gettext_activerecord (>= 2.1.0) - locale_rails (>= 2.0.5) - rails (>= 2.3.2) gherkin (2.4.21) json (>= 1.4.6) hike (1.2.1) @@ -83,9 +74,6 @@ GEM i18n (0.6.0) journey (1.0.3) json (1.7.3) - locale (2.0.5) - locale_rails (2.0.5) - locale (>= 2.0.5) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -184,7 +172,6 @@ DEPENDENCIES database_cleaner exception_notification fast_gettext - gettext_rails hpricot mocha nokogiri diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index 3320c8f..442f39d 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -3,9 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController protect 'edit_environment_design', :environment def available_blocks - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - @blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] @blocks += plugins.dispatch(:extra_blocks, :type => Environment) end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 3025533..9748164 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -4,6 +4,12 @@ class CmsController < MyProfileController include ArticleHelper + def search_tags + arg = params[:term].downcase + result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) + render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' + end + def self.protect_if(*args) before_filter(*args) do |c| user, profile = c.send(:user), c.send(:profile) diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 26bc18d..567de43 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -83,6 +83,10 @@ module ArticleHelper array.map { |object| {:id => object.id, :name => object.name} } end + def prepare_to_token_input_by_label(array) + array.map { |object| {:label => object.name, :value => object.name} } + end + def cms_label_for_new_children _('New article') end diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index fcedc07..e29bb4f 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -28,6 +28,7 @@ module LayoutHelper 'lightbox', 'colorbox', 'block_store', + 'inputosaurus', pngfix_stylesheet_path, ] + tokeninput_stylesheets plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } diff --git a/app/models/box.rb b/app/models/box.rb index df97a41..9aa00e8 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -28,9 +28,6 @@ class Box < ActiveRecord::Base CategoriesBlock, CommunitiesBlock, EnterprisesBlock, - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - EnvironmentStatisticsBlock, FansBlock, FavoriteEnterprisesBlock, FeedReaderBlock, @@ -53,9 +50,6 @@ class Box < ActiveRecord::Base CommunitiesBlock, DisabledEnterpriseMessageBlock, EnterprisesBlock, - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - EnvironmentStatisticsBlock, FansBlock, FavoriteEnterprisesBlock, FeaturedProductsBlock, diff --git a/app/models/environment.rb b/app/models/environment.rb index 952a165..861a932 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -177,9 +177,6 @@ class Environment < ActiveRecord::Base # "left" area env.boxes[1].blocks << LoginBlock.new - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - env.boxes[1].blocks << EnvironmentStatisticsBlock.new env.boxes[1].blocks << RecentDocumentsBlock.new # "right" area diff --git a/app/models/environment_statistics_block.rb b/app/models/environment_statistics_block.rb deleted file mode 100644 index 359891c..0000000 --- a/app/models/environment_statistics_block.rb +++ /dev/null @@ -1,33 +0,0 @@ -# TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from -# the Noosfero core soon, see ActionItem3045 - -class EnvironmentStatisticsBlock < Block - - def self.description - _('Environment stastistics (DEPRECATED)') - end - - def default_title - _('Statistics for %s') % owner.name - end - - def help - _('This block presents some statistics about your environment.') - end - - def content(args={}) - users = owner.people.visible.count - enterprises = owner.enterprises.visible.count - communities = owner.communities.visible.count - - info = [] - info << (n_('One user', '%{num} users', users) % { :num => users }) - unless owner.enabled?('disable_asset_enterprises') - info << (n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }) - end - info << (n_('One community', '%{num} communities', communities) % { :num => communities }) - - block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) - end - -end diff --git a/app/sweepers/profile_sweeper.rb b/app/sweepers/profile_sweeper.rb index e23f9b4..454b593 100644 --- a/app/sweepers/profile_sweeper.rb +++ b/app/sweepers/profile_sweeper.rb @@ -8,9 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer end def after_create(profile) - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - expire_statistics_block_cache(profile) end protected @@ -31,13 +28,6 @@ protected expire_blogs(profile) if profile.organization? end - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - def expire_statistics_block_cache(profile) - blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } - BlockSweeper.expire_blocks(blocks) - end - def expire_blogs(profile) profile.blogs.select{|b| !b.empty?}.each do |blog| pages = blog.posts.count / blog.posts_per_page + 1 diff --git a/app/views/cms/edit.html.erb b/app/views/cms/edit.html.erb index c38af1c..2508a60 100644 --- a/app/views/cms/edit.html.erb +++ b/app/views/cms/edit.html.erb @@ -31,9 +31,18 @@ <%= select_categories(:article, _('Categorize your article')) %> +
+ <%= f.text_field('tag_list', :size => 64) %> <%= content_tag( 'small', _('Separate tags with commas') ) %> + +
<%= options_for_article(@article, @tokenized_children) %>
diff --git a/app/views/layouts/_javascript.html.erb b/app/views/layouts/_javascript.html.erb index 33c05d4..f33bdc4 100644 --- a/app/views/layouts/_javascript.html.erb +++ b/app/views/layouts/_javascript.html.erb @@ -4,7 +4,7 @@ 'jquery-ui-1.10.4/js/jquery-ui-1.10.4.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery-validation/jquery.validate', 'jquery.cookie', 'jquery.ba-bbq.min.js', 'reflection', 'jquery.tokeninput', 'add-and-join', 'report-abuse', 'catalog', 'manage-products', 'autogrow', -'jquery-timepicker-addon/dist/jquery-ui-timepicker-addon', 'application.js', 'rails.js', :cache => 'cache/application' %> +'jquery-timepicker-addon/dist/jquery-ui-timepicker-addon', 'application.js', 'rails.js', 'inputosaurus.js', :cache => 'cache/application' %> <% language = FastGettext.locale %> <% %w{messages methods}.each do |type| %> diff --git a/baseplugins/statistics b/baseplugins/statistics new file mode 120000 index 0000000..6620f62 --- /dev/null +++ b/baseplugins/statistics @@ -0,0 +1 @@ +../plugins/statistics \ No newline at end of file diff --git a/db/migrate/20140827191326_remove_environment_statistics_block.rb b/db/migrate/20140827191326_remove_environment_statistics_block.rb new file mode 100644 index 0000000..0a65ca9 --- /dev/null +++ b/db/migrate/20140827191326_remove_environment_statistics_block.rb @@ -0,0 +1,9 @@ +class RemoveEnvironmentStatisticsBlock < ActiveRecord::Migration + def self.up + update("UPDATE blocks SET type = 'StatisticsBlock' WHERE type = 'EnvironmentStatisticsBlock'") + end + + def self.down + say("Nothing to undo (cannot recover the data)") + end +end diff --git a/db/schema.rb b/db/schema.rb index a80f7c2..bde81b5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140808185510) do +ActiveRecord::Schema.define(:version => 20140827191326) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -241,6 +241,7 @@ ActiveRecord::Schema.define(:version => 20140808185510) do t.string "source_type" t.string "user_agent" t.string "referrer" + t.text "setting" end add_index "comments", ["source_id", "spam"], :name => "index_comments_on_source_id_and_spam" @@ -294,8 +295,8 @@ ActiveRecord::Schema.define(:version => 20140808185510) do t.text "signup_welcome_text" t.string "languages" t.string "default_language" - t.string "noreply_email" t.string "redirection_after_signup", :default => "keep_on_same_page" + t.string "noreply_email" end create_table "external_feeds", :force => true do |t| @@ -450,6 +451,21 @@ ActiveRecord::Schema.define(:version => 20140808185510) do add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" add_index "products", ["profile_id"], :name => "index_products_on_profile_id" + create_table "profile_suggestions", :force => true do |t| + t.integer "person_id" + t.integer "suggestion_id" + t.string "suggestion_type" + t.text "categories" + t.boolean "enabled", :default => true + t.float "score", :default => 0.0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "profile_suggestions", ["person_id"], :name => "index_profile_suggestions_on_person_id" + add_index "profile_suggestions", ["score"], :name => "index_profile_suggestions_on_score" + add_index "profile_suggestions", ["suggestion_id"], :name => "index_profile_suggestions_on_suggestion_id" + create_table "profiles", :force => true do |t| t.string "name" t.string "type" @@ -483,11 +499,12 @@ ActiveRecord::Schema.define(:version => 20140808185510) do t.boolean "is_template", :default => false t.integer "template_id" t.string "redirection_after_login" + t.string "personal_website" + t.string "jabber_id" t.integer "friends_count", :default => 0, :null => false t.integer "members_count", :default => 0, :null => false t.integer "activities_count", :default => 0, :null => false - t.string "personal_website" - t.string "jabber_id" + t.integer "welcome_page_id" end add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" @@ -556,6 +573,31 @@ ActiveRecord::Schema.define(:version => 20140808185510) do t.integer "context_id" end + create_table "search_term_occurrences", :force => true do |t| + t.integer "search_term_id" + t.datetime "created_at" + t.integer "total", :default => 0 + t.integer "indexed", :default => 0 + end + + add_index "search_term_occurrences", ["created_at"], :name => "index_search_term_occurrences_on_created_at" + + create_table "search_terms", :force => true do |t| + t.string "term" + t.integer "context_id" + t.string "context_type" + t.string "asset", :default => "all" + t.float "score", :default => 0.0 + t.float "relevance_score", :default => 0.0 + t.float "occurrence_score", :default => 0.0 + end + + add_index "search_terms", ["asset"], :name => "index_search_terms_on_asset" + add_index "search_terms", ["occurrence_score"], :name => "index_search_terms_on_occurrence_score" + add_index "search_terms", ["relevance_score"], :name => "index_search_terms_on_relevance_score" + add_index "search_terms", ["score"], :name => "index_search_terms_on_score" + add_index "search_terms", ["term"], :name => "index_search_terms_on_term" + create_table "sessions", :force => true do |t| t.string "session_id", :null => false t.text "data" @@ -635,23 +677,25 @@ ActiveRecord::Schema.define(:version => 20140808185510) do create_table "users", :force => true do |t| t.string "login" t.string "email" - t.string "crypted_password", :limit => 40 - t.string "salt", :limit => 40 + t.string "crypted_password", :limit => 40 + t.string "salt", :limit => 40 t.datetime "created_at" t.datetime "updated_at" t.string "remember_token" t.datetime "remember_token_expires_at" t.text "terms_of_use" - t.string "terms_accepted", :limit => 1 + t.string "terms_accepted", :limit => 1 t.integer "environment_id" t.string "password_type" - t.boolean "enable_email", :default => false - t.string "last_chat_status", :default => "" - t.string "chat_status", :default => "" + t.boolean "enable_email", :default => false + t.string "last_chat_status", :default => "" + t.string "chat_status", :default => "" t.datetime "chat_status_at" - t.string "activation_code", :limit => 40 + t.string "activation_code", :limit => 40 t.datetime "activated_at" t.string "return_to" + t.string "private_token" + t.datetime "private_token_generated_at" end create_table "validation_infos", :force => true do |t| diff --git a/debian/control b/debian/control index c8f7e10..cd3c6e7 100644 --- a/debian/control +++ b/debian/control @@ -7,7 +7,6 @@ Build-Depends: debhelper (>= 7.0.50~), po4a, ruby-gettext, - ruby-gettext-rails, ruby-sqlite3, rake, rails3 (>= 3.2.6-1~), diff --git a/public/javascripts/inputosaurus.js b/public/javascripts/inputosaurus.js new file mode 100644 index 0000000..999d1a0 --- /dev/null +++ b/public/javascripts/inputosaurus.js @@ -0,0 +1,523 @@ +/** + * Inputosaurus Text + * + * Must be instantiated on an element + * Allows multiple input items. Each item is represented with a removable tag that appears to be inside the input area. + * + * @requires: + * + * jQuery 1.7+ + * jQueryUI 1.8+ Core + * + * @version 0.1.6 + * @author Dan Kielp + * @created October 3,2012 + * + */ + + +(function($) { + + var inputosaurustext = { + + version: "0.1.6", + + eventprefix: "inputosaurus", + + options: { + + // bindable events + // + // 'change' - triggered whenever a tag is added or removed (should be similar to binding the the change event of the instantiated input + // 'keyup' - keyup event on the newly created input + + // while typing, the user can separate values using these delimiters + // the value tags are created on the fly when an inputDelimiter is detected + inputDelimiters : [',', ';'], + + // this separator is used to rejoin all input items back to the value of the original + outputDelimiter : ',', + + allowDuplicates : false, + + parseOnBlur : false, + + // optional wrapper for widget + wrapperElement : null, + + width : null, + + // simply passing an autoComplete source (array, string or function) will instantiate autocomplete functionality + autoCompleteSource : '', + + // When forcing users to select from the autocomplete list, allow them to press 'Enter' to select an item if it's the only option left. + activateFinalResult : false, + + // manipulate and return the input value after parseInput() parsing + // the array of tag names is passed and expected to be returned as an array after manipulation + parseHook : null, + + // define a placeholder to display when the input is empty + placeholder: null, + + // when you check for duplicates it check for the case + caseSensitiveDuplicates: false + }, + + _create: function() { + var widget = this, + els = {}, + o = widget.options, + placeholder = o.placeholder || this.element.attr('placeholder') || null; + + this._chosenValues = []; + + // Create the elements + els.ul = $('