From 7fca57c5fb4c55b71e7d7ec804fb5a4235206c38 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Thu, 6 Feb 2020 17:53:44 +0800 Subject: [PATCH] add admin :download_excel_format --- .../admin/activities_controller.rb | 8 +++ .../download_excel_format.xlsx.axlsx | 64 +++++++++++++++++++ app/views/admin/activities/index.html.erb | 9 +++ config/routes.rb | 3 + 4 files changed, 84 insertions(+) create mode 100644 app/views/admin/activities/download_excel_format.xlsx.axlsx diff --git a/app/controllers/admin/activities_controller.rb b/app/controllers/admin/activities_controller.rb index 038abe3..739ce94 100644 --- a/app/controllers/admin/activities_controller.rb +++ b/app/controllers/admin/activities_controller.rb @@ -64,6 +64,14 @@ class Admin::ActivitiesController < OrbitMemberController render :layout => false end + def download_excel_format + respond_to do |format| + format.xlsx { + response.headers['Content-Disposition'] = 'attachment; filename="activities_format.xlsx"' + } + end + end + private def set_activity diff --git a/app/views/admin/activities/download_excel_format.xlsx.axlsx b/app/views/admin/activities/download_excel_format.xlsx.axlsx new file mode 100644 index 0000000..2917d85 --- /dev/null +++ b/app/views/admin/activities/download_excel_format.xlsx.axlsx @@ -0,0 +1,64 @@ +# encoding: utf-8 + +wb = xlsx_package.workbook + +wb.add_worksheet(name: "Activities") do |sheet| + + heading = sheet.styles.add_style(:b => true, :locked => true) + example = sheet.styles.add_style(:i => true) + + row = ["user_id"] + row1 = [""] + row2 = [""] + + row << "name" + row1 << "" + row2 << "" + + row << t("personal_activity.activity_name") + " - " + t("en") + row1 << "textfield" + row2 << "" + row << t("personal_activity.activity_name") + " - " + t("zh_tw") + row1 << "textfield" + row2 << "" + + row << t("personal_activity.activity_organizer") + " - " + t("en") + row1 << "textfield" + row2 << "" + row << t("personal_activity.activity_organizer") + " - " + t("zh_tw") + row1 << "textfield" + row2 << "" + + row << t("personal_activity.activity_area") + " - " + t("en") + row1 << "textfield" + row2 << "" + row << t("personal_activity.activity_area") + " - " + t("zh_tw") + row1 << "textfield" + row2 << "" + + row << t("personal_activity.year") + row1 << "number" + row2 << "Example : 2015 or 2014 or 1987" + + row << t("personal_activity.activity_start_date") + row1 << "date" + row2 << "Format: YYYY/MM/DD, Example: 2015/12/10" + + row << t("personal_activity.activity_end_date") + row1 << "date" + row2 << "Format: YYYY/MM/DD, Example: 2015/12/10" + + row << t("personal_activity.note") + row1 << "textarea" + row2 << "" + + sheet.add_row row, :style => heading + sheet.add_row row1 + sheet.add_row row2, :style => example + + User.where(:user_name.ne => "rulingcom").each do |user| + r = [user.user_name] + r << user.name + sheet.add_row r + end +end diff --git a/app/views/admin/activities/index.html.erb b/app/views/admin/activities/index.html.erb index 4cafc3f..975c777 100644 --- a/app/views/admin/activities/index.html.erb +++ b/app/views/admin/activities/index.html.erb @@ -17,6 +17,15 @@
+
+ + +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_activity_path, :class => 'btn btn-primary' %>
diff --git a/config/routes.rb b/config/routes.rb index 88dd939..b5fc50e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,9 @@ Rails.application.routes.draw do locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do namespace :admin do + get 'activities/download_excel_format' => 'activities#download_excel_format' + #post 'books/import_from_excel' => 'books#import_from_excel' + resources :activities do collection do # post 'merge_process' => 'books#merge_process'