From e9f39fd75e8dd193f54ed77147f44c863c61496f Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Mon, 8 Jul 2024 12:11:17 +0200 Subject: [PATCH] Use lists for the order of the import fields --- .../csv-export-for-backend.service.spec.ts | 6 +-- .../participant-csv-export.service.ts | 13 ++---- .../participant-import-list.component.ts | 6 +-- .../participant-import/definitions/index.ts | 40 +++++++++---------- .../account-import-list.component.ts | 6 +-- .../pages/account-import/definitions/index.ts | 30 +++++++------- .../account-export.service.ts | 10 ++--- 7 files changed, 46 insertions(+), 65 deletions(-) diff --git a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.spec.ts b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.spec.ts index ada121bf9c..af28c94b6e 100644 --- a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.spec.ts +++ b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.spec.ts @@ -113,11 +113,7 @@ describe(`CsvExportForBackendService`, () => { }); it(`test dummy export method with default settings`, () => { - service.dummyCSVExport( - Object.keys({ proper: `Fancy`, tea: `Tea`, strength: `Muscle` }), - toDummyExport, - `dummyAssortmentOfTeas` - ); + service.dummyCSVExport([`proper`, `tea`, `strength`], toDummyExport, `dummyAssortmentOfTeas`); expect(exportService.lastSavedFiles.length).toBe(1); expect(exportService.lastSavedFiles[0]).toEqual({ file: `proper,tea,strength\r\n"1","Earl Grey","5"\r\n,"Herbal tea",`, diff --git a/client/src/app/site/pages/meetings/pages/participants/export/participant-csv-export.service/participant-csv-export.service.ts b/client/src/app/site/pages/meetings/pages/participants/export/participant-csv-export.service/participant-csv-export.service.ts index 6076ef5b08..b3bd1b2b2d 100644 --- a/client/src/app/site/pages/meetings/pages/participants/export/participant-csv-export.service/participant-csv-export.service.ts +++ b/client/src/app/site/pages/meetings/pages/participants/export/participant-csv-export.service/participant-csv-export.service.ts @@ -5,10 +5,7 @@ import { CsvColumnDefinitionProperty, CsvColumnsDefinition } from 'src/app/gatew import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user'; import { MeetingCsvExportForBackendService } from '../../../../services/export/meeting-csv-export-for-backend.service'; -import { - participantColumnsWeight, - participantHeadersAndVerboseNames -} from '../../pages/participant-import/definitions'; +import { participantColumns } from '../../pages/participant-import/definitions'; import { ParticipantExportModule } from '../participant-export.module'; import { participantsExportExample } from '../participants-export-example'; @@ -43,16 +40,12 @@ export class ParticipantCsvExportService { // ] // ]); - public columns = Object.keys(participantHeadersAndVerboseNames).sort( - (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] - ); - public constructor(private csvExport: MeetingCsvExportForBackendService, private translate: TranslateService) {} public export(participants: ViewUser[]): void { this.csvExport.export( participants, - this.columns.map(key => { + participantColumns.map(key => { return { property: key } as CsvColumnDefinitionProperty; @@ -64,7 +57,7 @@ export class ParticipantCsvExportService { public exportCsvExample(): void { const rows: UserExport[] = participantsExportExample; this.csvExport.dummyCSVExport( - this.columns, + participantColumns, rows, `${this.translate.instant(`participants-example`)}.csv` ); diff --git a/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/components/participant-import-list/participant-import-list.component.ts b/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/components/participant-import-list/participant-import-list.component.ts index 715b2a0431..a52f9a9d51 100644 --- a/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/components/participant-import-list/participant-import-list.component.ts +++ b/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/components/participant-import-list/participant-import-list.component.ts @@ -3,7 +3,7 @@ import { TranslateService } from '@ngx-translate/core'; import { BaseViaBackendImportListMeetingComponent } from 'src/app/site/base/base-via-backend-import-list-meeting.component'; import { ImportListHeaderDefinition } from 'src/app/ui/modules/import-list'; -import { participantColumnsWeight, participantHeadersAndVerboseNames } from '../../definitions'; +import { participantColumns, participantHeadersAndVerboseNames } from '../../definitions'; import { ParticipantImportService } from '../../services'; @Component({ @@ -12,9 +12,7 @@ import { ParticipantImportService } from '../../services'; styleUrls: [`./participant-import-list.component.scss`] }) export class ParticipantImportListComponent extends BaseViaBackendImportListMeetingComponent { - public possibleFields = Object.keys(participantHeadersAndVerboseNames).sort( - (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] - ); + public possibleFields = participantColumns; public columns: ImportListHeaderDefinition[] = this.possibleFields.map(header => ({ property: header, diff --git a/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/definitions/index.ts b/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/definitions/index.ts index 05d09f0bf7..663ee73b74 100644 --- a/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/definitions/index.ts +++ b/client/src/app/site/pages/meetings/pages/participants/pages/participant-import/definitions/index.ts @@ -11,23 +11,23 @@ export const participantHeadersAndVerboseNames: { [key in keyof GeneralUser]?: a comment: `Comment` }; -export const participantColumnsWeight: { [key in keyof GeneralUser]?: any } = { - title: 1, - first_name: 2, - last_name: 3, - email: 4, - member_number: 5, - structure_level: 6, - groups: 7, - number: 8, - vote_weight: 9, - gender: 10, - pronoun: 11, - username: 12, - default_password: 13, - is_active: 14, - is_physical_person: 15, - is_present: 16, - saml_id: 17, - comment: 18 -}; +export const participantColumns: (keyof GeneralUser)[] = [ + `title`, + `first_name`, + `last_name`, + `email`, + `member_number`, + `structure_level`, + `groups`, + `number`, + `vote_weight`, + `gender`, + `pronoun`, + `username`, + `default_password`, + `is_active`, + `is_physical_person`, + `is_present`, + `saml_id`, + `comment` +]; diff --git a/client/src/app/site/pages/organization/pages/accounts/pages/account-import/components/account-import-list/account-import-list.component.ts b/client/src/app/site/pages/organization/pages/accounts/pages/account-import/components/account-import-list/account-import-list.component.ts index 0e7270e2bf..6246b34338 100644 --- a/client/src/app/site/pages/organization/pages/accounts/pages/account-import/components/account-import-list/account-import-list.component.ts +++ b/client/src/app/site/pages/organization/pages/accounts/pages/account-import/components/account-import-list/account-import-list.component.ts @@ -5,7 +5,7 @@ import { BaseViaBackendImportListComponent } from 'src/app/site/base/base-via-ba import { OrganizationSettingsService } from 'src/app/site/pages/organization/services/organization-settings.service'; import { ImportListHeaderDefinition } from 'src/app/ui/modules/import-list'; -import { accountColumnsWeight, accountHeadersAndVerboseNames } from '../../definitions'; +import { accountColumns, accountHeadersAndVerboseNames } from '../../definitions'; import { AccountImportService } from '../../services/account-import.service/account-import.service'; @Component({ @@ -14,9 +14,7 @@ import { AccountImportService } from '../../services/account-import.service/acco styleUrls: [`./account-import-list.component.scss`] }) export class AccountImportListComponent extends BaseViaBackendImportListComponent { - public possibleFields = Object.keys(accountHeadersAndVerboseNames).sort( - (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] - ); + public possibleFields = accountColumns; public columns: ImportListHeaderDefinition[] = this.possibleFields.map(header => ({ property: header, diff --git a/client/src/app/site/pages/organization/pages/accounts/pages/account-import/definitions/index.ts b/client/src/app/site/pages/organization/pages/accounts/pages/account-import/definitions/index.ts index 588b228dcc..5a12b341ce 100644 --- a/client/src/app/site/pages/organization/pages/accounts/pages/account-import/definitions/index.ts +++ b/client/src/app/site/pages/organization/pages/accounts/pages/account-import/definitions/index.ts @@ -7,18 +7,18 @@ export const accountHeadersAndVerboseNames: { [key in keyof User]?: any } = { default_vote_weight: _(`Vote weight`) }; -export const accountColumnsWeight: { [key in keyof User]?: any } = { - title: 1, - first_name: 2, - last_name: 3, - email: 4, - member_number: 5, - default_vote_weight: 6, - gender: 7, - pronoun: 8, - username: 9, - default_password: 10, - is_active: 11, - is_physical_person: 12, - saml_id: 13 -}; +export const accountColumns: (keyof User)[] = [ + `title`, + `first_name`, + `last_name`, + `email`, + `member_number`, + `default_vote_weight`, + `gender`, + `pronoun`, + `username`, + `default_password`, + `is_active`, + `is_physical_person`, + `saml_id` +]; diff --git a/client/src/app/site/pages/organization/pages/accounts/services/account-export.service/account-export.service.ts b/client/src/app/site/pages/organization/pages/accounts/services/account-export.service/account-export.service.ts index c9841b371f..8083938413 100644 --- a/client/src/app/site/pages/organization/pages/accounts/services/account-export.service/account-export.service.ts +++ b/client/src/app/site/pages/organization/pages/accounts/services/account-export.service/account-export.service.ts @@ -5,22 +5,18 @@ import { CsvExportForBackendService } from 'src/app/gateways/export/csv-export.s import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user'; import { AccountCsvExportExample } from '../../export/csv-export-example'; -import { accountColumnsWeight, accountHeadersAndVerboseNames } from '../../pages/account-import/definitions'; +import { accountColumns } from '../../pages/account-import/definitions'; import { AccountExportServiceModule } from '../account-export-service.module'; @Injectable({ providedIn: AccountExportServiceModule }) export class AccountExportService { - public columns = Object.keys(accountHeadersAndVerboseNames).sort( - (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] - ); - public constructor(private csvExportService: CsvExportForBackendService, private translate: TranslateService) {} public downloadCsvImportExample(): void { this.csvExportService.dummyCSVExport( - this.columns, + accountColumns, AccountCsvExportExample, `${this.translate.instant(`account-example`)}.csv` ); @@ -29,7 +25,7 @@ export class AccountExportService { public downloadAccountCsvFile(dataSource: ViewUser[]): void { this.csvExportService.export( dataSource, - this.columns.map(key => ({ + accountColumns.map(key => ({ property: key as keyof ViewUser })), `${this.translate.instant(`Accounts`)}.csv`