Compare commits
No commits in common. "dev" and "master" have entirely different histories.
|
@ -196,6 +196,7 @@ end
|
||||||
|
|
||||||
def add_entry
|
def add_entry
|
||||||
entry = TableEntry.new(table_entry_params)
|
entry = TableEntry.new(table_entry_params)
|
||||||
|
create_get_table_tags(entry)
|
||||||
entry.save
|
entry.save
|
||||||
entry.fix_have_data
|
entry.fix_have_data
|
||||||
table = UTable.find(params[:table_entry][:u_table_id])
|
table = UTable.find(params[:table_entry][:u_table_id])
|
||||||
|
@ -221,6 +222,7 @@ end
|
||||||
|
|
||||||
def update_entry
|
def update_entry
|
||||||
entry = TableEntry.find(params[:id])
|
entry = TableEntry.find(params[:id])
|
||||||
|
create_get_table_tags(entry)
|
||||||
entry.update_attributes(table_entry_params)
|
entry.update_attributes(table_entry_params)
|
||||||
entry.fix_have_data # when new column insert
|
entry.fix_have_data # when new column insert
|
||||||
table = entry.u_table
|
table = entry.u_table
|
||||||
|
@ -320,4 +322,27 @@ end
|
||||||
params.require(:table_entry).permit!
|
params.require(:table_entry).permit!
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -175,17 +175,20 @@ 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 !params[:orbithashtag].present?
|
if tag.nil?
|
||||||
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]}).filter_by_hashtag(OrbitHelper.page_hashtag_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]}, :table_tag_ids.in => [tag.id]).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if !params[:orbithashtag].present?
|
if tag.nil?
|
||||||
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]}).filter_by_hashtag(OrbitHelper.page_hashtag_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]}, :table_tag_ids.in => [tag.id]).can_display.sorting(params: params,table: table,paginated: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -209,7 +212,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.hashtags_for_frontend
|
"text" => entry.tags_for_frontend
|
||||||
}
|
}
|
||||||
entry.inc(view_count: 1)
|
entry.inc(view_count: 1)
|
||||||
related_entries = []
|
related_entries = []
|
||||||
|
@ -431,7 +434,7 @@ class UniversalTablesController < ApplicationController
|
||||||
cols << {"text" => ""}
|
cols << {"text" => ""}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
text = te.hashtags_for_frontend
|
text = te.tags_for_frontend
|
||||||
cols << {"text" => text}
|
cols << {"text" => text}
|
||||||
rows << {
|
rows << {
|
||||||
"columns" => cols
|
"columns" => cols
|
||||||
|
@ -498,11 +501,18 @@ class UniversalTablesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_cloud
|
def tag_cloud
|
||||||
ma = ModuleApp.find_by_key("universal_table")
|
tables = UTable.filter_by_widget_categories(OrbitHelper.widget_categories,false)
|
||||||
|
tags = TableTag.where(:u_table_id.in => tables.pluck(:id))
|
||||||
|
hashtags = tags.map do |tag|
|
||||||
{
|
{
|
||||||
"extras" => {
|
"title" => "##{tag.title}",
|
||||||
"orbithashtags" => ma.hashtags.get_all_module_hashtags_for_frontend_with_weight(OrbitHelper.widget_more_url)
|
"count" => tag.table_entries.count,
|
||||||
|
"url_to_show" => "#{OrbitHelper.widget_more_url}?tag=#{tag.title}"
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
{
|
||||||
|
"hashtags" => hashtags,
|
||||||
|
"extras" => {}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,6 @@ 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
|
||||||
|
|
|
@ -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" %>
|
||||||
|
@ -24,8 +24,7 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<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>
|
||||||
<%
|
<%
|
||||||
|
|
|
@ -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.hashtags_for_export
|
row << entry.table_tags.pluck("title").join("; ")
|
||||||
row << entry.get_related_entries_uid
|
row << entry.get_related_entries_uid
|
||||||
|
|
||||||
sheet.add_row row, style: wrap
|
sheet.add_row row, style: wrap
|
||||||
|
|
|
@ -27,22 +27,26 @@ 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,module_app)
|
def create_get_table_tags(entry,new_tags=nil,table)
|
||||||
updated_tags = []
|
entry.table_tags = []
|
||||||
new_tags.each do |tag_str|
|
new_tags.each do |tag|
|
||||||
tag_str = tag_str.gsub(/^#+/, '').downcase.strip
|
tt = get_tag(tag, table)
|
||||||
hashtag = module_app.hashtags.where(name: tag_str).first rescue nil
|
if tt.nil?
|
||||||
if hashtag.nil?
|
tt = TableTag.new
|
||||||
hashtag = Hashtag.new
|
tt.u_table_id = table.id
|
||||||
hashtag.name = tag_str
|
tt.title = tag.downcase.strip
|
||||||
hashtag.module_app_ids << module_app.id.to_s
|
tt.table_entry_ids << entry.id
|
||||||
hashtag.save
|
entry.table_tags << tt
|
||||||
updated_tags << hashtag.id
|
|
||||||
else
|
else
|
||||||
entry.hashtags.include?(hashtag) || updated_tags << hashtag.id
|
tt.table_entry_ids << entry.id
|
||||||
|
entry.table_tags << tt
|
||||||
|
end
|
||||||
|
tt.save
|
||||||
end
|
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]
|
||||||
|
@ -157,8 +161,7 @@ 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 ""
|
||||||
module_app = ModuleApp.find_by_key("universal_table")
|
create_get_table_tags(te, tags_text.split(";"), table) if row.cells.count >= 2
|
||||||
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)
|
||||||
|
@ -174,33 +177,4 @@ namespace :universal_table_tasks do
|
||||||
File.delete(file_path) if File.exist?(file_path)
|
File.delete(file_path) if File.exist?(file_path)
|
||||||
puts "Import finished. Total entries in table: #{table.table_entries.count}"
|
puts "Import finished. Total entries in table: #{table.table_entries.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Migrate old tags to new tags"
|
|
||||||
task :migrate_hashtags => :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
|
|
||||||
next if tt.table_entries.empty? # Skip if no entries are associated with the tag
|
|
||||||
puts "Processing tag: #{tt.title}"
|
|
||||||
module_app.reload
|
|
||||||
tag_str = tt.title.gsub(/^#+/, '').downcase.strip
|
|
||||||
hashtag = module_app.hashtags.where(name: tag_str).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
|
end
|
||||||
|
|
|
@ -22,7 +22,6 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue