diff --git a/content.js b/content.js index ae5d5d9..92ef34d 100644 --- a/content.js +++ b/content.js @@ -243,6 +243,43 @@ function escapeCsvValue(value) { return `"${stringValue.replace(/"/g, "\"\"")}"` } +const API_FIELD_MAP = { + "last_name": "Nachname", + "first_name": "Vorname", + "email": "E-Mail Adresse", + "telephone_number": "Telefonnummer", + "gender": "Geschlecht", + "academic_title_before_name": "Akademischer Grad vorangestellt", + "academic_title_after_name": "Akademischer Grad nachgestellt", + "professional_title": "Berufstitel", + "date_of_birth": "Geburtsdatum", + "highest_educational_degree": "Höchster Bildungsabschluss", + "highest_academic_education": "Höchster akademischer Abschluss", + "final_year_studies": "Letztes Studienjahr (Master oder PhD)", + "first_language": "Erstsprache", + "nationality_arr": "Staatsangehörigkeit", + "relevant_links": "Relevante Links", + "orcid_id": "ORCID ID", + "google_scholar_profile": "Google Scholar Profil", + "how_did_you_become_aware_arr": "Wie sind Sie auf die Stelle aufmerksam geworden?", +} + +function createApplicantsXlsx(applicantDetailsList) { + const sorted_mapped = applicantDetailsList.sort((appli1, appli2) => { + appli1.last_name.localeCompare(appli2.last_name) + }).map((appli) => { + const mapped = {} + Object.keys(API_FIELD_MAP).forEach(key => { + mapped[API_FIELD_MAP[key]] = appli[key] + }) + return mapped + }) + const sheet = XLSX.utils.json_to_sheet(sorted_mapped) + const book = XLSX.utils.book_new() + XLSX.utils.book_append_sheet(book, sheet, "Applications") + return new Uint8Array(XLSX.toXLSXBlob(book).buffer) +} + function createApplicantsCsv(applicantDetailsList) { const rows = [ CSV_FIELDS.join(",") @@ -523,6 +560,9 @@ function rip(event) { console.log("Creating applications.csv") archiveEntries["applications.csv"] = createApplicantsCsv(successfulApplicants) + console.log("Creating applications.xlsx") + archiveEntries["applications.xlsx"] = createApplicantsXlsx(successfulApplicants) + console.log("Creating index.html") archiveEntries["viewer.html"] = viewerHtmlSource diff --git a/lib/xlsx.js b/lib/xlsx.js index 919ab7b..1d69f29 100644 --- a/lib/xlsx.js +++ b/lib/xlsx.js @@ -27206,6 +27206,7 @@ function write_zip_denouement(z, o) { case "binary": oopts.type = "string"; break; case "string": throw new Error("'string' output type invalid for '" + o.bookType + "' files"); case "buffer": + case "blob": case "file": oopts.type = ftype; break; default: throw new Error("Unrecognized type " + o.type); } @@ -27219,6 +27220,7 @@ function write_zip_denouement(z, o) { /*jshint -W083 */ if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef /*jshint +W083 */ + if(o.type === "blob") return out if(o.type === "file") return write_dl(o.file, out); return o.type == "string" ? utf8read(out) : out; } @@ -27345,6 +27347,13 @@ function resolve_book_type(o) { o.bookType = _BT[o.bookType] || o.bookType; } +function toXLSXBlob(wb, filename, opts) { + var o = opts||{}; + o.type = 'blob'; + o.bookType = 'xlsx'; + return writeSync(wb, o); +} + function writeFileSync(wb, filename, opts) { var o = opts||{}; o.type = 'file'; o.file = filename; @@ -28078,6 +28087,7 @@ XLSX.readFile = readFileSync; //readFile XLSX.readFileSync = readFileSync; XLSX.write = writeSync; XLSX.writeFile = writeFileSync; +XLSX.toXLSXBlob = toXLSXBlob; XLSX.writeFileSync = writeFileSync; XLSX.writeFileAsync = writeFileAsync; XLSX.utils = utils; diff --git a/manifest.json b/manifest.json index 0eb4e42..b0ad33f 100644 --- a/manifest.json +++ b/manifest.json @@ -25,6 +25,7 @@ ], "js": [ "lib/fflate.min.js", + "lib/xlsx.js", "content.js" ], "css": [