Tag functionalities for new UI
This commit is contained in:
		
							parent
							
								
									ff03d66439
								
							
						
					
					
						commit
						bf3d20ea46
					
				|  | @ -0,0 +1,57 @@ | |||
| class Admin::ModuleTagsController < 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] | ||||
|     | ||||
|   def index | ||||
|     @tags = get_tags | ||||
|     @included_tags = @module_app.module_tags.where(is_default: true) | ||||
|     @default_tags = get_default_tags | ||||
|   end | ||||
| 
 | ||||
|   def new | ||||
| 
 | ||||
|   end | ||||
|    | ||||
|   def edit | ||||
|     @tag = Tag.find(params[:id]) | ||||
|   end | ||||
| 
 | ||||
|   def create | ||||
|     @tag = @module_app ? @module_app.module_tags.create(params[:tag]) | ||||
|   end | ||||
| 
 | ||||
|   def update | ||||
|     @tag = Tag.find(params[:id]) | ||||
|     @tag.update_attributes(params[:tag]) | ||||
|   end | ||||
| 
 | ||||
|   def destroy | ||||
|     @tag = Tag.find(params[:id]) | ||||
|     @tag.destroy | ||||
|     respond_to do |format| | ||||
|       format.js { render 'js/remove_element', :locals => {:id => "#{dom_id @tag}"} } | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def update_included_default | ||||
|     @module_app.update_attribute(:module_tag_ids, (@module_app.module_tag_ids - get_default_tag_ids) << params[:ids]) | ||||
|   end | ||||
|    | ||||
|   protected | ||||
| 
 | ||||
|   def setup_vars | ||||
|     @module_app = ModuleApp.find(params[:module_app_id]) rescue nil | ||||
|     raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil? | ||||
|     @module_app_id = @module_app.id rescue nil | ||||
|   end | ||||
| 
 | ||||
|   def get_default_tags | ||||
|     ModuleTag.where(is_default: true) | ||||
|   end | ||||
| 
 | ||||
|   def get_default_tag_ids | ||||
|     get_default_tags.map{|t| t.id} | ||||
|   end | ||||
|    | ||||
| end | ||||
|  | @ -1,11 +1,11 @@ | |||
| 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] | ||||
|   before_filter :set_module_app | ||||
|   before_filter :force_order_for_visitor, only: [:index] | ||||
|   before_filter :force_order_for_user, except: [:index] | ||||
|   before_filter :for_app_sub_manager, except: [:index] | ||||
|     | ||||
|   def index | ||||
|     @tags = get_tags | ||||
|     @module_apps = ModuleApp.where(has_tag: true) | ||||
|   end | ||||
| 
 | ||||
|   def new | ||||
|  | @ -17,7 +17,7 @@ class Admin::TagsController < OrbitBackendController | |||
|   end | ||||
| 
 | ||||
|   def create | ||||
|     @tag = @module_app ? @module_app.tags.create(params[:tag]) : Tag.create(params[:tag]) | ||||
|     @tag = @module_app.module_tags.create(params[:tag].merge(is_default: true)) | ||||
|   end | ||||
| 
 | ||||
|   def update | ||||
|  | @ -33,15 +33,50 @@ class Admin::TagsController < OrbitBackendController | |||
|     end | ||||
|   end | ||||
| 
 | ||||
|   protected | ||||
|    | ||||
|   def get_tags | ||||
|     @tags = @module_app.blank? ? Tag.all : @module_app.tags | ||||
|   def add_to_default | ||||
|     tags = Tag.find(params[:ids]) | ||||
|     tag_leases = tags.map{|t| t.tag_lease} | ||||
|     tags.each {|t| t.update_attribute(:is_default, true)} | ||||
|     tag_leases.each {|t| t.update_attribute(:module_app_ids, module_app_ids << @module_app.id)} | ||||
|   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 | ||||
|   def merge | ||||
|     tags = Tag.find(params[:ids]) | ||||
|     taggings = tags.map{|t| t.taggings} | ||||
|     tag_leases = tags.map{|t| t.tag_lease} | ||||
|     name = params[:name] | ||||
|     module_app_ids = tag_leases.map{|t| t.module_app_ids}.flatten.uniq | ||||
|     if tags.detect{|t| t.is_default == true} || module_app_ids.count > 1 | ||||
|       merge_default_tags(name, taggings, module_app_ids) | ||||
|     else | ||||
|       merge_tags(name, tags, module_app_ids[0]) | ||||
|     end | ||||
|     taggings.each(&:destroy) | ||||
|     tag_leases.each(&:destroy) | ||||
|   end | ||||
| 
 | ||||
