Add contestant export feature
This commit is contained in:
@@ -111,6 +111,19 @@ class ContestantsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def export
|
||||||
|
authorize @contest
|
||||||
|
|
||||||
|
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.csv do
|
||||||
|
response.headers["Content-Type"] = "text/csv"
|
||||||
|
response.headers["Content-Disposition"] = "attachment; filename=export.csv"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_contest
|
def set_contest
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ class ContestPolicy < ApplicationPolicy
|
|||||||
record.user.id == user.id || user.admin?
|
record.user.id == user.id || user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def export?
|
||||||
|
record.user.id == user.id || user.admin?
|
||||||
|
end
|
||||||
|
|
||||||
def scoreboard?
|
def scoreboard?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
4
app/views/contestants/export.csv.slim
Normal file
4
app/views/contestants/export.csv.slim
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
= CSV.generate_line [t("helpers.rank"), t("activerecord.attributes.contestant.name"), t("activerecord.attributes.contestant.display_time"), t("activerecord.attributes.contestant.completions")]
|
||||||
|
|
||||||
|
- @contestants.each_with_index do |contestant, index|
|
||||||
|
= CSV.generate_line([index + 1, contestant.name, contestant.display_time, contestant.completions.length])
|
||||||
@@ -40,8 +40,10 @@ javascript:
|
|||||||
= t("contestants.plural").capitalize
|
= t("contestants.plural").capitalize
|
||||||
a.ms-3.btn.btn-sm.btn-primary href=new_contest_contestant_path(@contest) style="margin-top: -3px"
|
a.ms-3.btn.btn-sm.btn-primary href=new_contest_contestant_path(@contest) style="margin-top: -3px"
|
||||||
| + #{t("helpers.buttons.add")}
|
| + #{t("helpers.buttons.add")}
|
||||||
a.ms-2.btn-sm.btn.btn-primary href=contest_import_path(@contest) style="margin-top: -3px"
|
a.ms-2.btn.btn-sm.btn.btn-primary href=contest_import_path(@contest) style="margin-top: -3px"
|
||||||
| #{t("helpers.buttons.import")}
|
| #{t("helpers.buttons.import")}
|
||||||
|
a.ms-2.btn.btn-sm.btn.btn-primary href="/contests/#{@contest.id}/export.csv" style="margin-top: -3px"
|
||||||
|
| #{t("helpers.buttons.export")}
|
||||||
- if @contest.categories.size > 0
|
- if @contest.categories.size > 0
|
||||||
.row
|
.row
|
||||||
.col
|
.col
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ en:
|
|||||||
create: "Create"
|
create: "Create"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
edit: "Edit"
|
edit: "Edit"
|
||||||
|
export: Export
|
||||||
import: CSV Import
|
import: CSV Import
|
||||||
open: Open
|
open: Open
|
||||||
refresh: Refresh
|
refresh: Refresh
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ fr:
|
|||||||
create: "Créer"
|
create: "Créer"
|
||||||
delete: "Supprimer"
|
delete: "Supprimer"
|
||||||
edit: "Modifier"
|
edit: "Modifier"
|
||||||
|
export: Exporter
|
||||||
import: Importer un CSV
|
import: Importer un CSV
|
||||||
open: Détails
|
open: Détails
|
||||||
refresh: Rafraîchir
|
refresh: Rafraîchir
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ Rails.application.routes.draw do
|
|||||||
post "import", to: "contestants#upload_csv"
|
post "import", to: "contestants#upload_csv"
|
||||||
get "import/:id", to: "contestants#convert_csv"
|
get "import/:id", to: "contestants#convert_csv"
|
||||||
post "import/:id", to: "contestants#finalize_import"
|
post "import/:id", to: "contestants#finalize_import"
|
||||||
|
get "export", to: "contestants#export"
|
||||||
end
|
end
|
||||||
resources :passwords, param: :token
|
resources :passwords, param: :token
|
||||||
resource :session
|
resource :session
|
||||||
|
|||||||
Reference in New Issue
Block a user