Compare commits

...

4 Commits
master ... dev

Author SHA1 Message Date
rulingcom 311f8acbe9 migrate script 2025-08-07 17:59:08 +08:00
rulingcom d0c1d488fc removed old methods to create tags 2025-08-06 22:14:17 +08:00
rulingcom 14017bfa66 removed old tags 2025-08-06 21:53:50 +08:00
rulingcom 2eea96c8bd global hashtags 2025-08-06 21:52:43 +08:00
7 changed files with 56 additions and 57 deletions

View File

@ -196,7 +196,6 @@ end
def add_entry
entry = TableEntry.new(table_entry_params)
create_get_table_tags(entry)
entry.save
entry.fix_have_data
table = UTable.find(params[:table_entry][:u_table_id])
@ -222,7 +221,6 @@ end
def update_entry
entry = TableEntry.find(params[:id])
create_get_table_tags(entry)
entry.update_attributes(table_entry_params)
entry.fix_have_data # when new column insert
table = entry.u_table
@ -322,27 +320,4 @@ end
params.require(:table_entry).permit!
end
def create_get_table_tags(entry,new_tags=nil)
if new_tags.nil?
new_tags = params["table_tags"].split(",")
end
tags = []
entry.table_tags = []
new_tags.each do |tag|
if is_uuid?(tag) === false
tt = TableTag.new
tt.u_table_id = entry.u_table.id
tt.title = tag.downcase.strip
tt.save
entry.table_tags << tt
else
tt = TableTag.find(tag)
entry.table_tags << tt
end
end
return tags
end
def is_uuid?(str)
!!(str =~ /\A[\da-f]{24}\z/i || str =~ /\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i)
end
end

View File