|   protected | ||||
| 
 | ||||
|   def create_default_tag(name, taggings, module_app_ids) | ||||
|     create_tag(@module_app, name, taggings, module_app_ids, true) | ||||
|   end | ||||
| 
 | ||||
|   def create_tag(module_app, name, taggings, module_app_ids=[module_app], default=false) | ||||
|     new_tag = module_app.tags.create(name_translations: name, is_default: default) | ||||
|     taggings.each do |tagging| | ||||
|       tagging.tag = new_tag | ||||
|       tagging.save | ||||
|     end | ||||
|     tag_lease = new_tag.create_tag_lease(module_app_ids: (module_app_ids << module_app).uniq, is_default: default) | ||||
|   end | ||||
| 
 | ||||
|   def merge_default_tags(name, taggings, module_app_ids) | ||||
|     create_default_tag(name, taggings, module_app_ids) | ||||
|   end | ||||
| 
 | ||||
|   def merge_tags(name, taggings, module_app_id) | ||||
|     module_app = ModuleApp.find(module_app_id) | ||||
|     create_tag(module_app, name, taggings) | ||||
|   end | ||||
|    | ||||
| end | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ class ModuleApp | |||
|   field :title | ||||
|   field :sidebar_order,type: Integer,default: 0 | ||||
| 
 | ||||
|   has_many :tags, as: :module_tag, dependent: :destroy | ||||
|   has_and_belongs_to_many :module_tags, dependent: :destroy | ||||
| 
 | ||||
|   def refetch_setting!(reg) | ||||
|     # %w{module_label category base_url version organization author intro update_info create_date}.each  do |field| | ||||
|  | @ -19,6 +19,7 @@ class ModuleApp | |||
|     self[:get_widget_style] = reg.get_widgets | ||||
|     self[:using_default_widget] = !reg.get_default_widget.blank? | ||||
|     self[:widgets] = reg.get_widgets | ||||
|     self[:has_tag] = reg.get_has_tags | ||||
|   end | ||||
| 
 | ||||
| 
 | ||||
|  | @ -136,4 +137,8 @@ class ModuleApp | |||
|     self.where(key: key)[0] rescue nil | ||||
|   end | ||||
|    | ||||
|   def tags | ||||
|     self.module_tags.map{|t| t.tag } | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  |  | |||
|  | @ -0,0 +1,21 @@ | |||
| class ModuleTag | ||||
|   include Mongoid::Document | ||||
|   include Mongoid::Timestamps | ||||
| 
 | ||||
|   field :is_default, type: Boolean, deault: false | ||||
| 
 | ||||
|   has_one :tag, as: :tag_lease, dependent: :destroy, autosave: true | ||||
|   has_and_belongs_to_many :module_apps | ||||
| 
 | ||||
|   after_initialize :init_tag | ||||
| 
 | ||||
|   private | ||||
| 
 | ||||
|   def init_tag | ||||
|     if new_record? | ||||
|       self.build_tag(name_translations: self.name_translations, is_default: self.is_default) | ||||
|       self.remove_attribute(:name_translations) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  | @ -11,14 +11,13 @@ class Tag | |||
|   is_impressionable :counter_cache => { :column_name => :view_count } | ||||
|    | ||||
|   field :name, localize: true | ||||
|   field :view_count, :type => Integer, :default => 0 | ||||
|   field :cloud_view_count, :type => Integer, :default => 0 | ||||
|   field :cloud_view_count, type: Integer, default: 0 | ||||
|   field :is_default, type: Boolean, deault: false | ||||
|   field :view_count, type: Integer, default: 0 | ||||
| 
 | ||||
