Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
311f8acbe9 | |
|
d0c1d488fc | |
|
14017bfa66 | |
|
2eea96c8bd |
|
@ -196,7 +196,6 @@ 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])
|
||||||
|
@ -222,7 +221,6 @@ 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
|
||||||
|
@ -322,27 +320,4 @@ 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,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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,7 +24,8 @@
|
||||||
<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.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
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -177,4 +174,31 @@ 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_tags => :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
|
||||||
|
puts "Processing tag: #{tt.title}"
|
||||||
|
module_app.reload
|
||||||
|
hashtag = module_app.hashtags.where(name: tt.title).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,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
|
||||||
|
|
Loading…
Reference in New Issue