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| new_tags.each do |tag|
if is_uuid?(tag) === false if is_uuid?(tag) === false
tt = TableTag.new tt = TableTag.new
tt.u_table_id = entry.u_table.id
tt.title = tag.downcase tt.title = tag.downcase
tt.save tt.save
entry.table_tags << tt entry.table_tags << tt

View File

@ -122,10 +122,21 @@ 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
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 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
end end
entries entries
@ -135,7 +146,6 @@ class UniversalTablesController < ApplicationController
params = OrbitHelper.params params = OrbitHelper.params
entry = TableEntry.where(:uid => params[:uid]).first rescue nil entry = TableEntry.where(:uid => params[:uid]).first rescue nil
rows = [] rows = []
entry.column_entries.each do |ce| entry.column_entries.each do |ce|
ct = ce.table_column ct = ce.table_column
text = ce.get_frontend_text(ct) text = ce.get_frontend_text(ct)
@ -146,6 +156,10 @@ class UniversalTablesController < ApplicationController
} if text != "" } if text != ""
end end
sorted = rows.sort{ |k,v| k["order"] <=> v["order"] } 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.inc(view_count: 1)
{ {
"entry" => sorted, "entry" => sorted,
@ -328,6 +342,8 @@ class UniversalTablesController < ApplicationController
cols << {"text" => ""} cols << {"text" => ""}
end end
end end
text = te.tags_for_frontend
cols << {"text" => text}
rows << { rows << {
"columns" => cols "columns" => cols
} }

View File

@ -41,6 +41,13 @@ class TableEntry
end.to_h end.to_h
end 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 def self.u_table
UTable.find(criteria.selector['u_table_id']) UTable.find(criteria.selector['u_table_id'])
end end

View File

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