tags finished

This commit is contained in:
rulingcom 2025-06-03 22:41:03 +08:00
parent 67264b9a9c
commit 858b400812
4 changed files with 28 additions and 3 deletions

View File

@ -321,6 +321,7 @@ class Admin::UniversalTablesController < OrbitAdminController
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
tt.save
entry.table_tags << tt

View File

@ -122,10 +122,21 @@ 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
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
if tag.nil?
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).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 => tag.id).sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
end
else
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).sorting(params: params,table: table,paginated: false)
if tag.nil?
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).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 => tag.id).sorting(params: params,table: table,paginated: false)
end
end
end
entries
@ -135,7 +146,6 @@ class UniversalTablesController < ApplicationController
params = OrbitHelper.params
entry = TableEntry.where(:uid => params[:uid]).first rescue nil
rows = []
entry.column_entries.each do |ce|
ct = ce.table_column
text = ce.get_frontend_text(ct)
@ -146,6 +156,10 @@ class UniversalTablesController < ApplicationController
} if text != ""
end
sorted = rows.sort{ |k,v| k["order"] <=> v["order"] }
sorted << {
"title" => t("universal_table.hashtags"),
"text" => entry.tags_for_frontend
}
entry.inc(view_count: 1)
{
"entry" => sorted,
@ -328,6 +342,8 @@ class UniversalTablesController < ApplicationController
cols << {"text" => ""}
end
end
text = te.tags_for_frontend
cols << {"text" => text}
rows << {
"columns" => cols
}

View File

@ -41,6 +41,13 @@ class TableEntry
end.to_h
end
def tags_for_frontend
params = OrbitHelper.params
self.table_tags.map{|tt|
"<a class='tag' href='/#{params[:locale]}#{params[:url]}?tag=#{tt.title}'>#" + tt.title + "</a>"
}.join("&nbsp;")
end
def self.u_table
UTable.find(criteria.selector['u_table_id'])
end

View File

@ -3,5 +3,6 @@ class TableTag
include Mongoid::Timestamps
field :title, type: String
field :u_table_id
has_and_belongs_to_many :table_entries, inverse_of: :table_tags
end