From 802ac1aee80ffc428f75953de468eb3c204ba3bb Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 27 Jul 2021 15:18:45 +0200 Subject: [PATCH] Add CSV import for supporters Supporters can now be imported via csv this was forgotten before --- .../motions/models/import-create-motion.ts | 29 ++++++++ .../motion-import-list.component.html | 30 ++++++-- .../services/motion-csv-export.service.ts | 17 ++++- .../motions/services/motion-import.service.ts | 72 +++++++++++++------ client/src/styles.scss | 2 +- 5 files changed, 118 insertions(+), 32 deletions(-) diff --git a/client/src/app/site/motions/models/import-create-motion.ts b/client/src/app/site/motions/models/import-create-motion.ts index 78a167d78..336128a3f 100644 --- a/client/src/app/site/motions/models/import-create-motion.ts +++ b/client/src/app/site/motions/models/import-create-motion.ts @@ -32,6 +32,11 @@ export class ImportCreateMotion extends CreateMotion { */ public csvSubmitters: CsvMapping[]; + /** + * Mapping for new/existing supporters. + */ + public csvSupporters: CsvMapping[]; + /** * Mapping for new/existing tags. */ @@ -115,6 +120,30 @@ export class ImportCreateMotion extends CreateMotion { return open; } + public solveSupporters(supporters: CsvMapping[]): number { + let open = 0; + const ids: number[] = []; + this.csvSupporters.forEach(csvSupporter => { + if (csvSupporter.id) { + ids.push(csvSupporter.id); + return; + } + if (!supporters.length) { + open += 1; + return; + } + const mapped = supporters.find(newSupporter => newSupporter.name === csvSupporter.name); + if (mapped) { + csvSupporter.id = mapped.id; + ids.push(mapped.id); + } else { + open += 1; + } + }); + this.supporters_id = ids; + return open; + } + /** * Function to iterate over the found tags. * diff --git a/client/src/app/site/motions/modules/motion-import/motion-import-list.component.html b/client/src/app/site/motions/modules/motion-import/motion-import-list.component.html index 0b88cc870..843c38424 100644 --- a/client/src/app/site/motions/modules/motion-import/motion-import-list.component.html +++ b/client/src/app/site/motions/modules/motion-import/motion-import-list.component.html @@ -18,8 +18,7 @@
- {{ header | translate }} + {{ header | translate }}