|   belongs_to :module_tag, polymorphic: true | ||||
|   belongs_to :tag_lease, polymorphic: true, dependent: :destroy | ||||
|   has_many :taggings, dependent: :destroy | ||||
| 
 | ||||
|   #field :cloud_amper,:type: Integer,:default=> 0  | ||||
| 
 | ||||
|   def self.sorted_for_cloud | ||||
|     tags = {} | ||||
|     self.all.each{ |tag| | ||||
|  |  | |||
|  | @ -111,6 +111,8 @@ Orbit::Application.routes.draw do | |||
|       end | ||||
|     end | ||||
| 
 | ||||
|     resources :module_tags | ||||
| 
 | ||||
|     resources :page_parts do | ||||
|       member do | ||||
|         get 'reload_after_widget_field_changed',:action=>'reload_widget_field' | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ module OrbitApp | |||
|         end | ||||
| 
 | ||||
|         class DataSheet | ||||
|           attr_reader :name,:key,:base_path,:module_label,:data_count | ||||
|           attr_reader :name,:key,:base_path,:module_label,:data_count, :has_tag | ||||
| 
 | ||||
|           def initialize(name, &block) | ||||
|             @name = name | ||||
|  | @ -37,6 +37,7 @@ module OrbitApp | |||
|             @front_end_app_pages = nil | ||||
|             @module_label = 'rulingcom.errors.init.module_app_noname' | ||||
|             @data_count = 1..15 # as default | ||||
|             @has_tag = nil | ||||
|             block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? | ||||
|             setup_module_app | ||||
|           end | ||||
|  | @ -148,6 +149,14 @@ module OrbitApp | |||
|               define_method(field){|var| instance_variable_set( "@" + field, var)} | ||||
|           end | ||||
| 
 | ||||
|           def taggable | ||||
|             @has_tag = true | ||||
|           end | ||||
| 
 | ||||
|           def get_has_tags | ||||
|             @has_tag.nil? ? false : true | ||||
|           end | ||||
| 
 | ||||
|         end # of class DataSheet | ||||
| 
 | ||||
|     end | ||||
|  |  | |||
|  | @ -1,3 +1 @@ | |||
| # require "action_view" | ||||
| 
 | ||||
| require "orbit_tag/taggable" | ||||
|  |  | |||
|  | @ -69,9 +69,12 @@ module OrbitTag | |||
|   end | ||||
| 
 | ||||
|   module Tagging | ||||
|     extend OrbitCoreLib::AppBackendUtility | ||||
|     def get_tags | ||||
|       @module_app ? @module_app.tags : Tag.all | ||||
|       @module_app.tags | ||||
|     end | ||||
| 
 | ||||
|     def get_default_tags | ||||
|       Tag.where(default: true) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -21,6 +21,8 @@ module Announcement | |||
|     category ["BulletinCategory"] | ||||
|     data_count 3..10 | ||||
| 
 | ||||
|     taggable | ||||
| 
 | ||||
|     widgets do | ||||
|       default_widget do | ||||
|         enable ["typeA","typeC"] | ||||
|  | @ -70,7 +72,7 @@ module Announcement | |||
| 
 | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Announcement'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Announcement'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:manager] | ||||
|  |  | |||
|  | @ -19,6 +19,8 @@ module Archive | |||
| 
 | ||||
|     category ["ArchiveFileCategory"] | ||||
| 
 | ||||
|     taggable | ||||
| 
 | ||||
|     widgets do | ||||
|       # default_widget do | ||||
|       #   query 'ArchiveFile.all' | ||||
|  | @ -66,7 +68,7 @@ module Archive | |||
|                             :available_for => [:manager] | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Archive'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Archive'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:admin] | ||||
|  |  | |||
|  | @ -10,6 +10,8 @@ module Calendar | |||
|     intro "I am intro" | ||||
|     update_info 'some update_info' | ||||
| 
 | ||||
