Skip to content

Commit

Permalink
Merge pull request #107 from NIAEFEUP/fix/csv-format
Browse files Browse the repository at this point in the history
CSV format matching SIGARRA's requirements
  • Loading branch information
Jumaruba authored Sep 22, 2022
2 parents 4c580cf + d56a4a3 commit c6c7a60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/components/planner/MoreActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,29 @@ const MoreActionsButton = ({ schedule, showGridHook, multipleOptionsHook }: Prop
}

const exportCSV = () => {
const header = ['Index']
const header = ['Ano', 'Nome', 'Sigla']
const lines = []
const columns = []

for (let i = 0; i < multipleOptions.options.length; i++) {
if (i === 0) for (let j = 0; j < schedule.length; j++) header.push(schedule[j].course.info.acronym)
const line = [`${i + 1}`]
if (i === 0) for (let j = 0; j < schedule.length; j++) header.push(`Option ${j}`)
const scheduleOption = multipleOptions.options[i]
for (let j = 0; j < scheduleOption.length; j++) line.push(scheduleOption[j].option?.class_name || '')
lines.push(line.join(';'))
const column = []
for (let j = 0; j < scheduleOption.length; j++) column.push(scheduleOption[j].option?.class_name || '')
}

const csv = [header.join(';'), lines.flat().join('\n')].join('\n')
for (let i = 0; i < columns[0].length; i++) {
const column = columns[i]
const info = multipleOptions.options[0][i].course.info
const line = [info.course_year, info.name, info.acronym]

for (let j = 0; j < column.length; j++) {
line.push(column[j])
}
lines.push(line.join(','))
}

const csv = [header.join(','), lines.flat().join('\n')].join('\n')
const blob = new Blob([csv], { type: 'text/csv' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
Expand Down
17 changes: 17 additions & 0 deletions src/config/local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"pathPrefix": "/tts/",
"paths": {
"about": "about",
"profile": "profile",
"planner": "planner",
"exchange": "exchange",
"faqs": "faqs",
"notfound": "*",
"home": "home"
},
"api": {
"port": 8000,
"host": "localhost",
"year": 2021
}
}

0 comments on commit c6c7a60

Please sign in to comment.