added downloaded times
This commit is contained in:
parent
736db91cb5
commit
a1a0d4b090
|
@ -1,7 +1,7 @@
|
||||||
class Admin::ArchiveFilesController < OrbitAdminController
|
class Admin::ArchiveFilesController < OrbitAdminController
|
||||||
|
|
||||||
def index
|
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
|
@categories = @module_app.categories
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@filter_fields = filter_fields(@categories, @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|
|
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 ""
|
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
|
||||||
extension = file.file.file.extension.downcase rescue ""
|
extension = file.file.file.extension.downcase rescue ""
|
||||||
url = file.file.url rescue ""
|
# url = file.file.url rescue ""
|
||||||
{
|
{
|
||||||
"file-name" => title,
|
"file-name" => title,
|
||||||
"file-type" => extension,
|
"file-type" => extension,
|
||||||
"file-url" => url
|
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,6 +47,17 @@ class ArchivesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
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
|
def widget
|
||||||
categories = OrbitHelper.widget_categories
|
categories = OrbitHelper.widget_categories
|
||||||
@categories = []
|
@categories = []
|
||||||
|
|
|
@ -7,6 +7,7 @@ class ArchiveFileMultiple
|
||||||
|
|
||||||
field :file_title, localize: true
|
field :file_title, localize: true
|
||||||
# field :description
|
# field :description
|
||||||
|
field :download_count, type: Integer, default: 0
|
||||||
field :choose_lang, :type => Array, :default => nil
|
field :choose_lang, :type => Array, :default => nil
|
||||||
|
|
||||||
field :should_destroy, :type => Boolean
|
field :should_destroy, :type => Boolean
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
<a class=" icon-remove"></a>
|
<a class=" icon-remove"></a>
|
||||||
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="downloaded_times">Downloaded <b><%= form_file.download_count %></b> time<%= form_file.download_count > 1 ? "s" : "" %>.</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -33,6 +33,12 @@
|
||||||
</td>
|
</td>
|
||||||
<td><%= format_value archive.updated_at rescue nil %></td>
|
<td><%= format_value archive.updated_at rescue nil %></td>
|
||||||
<td><%= User.find(archive.update_user_id).user_name 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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -4,6 +4,7 @@ en:
|
||||||
archive: Archive
|
archive: Archive
|
||||||
all: All
|
all: All
|
||||||
new: New
|
new: New
|
||||||
|
downloaded_times: Downloaded Times
|
||||||
show_lang: Language
|
show_lang: Language
|
||||||
download: Download
|
download: Download
|
||||||
archive: Archive
|
archive: Archive
|
||||||
|
|
|
@ -5,6 +5,7 @@ zh_tw:
|
||||||
download: 檔案下載
|
download: 檔案下載
|
||||||
archive: 檔案室
|
archive: 檔案室
|
||||||
Title: 標題
|
Title: 標題
|
||||||
|
downloaded_times: 下載次數
|
||||||
Files: 檔案
|
Files: 檔案
|
||||||
Category: 類別
|
Category: 類別
|
||||||
frontend:
|
frontend:
|
||||||
|
|
|
@ -6,6 +6,7 @@ locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_l
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :archive_files
|
resources :archive_files
|
||||||
end
|
end
|
||||||
|
get "/xhr/archive/download" => "archives#download_file"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue