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) entries = entries.page(params["page_no"]).per(OrbitHelper.page_data_count)
end end
else else
if params[:tag]
tag = TableTag.where(:title => params[:tag], :u_table_id => table.id).first
end
if paginated 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) 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 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 end
else 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) 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 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 end
end end
@ -212,7 +209,7 @@ class UniversalTablesController < ApplicationController
sorted = rows.sort{ |k,v| k["order"] <=> v["order"] } sorted = rows.sort{ |k,v| k["order"] <=> v["order"] }
sorted << { sorted << {
"title" => t("universal_table.hashtags"), "title" => t("universal_table.hashtags"),
"text" => entry.tags_for_frontend "text" => entry.hashtags_for_frontend
} }
entry.inc(view_count: 1) entry.inc(view_count: 1)
related_entries = [] related_entries = []
@ -434,7 +431,7 @@ class UniversalTablesController < ApplicationController
cols << {"text" => ""} cols << {"text" => ""}
end end
end end
text = te.tags_for_frontend text = te.hashtags_for_frontend
cols << {"text" => text} cols << {"text" => text}
rows << { rows << {
"columns" => cols "columns" => cols

View File

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

View File

@ -3,10 +3,10 @@
<%= stylesheet_link_tag "lib/main-forms" %> <%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %> <%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %> <%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "select2/select2" %> <%#= stylesheet_link_tag "select2/select2" %>
<% end %> <% end %>
<% content_for :page_specific_javascript do %> <% 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-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
@ -25,6 +25,7 @@
<label class="control-label"><%= t("universal_table.hashtags") %></label> <label class="control-label"><%= t("universal_table.hashtags") %></label>
<div class="controls"> <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>
</div> </div>
<% <%

View File

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

View File

@ -27,26 +27,22 @@ namespace :universal_table_tasks do
desc "Import entries from XLSX file" desc "Import entries from XLSX file"
task :import, [:file_path, :table_id, :site_locales] => :environment do |t, args| task :import, [:file_path, :table_id, :site_locales] => :environment do |t, args|
def create_get_table_tags(entry,new_tags=nil,table) def create_get_table_tags(entry,new_tags=nil,module_app)
entry.table_tags = [] updated_tags = []
new_tags.each do |tag| new_tags.each do |tag_str|
tt = get_tag(tag, table) tag_str = tag_str.gsub(/^#+/, '').downcase.strip
if tt.nil? hashtag = module_app.hashtags.where(name: tag_str).first rescue nil
tt = TableTag.new if hashtag.nil?
tt.u_table_id = table.id hashtag = Hashtag.new
tt.title = tag.downcase.strip hashtag.name = tag_str
tt.table_entry_ids << entry.id hashtag.module_app_ids << module_app.id.to_s
entry.table_tags << tt hashtag.save
updated_tags << hashtag.id
else else
tt.table_entry_ids << entry.id entry.hashtags.include?(hashtag) || updated_tags << hashtag.id
entry.table_tags << tt
end end
tt.save
end end
end entry.hashtags= updated_tags
def get_tag(str, table)
TableTag.where(:title => str.downcase.strip, :u_table_id => table.id).first rescue nil
end end
file_path = args[:file_path] file_path = args[:file_path]
@ -161,7 +157,8 @@ namespace :universal_table_tasks do
end end
tags_text = row.cells[-2].value.to_s rescue "" 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_uids = row.cells[-1].value.to_s.split(";").map(&:strip)
related_ids = TableEntry.where(:uid.in => related_uids).pluck(:id) related_ids = TableEntry.where(:uid.in => related_uids).pluck(:id)

View File

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