Add download module zip feature.

This commit is contained in:
BoHung Chiu 2021-03-04 17:38:15 +08:00
parent 8ec4b19c28
commit 8dd6ba7468
5 changed files with 20 additions and 0 deletions

View File

@ -11,6 +11,22 @@ class Admin::PersonalPluginFieldsController < OrbitAdminController
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@personal_plugin_field = PersonalPluginField.new @personal_plugin_field = PersonalPluginField.new
end end
def download
zip_path = "tmp/"
FileUtils.mkdir_p(zip_path) if !Dir.exist?(zip_path)
personal_plugin_field = PersonalPluginField.find(params[:personal_plugin_field_id]) rescue nil
if personal_plugin_field
zip_file_path = zip_path + "#{personal_plugin_field.module_name}.zip"
zip_file= ZipFileGenerator.new(zip_path + personal_plugin_field.module_name ,zip_file_path)
begin
zip_file.write
rescue
File.delete(zip_path + "#{personal_plugin_field.module_name}.zip")
zip_file.write
end
send_file(zip_file_path)
end
end
def copy def copy
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
attributes = PersonalPluginField.find(params[:personal_plugin_field_id]).attributes rescue {} attributes = PersonalPluginField.find(params[:personal_plugin_field_id]).attributes rescue {}

View File

@ -6,6 +6,7 @@
<%= link_to thead_field('fields_display_setting') ,admin_personal_plugin_field_fields_setting_path(personal_plugin_field.id),:class=> "btn btn-primary" %> <%= link_to thead_field('fields_display_setting') ,admin_personal_plugin_field_fields_setting_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
<%= link_to thead_field(:copy) ,admin_personal_plugin_field_copy_path(personal_plugin_field.id),:class=> "btn btn-primary" %> <%= link_to thead_field(:copy) ,admin_personal_plugin_field_copy_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
<button class="generate_plugin btn btn-primary" type="button" data-url="<%= admin_personal_plugin_field_generate_plugin_path(personal_plugin_field.id) %>"><%= thead_field("generate_plugin") %></button> <button class="generate_plugin btn btn-primary" type="button" data-url="<%= admin_personal_plugin_field_generate_plugin_path(personal_plugin_field.id) %>"><%= thead_field("generate_plugin") %></button>
<%= link_to thead_field(:download) ,admin_personal_plugin_field_download_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
<a data-confirm="Are you sure?" data-method="delete" href="<%=admin_personal_plugin_field_path(personal_plugin_field.id) %>" rel="nofollow" class="delete btn btn-primary"><%= t(:delete_) %></a> <a data-confirm="Are you sure?" data-method="delete" href="<%=admin_personal_plugin_field_path(personal_plugin_field.id) %>" rel="nofollow" class="delete btn btn-primary"><%= t(:delete_) %></a>
</td> </td>
</tr> </tr>

View File

@ -4,6 +4,7 @@ en:
restful_actions: restful_actions:
fields_setting: Fields Setting fields_setting: Fields Setting
personal_plugin_generator: personal_plugin_generator:
download: Download
author_translation_name: Author translation name author_translation_name: Author translation name
personal_plugin_generator: Personal Plugin Generate personal_plugin_generator: Personal Plugin Generate
personal_plugin_name: Personal Plugin Name Translation personal_plugin_name: Personal Plugin Name Translation

View File

@ -4,6 +4,7 @@ zh_tw:
restful_actions: restful_actions:
fields_setting: 欄位設定 fields_setting: 欄位設定
personal_plugin_generator: personal_plugin_generator:
download: 下載
author_translation_name: 著作人翻譯名稱 author_translation_name: 著作人翻譯名稱
personal_plugin_generator: 個人外掛生成 personal_plugin_generator: 個人外掛生成
personal_plugin_name: 個人外掛翻譯名稱 personal_plugin_name: 個人外掛翻譯名稱

View File

@ -8,6 +8,7 @@ Rails.application.routes.draw do
patch 'update_fields_setting' , to: 'personal_plugin_fields#update_fields_setting' patch 'update_fields_setting' , to: 'personal_plugin_fields#update_fields_setting'
get 'generate_plugin' , to: 'personal_plugin_fields#generate_plugin' get 'generate_plugin' , to: 'personal_plugin_fields#generate_plugin'
get 'copy' , to: 'personal_plugin_fields#copy' get 'copy' , to: 'personal_plugin_fields#copy'
get 'download' , to: 'personal_plugin_fields#download'
end end
resource :personal_plugin_field do resource :personal_plugin_field do
post 'check_plugin_exist' ,to: 'personal_plugin_fields#check_plugin_exist' post 'check_plugin_exist' ,to: 'personal_plugin_fields#check_plugin_exist'