From 9266fa577977255b8ca9cd09444e4c77facc8a60 Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 31 May 2024 10:23:28 +0200 Subject: [PATCH 1/8] Reorder the user imports fields --- .../participant-import/definitions/index.ts | 21 ++++++++++++++----- .../pages/account-import/definitions/index.ts | 18 ++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) 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 00b3ce9fd2..be690c27e3 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 @@ -1,12 +1,23 @@ -import { userHeadersAndVerboseNames } from 'src/app/domain/models/users/user.constants'; +import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { GeneralUser } from 'src/app/gateways/repositories/users'; -export const participantHeadersAndVerboseNames: { [key in keyof GeneralUser]?: string } = { - ...userHeadersAndVerboseNames, - is_present: `Is present`, +export const participantHeadersAndVerboseNames: { [key in keyof GeneralUser]?: any } = { + title: _(`Title`), + first_name: _(`Given name`), + last_name: _(`Surname`), + email: _(`Email`), + member_number: _(`Member number`), structure_level: `Structure levels`, + groups: `Groups`, number: `Participant number`, vote_weight: `Vote weight`, - groups: `Groups`, + gender: _(`Gender`), + pronoun: _(`Pronoun`), + username: _(`Username`), + default_password: _(`Initial password`), + is_active: _(`Active`), + is_physical_person: _(`Natural person`), + is_present: `Is present`, + saml_id: _(`SSO identification`), comment: `Comment` }; 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 fa1f9c6a3e..54e86da1d8 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 @@ -1,8 +1,18 @@ import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { User } from 'src/app/domain/models/users/user'; -import { userHeadersAndVerboseNames } from 'src/app/domain/models/users/user.constants'; -export const accountHeadersAndVerboseNames: { [key in keyof User]?: string } = { - ...userHeadersAndVerboseNames, - default_vote_weight: _(`Vote weight`) +export const accountHeadersAndVerboseNames: { [key in keyof User]?: any } = { + title: _(`Title`), + first_name: _(`Given name`), + last_name: _(`Surname`), + email: _(`Email`), + member_number: _(`Member number`), + default_vote_weight: _(`Vote weight`), + pronoun: _(`Pronoun`), + gender: _(`Gender`), + username: _(`Username`), + default_password: _(`Initial password`), + is_active: _(`Active`), + is_physical_person: _(`Natural person`), + saml_id: _(`SSO identification`) }; From 313f634332a3b0130d0c5d6519abe1833a3f95ee Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 31 May 2024 11:50:40 +0200 Subject: [PATCH 2/8] Swap gender and pronoun in account import field list --- .../pages/accounts/pages/account-import/definitions/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 54e86da1d8..dee2e37bee 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 @@ -8,8 +8,8 @@ export const accountHeadersAndVerboseNames: { [key in keyof User]?: any } = { email: _(`Email`), member_number: _(`Member number`), default_vote_weight: _(`Vote weight`), - pronoun: _(`Pronoun`), gender: _(`Gender`), + pronoun: _(`Pronoun`), username: _(`Username`), default_password: _(`Initial password`), is_active: _(`Active`), From 788065d339366c651ed4d4e7d881069f159f2f2d Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Thu, 4 Jul 2024 14:22:39 +0200 Subject: [PATCH 3/8] Remove surplus user.constant.ts --- .../app/domain/models/users/user.constants.ts | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 client/src/app/domain/models/users/user.constants.ts diff --git a/client/src/app/domain/models/users/user.constants.ts b/client/src/app/domain/models/users/user.constants.ts deleted file mode 100644 index dca1c1d2ee..0000000000 --- a/client/src/app/domain/models/users/user.constants.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; - -import { User } from './user'; - -export const userHeadersAndVerboseNames: { [key in keyof User]?: any } = { - title: _(`Title`), - first_name: _(`Given name`), - last_name: _(`Surname`), - email: _(`Email`), - pronoun: _(`Pronoun`), - gender: _(`Gender`), - username: _(`Username`), - default_password: _(`Initial password`), - is_active: _(`Active`), - is_physical_person: _(`Natural person`), - saml_id: _(`SSO identification`), - member_number: _(`Member number`) -}; From ccb22c48b57bde9375ad4a30fbe7f84b45708f21 Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 5 Jul 2024 12:19:11 +0200 Subject: [PATCH 4/8] Use other way to order the account and participant import fields --- .../app/domain/models/users/user.constants.ts | 18 ++++++++++ .../csv-export-for-backend.service.ts | 9 ++--- .../topic-export.service.ts | 2 +- .../participant-csv-export.service.ts | 21 +++++++---- .../participant-import-list.component.ts | 18 ++++++---- .../participant-import/definitions/index.ts | 36 ++++++++++++------- .../account-import-list.component.ts | 20 ++++++----- .../pages/account-import/definitions/index.ts | 32 ++++++++++------- .../account-export.service.ts | 14 +++++--- .../committee-import.service.ts | 2 +- 10 files changed, 113 insertions(+), 59 deletions(-) create mode 100644 client/src/app/domain/models/users/user.constants.ts diff --git a/client/src/app/domain/models/users/user.constants.ts b/client/src/app/domain/models/users/user.constants.ts new file mode 100644 index 0000000000..1a9f8af567 --- /dev/null +++ b/client/src/app/domain/models/users/user.constants.ts @@ -0,0 +1,18 @@ +import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; + +import { User } from './user'; + +export const userHeadersAndVerboseNames: { [key in keyof User]?: any } = { + title: _(`Title`), + first_name: _(`Given name`), + last_name: _(`Surname`), + email: _(`Email`), + member_number: _(`Member number`), + pronoun: _(`Pronoun`), + gender: _(`Gender`), + username: _(`Username`), + default_password: _(`Initial password`), + is_active: _(`Active`), + is_physical_person: _(`Natural person`), + saml_id: _(`SSO identification`) +}; diff --git a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts index ccb5189ef0..3b5b6a8c7e 100644 --- a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts +++ b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts @@ -101,14 +101,15 @@ export class CsvExportForBackendService { } } - public dummyCSVExport(headerAndVerboseNames: { [key in keyof I]: any }, rows: I[], filename: string): void { + public dummyCSVExport(headers: (keyof I)[], rows: I[], filename: string): void { const separator = DEFAULT_COLUMN_SEPARATOR; const encoding: `utf-8` | `iso-8859-15` = DEFAULT_ENCODING as any; - const headerRow = [Object.keys(headerAndVerboseNames).join(separator)]; + const headerRow = [headers.join(separator)]; + const content = rows.map(row => - Object.keys(headerAndVerboseNames) + headers .map(key => { - let value = row[key as keyof I] || ``; + let value = row[key] || ``; if (typeof value === `number`) { value = value.toString(10); } else if (typeof value === `boolean`) { diff --git a/client/src/app/site/pages/meetings/pages/agenda/modules/topics/pages/topic-import/services/topic-export.service/topic-export.service.ts b/client/src/app/site/pages/meetings/pages/agenda/modules/topics/pages/topic-import/services/topic-export.service/topic-export.service.ts index 32fe059035..5d198c0c6a 100644 --- a/client/src/app/site/pages/meetings/pages/agenda/modules/topics/pages/topic-import/services/topic-export.service/topic-export.service.ts +++ b/client/src/app/site/pages/meetings/pages/agenda/modules/topics/pages/topic-import/services/topic-export.service/topic-export.service.ts @@ -27,7 +27,7 @@ export class TopicExportService { ]; this.csvExportService.dummyCSVExport( - topicHeadersAndVerboseNames, + Object.keys(topicHeadersAndVerboseNames), rows, `${this.translate.instant(`Agenda`)}-${this.translate.instant(`example`)}.csv` ); 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 553df8fcb3..44766f44b7 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,7 +5,10 @@ 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 { participantHeadersAndVerboseNames } from '../../pages/participant-import/definitions'; +import { + participantColumnsWeight, + participantHeadersAndVerboseNames +} from '../../pages/participant-import/definitions'; import { ParticipantExportModule } from '../participant-export.module'; import { participantsExportExample } from '../participants-export-example'; @@ -45,11 +48,13 @@ export class ParticipantCsvExportService { public export(participants: ViewUser[]): void { this.csvExport.export( participants, - Object.keys(participantHeadersAndVerboseNames).map(key => { - return { - property: key - } as CsvColumnDefinitionProperty; - }) as CsvColumnsDefinition, + Object.keys(participantHeadersAndVerboseNames) + .sort((a, b) => participantColumnsWeight[a] - participantColumnsWeight[b]) + .map(key => { + return { + property: key + } as CsvColumnDefinitionProperty; + }) as CsvColumnsDefinition, this.translate.instant(`Participants`) + `.csv` ); } @@ -57,7 +62,9 @@ export class ParticipantCsvExportService { public exportCsvExample(): void { const rows: UserExport[] = participantsExportExample; this.csvExport.dummyCSVExport( - participantHeadersAndVerboseNames, + Object.keys(participantHeadersAndVerboseNames).sort( + (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] + ), 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 ee9e210032..e40acae54d 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 { participantHeadersAndVerboseNames } from '../../definitions'; +import { participantColumnsWeight, participantHeadersAndVerboseNames } from '../../definitions'; import { ParticipantImportService } from '../../services'; @Component({ @@ -12,13 +12,17 @@ import { ParticipantImportService } from '../../services'; styleUrls: [`./participant-import-list.component.scss`] }) export class ParticipantImportListComponent extends BaseViaBackendImportListMeetingComponent { - public possibleFields = Object.keys(participantHeadersAndVerboseNames); + public possibleFields = Object.keys(participantHeadersAndVerboseNames).sort( + (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] + ); - public columns: ImportListHeaderDefinition[] = Object.keys(participantHeadersAndVerboseNames).map(header => ({ - property: header, - label: (participantHeadersAndVerboseNames)[header], - isTableColumn: true - })); + public columns: ImportListHeaderDefinition[] = Object.keys(participantHeadersAndVerboseNames) + .sort((a, b) => participantColumnsWeight[a] - participantColumnsWeight[b]) + .map(header => ({ + property: header, + label: (participantHeadersAndVerboseNames)[header], + isTableColumn: true + })); /** * Constructor for list view bases 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 be690c27e3..05d09f0bf7 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 @@ -1,23 +1,33 @@ -import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; +import { userHeadersAndVerboseNames } from 'src/app/domain/models/users/user.constants'; import { GeneralUser } from 'src/app/gateways/repositories/users'; export const participantHeadersAndVerboseNames: { [key in keyof GeneralUser]?: any } = { - title: _(`Title`), - first_name: _(`Given name`), - last_name: _(`Surname`), - email: _(`Email`), - member_number: _(`Member number`), + ...userHeadersAndVerboseNames, structure_level: `Structure levels`, groups: `Groups`, number: `Participant number`, vote_weight: `Vote weight`, - gender: _(`Gender`), - pronoun: _(`Pronoun`), - username: _(`Username`), - default_password: _(`Initial password`), - is_active: _(`Active`), - is_physical_person: _(`Natural person`), is_present: `Is present`, - saml_id: _(`SSO identification`), 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 +}; 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 344179e150..a330bd3ed7 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 { accountHeadersAndVerboseNames } from '../../definitions'; +import { accountColumnsWeight, accountHeadersAndVerboseNames } from '../../definitions'; import { AccountImportService } from '../../services/account-import.service/account-import.service'; @Component({ @@ -14,14 +14,18 @@ import { AccountImportService } from '../../services/account-import.service/acco styleUrls: [`./account-import-list.component.scss`] }) export class AccountImportListComponent extends BaseViaBackendImportListComponent { - public possibleFields = Object.keys(accountHeadersAndVerboseNames); + public possibleFields = Object.keys(accountHeadersAndVerboseNames).sort( + (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] + ); - public columns: ImportListHeaderDefinition[] = Object.keys(accountHeadersAndVerboseNames).map(header => ({ - property: header, - label: (accountHeadersAndVerboseNames)[header], - isTableColumn: true, - customInfo: header === `gender` ? this.getTranslatedGenderInfoObservable() : undefined - })); + public columns: ImportListHeaderDefinition[] = Object.keys(accountHeadersAndVerboseNames) + .sort((a, b) => accountColumnsWeight[a] - accountColumnsWeight[b]) + .map(header => ({ + property: header, + label: (accountHeadersAndVerboseNames)[header], + isTableColumn: true, + customInfo: header === `gender` ? this.getTranslatedGenderInfoObservable() : undefined + })); public constructor( protected override translate: TranslateService, 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 dee2e37bee..588b228dcc 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 @@ -1,18 +1,24 @@ import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { User } from 'src/app/domain/models/users/user'; +import { userHeadersAndVerboseNames } from 'src/app/domain/models/users/user.constants'; export const accountHeadersAndVerboseNames: { [key in keyof User]?: any } = { - title: _(`Title`), - first_name: _(`Given name`), - last_name: _(`Surname`), - email: _(`Email`), - member_number: _(`Member number`), - default_vote_weight: _(`Vote weight`), - gender: _(`Gender`), - pronoun: _(`Pronoun`), - username: _(`Username`), - default_password: _(`Initial password`), - is_active: _(`Active`), - is_physical_person: _(`Natural person`), - saml_id: _(`SSO identification`) + ...userHeadersAndVerboseNames, + 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 }; 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 4c673c2e64..5d220dcec6 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,7 +5,7 @@ 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 { accountHeadersAndVerboseNames } from '../../pages/account-import/definitions'; +import { accountColumnsWeight, accountHeadersAndVerboseNames } from '../../pages/account-import/definitions'; import { AccountExportServiceModule } from '../account-export-service.module'; @Injectable({ @@ -16,7 +16,9 @@ export class AccountExportService { public downloadCsvImportExample(): void { this.csvExportService.dummyCSVExport( - accountHeadersAndVerboseNames, + Object.keys(accountHeadersAndVerboseNames).sort( + (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] + ), AccountCsvExportExample, `${this.translate.instant(`account-example`)}.csv` ); @@ -25,9 +27,11 @@ export class AccountExportService { public downloadAccountCsvFile(dataSource: ViewUser[]): void { this.csvExportService.export( dataSource, - Object.keys(accountHeadersAndVerboseNames).map(key => ({ - property: key as keyof ViewUser - })), + Object.keys(accountHeadersAndVerboseNames) + .map(key => ({ + property: key as keyof ViewUser + })) + .sort((a, b) => accountColumnsWeight[a.property] - accountColumnsWeight[b.property]), `${this.translate.instant(`Accounts`)}.csv` ); } diff --git a/client/src/app/site/pages/organization/pages/committees/pages/committee-import/services/committee-import.service/committee-import.service.ts b/client/src/app/site/pages/organization/pages/committees/pages/committee-import/services/committee-import.service/committee-import.service.ts index 294660e339..cfcd8c84d4 100644 --- a/client/src/app/site/pages/organization/pages/committees/pages/committee-import/services/committee-import.service/committee-import.service.ts +++ b/client/src/app/site/pages/organization/pages/committees/pages/committee-import/services/committee-import.service/committee-import.service.ts @@ -38,7 +38,7 @@ export class CommitteeImportService extends BaseBackendImportService { public downloadCsvExample(): void { this.exporter.dummyCSVExport( - committeeHeadersAndVerboseNames, + Object.keys(committeeHeadersAndVerboseNames), COMMITTEE_CSV_EXPORT_EXAMPLE, `${this.translate.instant(`committee-example`)}.csv` ); From aacdc8ec57db0d980b83c8057cb7cd131b149010 Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 5 Jul 2024 13:15:20 +0200 Subject: [PATCH 5/8] Fix type --- .../export/csv-export.service/csv-export-for-backend.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts index 3b5b6a8c7e..a20a764c6e 100644 --- a/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts +++ b/client/src/app/gateways/export/csv-export.service/csv-export-for-backend.service.ts @@ -101,7 +101,7 @@ export class CsvExportForBackendService { } } - public dummyCSVExport(headers: (keyof I)[], rows: I[], filename: string): void { + public dummyCSVExport(headers: string[], rows: I[], filename: string): void { const separator = DEFAULT_COLUMN_SEPARATOR; const encoding: `utf-8` | `iso-8859-15` = DEFAULT_ENCODING as any; const headerRow = [headers.join(separator)]; From 7921c8f127d3bcbd35ec52e98abb679f1e2cf56e Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 5 Jul 2024 13:45:31 +0200 Subject: [PATCH 6/8] Fix csv export test --- .../csv-export.service/csv-export-for-backend.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c5a9a36b29..ada121bf9c 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 @@ -114,7 +114,7 @@ describe(`CsvExportForBackendService`, () => { it(`test dummy export method with default settings`, () => { service.dummyCSVExport( - { proper: `Fancy`, tea: `Tea`, strength: `Muscle` }, + Object.keys({ proper: `Fancy`, tea: `Tea`, strength: `Muscle` }), toDummyExport, `dummyAssortmentOfTeas` ); From 91dd7f7323a9eb6988cb6d325a3823831bd6c7d3 Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Fri, 5 Jul 2024 14:40:39 +0200 Subject: [PATCH 7/8] Cleanup --- .../participant-csv-export.service.ts | 20 +++++++++---------- .../participant-import-list.component.ts | 12 +++++------ .../account-import-list.component.ts | 14 ++++++------- .../account-export.service.ts | 16 +++++++-------- 4 files changed, 29 insertions(+), 33 deletions(-) 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 44766f44b7..6076ef5b08 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 @@ -43,18 +43,20 @@ 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, - Object.keys(participantHeadersAndVerboseNames) - .sort((a, b) => participantColumnsWeight[a] - participantColumnsWeight[b]) - .map(key => { - return { - property: key - } as CsvColumnDefinitionProperty; - }) as CsvColumnsDefinition, + this.columns.map(key => { + return { + property: key + } as CsvColumnDefinitionProperty; + }) as CsvColumnsDefinition, this.translate.instant(`Participants`) + `.csv` ); } @@ -62,9 +64,7 @@ export class ParticipantCsvExportService { public exportCsvExample(): void { const rows: UserExport[] = participantsExportExample; this.csvExport.dummyCSVExport( - Object.keys(participantHeadersAndVerboseNames).sort( - (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] - ), + this.columns, 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 e40acae54d..715b2a0431 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 @@ -16,13 +16,11 @@ export class ParticipantImportListComponent extends BaseViaBackendImportListMeet (a, b) => participantColumnsWeight[a] - participantColumnsWeight[b] ); - public columns: ImportListHeaderDefinition[] = Object.keys(participantHeadersAndVerboseNames) - .sort((a, b) => participantColumnsWeight[a] - participantColumnsWeight[b]) - .map(header => ({ - property: header, - label: (participantHeadersAndVerboseNames)[header], - isTableColumn: true - })); + public columns: ImportListHeaderDefinition[] = this.possibleFields.map(header => ({ + property: header, + label: (participantHeadersAndVerboseNames)[header], + isTableColumn: true + })); /** * Constructor for list view bases 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 a330bd3ed7..0e7270e2bf 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 @@ -18,14 +18,12 @@ export class AccountImportListComponent extends BaseViaBackendImportListComponen (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] ); - public columns: ImportListHeaderDefinition[] = Object.keys(accountHeadersAndVerboseNames) - .sort((a, b) => accountColumnsWeight[a] - accountColumnsWeight[b]) - .map(header => ({ - property: header, - label: (accountHeadersAndVerboseNames)[header], - isTableColumn: true, - customInfo: header === `gender` ? this.getTranslatedGenderInfoObservable() : undefined - })); + public columns: ImportListHeaderDefinition[] = this.possibleFields.map(header => ({ + property: header, + label: (accountHeadersAndVerboseNames)[header], + isTableColumn: true, + customInfo: header === `gender` ? this.getTranslatedGenderInfoObservable() : undefined + })); public constructor( protected override translate: TranslateService, 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 5d220dcec6..c9841b371f 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 @@ -12,13 +12,15 @@ import { AccountExportServiceModule } from '../account-export-service.module'; 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( - Object.keys(accountHeadersAndVerboseNames).sort( - (a, b) => accountColumnsWeight[a] - accountColumnsWeight[b] - ), + this.columns, AccountCsvExportExample, `${this.translate.instant(`account-example`)}.csv` ); @@ -27,11 +29,9 @@ export class AccountExportService { public downloadAccountCsvFile(dataSource: ViewUser[]): void { this.csvExportService.export( dataSource, - Object.keys(accountHeadersAndVerboseNames) - .map(key => ({ - property: key as keyof ViewUser - })) - .sort((a, b) => accountColumnsWeight[a.property] - accountColumnsWeight[b.property]), + this.columns.map(key => ({ + property: key as keyof ViewUser + })), `${this.translate.instant(`Accounts`)}.csv` ); } From e9f39fd75e8dd193f54ed77147f44c863c61496f Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Mon, 8 Jul 2024 12:11:17 +0200 Subject: [PATCH 8/8] 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`