New UI changes(tags, categories, authorisations, module index…)
To run: - ruby lib/remove_old_tags.rb DB_NAME - rake new_ui:migrate_tags - rake new_ui:migrate_categories['APP_KEY,''MODEL_NAME'] (check new_ui.rake for more details)
This commit is contained in:
1 parent
07b3857465
commit
856898016b
1495 files changed
+52132
-9876
No files matched your search
@@ -8,7 +8,7 @@ module ContextLinkRenderer
|
||||
@params = params
|
||||
@current_user = current_user
|
||||
if display?
|
||||
content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil)
|
||||
content_tag :li, link_to(content_tag(:span, I18n.t(@label_i18n)), eval(@path)), :class => (active? ? 'active' : nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,10 +9,14 @@ module Renderer
|
||||
protected
|
||||
def active_for_app_auth?
|
||||
module_app = get_module_app
|
||||
if module_app.nil?
|
||||
false
|
||||
if controller.eql?('admin/module_apps_new_interface')
|
||||
if module_app.nil?
|
||||
false
|
||||
else
|
||||
module_app.id.to_s == @params[:module_app_id] ? true : false
|
||||
end
|
||||
else
|
||||
module_app.id.to_s == @params[:module_app_id] ? true : false
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,6 +32,32 @@ protected
|
||||
end
|
||||
end
|
||||
|
||||
def active_for_category?
|
||||
module_app = get_module_app
|
||||
if controller.eql?('admin/categories')
|
||||
if module_app.nil?
|
||||
false
|
||||
else
|
||||
module_app.id.to_s == @params[:module_app_id] ? true : false
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def active_for_tag?
|
||||
module_app = get_module_app
|
||||
if controller.eql?('admin/module_tags')
|
||||
if module_app.nil?
|
||||
false
|
||||
else
|
||||
module_app.id.to_s == @params[:module_app_id] ? true : false
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def current_user
|
||||
current_or_guest_user
|
||||
end
|
||||
|
||||
@@ -1,21 +1,39 @@
|
||||
module SideBarRenderer
|
||||
include Renderer
|
||||
include AdminHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
def render(request,params,user,current_module_app)
|
||||
@belong_module_app = get_module_app
|
||||
@current_module_app = current_module_app
|
||||
@request = request
|
||||
@params = params
|
||||
@current_user = user
|
||||
if display?
|
||||
content_tag :div, class: "sub-nav-block #{@icon_class}" do
|
||||
concat content_tag :h4, I18n.t(@head_label)
|
||||
concat (content_tag :ul, class: "nav nav-list" do
|
||||
@context_links.sort_by {| obj | obj.priority}.map{ |link|
|
||||
link.render(request, params, @current_module_app, @current_user, @belong_module_app)
|
||||
}.join.html_safe
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def render_head(request, params, user, current_module_app)
|
||||
@belong_module_app = get_module_app
|
||||
@current_module_app = current_module_app
|
||||
@request = request
|
||||
@params = params
|
||||
@current_user = user
|
||||
if display?
|
||||
content_tag :li, :class => (module_sidebar_active? ? 'active' : nil) do
|
||||
buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link))
|
||||
buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))
|
||||
@context_links.sort_by! {| obj | obj.priority}.collect do |link|
|
||||
link.render(request,params,@current_module_app,@current_user,@belong_module_app)
|
||||
end.join.html_safe
|
||||
end
|
||||
content_tag :li, class: (module_sidebar_active? ? 'active' : nil) do
|
||||
link_to eval(@head_link) do
|
||||
content_tag :span do
|
||||
content_tag(:i, nil, class: @icon_class)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -35,7 +53,7 @@ module SideBarRenderer
|
||||
end
|
||||
|
||||
def module_sidebar_active?
|
||||
active_for_controller? or active_for_app_auth? or active_for_ob_auths?
|
||||
active_for_controller? or active_for_app_auth? or active_for_ob_auths?or active_for_category? or active_for_tag?
|
||||
end
|
||||
|
||||
def active_for_controller?
|
||||
|
||||
@@ -37,7 +37,9 @@ module OrbitApp
|
||||
@front_end_app_pages = nil
|
||||
@module_label = 'rulingcom.errors.init.module_app_noname'
|
||||
@data_count = 1..15 # as default
|
||||
@has_category = nil
|
||||
@has_tag = nil
|
||||
@is_authorizable = nil
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
setup_module_app
|
||||
end
|
||||
@@ -92,6 +94,10 @@ module OrbitApp
|
||||
@data_count
|
||||
end
|
||||
|
||||
def get_icon_class
|
||||
@side_bar.get_icon_class
|
||||
end
|
||||
|
||||
def get_widget_by_path(path)
|
||||
if @widget_set
|
||||
@widget_set.find_by_path(path)
|
||||
@@ -112,14 +118,6 @@ module OrbitApp
|
||||
@widget_set.nil? ? {} : @widget_set.to_module_app_format
|
||||
end
|
||||
|
||||
def get_categories
|
||||
@widget_set.get_categories rescue []
|
||||
end
|
||||
|
||||
def get_tags
|
||||
@widget_set.get_tags rescue []
|
||||
end
|
||||
|
||||
def front_end(&block) #setter for front_end from init
|
||||
@front_end_app_pages = FrontendUtility::AppPageSet.new(@name,@key,&block)
|
||||
end
|
||||
@@ -145,14 +143,30 @@ module OrbitApp
|
||||
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
||||
end
|
||||
|
||||
def authorizable
|
||||
@is_authorizable = true
|
||||
end
|
||||
|
||||
def categorizable
|
||||
@has_category = true
|
||||
end
|
||||
|
||||
def taggable
|
||||
@has_tag = true
|
||||
end
|
||||
|
||||
def get_has_category
|
||||
@has_category.nil? ? false : true
|
||||
end
|
||||
|
||||
def get_has_tags
|
||||
@has_tag.nil? ? false : true
|
||||
end
|
||||
|
||||
def get_is_authorizable
|
||||
@is_authorizable.nil? ? false : true
|
||||
end
|
||||
|
||||
end # of class DataSheet
|
||||
|
||||
end
|
||||
|
||||
@@ -48,6 +48,7 @@ module OrbitApp
|
||||
@active_for_controllers = []
|
||||
@active_for_object_auth = []
|
||||
@active_for_app_auth = []
|
||||
@active_for_tag = []
|
||||
@head_link = ""
|
||||
@app_base_path = ''
|
||||
@module_app_key = key
|
||||
@@ -63,11 +64,19 @@ module OrbitApp
|
||||
def get_sidebar_order!
|
||||
@sidebar_order = (get_module_app.sidebar_order rescue 0)
|
||||
end
|
||||
|
||||
def get_icon_class
|
||||
@icon_class
|
||||
end
|
||||
|
||||
def get_module_app
|
||||
@get_module_app.call
|
||||
end
|
||||
|
||||
def get_module_app_key
|
||||
@module_app_key
|
||||
end
|
||||
|
||||
def head_label_i18n(var,options ={})
|
||||
@head_label = var
|
||||
@icon_class = options[:icon_class]
|
||||
@@ -139,6 +148,8 @@ module OrbitApp
|
||||
@active_for_action = options[:active_for_action] || []
|
||||
@active_for_object_auth = options[:active_for_object_auth] || []
|
||||
@active_for_app_auth = options[:active_for_app_auth] || []
|
||||
@active_for_category = options[:active_for_category] || []
|
||||
@active_for_tag = options[:active_for_tag] || []
|
||||
@module_app_key = options[:module_app_key]
|
||||
@get_module_app = options[:get_module_app]
|
||||
end
|
||||
@@ -169,7 +180,9 @@ module OrbitApp
|
||||
for_action = @active_for_action.blank? ? false : active_for_action?
|
||||
for_app_auth = @active_for_app_auth.blank? ? false : active_for_app_auth?
|
||||
for_ob_auth = @active_for_object_auth.blank? ? false : active_for_ob_auths?
|
||||
for_action || for_app_auth || for_ob_auth
|
||||
for_category = @active_for_category.blank? ? false : active_for_category?
|
||||
for_tag = @active_for_tag.blank? ? false : active_for_tag?
|
||||
for_action || for_app_auth || for_ob_auth || for_tag
|
||||
end
|
||||
|
||||
def active_for_action?
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
module OrbitCategory
|
||||
module Categorizable
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval 'categorizable'
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def categorizable
|
||||
class_eval do
|
||||
field :category_id, type: BSON::ObjectId
|
||||
has_one :buffer_category, as: :categorizable, autosave: true, dependent: :destroy
|
||||
accepts_nested_attributes_for :buffer_category, allow_destroy: true
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def remove_id(id)
|
||||
self.update_attribute(:category_id, id)
|
||||
end
|
||||
|
||||
def category
|
||||
self.buffer_category.category if self.buffer_category
|
||||
end
|
||||
|
||||
def category=(id)
|
||||
self.buffer_category.destroy if self.buffer_category
|
||||
self.build_buffer_category(category_id: id)
|
||||
self.category_id = id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
module OrbitCategory
|
||||
module Categorizing
|
||||
|
||||
def get_categories_for_index
|
||||
if is_manager? || is_admin?
|
||||
@module_app.categories.all
|
||||
else
|
||||
@module_app.categories.enabled
|
||||
end
|
||||
end
|
||||
|
||||
def get_categories_for_form(func_authed_for_sub_manager = "submit_#{@module_app.key}")
|
||||
categories = if is_manager? || is_admin?
|
||||
@module_app.categories.enabled
|
||||
elsif is_sub_manager?
|
||||
@module_app.categories.enabled.authed_for_user(current_user, func_authed_for_sub_manager)
|
||||
end
|
||||
if categories.empty?
|
||||
flash[:alert] = t(:no_category)
|
||||
redirect_to :action => :index
|
||||
end
|
||||
categories
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
+1
-31
@@ -12,36 +12,6 @@ module OrbitCoreLib
|
||||
end
|
||||
end
|
||||
|
||||
module BelongsToCategoryMayDisable
|
||||
def self.included(base)
|
||||
base.instance_eval("belongs_to :#{base::BelongsToCategory.to_s}")
|
||||
base.instance_eval("
|
||||
scope :currently_available_by_category, lambda { |category|
|
||||
check_data = category.to_a.collect{|cate| cate.id}
|
||||
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
|
||||
}
|
||||
")
|
||||
base.instance_eval("scope :admin_manager_all,find(:all)")
|
||||
# base.instance_eval("scope :all,where(disable: false)")
|
||||
base.instance_eval("
|
||||
scope :all, lambda {
|
||||
category = base::BelongsToCategory.to_s.classify.constantize.all
|
||||
check_data = category.to_a.collect{|cate| cate.id}
|
||||
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
|
||||
}
|
||||
")
|
||||
base.class_eval("
|
||||
def disable?
|
||||
#{base::BelongsToCategory.to_s}.disable?
|
||||
end
|
||||
")
|
||||
end
|
||||
|
||||
|
||||
# end
|
||||
|
||||
|
||||
end
|
||||
module ObjectDisable
|
||||
def self.included(base)
|
||||
|
||||
@@ -103,7 +73,7 @@ module OrbitCoreLib
|
||||
|
||||
def get_object_auth_by_title(title)
|
||||
oa = self.object_auths.where({title: title }).first
|
||||
if oa.nil? && (self.class::ObjectAuthTitlesOptions.include? title)
|
||||
if oa.nil? #&& (self.class::ObjectAuthTitlesOptions.include? title)
|
||||
oa = self.object_auths.create title: title
|
||||
end
|
||||
oa
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
require "orbit_model/approval"
|
||||
require "orbit_model/language_restrict"
|
||||
require "orbit_model/status"
|
||||
require "orbit_model/time_frame"
|
||||
@@ -0,0 +1,64 @@
|
||||
module OrbitModel
|
||||
|
||||
module Approval
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
field :is_checked, :type => Boolean, :default => false
|
||||
field :is_pending, :type => Boolean, :default => true
|
||||
field :is_rejected, :type => Boolean, :default => false
|
||||
field :not_checked_reason
|
||||
class_variable_defined?(:@@can_display) ? \
|
||||
class_variable_set(:@@can_display, class_variable_get(:@@can_display).merge({is_checked: true, is_rejected: false, is_pending: false})) : \
|
||||
class_variable_set(:@@can_display, {is_checked: true, is_rejected: false, is_pending: false})
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def de_pending
|
||||
self.is_pending = false
|
||||
end
|
||||
|
||||
def de_pending!
|
||||
de_pending
|
||||
self.save!
|
||||
end
|
||||
|
||||
def is_checked?
|
||||
!self.is_pending && self.is_checked && (self.is_rejected == false)
|
||||
end
|
||||
|
||||
def is_pending?
|
||||
self.is_pending
|
||||
end
|
||||
|
||||
def is_rejected?
|
||||
!self.is_pending && self.is_rejected && (self.is_rejected == true)
|
||||
end
|
||||
|
||||
def proc_check(check,not_pass_info = "")
|
||||
self.is_checked = true
|
||||
if check == "true"
|
||||
self.is_rejected = false
|
||||
elsif check == "false"
|
||||
self.is_rejected = true
|
||||
self.not_checked_reason = not_pass_info
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
module OrbitModel
|
||||
|
||||
module LanguageRestrict
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
before_save :update_available_language
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
private
|
||||
|
||||
def update_available_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
module OrbitModel
|
||||
|
||||
module Status
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
self.class_variable_defined?(:@@can_display) ? \
|
||||
self.class_variable_set(:@@can_display, self.class_variable_get(:@@can_display).merge({is_hidden: false})) : \
|
||||
self.class_variable_set(:@@can_display, {is_hidden: false})
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def is_hot?
|
||||
self.is_hot
|
||||
end
|
||||
|
||||
def is_hidden?
|
||||
self.is_hidden
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
module OrbitModel
|
||||
|
||||
module TimeFrame
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
field :postdate , :type => DateTime
|
||||
field :deadline , :type => DateTime
|
||||
before_save :check_deadline
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def is_expired?
|
||||
Date.today > self.deadline ? true : false rescue false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_deadline
|
||||
if(!self.deadline.nil? and (self.deadline < self.postdate ))
|
||||
self.deadline = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,96 @@
|
||||
module OrbitTag
|
||||
|
||||
module Merging
|
||||
|
||||
protected
|
||||
|
||||
def clone_tag(module_tag, parent_id=nil, set_parent=nil)
|
||||
new_tag = module_tag.clone
|
||||
new_tag['_id'] = BSON::ObjectId.new
|
||||
new_tag['module_app_id'] = @module_app.id
|
||||
new_tag['parent_id'] = parent_id
|
||||
new_tag.save
|
||||
module_tag.update_attribute(:parent_id, new_tag.id) if set_parent
|
||||
end
|
||||
|
||||
def clone_tag_from_default(default_tag)
|
||||
clone_tag(default_tag, default_tag.id)
|
||||
end
|
||||
|
||||
def clone_tag_to_default(default_tag)
|
||||
clone_tag(default_tag, nil, true)
|
||||
end
|
||||
|
||||
def merge_default_tags(name, tag_leases)
|
||||
parent = @module_app.module_tags.create(name_translations: name, is_default: true)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, parent|
|
||||
sorted = parent.children.inject(sorted) do |children, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if children[module_app_id]
|
||||
children[module_app_id] += [lease]
|
||||
else
|
||||
children[module_app_id] = [lease]
|
||||
end
|
||||
children
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
tag_leases.each(&:destroy)
|
||||
parent
|
||||
end
|
||||
|
||||
def merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
lease_by_module_app_id.each do |module_app_id, leases|
|
||||
if leases.count > 0
|
||||
taggings = leases.map { |l| l.tag.taggings }.flatten
|
||||
module_tag = merge_tags(parent.name_translations, taggings, module_app_id, true)
|
||||
module_tag.update_attribute(:parent_id, parent.id)
|
||||
leases.each(&:destroy)
|
||||
else
|
||||
leases[0].update_attributes(name_translations: parent.name_translations, is_default: true, parent_id: parent.id) unless leases[0].is_default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_tags(name, taggings, module_app_id, default=nil)
|
||||
module_app = ModuleApp.find(module_app_id)
|
||||
new_tag = module_app.module_tags.create(name_translations: name, module_app_id: module_app.id, is_default: default)
|
||||
taggings.each do |tagging|
|
||||
tagging.taggable.taggings.create(tag_id: new_tag.tag.id) unless tagging.taggable.taggings.detect{|t| t.tag_id.eql?(new_tag.tag.id)}
|
||||
end
|
||||
new_tag
|
||||
end
|
||||
|
||||
def merge_with_default_tags(name, tag_leases)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, lease|
|
||||
module_app_id = lease.is_default ? 'default' : lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
if lease_by_module_app_id['default'].count > 1
|
||||
parent = merge_default_tags(name, lease_by_module_app_id['default'])
|
||||
else
|
||||
parent = lease_by_module_app_id['default'][0]
|
||||
parent.update_attributes(name_translations: name)
|
||||
end
|
||||
lease_by_module_app_id.delete('default')
|
||||
lease_by_module_app_id = parent.children.inject(lease_by_module_app_id) do |sorted, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
+54
-60
@@ -1,16 +1,14 @@
|
||||
module OrbitTag
|
||||
module Taggable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval 'taggable'
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def taggable
|
||||
init_tag
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_tag
|
||||
class_eval do
|
||||
field :tags_to_destroy, type: Array, default: []
|
||||
field :tagged_ids, type: Array, default: []
|
||||
@@ -18,59 +16,61 @@ module OrbitTag
|
||||
has_many :taggings, as: :taggable, autosave: true, dependent: :destroy
|
||||
accepts_nested_attributes_for :taggings, allow_destroy: true
|
||||
after_save :remove_taggings, unless: Proc.new{self.tags_to_destroy.blank?}
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
def remove_id(id)
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tagged_ids, self.tagged_ids - [id.to_s])
|
||||
end
|
||||
module InstanceMethods
|
||||
|
||||
def remove_id(id)
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tagged_ids, self.tagged_ids - [id.to_s])
|
||||
end
|
||||
end
|
||||
|
||||
def sorted_tags
|
||||
if tags.blank?
|
||||
[]
|
||||
else
|
||||
tag_array = tags.inject([]){ |result, value|
|
||||
result << [value.name, value]
|
||||
}
|
||||
tag_array.sort.map{|x| x[1] }
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag}.compact
|
||||
end
|
||||
|
||||
def tags=(tag_ids)
|
||||
tag_ids = [tag_ids].flatten
|
||||
tag_ids.delete('')
|
||||
ids = self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
tag_ids.each do |tag_id|
|
||||
unless ids.include? tag_id
|
||||
self.taggings.build(tag_id: tag_id)
|
||||
end
|
||||
end
|
||||
self.tags_to_destroy = self.taggings.where(:tag_id.in => (ids - tag_ids)).map{|t| t.id}
|
||||
self.tagged_ids = tag_ids
|
||||
end
|
||||
|
||||
def sorted_tags
|
||||
if tags.blank?
|
||||
[]
|
||||
else
|
||||
tag_array = tags.inject([]){ |result, value|
|
||||
result << [value.name, value]
|
||||
}
|
||||
tag_array.sort.map{|x| x[1] }
|
||||
end
|
||||
end
|
||||
def tag_ids
|
||||
self.tags.map{|t| t.tag.id}
|
||||
end
|
||||
|
||||
def tags
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag}.compact
|
||||
end
|
||||
def tag_ids=(ids)
|
||||
self.tags = ids
|
||||
end
|
||||
|
||||
def tags=(tag_ids)
|
||||
ids = [tag_ids].flatten
|
||||
tag_ids.delete('')
|
||||
ids = self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
tag_ids.each do |tag_id|
|
||||
unless ids.include? tag_id
|
||||
self.taggings.build(tag_id: tag_id)
|
||||
end
|
||||
end
|
||||
self.tags_to_destroy = self.taggings.where(:tag_id.in => (ids - tag_ids)).map{|t| t.id}
|
||||
end
|
||||
private
|
||||
|
||||
def tag_ids
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
end
|
||||
|
||||
def tag_ids=(ids)
|
||||
self.tags = ids
|
||||
ids = [ids].flatten
|
||||
ids.delete('')
|
||||
self.tagged_ids = ids
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_taggings
|
||||
self.taggings.where(:_id.in => self.tags_to_destroy).destroy
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tags_to_destroy, [])
|
||||
end
|
||||
end
|
||||
def remove_taggings
|
||||
self.taggings.where(:_id.in => self.tags_to_destroy).destroy
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tags_to_destroy, [])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,10 +78,4 @@ module OrbitTag
|
||||
|
||||
end
|
||||
|
||||
module Tagging
|
||||
extend OrbitCoreLib::AppBackendUtility
|
||||
def get_tags
|
||||
@module_app ? @module_app.tags : Tag.all
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
module OrbitTag
|
||||
|
||||
module Tagging
|
||||
|
||||
def get_tags
|
||||
@module_app.tags
|
||||
end
|
||||
|
||||
def get_default_tags
|
||||
Tag.where(is_default: true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -29,7 +29,7 @@ module ParserCommon
|
||||
res << "_#{i}" if i
|
||||
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
|
||||
res << "'>"
|
||||
root = "/"
|
||||
root = ""
|
||||
res << "<a href='#{edit ? root + admin_page_path(page.id) : (page.class.to_s.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>"
|
||||
if page.visible_children.size > 0 && current < menu.levels
|
||||
res << "<span class='dot'></span>"
|
||||
@@ -132,7 +132,7 @@ module ParserCommon
|
||||
res << "<ul class='list'>"
|
||||
menu_page.visible_children.each do |child|
|
||||
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
|
||||
root = "/"
|
||||
root = ""
|
||||
res << "<a href='#{edit ? root + admin_page_path(child.id) : (child.class.to_s.eql?('Page') ? root + child.path : child.url)}'>#{child.title}</a>"
|
||||
res << "</li>"
|
||||
end
|
||||
@@ -273,8 +273,8 @@ module ParserCommon
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
|
||||
part_title = part.title rescue nil
|
||||
if edit
|
||||
ret << "<div id='#{content['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" if part
|
||||
ret << "<div class='edit_link' style='display:none'>"
|
||||
ret << "<div id='#{content['name']}' part_id='#{part.id}' class='editable'>" if part
|
||||
ret << "<div class='edit_link'>"
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part
|
||||
ret << '</div>'
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require 'mongo'
|
||||
|
||||
db = Mongo::Connection.new("localhost", 27017).db(ARGV[0])
|
||||
|
||||
p db["tags"].remove(:_type => {:$ne => 'Tag'})
|
||||
@@ -0,0 +1,72 @@
|
||||
namespace :new_ui do
|
||||
|
||||
# :category_name is optional, depends on the naming of the category model: if no conventional, specify it
|
||||
task :migrate_categories, [:app_key, :model_name, :category_name] => :environment do |t, args|
|
||||
@db = Mongoid.database
|
||||
if args[:app_key] && args[:model_name]
|
||||
migrate_category(args[:app_key], args[:model_name], args[:category_name])
|
||||
else
|
||||
module_apps = [ %w(announcement bulletin),
|
||||
%w(archive archive_file),
|
||||
%w(ask ask_question ask),
|
||||
%w(asset asset),
|
||||
%w(faq qa),
|
||||
%w(gallery gallery_album gallery),
|
||||
%w(personal_book writing_book),
|
||||
%w(personal_conference writing_conference),
|
||||
%w(personal_experience experience),
|
||||
%w(personal_honor honor),
|
||||
%w(personal_journal writing_journal),
|
||||
%w(personal_patent writing_patent),
|
||||
%w(personal_project project),
|
||||
%w(web_resource web_link)
|
||||
]
|
||||
module_apps.each{|value_array| migrate_category(value_array[0], value_array[1], value_array[2])}
|
||||
end
|
||||
end
|
||||
|
||||
def migrate_category(app_key, model_name, category_name=nil)
|
||||
category_name = model_name unless category_name
|
||||
# # coll_cat = @db["#{category_name}_categories"]
|
||||
# # categories = coll_cat.find if coll_cat
|
||||
categories = "#{category_name}_categories".classify.constantize.admin_manager_all
|
||||
categories = "#{category_name}_categories".classify.constantize.all if categories.blank?
|
||||
module_app = ModuleApp.where(key: app_key)[0]
|
||||
categories.each do |category|
|
||||
new_category = module_app.categories.build
|
||||
new_category.title_translations = category['title']
|
||||
new_category.disable = category['disable']
|
||||
new_category.save
|
||||
model_name.classify.constantize.where("#{category_name}_category_id" => category['_id']).each do |object|
|
||||
if object.id.is_a?(String)
|
||||
object.destroy
|
||||
else
|
||||
object.category = new_category.id
|
||||
object.remove_attribute("#{category_name}_category_id")
|
||||
object.save
|
||||
end
|
||||
end
|
||||
category.destroy
|
||||
end
|
||||
end
|
||||
|
||||
task :migrate_tags => :environment do
|
||||
tags = Tag.where(_type: 'Tag')
|
||||
tags.each do |tag|
|
||||
module_app = ModuleApp.find(tag.module_tag_id)
|
||||
new_tag = module_app.module_tags.build
|
||||
new_tag.name_translations = tag['name']
|
||||
new_tag.is_default = tag['is_default']
|
||||
new_tag.save
|
||||
n_tag = new_tag.tag
|
||||
n_tag.cloud_view_count = tag['cloud_view_count']
|
||||
n_tag.view_count = tag['view_count']
|
||||
n_tag.save
|
||||
tag.taggings.each do |tagging|
|
||||
tagging.taggable.taggings.create(tag_id: n_tag.id)
|
||||
end
|
||||
tag.destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user