|     taggable | ||||
|      | ||||
|     side_bar do | ||||
|       head_label_i18n  'calendar.calendar',:icon_class=>"icons-calendar" | ||||
|       available_for [:admin,:guest,:manager,:sub_manager] | ||||
|  | @ -25,7 +27,7 @@ module Calendar | |||
|                             :available_for => [:manager] | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Calendar'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Calendar'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:manager] | ||||
|  |  | |||
|  | @ -37,6 +37,8 @@ module Faq | |||
|       # end | ||||
|     end | ||||
|      | ||||
|     taggable | ||||
| 
 | ||||
|     side_bar do | ||||
|       head_label_i18n  'faq.faq',:icon_class=>"icons-help" | ||||
|       available_for [:admin,:guest,:manager,:sub_manager] | ||||
|  | @ -64,7 +66,7 @@ module Faq | |||
|                             :available_for => [:manager] | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Faq'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Faq'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:manager] | ||||
|  |  | |||
|  | @ -18,6 +18,8 @@ module Gallery | |||
| 
 | ||||
|     category ["gallery_categories"] | ||||
| 
 | ||||
|     taggable | ||||
| 
 | ||||
|     widgets do | ||||
|       # default_widget do | ||||
|       #   query 'Bulletin.all' | ||||
|  | @ -55,7 +57,7 @@ module Gallery | |||
|                             :available_for => [:manager] | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Gallery'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'Gallery'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:manager] | ||||
|  |  | |||
|  | @ -0,0 +1,4 @@ | |||
| en: | ||||
| 
 | ||||
|   module_name: | ||||
|     tag: Tag | ||||
|  | @ -0,0 +1,4 @@ | |||
| zh_tw: | ||||
| 
 | ||||
|   module_name: | ||||
|     tag: 標籤 | ||||
|  | @ -0,0 +1,33 @@ | |||
| module Tag | ||||
|   OrbitApp.registration "Tag", type: 'ModuleApp' do | ||||
|     module_label 'module_name.tag' | ||||
|     base_url File.expand_path File.dirname(__FILE__)     | ||||
|      | ||||
|     # version "0.1" | ||||
|     # organization "Rulingcom" | ||||
|     # author "RD dep" | ||||
|     # intro "I am intro" | ||||
|     # update_info 'some update_info' | ||||
| 
 | ||||
|      | ||||
|     side_bar do | ||||
|       head_label_i18n 'module_name.tag', icon_class: "icons-tag" | ||||
|       available_for [:admin, :manager] | ||||
|       active_for_controllers ({public: ['admin/tags']}) | ||||
| 
 | ||||
|       head_link_path "admin_tags_path" | ||||
|        | ||||
|       context_link 'all', | ||||
|         link_path: "admin_tags_path", | ||||
|         priority: 1, | ||||
|         active_for_action: {tags: :index}, | ||||
|         available_for: [:admin, :manager] | ||||
| 
 | ||||
|       context_link 'module_authorization', | ||||
|         link_path: "admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: 'Tag'}))", | ||||
|         priority: 2, | ||||
|         active_for_app_auth: 'tags', | ||||
|         available_for: [:admin] | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  | @ -12,6 +12,8 @@ module WebResource | |||
| 
 | ||||
|     category ["WebLinkCategory"] | ||||
| 
 | ||||
|     taggable | ||||
| 
 | ||||
|     widgets do | ||||
|       # default_widget do | ||||
|       #   query 'Bulletin.all' | ||||
|  | @ -53,7 +55,7 @@ module WebResource | |||
|                             :available_for => [:manager] | ||||
| 
 | ||||
|       context_link 'tags', | ||||
|                             :link_path=>"admin_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'WebResource'}))" , | ||||
|                             :link_path=>"admin_module_tags_path(:module_app_id => ModuleApp.first(conditions: {title: 'WebResource'}))" , | ||||
|                             :priority=>4, | ||||
|                             # :active_for_action=>{:bulletin_categorys=>:index}, | ||||
|                             :available_for => [:manager] | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue