added downloaded times
This commit is contained in:
parent
736db91cb5
commit
a1a0d4b090
|
@ -1,7 +1,7 @@
|
|||
class Admin::ArchiveFilesController < OrbitAdminController
|
||||
|
||||
def index
|
||||
@table_fields = [:status, :category, :title, :update_at,:last_modified]
|
||||
@table_fields = [:status, :category, :title, :update_at,:last_modified,"archive.downloaded_times"]
|
||||
@categories = @module_app.categories
|
||||
@tags = @module_app.tags
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
|
|
|
@ -22,11 +22,11 @@ class ArchivesController < ApplicationController
|
|||
files = archive.archive_file_multiples.order_by(:sort_number=>'asc').collect do |file|
|
||||
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
|
||||
extension = file.file.file.extension.downcase rescue ""
|
||||
url = file.file.url rescue ""
|
||||
# url = file.file.url rescue ""
|
||||
{
|
||||
"file-name" => title,
|
||||
"file-type" => extension,
|
||||
"file-url" => url
|
||||
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -47,6 +47,17 @@ class ArchivesController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
def download_file
|
||||
file_id = params[:file]
|
||||
file = ArchiveFileMultiple.find(file_id) rescue nil
|
||||
if !file.nil?
|
||||
file.download_count = file.download_count + 1
|
||||
file.save
|
||||
redirect_to file.file.url and return
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def widget
|
||||
categories = OrbitHelper.widget_categories
|
||||
@categories = []
|
||||
|
|
|
@ -7,6 +7,7 @@ class ArchiveFileMultiple
|
|||
|
||||
field :file_title, localize: true
|
||||
# field :description
|
||||
field :download_count, type: Integer, default: 0
|
||||
field :choose_lang, :type => Array, :default => nil
|
||||
|
||||
field :should_destroy, :type => Boolean
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<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>
|
||||
|
|
|
@ -33,6 +33,12 @@
|
|||
</td>
|
||||
<td><%= format_value archive.updated_at rescue nil %></td>
|
||||
<td><%= User.find(archive.update_user_id).user_name rescue nil %></td>
|
||||
<% download_total = 0
|
||||
archive.archive_file_multiples.each do |afm|
|
||||
download_total = download_total + afm.download_count
|
||||
end
|
||||
%>
|
||||
<td><%= download_total %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -4,6 +4,7 @@ en:
|
|||
archive: Archive
|
||||
all: All
|
||||
new: New
|
||||
downloaded_times: Downloaded Times
|
||||
show_lang: Language
|
||||
download: Download
|
||||
archive: Archive
|
||||
|
|
|
@ -5,6 +5,7 @@ zh_tw:
|
|||
download: 檔案下載
|
||||
archive: 檔案室
|
||||
Title: 標題
|
||||
downloaded_times: 下載次數
|
||||
Files: 檔案
|
||||
Category: 類別
|
||||
frontend:
|
||||
|
|
|
@ -6,6 +6,7 @@ locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_l
|
|||
namespace :admin do
|
||||
resources :archive_files
|
||||
end
|
||||
get "/xhr/archive/download" => "archives#download_file"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue