Add file column type.

This commit is contained in:
邱博亞 2024-07-21 15:26:48 +08:00
parent 0a3fc812c4
commit 03a22138af
15 changed files with 677 additions and 38 deletions

View File

@ -82,22 +82,7 @@ class UniversalTablesController < ApplicationController
tablecolumns.each do |column|
ce = te.column_entries.where(:table_column_id => column.id).first rescue nil
if !ce.nil?
text = ""
case ce.type
when "text"
text = ce.text
when "integer"
text = ce.number
when "editor"
text = ce.content
when "date"
text = format_date(ce.date, column.date_format)
when "period"
text = format_date(ce.period_from, column.date_format) + " ~ " + format_date(ce.period_to, column.date_format)
text = "" if text.starts_with?(" ~")
when "image"
text = "<img src='#{ce.image.thumb.url}' class='image-preview' />"
end
text = ce.get_frontend_text(column)
if column.is_link_to_show
text = "<a href='#{OrbitHelper.url_to_show("-" + te.uid)}'>#{text}</a>"
end
@ -172,6 +157,14 @@ class UniversalTablesController < ApplicationController
text = "" if text.starts_with?(" ~")
when "image"
text = host_url + ce.image.thumb.url
when "file"
file_links = []
locale = I18n.locale.to_s
ce.column_entry_files.desc(:sort_number).each do |entry_file|
next unless entry_file.choose_lang_display(locale)
file_links << (host_url + entry_file.get_link)
end
text = file_links.join("\r\n")
end
cols << {"text" => text}
else
@ -233,23 +226,7 @@ class UniversalTablesController < ApplicationController
entry.column_entries.each do |ce|
ct = ce.table_column
text = ""
case ce.type
when "text"
text = ce.text
when "integer"
text = ce.number
when "editor"
text = ce.content
when "date"
text = format_date(ce.date, ce.table_column.date_format)
when "period"
text = format_date(ce.period_from, ce.table_column.date_format) + " ~ " + format_date(ce.period_from, ce.table_column.date_format)
text = "" if text.starts_with?(" ~")
when "image"
text = "<img src='#{ce.image.thumb.url}' class='image-preview' />"
end
text = ce.get_frontend_text(ct)
rows << {
"title" => ct.title,
"text" => text,
@ -266,4 +243,33 @@ class UniversalTablesController < ApplicationController
}
}
end
def download_file
file_id = params[:file]
file = ColumnEntryFile.find(file_id) rescue nil
if !file.nil? && file.file.present?
file.inc(download_count: 1)
@url = file.file.url
begin
@path = file.file.file.file rescue ""
@filename = File.basename(@path)
@ext = @filename.split(".").last
if @ext == "png" || @ext == "jpg" || @ext == "bmp" || @ext == "pdf"
render "download_file",:layout=>false
else
if (current_site.accessibility_mode rescue false)
render "redirect_to_file",:layout=>false
else
user_agent = request.user_agent.downcase
@escaped_file_name = user_agent.match(/(msie|trident)/) ? CGI::escape(@filename) : @filename
send_file(@path, :type=>"application/octet-stream", :filename => @escaped_file_name, :x_sendfile=> true)
end
end
rescue
redirect_to @url
end
else
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found
end
end
end

View File

@ -2,6 +2,9 @@ class ColumnEntry
include Mongoid::Document
include Mongoid::Timestamps
include Admin::UniversalTablesHelper
include ActionView::Helpers::NumberHelper
field :text, :localize => true
field :content, :localize => true
field :date, type: DateTime
@ -11,6 +14,10 @@ class ColumnEntry
mount_uploader :image, ImageUploader
has_many :column_entry_files, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :column_entry_files, :allow_destroy => true
after_save :save_column_entry_files
belongs_to :table_entry, index: true
belongs_to :table_column, index: true
@ -23,4 +30,42 @@ class ColumnEntry
def type
self.table_column.type
end
def save_column_entry_files
return if @skip_callback
self.column_entry_files.each do |t|
if t.should_destroy
t.destroy
end
end
end
def get_frontend_text(column)
text = ""
case self.type
when "text"
text = self.text
when "integer"
text = self.number
when "editor"
text = self.content
when "date"
text = format_date(self.date, column.date_format)
when "period"
text = format_date(self.period_from, column.date_format) + " ~ " + format_date(self.period_to, column.date_format)
text = "" if text.starts_with?(" ~")
when "image"
text = "<img src='#{self.image.thumb.url}' class='image-preview' />"
when "file"
locale = I18n.locale.to_s
text = "<ul class=\"column_entry_files\">"
self.column_entry_files.desc(:sort_number).each do |entry_file|
next unless entry_file.choose_lang_display(locale)
file_title = entry_file.get_file_title
text += "<li class=\"column_entry_file\"><a class=\"column_entry_file_link\" href=\"#{entry_file.get_link}\" title=\"#{file_title}\" target=\"_blank\">#{file_title}</a><span class=\"file_size\">(#{number_to_human_size(entry_file.file.size)})</span><span class=\"view_count\"><i class=\"fa fa-eye\" title=\"#{I18n.t("universal_table.downloaded_times")}\"></i><span class=\"view-count\">#{entry_file.download_count}</span></span></li>"
end
text += "</ul>"
end
text
end
end

View File

@ -0,0 +1,36 @@
class ColumnEntryFile
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, AssetUploader
field :file_title, localize: true
# field :description
field :download_count, type: Integer, default: 0
field :choose_lang, :type => Array, :default => I18n.available_locales.map{|l| l.to_s}
field :should_destroy, :type => Boolean
field :sort_number, :type => Integer
# default_scope asc(:sort_number)
def choose_lang_display(lang)
self.file.present? && self.choose_lang.include?(lang)
end
def get_file_title
_file_title = self.file_title
if _file_title.blank? && self.file.present?
_file_title = self[:file]
end
_file_title
end
def get_link
"/xhr/universal_table/download?file=#{self.id}"
end
belongs_to :column_entry, index: true
end

View File

@ -17,7 +17,7 @@ class UTable
accepts_nested_attributes_for :table_columns, :allow_destroy => true
FIELD_TYPES = ["text", "integer", "editor", "image", "date", "period"]
FIELD_TYPES = ["text", "integer", "editor", "image", "date", "period", "file"]
DATE_FORMATS = ["yyyy/MM/dd hh:mm", "yyyy/MM/dd","yyyy/MM", "yyyy"]
def default_ordered
if self.ordered_with_created_at

View File

@ -0,0 +1,289 @@
<% # encoding: utf-8 %>
<% content_for :page_specific_css do %>
<style type="text/css">
.sort-order-icon{
font-size: 25px;
cursor: move;
}
</style>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "lib/jquery-ui-sortable.min" %>
<% end %>
<style>
#fileupload {
position: relative;
clear: both;
overflow: hidden;
height: 254px;
}
#fileupload #dropzone.drop {
position: absolute;
left: 0;
right: 0;
border: 2px dashed #0088CC;
border-radius: 10px;
color: #0088CC;
background-color: #FFFFFF;
z-index: 0;
}
#fileupload #dropzone {
padding: 30px;
text-align: center;
font-size: 3em;
font-family: 'Raleway';
line-height: 1.2em;
color: #e4e4e4;
}
#fileupload #dropzone.in {
opacity: .7;
z-index: 2;
border-color: #faa732;
color: #faa732;
}
</style>
<div class="control-group">
<%= f.label :text, column.title, :class => "control-label" %>
<div class="controls">
<p class="add-btn">
<%= hidden_field_tag 'column_entry_file_field_count', file_field.column_entry_files.count %>
<a id="add_file" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
<hr>
<!-- Add -->
<div class="add-target" id="add-target"></div>
<!-- Exist -->
<% if file_field && !file_field.column_entry_files.blank? %>
<div class="exist plugin-sortable">
<% file_field.column_entry_files.desc(:sort_number).each_with_index do |column_entry_file, i| %>
<%= f.fields_for :column_entry_files, column_entry_file do |f| %>
<%= render :partial => 'form_file', :locals => {:f => f, :i => i,:form_file => column_entry_file} %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
<div id="fileupload" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);" ondragleave="(function(){$('#dropzone').removeClass('in');})()">
<div id="dropzone" class="drop">
<div data-icons=""></div>
<%=t("universal_table.drag_file_to_here")%>
</div>
</div>
</div>
</div>
<% if !file_field.new_record? %>
<%= f.hidden_field :id %>
<% else %>
<%= f.hidden_field :table_column_id, :value => column.id %>
<% end %>
</div>
<% content_for :page_specific_javascript do %>
<script>
if (!FileReader.prototype.readAsBinaryString) {
console.log('readAsBinaryString definition not found');
FileReader.prototype.readAsBinaryString = function (fileData) {
var binary = '';
var pk = this;
var reader = new FileReader();
reader.onload = function (e) {
var bytes = new Uint8Array(reader.result);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) {
var a = bytes[i];
var b = String.fromCharCode(a)
binary += b;
}
pk.content = binary;
$(pk).trigger('onload');
}
reader.readAsArrayBuffer(fileData);
}
}
function FileListItems (files) {
var b;
try{
b = new DataTransfer();
}catch(e){
if(window.dataTransfer){
b = window.dataTransfer;
}else{
if(typeof(ClipboardEvent) == "undefined"){ //IE
b = new DataTransfer();
}else{
b = new ClipboardEvent("").clipboardData;
}
}
}
if(b.items){
b.items.clear();
}else{
if(b.files.length != 0 ){
var files_length = b.files.length;
for(var i = files_length - 1;i >= 0;i = i - 1){
delete b.files[i];
}
}
if(b.files.length != 0){
return files
}
}
for (var i = 0, len = files.length; i<len; i++){
if(b.items){
b.items.add(files[i])
}else{
b.files[i] = files[i];
}
}
return b.files
}
function change_files_to_file_field(file_field,files){
var fileupload = $(file_field).parents(".fileupload");
if(fileupload.length > 0){
fileupload.find(".fileupload-preview").text(files[0].name);
}
var files_list = new FileListItems(files)
try{
$(file_field)[0].files = files_list;
}catch(e){console.log(e)}
if($(file_field)[0].files.length == 0){ //Change failed
var file_field_values = [];
var file_reader = new FileReader();
$("[name=\""+$(file_field)[0].name+"\"][type=\"hidden\"]").remove();
var hidden_input = $("<input type=\"hidden\" name=\""+$(file_field)[0].name+"\">");
var hidden_input_values = [];
$(file_field).after(hidden_input);
var files_list_length = files_list.length;
for(var i = 0; i < files_list_length; i++){
var file = files_list[i];
$(file_field)[0].files[i] = file;
file_reader.readAsBinaryString(files_list[i]);
file_reader.onload = (function(hidden_input,file,i,files_list_length) {
return function(e) {
var file_info = {};
file_info["name"] = file.name;
file_info["type"] = file.type;
if (file_reader.result)
file_reader.content = file_reader.result;
file_info["content"] = e ? e.target.result : file_reader.content;
if(Array.isArray(hidden_input_values)){
hidden_input_values.push(file_info);
}
if(i == files_list_length - 1){
if(hidden_input_values.length == 1){
hidden_input_values = hidden_input_values[0];
}
hidden_input.val(JSON.stringify(hidden_input_values));
}
};})(hidden_input,file,i,files_list_length);
file_field_values.push("C:\\fakepath\\" + files_list[i].name);
}
Object.defineProperty($(file_field)[0].files, "length", {
// only returns odd die sides
get: function () {
var length = 0;
while(this[length]){
length++;
}
return length;
}
});
Object.defineProperty($(file_field)[0], "value", {
// only returns odd die sides
get: function () {
return (this.getAttribute('value') ? this.getAttribute('value') : "");
},
set: function(value) {
this.setAttribute('value',value);
}
});
$(file_field)[0].value = file_field_values.join(", ");
}
}
function dragOverHandler(ev) {
document.activeElement.blur();
$(ev.target).addClass("in");
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
}
function dropHandler(ev) {
window.ev = ev;
window.dataTransfer = ev.dataTransfer;
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
var files = [];
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.items.length; i++) {
// If dropped items aren't files, reject them
if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile();
files.push(file)
}
}
} else {
// Use DataTransfer interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
var file = ev.dataTransfer.files[i];
files.push(file)
}
}
files.forEach(function(file){
var single_file = [file];
var file_field = add_file_field();
change_files_to_file_field(file_field,single_file);
})
window.files = files;
var target = ev.target ? ev.target : ev.srcElement;
$(target).removeClass("in");
}
function add_file_field(){
var self = $('#add_file');
var new_id = $(self).prev().attr('value');
var old_id = new RegExp("new_column_entry_files", "g");
var on = $('.language-nav li.active').index();
var le = $('#add-target').children('.start-line').length;
$(self).prev().attr('value', parseInt(new_id) + 1);
$('#add-target').prepend(("<%= escape_javascript(add_attribute 'form_file', f, :column_entry_files) %>").replace(old_id, new_id).replace("new_column_entry_file_sort_order_XXX", parseInt(new_id) + 1));
var file_field = $('#add-target').find("*").eq(0).find("[type=\"file\"]");
$('#add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$(self).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
});
formTip();
return file_field;
}
$(document).ready(function() {
$(".plugin-sortable").sortable({
update : function(event, ui){
var existingfiles = $(".exist.plugin-sortable div.fileupload")
existingfiles.each(function(i, file){
$(file).find("input.file-sort-number-field").val(existingfiles.length - i);
})
}
});
$('.main-forms .add-on').tooltip();
$(document).on('click', '#add_file', add_file_field);
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove();
});
$(document).on('click',"[type='file']",function(){
$("[name=\""+$(this).attr("name")+"\"][type=\"hiiden\"]").remove();
});
$(document).on('click', '.remove_existing_record', function(){
if(confirm("<%= I18n.t(:sure?)%>")){
$(this).children('.should_destroy').attr('value', 1);
$(this).parents('.start-line').hide();
}
});
});
</script>
<% end %>

View File

@ -0,0 +1,65 @@
<% if form_file.new_record? %>
<div class="fileupload fileupload-new start-line" data-provides="fileupload">
<% else %>
<div class="fileupload fileupload-exists start-line" data-provides="fileupload">
<i class="icons-list-2 sort-order-icon"></i>
<% if form_file.file.blank? %>
<%= t(:no_file) %>
<% else %>
<%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %>
<% end %>
<% end %>
<div class="input-prepend input-append">
<label>
<span class="add-on btn btn-file" title="<%= t(:file_) %>">
<i class="icons-paperclip"></i>
<%= f.file_field :file %>
</span>
<div class="uneditable-input input-medium">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"><%= (form_file.new_record? || form_file.file.blank?) ? t(:select_file) : t(:change_file) %></span>
</div>
</label>
<span class="add-on icons-pencil" title="<%= t('file.name') %>"></span>
<span class="tab-content">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<span class="tab-pane fade <%= ( i == 0 ) ? "in active" : '' %> <%= locale %>">
<%= f.fields_for :file_title_translations do |f| %>
<%= f.text_field locale, :class => "input-medium", placeholder: t('file.name'), :value => (form_file.file_title_translations[locale] rescue nil) %>
<% end %>
</span>
<% end %>
</span>
<span class="add-on btn-group btn" title="<%= t('universal_table.show_lang') %>">
<i class="icons-earth"></i> <span class="caret"></span>
<ul class="dropdown-menu">
<% @site_in_use_locales.each do |locale| %>
<li>
<label class="checkbox">
<%= check_box_tag "#{f.object_name}[choose_lang][]", locale, form_file.choose_lang.include?(locale.to_s) %>
<%= t(locale.to_s) %>
</label>
</li>
<% end %>
</ul>
<%= hidden_field_tag "#{f.object_name}[choose_lang][]", '' %>
</span>
<% if form_file.new_record? %>
<span class="delete_file add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>
<%= f.hidden_field :sort_number, :value => "new_column_entry_file_sort_order_XXX", :class => "input-mini" %>
</span>
<% else %>
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<%= f.hidden_field :sort_number , :class => "file-sort-number-field" %>
<a class=" icon-remove"></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
</span>
<span class="downloaded_times">Downloaded <b><%= form_file.download_count %></b> time<%= form_file.download_count > 1 ? "s" : "" %>.</span>
<% end %>
</div>
</div>

