chris tags update

This commit is contained in:
Matthew K. Fu JuYuan committed 2013-04-26 11:26:10 +08:00
1 parent 2945e14385
commit d047a3d62a
102 files changed
+3111 -378

No files matched your search

+7 -21
View File
@@ -2,16 +2,10 @@ class Admin::TagsController < OrbitBackendController
before_filter :force_order_for_visitor,:only=>[:index]
before_filter :force_order_for_user,:except => [:index]
before_filter :for_app_sub_manager,:except => [:index]
# layout 'new_admin'
# before_filter :authenticate_user!
# before_filter :is_admin?
# before_filter :set_module_app
before_filter :set_module_app
def index
get_tags
@module_app_id = @module_app.id rescue nil
@tags = get_tags
end
def new
@@ -23,12 +17,7 @@ class Admin::TagsController < OrbitBackendController
end
def create
if params[:tag][:module_app_id].blank?
@tag = Tag.create(params[:tag])
else
module_app = ModuleApp.find(params[:tag][:module_app_id])
@tag = eval("#{module_app.key.camelize}Tag").create(params[:tag])
end
@tag = @module_app ? @module_app.tags.create(params[:tag]) : Tag.create(params[:tag])
end
def update
@@ -47,15 +36,12 @@ class Admin::TagsController < OrbitBackendController
protected
def get_tags
@tags = (@module_app ? @module_app.tags : Tag.all)
@tags = @module_app.blank? ? Tag.all : @module_app.tags
end
def setup_vars
@app_key = request.env['HTTP_REFERER'].split('/')[4]
if @app_key
@app_key.gsub!(/[?].*/, '')
@module_app = ModuleApp.first(conditions: {:key => @app_key})
end
def set_module_app
@module_app = ModuleApp.find(params[:module_app_id]) if params[:module_app_id]
@module_app_id = @module_app.id rescue nil
end
end
@@ -1,6 +1,7 @@
class OrbitBackendController < ApplicationController
include OrbitCoreLib::AppBackendUtility
include OrbitCoreLib::PermissionUtility
include OrbitTag::Tagging
include AdminHelper
include ApplicationHelper
@@ -60,6 +61,20 @@ class OrbitBackendController < ApplicationController
when :referenced_in
objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id")
end
elsif option.eql?('tags')
tag_array = @module_app.tags.inject([]){ |result, value|
result << [value.name, value]
}
params[:direction].eql?('asc') ? tag_array.sort : tag_array.sort.reverse!
sorted_objects = Array.new
tag_array.each do |x|
taggings = x[1].taggings
taggings.each {|tagging| sorted_objects << tagging.taggable }
end
# debugger
sorted_objects.flatten!
sorted_objects.uniq!
objects = get_with_nil(objects, option, sorted_objects)
end
end
end
+6 -4
View File
@@ -8,6 +8,8 @@ class ModuleApp
field :title
field :sidebar_order,type: Integer,default: 0
has_many :tags, as: :module_tag, dependent: :destroy
def refetch_setting!(reg)
# %w{module_label category base_url version organization author intro update_info create_date}.each do |field|
# self[field.to_sym] = reg.send field
@@ -118,10 +120,6 @@ class ModuleApp
has_one :app_auth,dependent: :delete
def get_tags
get_registration.get_tags
end
def get_categories
get_registration.get_categories
end
@@ -133,5 +131,9 @@ class ModuleApp
def get_registration
OrbitApp::Module::Registration.find_by_key(key)
end
def self.find_by_key(key)
self.where(key: key)[0] rescue nil
end
end
+4 -1
View File
@@ -10,10 +10,13 @@ class Tag
is_impressionable :counter_cache => { :column_name => :view_count }
field :key
field :name, localize: true
field :view_count, :type => Integer, :default => 0
field :cloud_view_count, :type => Integer, :default => 0
belongs_to :module_tag, polymorphic: true
has_many :taggings, dependent: :destroy
#field :cloud_amper,:type: Integer,:default=> 0
def self.sorted_for_cloud
+9
View File
@@ -0,0 +1,9 @@
class Tagging
include Mongoid::Document
include Mongoid::Timestamps
field :to_destroy, default: false
belongs_to :tag
belongs_to :taggable, polymorphic: true
end
+1 -1
View File
@@ -17,7 +17,7 @@
<div class="label-group">
<div class="label-td">
<% asset.sorted_tags.each do |tag| %>
<span class="label label-tags"><%= tag[I18n.locale] %></span>
<span class="label label-tags"><%= tag.name %></span>
<% end %>
</div>
</div>
+1 -1
View File
@@ -25,7 +25,7 @@
<% @tags.each do |tag| %>
<%= content_tag :label, :class => "checkbox inline" do -%>
<%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %>
<%= tag[I18n.locale] %>
<%= tag.name %>
<%= hidden_field_tag 'asset[tag_ids][]', '' %>
<% end %>
<% end %>
@@ -13,7 +13,7 @@
<%= nil_checkbox_button(object,:tag) %>
<%= content_tag_for(:label, @tags,:class=>"radio inline") do |tag|%>
<%= check_box_tag("#{field_name}[tag][]", tag.id, tag_checked_value(object,tag.id),:class=>'select_option' ) %>
<%= tag[I18n.locale]%>
<%= tag.name%>
<% end if @tags%>
</fieldset>
<% else %>
+6 -4
View File
@@ -1,7 +1,9 @@
<%= form_for :tag, :url => admin_tags_path, :remote => true, :html => {:id => 'tag_form'} do |f| %>
<% @site_valid_locales.each do |locale| %>
<%= I18nVariable.from_locale(locale) %>:<%= f.text_field locale %>
<% end %>
<%= f.hidden_field :module_app_id, :value => @module_app_id %>
<%= f.fields_for :name_translations do |f| %>
<% @site_valid_locales.each do |locale| %>
<%= I18nVariable.from_locale(locale) %>:<%= f.text_field locale %>
<% end %>
<% end %>
<%= hidden_field_tag :module_app_id, @module_app_id %>
<%= f.submit t(:add) %>
<% end %>
+6 -4
View File
@@ -1,7 +1,9 @@
<%= form_for :tag, :url => admin_tag_path(tag), :method => :put, :remote => true do |f| %>
<% @site_valid_locales.each do |locale| %>
<%= I18nVariable.from_locale(locale) %>:<%= f.text_field locale %>
<% end %>
<%= f.hidden_field :module_app_id, :value => tag.module_app_id %>
<%= f.fields_for :name_translations do |f| %>
<% @site_valid_locales.each do |locale| %>
<%= I18nVariable.from_locale(locale) %>:<%= f.text_field locale, value: @tag.name_translations[locale] %>
<% end %>
<% end %>
<%= hidden_field_tag :module_app_id, @module_app_id %>
<%= f.submit t(:update_) %>
<% end %>
+2 -2
View File
@@ -3,11 +3,11 @@
<i class="icons-tag"></i>
<% @site_valid_locales.each do |locale| %>
<%#= I18nVariable.from_locale(locale) %>
<%= tag[locale] %>
<%= tag.name_translations[locale] %>
<% end %>
</div>
<div class="action">
<%= link_to t(:edit), edit_admin_tag_path(tag), :remote => true %>
<%= link_to t(:edit), edit_admin_tag_path(tag, :module_app_id => @module_app_id), :remote => true %>
<%= link_to t(:delete_), admin_tag_path(tag), :confirm => t('sure?'), :method => :delete, :remote => true %>
</div>
</div>
@@ -48,7 +48,7 @@
<div class="accordion-body collapse" id="collapse-tags">
<div class="accordion-inner" data-toggle="buttons-checkbox">
<% @sub_role_tags.each do |sr_tag|%>
<a href="#" class="btn"><%= sr_tag[I18n.locale] %></a>
<a href="#" class="btn"><%= sr_tag.name %></a>
<% end -%>
</div>
<div class="filter-clear">