diff --git a/app/controllers/admin/archive_files_controller.rb b/app/controllers/admin/archive_files_controller.rb index 1bf12bb..d193043 100644 --- a/app/controllers/admin/archive_files_controller.rb +++ b/app/controllers/admin/archive_files_controller.rb @@ -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) diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index a67fd25..10b8ae7 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -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 = [] diff --git a/app/models/archive_file_multiple.rb b/app/models/archive_file_multiple.rb index b5993d9..a5d81a5 100644 --- a/app/models/archive_file_multiple.rb +++ b/app/models/archive_file_multiple.rb @@ -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 diff --git a/app/views/admin/archive_files/_form_file.html.erb b/app/views/admin/archive_files/_form_file.html.erb index 0d020f9..82ae0ee 100644 --- a/app/views/admin/archive_files/_form_file.html.erb +++ b/app/views/admin/archive_files/_form_file.html.erb @@ -60,6 +60,7 @@ <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + Downloaded <%= form_file.download_count %> time<%= form_file.download_count > 1 ? "s" : "" %>. <% end %> diff --git a/app/views/admin/archive_files/_index.html.erb b/app/views/admin/archive_files/_index.html.erb index 08d50f9..a06d5b9 100644 --- a/app/views/admin/archive_files/_index.html.erb +++ b/app/views/admin/archive_files/_index.html.erb @@ -33,6 +33,12 @@