added downloaded times

This commit is contained in:
Harry Bomrah 2015-03-18 17:59:03 +08:00
parent 736db91cb5
commit a1a0d4b090
8 changed files with 25 additions and 3 deletions

View File

@ -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)

View File

@ -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 = []

View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -4,6 +4,7 @@ en:
archive: Archive
all: All
new: New
downloaded_times: Downloaded Times
show_lang: Language
download: Download
archive: Archive

View File

@ -5,6 +5,7 @@ zh_tw:
download: 檔案下載
archive: 檔案室
Title: 標題
downloaded_times: 下載次數
Files: 檔案
Category: 類別
frontend:

View File

@ -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