global hashtags

This commit is contained in:
rulingcom 2025-08-06 21:52:43 +08:00
parent a10c7ba466
commit 2eea96c8bd
6 changed files with 28 additions and 31 deletions

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" %>
@ -25,6 +25,7 @@
<label class="control-label"><%= t("universal_table.hashtags") %></label>
<div class="controls">
<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
entry.hashtags.include?(hashtag) || updated_tags << hashtag.id
end
tt.save
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)

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