View File

@ -43,6 +43,10 @@ wb.add_worksheet(name: "Structure") do |sheet|
row << column.title + "-To"
row1 << column.key
row2 << column.type + " : " + column.date_format.upcase + "-period_to"
when "file"
row << column.title
row1 << column.key
row2 << "Please leave this column blank. Upload the files manually."
end
end

View File

@ -53,6 +53,14 @@
<% if !ce.period_from.nil? %>
<%= format_date(ce.period_from, column.date_format) %> ~ <%= format_date(ce.period_to, column.date_format) %>
<% end %>
<% when "file" %>
<% locale = I18n.locale.to_s %>
<ol>
<% ce.column_entry_files.desc(:sort_number).each do |entry_file| %>
<% next unless entry_file.choose_lang_display(locale) %>
<li><%= link_to entry_file.get_file_title, entry_file.file.url, target: "_blank" %></li>
<% end %>
</ol>
<% end %>
<% else %>
&nbsp;

View File

@ -0,0 +1,147 @@
<% if @ext == 'pdf' %>
<%= render partial: 'archives/viewer' %>
<% else %>
<html lang="<%= I18n.locale.to_s%>" style="margin: 0em; padding: 0em; width: 100%; height: 100%; overflow: hidden; background-color: rgb(230, 230, 230);">
<head>
<meta name="viewport" content="width=device-width, minimum-scale=0.1">
<title><%=@filename%></title>
<%= stylesheet_link_tag "archive/download_file.css" %>
</head>
<body>
<h1 style="display: none;"><%=@filename%></h1>
<% if @ext != "png" && @ext != "jpg" && @ext != "bmp" %>
<object data="<%=@url%>" height="100%" type="application/<%=@ext%>" width="100%">
<iframe height="100%" src="<%=@url%>" title="<%=@filename%>" width="100%"></iframe>
<img alt="<%=@filename%>" src="<%=@url%>">
</object>
<% else %>
<img alt="<%=@filename%>" src="<%=@url%>">
<script type="text/javascript">
var img = document.getElementsByTagName('img')[0];
var width = img.width;
var height = img.height;
window.innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
window.innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var window_width = window.innerWidth;
var window_height = window.innerHeight;
var zoom_in_cursor,zoom_out_cursor;
var IE_ver = 11;
if(navigator.userAgent.search("MSIE") != -1){
IE_ver = Number(navigator.userAgent.split("MSIE")[1].split(";")[0]);
}
if(IE_ver <= 8){
img.style.marginTop = "-"+img.height/2+"px";
img.style.marginLeft = "-"+img.width/2+"px";
}else{
img.style.transform= "translate(-50%, -50%)";
img.style["-ms-transform"]= "translate(-50%, -50%)";
img.style["-moz-transform"]= "translate(-50%, -50%)";
}
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
zoom_in_cursor = 'url("/assets/archive/zoomin.cur"), auto';
zoom_out_cursor = 'url("/assets/archive/zoomout.cur"), auto';
}else{
zoom_in_cursor = 'zoom-in';
zoom_out_cursor = 'zoom-out';
}
if(height > window_height && (height / width) > (window_height / window_width) ){
img.height = window_height;
img.width = window_height / height * width;
img.style.cursor = zoom_in_cursor;
if(IE_ver <= 8){
img.style.marginTop = "-"+img.height/2+"px";
img.style.marginLeft = "-"+img.width/2+"px";
}
img.onclick=function(e){
var event = e || window.event;
if(img.style.cursor == zoom_in_cursor){
var cursor_x = event.clientX;
var cursor_y = event.clientY;
img.height = height;
img.width = width;
img.style.cursor = zoom_out_cursor;
document.getElementsByTagName('html')[0].style.overflow = "";
img.style.transform= "none";
img.style["-ms-transform"]= "none";
img.style["-moz-transform"]= "none";
img.style.top= "0";
img.style.left= "0";
if(IE_ver <= 8){
img.style.marginTop = "0";
img.style.marginLeft = "0";
}
window.scroll(
(((cursor_x - (window_width - window_height / height * width)/2) * height / window_height) - window_width / 2),
((cursor_y * height / window_height) - window_height / 2)
);
}else{
img.height = window_height;
img.width = window_height / height * width;
img.style.cursor = zoom_in_cursor;
document.getElementsByTagName('html')[0].style.overflow = "hidden";
if(IE_ver <= 8){
img.style.marginTop = "-"+img.height/2+"px";
img.style.marginLeft = "-"+img.width/2+"px";
}else{
img.style.transform= "translate(-50%, -50%)";
img.style["-ms-transform"]= "translate(-50%, -50%)";
img.style["-moz-transform"]= "translate(-50%, -50%)";
}
img.style.top= "50%";
img.style.left= "50%";
window.scroll(0, 0);
}
};
}else if(width > window_width){
img.width = window_width;
img.height = window_width / width * height;
img.style.cursor = zoom_in_cursor;
if(IE_ver <= 8){
img.style.marginTop = "-"+img.height/2+"px";
img.style.marginLeft = "-"+img.width/2+"px";
}
img.onclick=function(e){
var event = e || window.event;
if(img.style.cursor == zoom_in_cursor){
var cursor_x = event.clientX;
var cursor_y = event.clientY;
img.height = height;
img.width = width;
img.style.cursor = zoom_out_cursor;
document.getElementsByTagName('html')[0].style.overflow = "";
img.style.transform= "none";
img.style["-ms-transform"]= "none";
img.style["-moz-transform"]= "none";
img.style.top= "0";
img.style.left= "0";
if(IE_ver <= 8){
img.style.marginTop = "0";
img.style.marginLeft = "0";
}
window.scroll( ((cursor_x * height / window_height) - window_width / 2),
(((cursor_y - (window_height - window_width / width * height)/2) * height / window_height) - window_height / 2)
);
}else{
img.width = window_width;
img.height = window_width / width * height;
img.style.cursor = zoom_in_cursor;
document.getElementsByTagName('html')[0].style.overflow = "hidden";
if(IE_ver <= 8){
img.style.marginTop = "-"+img.height/2+"px";
img.style.marginLeft = "-"+img.width/2+"px";
}else{
img.style.transform= "translate(-50%, -50%)";
img.style["-ms-transform"]= "translate(-50%, -50%)";
img.style["-moz-transform"]= "translate(-50%, -50%)";
}
img.style.top= "50%";
img.style.left= "50%";
window.scroll(0, 0);
}
};
}
</script>
<% end %>
</body>
</html>
<% end %>

View File

@ -8,11 +8,13 @@ wb.add_worksheet(name: "Table") do |sheet|
headings = @tablecolumns.collect{|tc| tc.title}
sheet.add_row headings, :style => heading
wrap = sheet.styles.add_style alignment: {wrap_text: true}
@rows.each do |r|
row = []
r["columns"].each do |col|
row << col["text"]
end
sheet.add_row row
sheet.add_row row, style: wrap
end
end

View File

@ -0,0 +1,17 @@
<html lang="<%= I18n.locale.to_s%>">
<head>
<title><%=@filename%></title>
<link href="/assets/archive/download_file.css" rel="stylesheet" media="all">
</head>
<body style="background: #fff;">
<div class="wrap_block">
<h1 style="display: none;"><%=@filename%></h1>
<% download_text = t('download') + " " + @filename %>
<h2 align="center"><a href="<%=@url%>" target="blank" download="<%=@filename%>" title="<%=download_text%>"><%=download_text%></a></h2>
<p align="center">
<a href="javascript:window.close();" title="<%=t('close')%>"><%=t('close')%></a>
</p>
</div>
<script>window.location.href="<%=@url%>";</script>
</body>
</html>

View File

@ -5,6 +5,7 @@ wb = xlsx_package.workbook
wb.add_worksheet(name: "Structure") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
type = sheet.styles.add_style(:i => true)
wrap = sheet.styles.add_style alignment: {wrap_text: true}
row = []
row1 = []
@ -40,6 +41,10 @@ wb.add_worksheet(name: "Structure") do |sheet|
row << column.title + "-From ~ To"
row1 << column.key
row2 << column.type + " : " + column.date_format.upcase + "-period_from ~ period_to"
when "file"
row << column.title
row1 << column.key
row2 << "Please leave this column blank. Upload the files manually."
end
end
@ -90,9 +95,17 @@ wb.add_worksheet(name: "Structure") do |sheet|
when "yyyy"
row << (column.period_from.strftime("%Y")rescue "") + " ~ " + (column.period_to.strftime("%Y") rescue "")
end
when "file"
file_links = []
locale = I18n.locale.to_s
column.column_entry_files.desc(:sort_number).each do |entry_file|
next unless entry_file.choose_lang_display(locale)
file_links << (url + entry_file.get_link)
end
row << file_links.join("\r\n")
end
end
sheet.add_row row
sheet.add_row row, style: wrap
end
end

View File

@ -17,4 +17,7 @@ en:
sort_number: Sort Number
created_at: Created Time
edit_sort: Edit Sorting
manual_update_sort: Manually Update Sorting
manual_update_sort: Manually Update Sorting
drag_file_to_here: Drag file to here
show_lang: Language
downloaded_times: Downloaded Times

View File

@ -17,4 +17,7 @@ zh_tw:
sort_number: 排序數
created_at: 創建時間
edit_sort: 編輯排序
manual_update_sort: 手動更新排序
manual_update_sort: 手動更新排序
drag_file_to_here: 拖移檔案到此
show_lang: 呈現語系
downloaded_times: 下載次數

View File

@ -21,6 +21,7 @@ Rails.application.routes.draw do
end
end
get "/xhr/universal_table/export", to: 'universal_tables#export_filtered'
get "/xhr/universal_table/download", to: "universal_tables#download_file"
end
end