Skip to content

Commit

Permalink
Style Download CSV files modal
Browse files Browse the repository at this point in the history
See #2350
  • Loading branch information
matiasgarciaisaia committed Nov 12, 2024
1 parent 359e5c1 commit a18380a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
26 changes: 24 additions & 2 deletions assets/css/_card-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,22 @@
display: flex;
align-items: center;
.switch {
display: inline-block;
vertical-align: middle;
display: flex;
align-items: center;
gap: 0.5rem;
label {
display: flex;
align-items: center;
}
.lever {
margin-left: 0;
}
.label {
@extend .grey-text;
font-size: 1rem;
margin-right: 0.5rem;
display: flex;
white-space: nowrap;
}
}
.link {
Expand All @@ -144,6 +151,7 @@
vertical-align: middle;
width: 98%;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
}
.buttons {
Expand Down Expand Up @@ -171,6 +179,20 @@
.btn-icon-grey {
margin-left: initial;
}

.file-generation {
display: flex;
align-items: center;
gap: 0.5rem;
}

a {
display: inline-flex;
}

.material-icons {
display: inline-flex;
}
}
div.link {
@extend .grey-text;
Expand Down
7 changes: 4 additions & 3 deletions assets/js/components/respondents/RespondentIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,25 +484,26 @@ class RespondentIndex extends Component<Props, State> {

const fileExists = !!fileStatus?.created_at

const downloadButtonTooltip = fileExists ? t("Download file") : t("File not yet generated")
const downloadButtonClass = fileExists ? "black-text" : "grey-text"
const downloadButtonOnClick = fileExists ? item.onDownload : null
const createdAtLabel = fileExists ? <TimeAgo date={(fileStatus?.created_at || 0) * 1000} formatter={this.timeFormatter} /> : null

const fileCreating = !!fileStatus?.creating
const generateButtonClass = fileCreating ? "btn-icon-grey" : "black-text"
const generateButtonClass = fileCreating ? "grey-text" : "black-text"
const generateButtonOnClick = fileCreating ? null : item.onGenerate
const generatingFileLabel = fileCreating ? "Generating..." : ""

// TODO: we could avoid generating the whole section for files that are not the current one
const downloadButton = !currentFile ? null : (
<div className="file-download">
<Tooltip text={t("Download file")}>
<Tooltip text={downloadButtonTooltip}>
<a className={downloadButtonClass} onClick={downloadButtonOnClick}>
<i className="material-icons">get_app</i>
</a>
</Tooltip>
<span className="">{t("Download last generated file")}</span>
<span className="grey-text">
<span className="grey-text file-generation">
{ createdAtLabel }
{ generatingFileLabel }
<Tooltip text={t("Regenerate file")}>
Expand Down
15 changes: 7 additions & 8 deletions lib/ask_web/controllers/respondent_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,11 @@ defmodule AskWeb.RespondentController do
render(conn, "status.json", status: status)
end

defp file_redirection(conn, survey, file_type) do
defp serve_file(conn, survey, file_type) do
file_url = SurveyResults.file_path(survey, file_type)

render(conn, "file-redirect.json",
file_url: "/#{file_url}" # TODO: there may be better ways of avoiding relative URLs
)
# FIME: /priv/static is probably temporary
send_file(conn, 200, "./priv/static/" <> file_url)
end

def results_csv(conn, %{"project_id" => project_id, "survey_id" => survey_id} = params) do
Expand All @@ -765,7 +764,7 @@ defmodule AskWeb.RespondentController do

ActivityLog.download(project, conn, survey, "survey_results") |> Repo.insert()

file_redirection(conn, survey, {:respondents_results, filter})
serve_file(conn, survey, {:respondents_results, filter})
end

def generate_results(conn, %{"project_id" => project_id, "survey_id" => survey_id} = params) do
Expand Down Expand Up @@ -822,7 +821,7 @@ defmodule AskWeb.RespondentController do

ActivityLog.download(project, conn, survey, "disposition_history") |> Repo.insert()

file_redirection(conn, survey, :disposition_history)
serve_file(conn, survey, :disposition_history)
end

def incentives(conn, %{"project_id" => project_id, "survey_id" => survey_id}) do
Expand All @@ -838,7 +837,7 @@ defmodule AskWeb.RespondentController do

ActivityLog.download(project, conn, survey, "incentives") |> Repo.insert()

file_redirection(conn, survey, :incentives)
serve_file(conn, survey, :incentives)
end

def generate_incentives(conn, %{"project_id" => project_id, "survey_id" => survey_id}) do
Expand All @@ -864,7 +863,7 @@ defmodule AskWeb.RespondentController do

ActivityLog.download(project, conn, survey, "interactions") |> Repo.insert()

file_redirection(conn, survey, :interactions)
serve_file(conn, survey, :interactions)
end

def generate_interactions(conn, %{"project_id" => project_id, "survey_id" => survey_id}) do
Expand Down
1 change: 1 addition & 0 deletions locales/template/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"Fallback delay": "",
"Fallback delay is invalid": "",
"Fallback mode": "",
"File not yet generated": "",
"Filter using the following format": "",
"Filtered survey results": "",
"Flag": "",
Expand Down

0 comments on commit a18380a

Please sign in to comment.