@ -175,20 +175,17 @@ class UniversalTablesController < ApplicationController
entries = entries.page(params["page_no"]).per(OrbitHelper.page_data_count)
end
else
if params[:tag]
tag = TableTag.where(:title => params[:tag], :u_table_id => table.id).first
end
if paginated
if tag.nil?
if !params[:orbithashtag].present?
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
else
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids.in => [tag.id]).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).filter_by_hashtag(OrbitHelper.page_hashtag_id).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
end
else
if tag.nil?
if !params[:orbithashtag].present?
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).can_display.sorting(params: params,table: table,paginated: false)
else
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids.in => [tag.id]).can_display.sorting(params: params,table: table,paginated: false)
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).filter_by_hashtag(OrbitHelper.page_hashtag_id).can_display.sorting(params: params,table: table,paginated: false)
end
end
end
@ -212,7 +209,7 @@ class UniversalTablesController < ApplicationController
sorted = rows.sort{ |k,v| k["order"] <=> v["order"] }
sorted << {
"title" => t("universal_table.hashtags"),
"text" => entry.tags_for_frontend
"text" => entry.hashtags_for_frontend
}
entry.inc(view_count: 1)
related_entries = []
@ -434,7 +431,7 @@ class UniversalTablesController < ApplicationController
cols << {"text" => ""}
end
end
text = te.tags_for_frontend
text = te.hashtags_for_frontend
cols << {"text" => text}
rows << {
"columns" => cols

View File

@ -2,6 +2,7 @@ class TableEntry
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitHashtag::Hashtaggable
include Slug
attr_accessor :sort_value

View File

@ -3,10 +3,10 @@
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "select2/select2" %>
<%#= stylesheet_link_tag "select2/select2" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "select2/select2.min" %>
<%#= javascript_include_tag "select2/select2.min" %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
@ -24,7 +24,8 @@
<div class="control-group">
<label class="control-label"><%= t("universal_table.hashtags") %></label>
<div class="controls">
<input id="universal_table_tags" name="table_tags" />
<!-- <input id="universal_table_tags" name="table_tags" /> -->
<%= select_hashtags(f, @module_app) %>
</div>
</div>
<%

View File

@ -84,7 +84,7 @@ wb.add_worksheet(name: "Structure") do |sheet|
row << (column.content_translations[locale.to_s] rescue "")
end
when "image"
row << (column&.image&.url.present? ? (url + column.image.url) : "")
row << (column.image.url.present? ? (url + column.image.url) : "")
when "date"
format_str = case col.date_format
when "yyyy/MM/dd hh:mm" then "%Y/%m/%d %H:%M"
@ -137,7 +137,7 @@ wb.add_worksheet(name: "Structure") do |sheet|
end
end
row << entry.table_tags.pluck("title").join("; ")
row << entry.hashtags_for_export
row << entry.get_related_entries_uid
sheet.add_row row, style: wrap

View File

@ -27,26 +27,22 @@ namespace :universal_table_tasks do
desc "Import entries from XLSX file"
task :import, [:file_path, :table_id, :site_locales] => :environment do |t, args|
def create_get_table_tags(entry,new_tags=nil,table)
entry.table_tags = []
new_tags.each do |tag|
tt = get_tag(tag, table)
if tt.nil?
tt = TableTag.new
tt.u_table_id = table.id
tt.title = tag.downcase.strip
tt.table_entry_ids << entry.id
entry.table_tags << tt
def create_get_table_tags(entry,new_tags=nil,module_app)
updated_tags = []
new_tags.each do |tag_str|
tag_str = tag_str.gsub(/^#+/, '').downcase.strip
hashtag = module_app.hashtags.where(name: tag_str).first rescue nil
if hashtag.nil?
hashtag = Hashtag.new
hashtag.name = tag_str
hashtag.module_app_ids << module_app.id.to_s
hashtag.save
updated_tags << hashtag.id
else
tt.table_entry_ids << entry.id
entry.table_tags << tt
end
tt.save
entry.hashtags.include?(hashtag) || updated_tags << hashtag.id
end
end
def get_tag(str, table)
TableTag.where(:title => str.downcase.strip, :u_table_id => table.id).first rescue nil
entry.hashtags= updated_tags
end
file_path = args[:file_path]
@ -161,7 +157,8 @@ namespace :universal_table_tasks do
end
tags_text = row.cells[-2].value.to_s rescue ""
create_get_table_tags(te, tags_text.split(";"), table) if row.cells.count >= 2
module_app = ModuleApp.find_by_key("universal_table")
create_get_table_tags(te, tags_text.split(";"), module_app) if row.cells.count >= 2
related_uids = row.cells[-1].value.to_s.split(";").map(&:strip)
related_ids = TableEntry.where(:uid.in => related_uids).pluck(:id)
@ -177,4 +174,31 @@ namespace :universal_table_tasks do
File.delete(file_path) if File.exist?(file_path)
puts "Import finished. Total entries in table: #{table.table_entries.count}"
end
desc "Migrate old tags to new tags"
task :migrate_tags => :environment do
module_app = ModuleApp.find_by_key("universal_table")
dataset = {}
TableTag.all.each do |tt|
next if tt.title.blank? # Skip if tag name is blank
puts "Processing tag: #{tt.title}"
module_app.reload
hashtag = module_app.hashtags.where(name: tt.title).first_or_initialize
hashtag.module_app_ids << module_app.id.to_s unless hashtag.module_app_ids.include?(module_app.id.to_s)
puts "New record #{hashtag.new_record?}"
hashtag.save if hashtag.new_record?
puts "Hashtag ID: #{hashtag.id} - #{hashtag.name}"
tt.table_entries.each do |te|
unless te.hashtags.include?(hashtag)
dataset[te] ||= []
dataset[te] << hashtag.id
end
end
end
dataset.each do |te, tag_ids|
puts "Updating TableEntry #{te.id} with tags: #{tag_ids.join(', ')}"
te.hashtags= tag_ids
te.save
end
end
end

View File

@ -22,6 +22,7 @@ module UniversalTable
widget_methods ["widget","tag_cloud"]
widget_settings [{"data_count"=>30}]
# taggable "Bulletin"
hashtaggable "TableEntry"
categorizable
authorizable
frontend_enabled